#12867·qwen-code

feat(managed-agent): Stage D follow-ups for durable lifecycle, Turns, Actions, durable admission and AgentDefinition

Author: wenshaoCreated Sep 27, 2026Updated Sep 30, 2026
Labelspriority/P2type/feature-requestcategory/corescope/session-managementroadmap/session-managementroadmap/multi-agentneed-discussiondaemon

What would you like to be added?

This covers the rest of Stage D in #12380, after D1–D3 (#12793) delivered the in-repo contract, Session query and event replay: durable lifecycle, Turns, Actions, the java_durable admission profile and AgentDefinition. Sections 1 and 10 of the API contract (pinned at 6891216) list these as Stage D interfaces. I'm claiming them and would start with lifecycle, which depends on nothing else.

Where main is today

  • Contract. The in-repo OpenAPI is at v1.17.0.
    • 9 routes are implemented: Session create, list and get, event query and stream, and their WebShell counterparts.
    • 12 are partial: rename, archive, unarchive, delete, command admission (POST …/events, WebShell turns/submit and turns/cancel), Items, and the four Workspace discovery routes.
    • Of the 35 planned routes, 14 belong to Stage H. The rest are AgentDefinition, Turns, Artifacts, cwd change and operations, Actions, and the close/archive/delete lifecycle routes.
  • Known gaps. The contract test's known-gap list has three lines left, all lifecycle. archive and delete answer synchronously with 200 instead of a durable 202 command operation, and DeletedSession has no schema.
  • Turns. Turns are already stored in managed_agent_turn, and a Session exposes only its active_turn. There is no Turn list or detail route.
  • Actions. The TypeScript Session authority records action.changed events. The Harness requests a tool-call Action through requestToolAction and can park in a durable await_action wait. But nothing outside tests calls resolveAction, so no trusted entry can answer an approval yet. The Hosted tool turns (#12831, #12848) run under a trusted, preapproved profile.
  • Admission. Command admission is partial, and #12380 keeps qwen_confirmed for the existing product entry. The java_durable profile, which returns an operation, an admission stage and a delivery state, is not implemented.
  • AgentDefinition. D2 pins agent_revision from a server setting (QWEN_MANAGED_AGENT_REVISION), stored with each Session at admission. /v1/agents is planned.
  • Roles. Requests carry a trusted tenant and actor. Section 10's role matrix is not implemented: reader, operator and owner; 404 without read access and 403 with read but without operate; an idempotency domain that includes the actor.

Proposed slices

Slice Deliverable Exit check
D4 — durable lifecycle close, archive and delete become separate durable operations that answer 202 with a command operation, on both surfaces. They are queryable through GET operations/{operationId} and WebShell operations/query, and a delete tombstone stays queryable through the retry window. archive accepts only a closed Session. delete never deletes the shared Workspace. close and delete still pass the existing Hooks and resource settlement, so a 202 never claims that tools stopped. The three known-gap lines are gone, and the lifecycle routes move to implemented. A replayed key returns the original operation, and a different payload under the same key conflicts.
D5 — Turns GET turns and GET turns/{turnId} as a read model over managed_agent_turn, with the contract's cursor and limit rules. Both routes are implemented. Cross-tenant reads return 404.
D6 — Actions Public and WebShell Actions list, get and respond, backed by the authority's action.changed records. A response goes through a trusted entry to resolveAction, with the original input or policy revision and option or question IDs. The original arbiter decides between vote_recorded and decided, and responder eligibility is checked. An approval the Harness requested can be answered through either surface, and the Turn continues. A replayed response returns the original result, and a responder without the right gets 403.
D7 — java_durable admission An opt-in admission profile that returns the operation, admission stage and delivery state. Here 202 means "saved, and responsible for delivery". It reuses durable command delivery and original-command reconciliation. qwen_confirmed stays the default for the product entry. Lost responses resolve through the original operation without duplicate side effects. The capability stays off unless enabled.
D8 — AgentDefinition POST /v1/agents and GET/POST /v1/agents/{agentId} with immutable revisions. A Session pins the revision it was admitted with, replacing the server setting. Updating a definition never changes a running Session. A new Session uses the new revision.

The role checks from section 10 go into each slice as its routes land, not into a separate slice. D4 and D5 can start now.

Out of scope

  • Other stages' routes. Artifact listing and download (O3), cwd change (W2), and task, catalog, channel and automation routes (Stage H).
  • Event retention. Pruning, which is what raises D3's replay floor.
  • Approval production. Adding approvals to the Hosted tool profiles. D6 exposes and resolves Actions; it does not decide which tools need them.

Questions before implementation

  1. Approvals on the Hosted path. D6 is only testable end to end once a Hosted profile actually requests an approval. Should that come with the Hosted tool work (E), or with D6?
  2. java_durable scope. Is D7 needed before production enablement, or only for external callers after it? Should its delivery log extend managed_agent_command?
  3. AgentDefinition content. What does a definition hold (model, tool profile, Workspace defaults, published configuration reference)? Is publishing it part of D8, or a separate control-plane slice?
  4. Roles. Where do reader, operator and owner come from: claims from the trusted gateway, or a grant table like the Workspace access table?

Why is this needed?

D1–D3 made the existing Session and event routes match the contract. The remaining public surface is still missing or synchronous:

  • A client cannot close, archive or delete a Session with the durable semantics the contract promises.
  • A client cannot list a Session's Turns or answer an approval.
  • A client cannot rely on 202 meaning that delivery is owned.
  • A client cannot pin the Agent it runs.

#12380 requires lost responses to resolve through original identities, approvals to resolve through the original arbiter, and actor/tenant isolation before production enablement. These slices close those requirements on the public API.

Part of #12380. Follows #12793.

中文说明

希望增加什么?

D1–D3(#12793)交付了仓库内契约、会话查询和事件回放。本 issue 覆盖 #12380 中 D 阶段的剩余部分:持久的生命周期、Turn、Actions、java_durable 准入方式和 AgentDefinition。API 契约(固定在 6891216)第 1 节和第 10 节把这些列为 D 阶段接口。我认领这部分,并打算先做不依赖其他工作的生命周期。

main 上的现状

  • 契约。 仓库内 OpenAPI 为 v1.17.0。
    • 9 条路由为 implemented:会话创建、列表、查询,事件查询与流,以及 WebShell 的对应路由。
    • 12 条为 partial:改名、归档、取消归档、删除、命令准入(POST …/events、WebShell turns/submit 与 turns/cancel)、Items,以及 4 条 Workspace 发现路由。
    • 35 条 planned 中有 14 条属于 H 阶段。其余是 AgentDefinition、Turn、Artifact、cwd 切换与 operation、Actions,以及 close/archive/delete 生命周期路由。
  • 已知差异。 契约测试的已知差异清单只剩三行,全部是生命周期:archive 与 delete 同步返回 200,而不是持久的 202 命令 operation;DeletedSession 没有 schema。
  • Turn。 Turn 已保存在 managed_agent_turn,会话只暴露 active_turn,没有 Turn 列表或详情路由。
  • Actions。 TypeScript 会话 authority 会记录 action.changed 事件。Harness 通过 requestToolAction 请求工具调用类 Action,并可以停在持久的 await_action 等待中。但除测试外没有任何地方调用 resolveAction,所以还没有可信入口能回答审批。Hosted 工具回合(#12831、#12848)运行在受信任、预批准的配置下。
  • 准入。 命令准入为 partial,#12380 规定现有产品入口保留 qwen_confirmed。尚未实现 java_durable 准入方式,即返回 operation、准入阶段与投递状态的那种。
  • AgentDefinition。 D2 用服务端配置(QWEN_MANAGED_AGENT_REVISION)固定 agent_revision,在准入时随会话保存。/v1/agents 仍是 planned。
  • 角色。 请求带有可信的租户与 actor。第 10 节的角色矩阵尚未实现:reader、operator、owner;无读权限返回 404,有读权限但无操作权限返回 403;幂等范围包含 actor。

拆分

切片 交付内容 验收
D4 — 持久生命周期 close、archive、delete 在两个入口都成为各自独立的持久操作,返回 202 与命令 operation。可以通过 GET operations/{operationId} 和 WebShell operations/query 查询,删除后的墓碑在重试期内仍可查。archive 只接受已关闭的会话。delete 绝不删除共享的 Workspace。close 与 delete 仍经过现有的 Hooks 与资源结算,202 不表示工具已停止。 三行已知差异全部消失,生命周期路由改为 implemented。重复使用同一幂等键返回原 operation,同键不同载荷则冲突。
D5 — Turn 基于 managed_agent_turn 的只读模型 GET turns 与 GET turns/{turnId},遵循契约的游标与 limit 规则。 两条路由改为 implemented。跨租户读取返回 404。
D6 — Actions 公开 API 与 WebShell 的 Actions 列表、查询与回答,数据来自 authority 的 action.changed 记录。回答经可信入口调用 resolveAction,携带原始输入或策略版本,以及选项或问题 ID。由原仲裁者决定是 vote_recorded 还是 decided,并校验回答者资格。 Harness 发起的审批可以通过任一入口回答,Turn 随之继续。重复的回答返回原结果,无权的回答者得到 403。
D7 — java_durable 准入 可选开启的准入方式,返回 operation、准入阶段与投递状态,这里的 202 表示"已保存,并负责投递"。它复用持久命令投递与原命令对账。产品入口默认仍用 qwen_confirmed。 响应丢失时通过原 operation 找回结果,不会重复产生副作用。未开启时该能力保持关闭。
D8 — AgentDefinition POST /v1/agents,以及带不可变 revision 的 GET/POST /v1/agents/{agentId}。会话固定准入时的 revision,取代服务端配置。 更新定义不影响运行中的会话,新会话使用新 revision。

第 10 节的角色校验随各切片的路由一起落地,不单独成片。D4 与 D5 现在即可开始。

不在范围内

  • 其他阶段的路由。 Artifact 列表与下载(O3)、cwd 切换(W2),以及 task、catalog、channel、automation 路由(H 阶段)。
  • 事件保留。 事件清理,也就是抬高 D3 回放下限的那部分工作。
  • 审批的产生。 在 Hosted 工具配置中加入审批。D6 负责暴露和解决 Actions,不决定哪些工具需要审批。

实现前需要确认的问题

  1. Hosted 路径上的审批。 只有当某个 Hosted 配置真的发起审批时,D6 才能端到端测试。这部分应随 Hosted 工具工作(E)一起做,还是随 D6 一起做?
  2. java_durable 的范围。 D7 是生产启用前就需要,还是只在之后面向外部调用方?它的投递日志是否沿用 managed_agent_command?
  3. AgentDefinition 的内容。 一个定义包含哪些内容(模型、工具配置、Workspace 默认值、已发布配置的引用)?发布定义属于 D8,还是单独的控制面切片?
  4. 角色从哪里来。 reader、operator、owner 来自可信网关的声明,还是像 Workspace 访问表那样的授权表?

为什么需要?

D1–D3 让现有的会话与事件路由符合契约。剩下的公开接口仍然缺失,或者是同步实现:

  • 客户端无法按契约承诺的持久语义关闭、归档或删除会话。
  • 客户端无法列出会话的 Turn,也无法回答审批。
  • 客户端无法把 202 当作"已负责投递"来依赖。
  • 客户端无法固定所运行的 Agent 版本。

#12380 要求:丢失的响应通过原始身份解决;审批由原仲裁者决定;生产启用前要有 actor 与租户隔离。这些切片在公开 API 上补齐这些要求。

属于 #12380,接续 #12793。