Skip to content

docs(design): target contracts for the Agents and Collaboration owners - #2098

Closed
eric8810 wants to merge 5 commits into
mainfrom
dim/2020-agents-contract
Closed

eric8810 wants to merge 5 commits into
mainfrom
dim/2020-agents-contract

Conversation

@eric8810

@eric8810 eric8810 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #2020 · Refs #2015

Summary

Cross-scope access follows ADR 027: docs/design/contracts/session-access.md and docs/design/appserver/sessions-service.md defer to ADR 027 and this contract, and keep only the input-source, configuration, withdrawal, fixed-prefix, lifecycle, submission-identity and authority facts that outlive sessions.

Target contracts for the Agent directory and Collaboration board, after the §7 review of #2029 (869ef0d7e):

  • Agents.md: one process owner for Agent and Session instances and admission, one face sessions marked on Agents. agentIndex, sessionPermissions and the AgentDirectory/AgentIndex split are deleted. Operations are ids and values (18): agents, create_agent, close_agent, create_session, close_session, delete_session, fork_session, acquire, release, observe, session, sessions, defaults, instance, members, permissionDefaults, quiesce, settle. Agent and member records are Agents' own; the storage engine carries no face for them. sessionPermissions retires: permissionDefaults moves onto sessions.permissionDefaults, and a line's current permission state is Permission's published value read by line id (no proxy operation). Model resolution uses Provider's resolve/preferences. The removed sessions.lookup/pending/stop name their actual owners (idempotent inputQueue.submit, inputQueue.pending, Loop's stop_turn), and those receipts are raised with 所有者扫描:分支轮次链路 #2027. A delete publishes one agent/session-deleted notice for EventHub. The removed sessions.* directory calls are mapped to their targets in Agents.md. No AgentHost, Session or SessionUse crosses.
  • Collaboration.md (process): Team relations, establishment, close, observation, the address space, and the delegation lifetime carried over from the current page.
  • CollaborationSession.md (Session): the agent tool and its texts, the two guide entries, the three session.collaboration.* methods, the approval route, the routing index and the collaborationSession face. Per cross-cutting decision 2 the part writes a line's input and reads a line's published value by id; it holds no Branch, no service::<T>(branch) and folds no line state.
  • CollaborationTimeline.md (branch): one line's delegations, its collaboration/* facts, the approval route of that line, the published delegation value the Session part reads, and settlement on rebuild and close.

sessionPermissions.* follows process-owner-operations.md: the two reads move to sessions.permission*, they are not deleted.

Client-visible changes

None: the client protocol, its error codes and the agent tool's texts and results are unchanged. The removed sessions methods are plugin-facing only.

Requirements raised

Delivery part: comment.

Verification

  • node scripts/adr-check.mjs --base origin/main
  • cargo run --locked -p xtask-check

Merge order

#2029 → #2080 → #2091/#2092/#2093 → #2094 → #2096 → the rest.

Sibling heads this change is aligned with: #2091 f7425d55c, #2092 d96802349, #2093 4209c4464, #2102 3b48e1248, #2103 59a77a3d1. A paragraph that depends on a sibling names that PR; its head is the one above.

@eric8810

Copy link
Copy Markdown
Collaborator Author

评审(head 07d0182b7):需改 2 处;create_session、close_session、delete_session、acquire/release、observe 回调、CollaborationTimeline 按 line id 访问符合。

  1. Agents 的 permission{sessionId, branchId} 是代查。 它返回的是 Permission 发布的状态,例外里也写了是经 Agents 持有的 Session facade 读取。调用方应按 line id 直接读 Permission 的值;permissionDefaults 是 Agents 自己的创建默认,可以保留。
  2. Collaboration 从 sqliteStorage.members 重建。 随 docs(storage): define the session storage owners' target contracts #2091 第 1 条,成员行归 Agents/Collaboration 自己,不经存储引擎的业务操作读取。

@eric8810

Copy link
Copy Markdown
Collaborator Author

已按评审修改,head 538c68842。

  1. 存储引擎不代查。 Agents 契约新增「Agent 与成员记录归 Agents 自己拥有」:create_session 写入、members({leaderSessionId?}) → [{memberSessionId, leaderSessionId, memberAgentId}] 读取,存储引擎只执行事务,不是面。Agents.md 的依赖表删掉 sqliteStorage.agents/save/delete/agentOwner/ownedAgents/unfinishedOwned;Collaboration.md 的重建改读 sessions.members,依赖表删掉 sqliteStorage.members/memberSessions/agentOwner/ownedAgents;交付评论的删除清单与迁移表同步,并写明 sqliteStorage 只剩 storageReport 与离线操作(docs(storage): define the session storage owners' target contracts #2091)。
  2. 删掉 Agents 的 permission{sessionId, branchId}。 一行的当前权限状态改为调用方按 line id 读 Permission 发布的值(line_owner::<Permission>(line)?.published());permissionDefaults 保留为 sessions.permissionDefaults。同步改了需求表、调用方示例、错误表(删掉 branch 种类)、流程表、绑定附录与交付评论的迁移/验收;面仍是 18 个操作(permission 换成了 members)。
  3. 评审判定符合的 create_session、close_session、delete_session、acquire/release、observe 回调、CollaborationTimeline 按 line id 访问未改。
  4. 跨 PR 第 1 条一并落到措辞:(session, line) 访问面按 line id 解析分支组服务,调用方写 line_owner::<T>(line)?.op(..),不设转发门面、不走字符串路由(Collaboration.md、CollaborationSession.md、CollaborationTimeline.md 的 Requirements 与交付评论的 所有者扫描:SessionScope 与 Session 宿主端口 #2025 行)。

向其他所有者的需求更新:#2025 增补「按 line id 读 Permission 的发布值」并要求 typed line_owner;#2027、#2018 两条不变。

@eric8810

Copy link
Copy Markdown
Collaborator Author

已按 ADR 027 修改 Session 访问契约,head 811a3891d。

  1. docs/design/contracts/session-access.md:开头写明被 ADR 027 与 Agents 契约取代;新增「Cross-scope access by id」一节(sessionId / (sessionId, branchId)、实例键解析、只到共享数据面、不含登记点与生命周期服务、对语言运行时与 leaf 可用);删除结构图与 sessions 结构行、§6 的 sessions 行、附录 A.1 方法表、附录 E 的 sessions 绑定、sessions 相关流程与附录 B–D;保留 A.2 输入源约定、A.3 SessionConfig、A.4 撤回、A.5 固定前缀读取,并链到 InputQueue/TimelineTree;§7 改写为 ADR 027 的路径对语言运行时与 leaf 可用、客户端仍经 Rpc 与 Session 授权;规则检查与需求同步。
  2. docs/design/appserver/sessions-service.md:改为短文档,说明被 ADR 027 与 Agents 契约取代;保留仍有效的生命周期、提交身份、安全与已交付需求;新增「旧决定现在在哪」表,逐项指到 Agents/InputQueue/Loop/TimelineTree。
  3. docs/design/plugins/Agents.md:Session access 一节链 ADR 027;需求第 1 条改为「按实例键解析 Session 组与分支组的数据面,不含登记点与生命周期服务,并经 rutis 会话对语言运行时与 leaf 可用」;迁移表为 lookup、idle、defaultBranchId、history、stop 等每个方法写明去向并链到对应契约(stop → docs(design): target contracts for the branch turn chain #2102 Loop,输入/回执/待处理 → docs(design): target contracts for the branch turn chain #2102 InputQueue,历史/默认行 → docs(design): define the line directory owner contract #2092 TimelineTree)。
  4. 交付评论(所有者扫描:Agent 目录与协作 #2020)同步:删除清单加入被删的 sessions 方法与类型(LaunchRequest 起、SessionsService、SessionPermissions 等)以及两份文档中删除的段落;迁移表覆盖 Scheduler、Workflow、EventHub、Collaboration、Rpc 的每个调用点;首行 head 改为 811a3891d。

检查:node scripts/adr-check.mjs --base origin/main 与 cargo run --locked -p xtask-check 通过。

@eric8810

Copy link
Copy Markdown
Collaborator Author

已按 A–G 自查修改,head 6031c48c7。

  • A 绑定附录:错误类型改为 #[serde(tag = "code")] 并列出错误表里的全部 16 个 code;create_agent/create_session/close_session/delete_session/fork_session/settle 用「先受理、再返回 future」的 impl Future + Send + 'static 形状,acquire/release/observe/quiesce 是同步受理;caller: &Ctx 加到全部绑定调用行的操作(observe 的注册、租约、关停);回调改为直接参数 on_end: EndListener,不放进请求结构;observe 回调无错误返回值,不存在硬编码 code;补全请求/回复类型(AgentsReply、AgentRef、LeaseRequest、Observed、MembersReply 等),示例签名与附录一致。
  • B 内部一致:quiesce 的错误表加 closed;delete_session 的流程写明中途失败留下什么、重试如何收尾;cancelled 只出现在可取消的 create_session/create_agent/fork_session(及 Collaboration 的 establish);写入方与 Rule check 的部件数(Agents 一、Collaboration 一、CollaborationSession 一、CollaborationTimeline 一)与 README 的行一致。
  • C 取代关系:四份契约各加 Supersedes 小节;现有文档中只改描述本所有者的段落:service-faces.md §3.3 的 agentIndex 行与 collaborationDirectory.relations 示例、contracts/resource-owner-operations.md §Persistent Agents、plugins/SessionTitle.md §3.4、resource-faces.md 的 sessions.delete 名称。
  • D 客户端:协议、错误码、agent 工具文本与结果不变;Agents.md 单列 Client-visible changes: none。
  • F 引用与合并:给其他 PR 新增文档的链接改用 PR URL(docs(storage): define the session storage owners' target contracts #2091 SessionStore/ManagedWorktrees、docs(design): define the line directory owner contract #2092 TimelineTree、docs(design): target contracts for the branch turn chain #2102 InputQueue/Loop、design(tools): target contracts for the branch tool chain #2100 Permission、design(provider): target contracts for the model and provider owners #2096 Provider、design(settings): owner contracts for Settings and the settings sections #2094 CollaborationModelPolicy、docs(principles): add owners and operations #2029 ADR 027);README 索引行改为三份 Collaboration 文档,By scope 表补 Agents、Collaboration、CollaborationSession、CollaborationTimeline。
  • G 访问面:Session access 与三份 Collaboration 契约改为「按 id 可调用分支组任何数据面,登记点与生命周期服务除外」,不再限制为写输入与读发布值;line_owner::<T>(line)?.op(..) 的写法与 ADR 027 一致。

检查:node scripts/adr-check.mjs --base origin/main、cargo run --locked -p xtask-check 通过。

@eric8810

eric8810 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator Author

已按 A–G 自查修改,head 053b2d4a8。

  • A 绑定附录:错误类型改为 #[serde(tag = "code")] 并列出错误表里的全部 16 个 code;create_agent/create_session/close_session/delete_session/fork_session/settle 用「先受理、再返回 future」的 impl Future + Send + 'static 形状,acquire/release/observe/quiesce 是同步受理;caller: &Ctx 加到全部绑定调用行的操作(observe 的注册、租约、关停);回调改为直接参数 on_end: EndListener,不放进请求结构;observe 回调无错误返回值,不存在硬编码 code;补全请求/回复类型(AgentsReply、AgentRef、LeaseRequest、Observed、MembersReply 等),示例签名与附录一致。
  • B 内部一致:quiesce 的错误表加 closed;delete_session 的流程写明中途失败留下什么、重试如何收尾;cancelled 只出现在可取消的 create_session/create_agent/fork_session(及 Collaboration 的 establish);写入方与 Rule check 的部件数(Agents 一、Collaboration 一、CollaborationSession 一、CollaborationTimeline 一)与 README 的行一致。
  • C 取代关系:四份契约各加 Supersedes 小节;现有文档中只改描述本所有者的段落:service-faces.md §3.3 的 agentIndex 行与 collaborationDirectory.relations 示例、contracts/resource-owner-operations.md §Persistent Agents、plugins/SessionTitle.md §3.4、resource-faces.md 的 sessions.delete 名称。
  • D 客户端:协议、错误码、agent 工具文本与结果不变;Agents.md 单列 Client-visible changes: none。
  • F 引用与合并:给其他 PR 新增文档的链接改用 PR URL(docs(storage): define the session storage owners' target contracts #2091 SessionStore/ManagedWorktrees、docs(design): define the line directory owner contract #2092 TimelineTree、docs(design): target contracts for the branch turn chain #2102 InputQueue/Loop、design(tools): target contracts for the branch tool chain #2100 Permission、design(provider): target contracts for the model and provider owners #2096 Provider、design(settings): owner contracts for Settings and the settings sections #2094 CollaborationModelPolicy、docs(principles): add owners and operations #2029 ADR 027);README 索引行改为三份 Collaboration 文档,By scope 表补 Agents、Collaboration、CollaborationSession、CollaborationTimeline。
  • G 访问面:Session access 与三份 Collaboration 契约改为「按 id 可调用分支组任何数据面,登记点与生命周期服务除外」,不再限制为写输入与读发布值;line_owner::<T>(line)?.op(..) 的写法与 ADR 027 一致。

检查:node scripts/adr-check.mjs --base origin/main、cargo run --locked -p xtask-check 通过。

@yyhhyyyyyy yyhhyyyyyy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: Agents and Collaboration owner contracts

Scope: refs #2020 and #2015. This PR is the Agents and Collaboration part of the design owner series: it adds Agents.md, CollaborationSession.md and CollaborationTimeline.md, rewrites Collaboration.md, and replaces the sessions service with access by id in sessions-service.md and session-access.md.

Verdict: REQUEST_CHANGES

P1

None.

P2

1. The sessions-service rewrite breaks references across the docs tree

Problem: the rewrite keeps only five short sections; all anchors for the removed sections 2, 3, 6.x, 8.x, 11 and 17 are gone. 36 English and 32 Chinese links now target missing anchors, for example docs/design/plugins/Scheduler.md:266,270,290, docs/design/plugins/Workflow.md:276,286,538, docs/design/appserver/idle-unload.md:12,48 and docs/design/appserver/native-storage-format.md:810. This PR also adds two broken links itself: docs/design/plugins/Agents.md:241 (#3-decisions) and docs/design/contracts/session-access.md:62 (#where-the-submission-identity-lives).
Failure scenario: after merge, navigation fails across the docs tree and none of the "where each old decision lives" claims can be followed. The self-check commit did not cover links, and scripts/adr-check.mjs only checks ADR freezes.
Fix: keep the old headings as anchor stubs, or update every inbound link. Add a docs link check to the repository scripts.

2. The CONFLICTING merge drops a main-side contract

Problem: origin/main added a normative session.attach.expectedConfig paragraph to docs/design/contracts/session-access.md after the merge base, and this PR deletes the section that holds it. git merge-tree origin/main HEAD reports docs/design/contracts/session-access.md as the only conflict.
Failure scenario: resolving the conflict by taking this side silently removes the session_config_mismatch and -32602 contract added on main.
Fix: move that paragraph to the owner that keeps attach expectations (for example session-boundary.md or cold-attach-profile.md) before deleting the section, then re-run the merge.

3. Lease lifetime is contradictory

Problem: docs/design/appserver/sessions-service.md:8 says a lease "is held only while a call runs", while docs/design/contracts/session-access.md:13 and the acquire/release rows in Agents.md keep a lease on the caller's row across calls until release or row unload.
Failure scenario: a caller that follows sessions-service.md drops its pin between calls; idle unload can then end the generation and the next call addresses another instance.
Fix: state the row-owned lease rule once, citing ADR 027 D5.

4. ADR 027 decision numbers are shifted

Problem: in ADR 027 (#2029), D2 is runtime routing, D3 is the data-faces-only rule (registration and lifecycle excluded, language runtimes, Rpc for clients), D4 is "call by id is not a dependency", and D5 is the lease. The new pages cite D2 for the exclusion and D4 for the lease at docs/design/plugins/Agents.md:236,272, docs/design/contracts/session-access.md:11,13,28, docs/design/plugins/Collaboration.md:123, docs/design/plugins/CollaborationSession.md:73,128 and docs/design/plugins/CollaborationTimeline.md:60,93.
Failure scenario: implementers apply the wrong decisions and either miss the exclusion of registration and lifecycle services or treat the lease as a dependency rule.
Fix: cite D3 for the exclusions and D5 for the lease.

5. Request-less reads disagree with the binding

Problem: the operation table gives agents, sessions, defaults, instance and permissionDefaults a {} request and a closed error, while the appendix methods at docs/design/plugins/Agents.md:506,560,562,564,571 take no request and return a value.
Failure scenario: the face is specified both as zero-argument and infallible, and as one-empty-object and fallible; the generated wire and error contract cannot match both.
Fix: mark these requests as none and drop closed, or make each method return Result and take an empty request.

6. delete_session has two in-use shapes

Problem: the reply is {removed} or {inUse}, and in_use is also an error kind. Current code returns DeleteOutcome::InUse as a normal outcome, and the RPC maps it to the session_active error (crates/dim-app-server/src/connection.rs:1390-1397).
Failure scenario: a caller cannot tell whether to inspect Ok(DeleteReply.in_use) or Err(AgentsError::InUse), and two implementations will diverge.
Fix: keep one shape and state how Rpc maps it back to session_active.

7. observe cannot produce its documented "none" reply

Problem: the table says {agentId, generation} or none, while the appendix returns Result<Observed, AgentsError> at docs/design/plugins/Agents.md:556.
Failure scenario: the no-loaded-generation case has no wire representation.
Fix: return Option<Observed>.

8. process-owner-operations still keeps sessions.permission

Problem: docs/design/contracts/process-owner-operations.md:25 still defines both sessions.permission({sessionId,branchId}) and sessions.permissionDefaults({}), while docs/design/plugins/Agents.md:173 says this face does not return a line's policy and docs/design/contracts/session-access.md:21 assigns that read to Permission.
Failure scenario: two target contracts disagree, and keeping sessions.permission reintroduces the forwarding method that rule 7 forbids.
Fix: update that row to permissionDefaults only and fix its line 12 pointer to this contract.

9. The delete-notice replacement removes two events with live consumers

Problem: docs/design/plugins/Agents.md:232 deletes agent/session-restored and agent/unloaded-session-deleted, but docs/design/contracts/process-owner-operations.md:39 says to keep both, and observe is one shot per loaded generation. Provider reattaches startup ownership on restore (crates/dim-app-server/src/provider.rs:3524) and releases it on an unloaded delete (crates/dim-app-server/src/provider.rs:3532); Collaboration re-arms its watch on restore and ends relations on an unloaded delete (crates/dim-app-server/src/collaboration.rs:706,728).
Failure scenario: a restored member is never observed again, and an unloaded Session deleted after an unload leaves a startup binding and a Team relation behind.
Fix: keep both events, or define a persistent watch plus a delete notice for these owners, and update the peer row.

10. The binding appendix does not compile

Problem: SessionConfig is dim_agent_runtime::SessionConfig (crates/dim-agent-runtime/src/config.rs:39), not a dim_agent_types item; crate::protocol::AgentProfile at docs/design/plugins/Agents.md:306,320 does not exist (dim_agent_types::AgentProfile is re-exported at crates/dim-app-server/src/agents.rs:15); CreatedWorktreeReply derives only Serialize (crates/dim-app-server/src/worktrees.rs:1165), so deriving Deserialize for CreatedSession fails.
Failure scenario: an implementer cannot copy the appendix, and the contract's Rust binding does not build.
Fix: correct the import paths and the derive, or exclude the worktree reply from the deserialized shape.

11. The observe callback type is not a valid routed callback

Problem: EndListener at docs/design/plugins/Agents.md:424 returns BoxFuture<'static, ()>. The rutis service macro decodes a callback parameter only as Arc or Box of Fn(..) -> BoxFuture<'static, Result<X, E>> with E: From<rutis::host::CallError>; this alias falls through to the data path and fails the Deserialize bound.
Failure scenario: the appendix does not compile and other languages cannot pass onEnd.
Fix: return Result<(), rutis::Error> and use Arc, matching the caller example at line 100.

P3

  • Permalinks: docs/design/plugins/Agents.md:13 points at AgentDirectory (crates/dim-app-server/src/agents.rs:330-384) instead of SessionSlot (agents.rs:168-183); docs/design/plugins/CollaborationSession.md:12 points at plugin key wiring (crates/dim-app-server/src/collaboration.rs:3535-3560) instead of the guide registration (collaboration.rs:3582-3598); docs/design/plugins/CollaborationTimeline.md:12 points at the CollaborationSession struct (collaboration.rs:972-1080) instead of the fact writes. Re-anchor them.
  • Forward links: docs/design/contracts/session-access.md:18-21 and docs/design/appserver/sessions-service.md:15,31,38 use relative links to plugins/InputQueue.md and plugins/Loop.md (#2102), plugins/TimelineTree.md (#2092), plugins/Permission.md (#2100) and ../../adr/027-cross-scope-access-by-id.md (#2029). These targets are not on main. Use PR-file URLs, or merge after the owners.
  • docs/design/contracts/session-access.md:189 repeats the TimelineTree paragraph twice and still cites the removed section 9.2. Keep one copy and link TimelineTree.
  • docs/design/plugins/Agents.md:223-224 names publishedCutoff? and window; #2102 defines through plus includeBlockPresence, and #2092 defines limit. Use the owners' field names, and reconcile requirement 2 at line 273 with the same shape.
  • docs/design/plugins/Collaboration.md:158 says retain_startup takes an admission id only. The current method takes (&Session, &ModelSelection) (crates/dim-app-server/src/provider/startup.rs:537), and #2096's target row is retain_startup({session, model}). Remove or restate the requirement.
  • docs/design/plugins/CollaborationTimeline.md:167 renames variants only; the field encodes as member_session_id. Add rename_all_fields = "camelCase".
  • docs/design/plugins/Agents.md:57,101 uses defaults.policy (SessionConfig has permission_policy) and Observe (the appendix defines ObserveRequest).
  • docs/design/plugins/Agents.md:226 maps only deleted, closed and loaded; unknown is a state in the same table, and an id never seen answers it.
  • docs/design/plugins/Agents.md:149 has no error for an Agent that exists but is unavailable, although agents carries unavailable? and the current launch reports that reason.
  • docs/design/plugins/Agents.md:478 always serializes paused and running, while the table says {paused} or {running}; settle is listed as errorless but returns Result.
  • Supersedes is incomplete: docs/design/plugins/Scheduler.md:62,251,290,435, docs/design/plugins/Workflow.md:208,269,286,546, docs/design/worktree-management.md:39 and docs/design/p6-p7-bindings.md:22 still teach sessions.launch, sessions.input, sessions.stop and sessions.delete, and the Scheduler edits in #2097 keep sessions.launch. Update them in this series or record the follow-ups, so the merged tree does not name removed methods.

Verification: node scripts/adr-check.mjs --base 5a279d6988c80692a77f3438fff4d26f7875e4c9 passes. GitHub reports no checks for this head. The local checkout is at 053b2d4a8cf139edd84199ab544282ff5ac46db3, with merge base 5a279d6988c80692a77f3438fff4d26f7875e4c9.

[Appendix B.2](../overview.md#b2-app-server-process-plugins), Agents row. Scope: [ADR 002](../../adr/002-plugin-scope.md)
process scope, inside the existing Agents plugin. Consumers: [Scheduler](../plugins/Scheduler.md) (P6) and
[Workflow](../plugins/Workflow.md) (P7), both TypeScript.
Status: replaced by [ADR 027](../../adr/027-cross-scope-access-by-id.md) and the [Agents contract](../plugins/Agents.md). This page keeps the lifecycle, submission-identity and authority facts that outlive the `sessions` methods, and lists where each old decision now lives.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This rewrite removes the headings for sections 2, 3, 6.x, 8.x, 11 and 17. 36 English and 32 Chinese pages link to those anchors, for example docs/design/plugins/Scheduler.md:266,270,290, docs/design/plugins/Workflow.md:276,286,538 and docs/design/appserver/idle-unload.md:12,48; this PR also adds two broken links, docs/design/plugins/Agents.md:241 (#3-decisions) and docs/design/contracts/session-access.md:62 (#where-the-submission-identity-lives). Failure: the links 404 after merge and the stated decision mapping cannot be followed. Fix: keep the old headings as anchor stubs or update every inbound link, and add a docs link check because scripts/adr-check.mjs only checks ADR freezes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 88e76b6 for the sessions-service anchors: the Superseded anchors block restores sections 1 to 17, and the links in Scheduler, Workflow, idle-unload and native-storage-format now resolve. The same defect remains in session-access.md and Collaboration.md; the new review covers that separately.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3d5ade8 for the remaining pages. session-access.md and Collaboration.md now keep the old headings under Superseded anchors, and a docs link check over 335 files finds 0 new broken relative links against main. One stub still misdirects: see the note on 4675478948 about #3-flows.

Those calls return values or throw generated `RustError`, while `sessions`
retains its existing envelope. See [native access §2](../p6-p7-bindings.md#2-read-only-permission-access).
- **Ownership.** Agents owns a launched Session's instance and record like any other Session: clients list it, a user can attach to it, answer its approvals, stop, close or delete it. The caller owns only its own records that name the Session and the inputs it wrote ([Agents](../plugins/Agents.md)). Closing or deleting the starter does not touch a launched Session.
- **Loading.** A Session stays loaded while a lease holds it or its work runs; Agents unloads it once no lease has held it for `idle_unload_after` and it is idle ([idle unload](idle-unload.md), [lifecycle §5](../../architecture/rust-agent/lifecycle.md#5-stop-与-close)). The next call restores it. A lease is held only while a call runs ([Agents: `acquire`](../plugins/Agents.md#operations)).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: "A lease is held only while a call runs" contradicts docs/design/contracts/session-access.md:13 and the acquire/release rows in Agents.md, where the caller's row holds the lease across calls until release or row unload. Failure: a caller following this line drops its pin between calls and idle unload can end the generation, so the next call addresses another instance. Fix: state the row-owned lease rule once, citing ADR 027 D5.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 88e76b6. sessions-service.md:8 now states that the lease belongs to the calling row and is settled on release or row unload, citing ADR 027 D5, which matches session-access.md:13 and the acquire/release rows.

Comment thread docs/design/contracts/session-access.md Outdated
```

`input/withdraw { input_id, reason? }` is a command event, and `input/deleted { input_id }` is InputQueue's result fact. Legitimate producers write the command: clients through `session.input.withdraw`, which InputQueue provides through `sessionMethods` ([session-boundary](session-boundary.md#a1-method-contributions)), and process callers through `sessions.withdraw`. InputQueue consumes commands in sequence order and decides from its own decision state only ([time bus §4](../../architecture/rust-agent/time-bus.md#4-写入前的复核归各状态机)): the command takes effect only if InputQueue still holds that `input/message` unapplied. Once InputQueue has written `input/applied` for an input, the input belongs to Loop and cannot be withdrawn; Loop needs no change. For one input, at most one of `input/applied` and `input/deleted` exists.
A process-scope caller reaches any Session-group data face with `sessionId` and any branch-group data face with `(sessionId, branchId)`; a Session-scope caller reaches its own line's owners with `branchId`. The address is not limited to input writes or published-value reads. The mechanism resolves the instance key to the target scope's data-face dispatch and the caller calls the owner's own operation ([ADR 027](../../adr/027-cross-scope-access-by-id.md) D1). Nothing forwards by operation name, wraps a request or reply, or restates the owner's error. An unknown, unloaded or closing target ends resolution with the mechanism's own error.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This rewrite deletes the section holding main's session.attach.expectedConfig paragraph, which origin/main added after the merge base; git merge-tree origin/main HEAD reports this file as the only conflict. Failure: resolving the conflict by taking this side silently drops the expectedConfig and session_config_mismatch contract. Fix: move that paragraph to the owner that keeps attach expectations (for example session-boundary.md or cold-attach-profile.md) before deleting the section.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 88e76b6 for expectedConfig: section 2 Attach expectations keeps the paragraph with session_config_mismatch and -32602. The sibling expectedCwd paragraph from origin/main:docs/design/contracts/session-access.md:73 is still missing; the new review covers it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3d5ade8. docs/design/contracts/session-access.md:26 restores main's session.attach.expectedCwd paragraph byte for byte (origin/main:docs/design/contracts/session-access.md:73), and docs/design/acp-gateway-implementation.md:452 now links #2-attach-expectations.

Comment thread docs/design/contracts/session-access.md Outdated
A process-scope caller reaches any Session-group data face with `sessionId` and any branch-group data face with `(sessionId, branchId)`; a Session-scope caller reaches its own line's owners with `branchId`. The address is not limited to input writes or published-value reads. The mechanism resolves the instance key to the target scope's data-face dispatch and the caller calls the owner's own operation ([ADR 027](../../adr/027-cross-scope-access-by-id.md) D1). Nothing forwards by operation name, wraps a request or reply, or restates the owner's error. An unknown, unloaded or closing target ends resolution with the mechanism's own error.

## 4. Timing and conflicts
Resolution reaches the target scope's shared data faces only. Registration points (`sessionMethods`, `toolRegistry`) and lifecycle services are not reachable this way (ADR 027 D2). The path is available to Rust parts, language runtimes and leaves through rutis sessions; clients keep using Rpc's method tables and Session authorization. Which links reach it is the deployment's ([service faces §2.1](../service-faces.md#21-目标)).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The ADR 027 numbers do not match #2029. D2 is runtime routing; D3 is the data-faces-only rule, including the exclusion of registration and lifecycle services and the language and Rpc paths; D4 is "call by id is not a dependency"; D5 is the lease. This line cites D2 for the exclusion, and the same shift appears at Agents.md:236,272, session-access.md:13,28, Collaboration.md:123, CollaborationSession.md:73,128 and CollaborationTimeline.md:60,93. Failure: implementers apply the wrong decisions. Fix: D3 for the exclusions and D5 for the lease.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 88e76b6. The D3 citations now cover the data-face exclusions and the language paths, and D5 covers the lease, matching ADR 027 at da6f4a9.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original shift is fixed, but c3acab3 regressed the citation in the other direction: session-access.md:9 and Agents.md:275 now cite D1 for routing and the instance key, which are D2 (docs/adr/027-cross-scope-access-by-id.md:28-33). See the new inline comments on those lines.

Comment thread docs/design/contracts/session-access.md Outdated
| Block | Owner |
| --- | --- |
| Session creation, close, delete, fork, admission values and leases | [Agents](../plugins/Agents.md) |
| Input submission, its receipt, pending state and withdrawal | [InputQueue](../plugins/InputQueue.md) |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The block table uses relative links to files that are not on main: plugins/InputQueue.md and plugins/Loop.md exist only in #2102, plugins/TimelineTree.md in #2092, plugins/Permission.md in #2100, and ../../adr/027-cross-scope-access-by-id.md in #2029. Failure: the rendered page 404s until every sibling PR merges. Fix: use the PR-file URLs as Collaboration.md does, or merge this page after the owners.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partially fixed in 88e76b6. session-access.md and process-owner-operations.md now use PR-file URLs for the sibling-PR targets, but sessions-service.md:3,15,31,38,39 and Agents.md:239,275 still link relative to ../../adr/027-cross-scope-access-by-id.md and ../plugins/InputQueue.md, Loop.md and TimelineTree.md, which are not on main. Use PR-file URLs there too.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3d5ade8. The remaining relative links in sessions-service.md and Agents.md now use PR-file URLs for ADR 027 (#2029), InputQueue and Loop (#2102) and TimelineTree (#2092). No relative links to those targets remain in the changed pages.

Comment thread docs/design/plugins/Agents.md Outdated

```rust
use dim_agent_capabilities::host::CancelledFn;
use dim_agent_types::{PermissionPolicy, SessionConfig};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The appendix does not compile. SessionConfig is dim_agent_runtime::SessionConfig (crates/dim-agent-runtime/src/config.rs:39), not a dim_agent_types item; crate::protocol::AgentProfile at lines 306 and 320 does not exist (dim_agent_types::AgentProfile is re-exported at crates/dim-app-server/src/agents.rs:15); CreatedWorktreeReply derives only Serialize (crates/dim-app-server/src/worktrees.rs:1165), so CreatedSession's Deserialize fails. Failure: an implementer cannot copy the binding. Fix: correct the paths and the derive, or exclude the worktree reply from the deserialized shape.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partially fixed in 88e76b6. SessionConfig, AgentProfile and the worktree reply are fixed. The appendix still does not compile: PublicService is imported twice (lines 301 and 304), and CreateAgent.profile at line 328 still uses crate::protocol::AgentProfile. The new review covers it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3d5ade8 for the Agents appendix. The duplicate PublicService import is gone, CreateAgent.profile uses the imported AgentProfile, and the derives match the crate types (CreateWorktree is Deserialize-only, CreatedSession Serialize-only). The same wrong path remains in Collaboration.md:173; the new review covers it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Agents appendix is fixed. Collaboration.md:173 still does not compile: crate::protocol::AgentProfile does not exist, and the untagged enum needs rename_all_fields = "camelCase". See the thread on that line.

Comment thread docs/design/plugins/Agents.md Outdated
Unloaded,
}

pub type EndListener = Box<dyn Fn(EndNotice) -> BoxFuture<'static, ()> + Send + Sync>;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: EndListener is not a valid routed callback. The rutis service macro accepts a callback only as Arc or Box of Fn(..) -> BoxFuture<'static, Result<X, E>> with E: From<rutis::host::CallError>; this alias returns BoxFuture<'static, ()>, so it falls through to the data path and fails the Deserialize bound. Failure: the appendix does not compile and other languages cannot pass onEnd. Fix: return Result<(), rutis::Error> and use Arc, matching the caller example at line 100.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 88e76b6. EndListener is now Arc<dyn Fn(EndNotice) -> BoxFuture<'static, Result<(), rutis::Error>> + Send + Sync>, matching rutis 0.23's FromFunction impl, and the caller example returns Ok(()).

Comment thread docs/design/plugins/Collaboration.md Outdated

## Requirements raised to other owners

1. **Provider retains a startup connection by source id for a member.** A member inherits the leader's adopted model; when that model carries a startup connection, retention needs the connection the leader's creator admitted, and Provider's `retain_startup` takes an admission id only. Either `retain_startup` accepts `{source, session}` for a source another Session already admitted, or Provider states that an inherited startup connection is not retained for a member. Raised with [#2019](https://github.com/arcships/dim/issues/2019).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The premise is stale. retain_startup already takes (&Session, &ModelSelection) (crates/dim-app-server/src/provider/startup.rs:537) and resolves the source id that the creating Session admitted; the current Collaboration path already calls it for a member (crates/dim-app-server/src/collaboration.rs:406), and #2096's target row is retain_startup({session, model}). Failure: the requirement asks for work that is already done. Fix: remove the requirement or restate the remaining gap.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 88e76b6. The retain_startup requirement is removed and the dependency row now states retain_startup({session, model}), matching #2096's Provider target.

pub struct DelegationState { pub open: Vec<OpenDelegation>, pub closing: bool }

#[derive(serde::Serialize, serde::Deserialize)]
#[serde(tag = "status", rename_all = "camelCase")]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: rename_all = "camelCase" on an internally tagged enum renames variants only, so Delivered::Ok encodes as {"status":"ok","member_session_id":"..."}, not the documented memberSessionId. Failure: the wire shape differs from the contract. Fix: add rename_all_fields = "camelCase" or rename the field.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 88e76b6. Delivered now has rename_all_fields = "camelCase", so member_session_id encodes as memberSessionId.

Comment thread docs/design/plugins/Agents.md Outdated
Rpc creating a client Session from a request naming an Agent, a cwd and a policy:

```rust
let policy = request.policy.unwrap_or_else(|| defaults.policy.clone()); // business default

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The caller example reads defaults.policy, but the defaults operation returns SessionConfig, whose field is permission_policy (crates/dim-agent-runtime/src/config.rs:41); the observe example at line 101 also uses Observe while the appendix defines ObserveRequest. Failure: copied examples do not compile. Fix: use defaults.permission_policy and ObserveRequest.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 88e76b6. The caller example uses defaults.permission_policy and ObserveRequest, and the observe closure returns Ok(()).

One face on the Agents owner; Collaboration split into its process, Session and
branch owners. Session access follows ADR 027 by id, and the sessions service
page and contract defer to this contract. Refs #2020, Refs #2015.
Keep the sessions-service anchors and main's attach-expectation paragraph,
route by id with #2127, cite ADR 027 D3/D5, keep the restore and
unloaded-delete events, and make the binding appendix compile.
@eric8810
eric8810 force-pushed the dim/2020-agents-contract branch from 053b2d4 to 88e76b6 Compare November 24, 2026 03:25
@eric8810

Copy link
Copy Markdown
Collaborator Author

已按评审与自查标准修改,head 88e76b662(已 rebase 到 origin/main 6e86d48c8)。

评审逐条处理:

  • P2-1 锚点:sessions-service.md 保留 §1–§17、6.1–6.11、8.1–8.7、附录 A 的标题作锚点(每节一行指向新所有者),68 条入链恢复;另修本 PR 自带的两个断链(Agents.md 的 #3-decisions、session-access.md 的 #where-the-submission-identity-lives)。仓库脚本的文档链接检查不在本 PR 范围,记为后续。
  • P2-2 冲突丢内容:main 新增的 session.attach.expectedConfig 段落(含 session_config_mismatch/-32602)保留在本契约 §2「Attach expectations」,rebase 后仍在。
  • P2-3 租约生命周期:sessions-service.md 改为「租约属于调用行,跨调用保留,acquire 取、release 或行卸载结算(ADR 027 D5)」。
  • P2-4 决定编号:排除登记点与生命周期服务引 D3,租约引 D5,路由引 D1/D2;五份文档全部改过。
  • P2-5 无请求读:agents、sessions、defaults、instance、permissionDefaults 的请求与错误都改为 —,附录返回普通值。
  • P2-6 delete 两套在用形状:只保留回复 {removed:false, inUse:reason},删掉 in_use 错误种类,并写明 Rpc 映射回 session_active。
  • P2-7 observe 的 null:附录改为 Result<Option<Observed>, AgentsError>,与「或 null」一致。
  • P2-8 process-owner-operations:sessions.permission 行改为「按 (sessionId, branchId) 读 Permission 的发布值」,只留 sessions.permissionDefaults;指回本契约 PR。
  • P2-9 保留两个事件:agent/session-restored、agent/unloaded-session-deleted、agent/session-deleted 三个都保留,写明 Provider 与 Collaboration 各自消费哪个。
  • P2-10 附录编译:SessionConfig 取自 dim_agent_runtime,AgentProfile 取自 dim_agent_types;worktree 回复按数据承载;CreateSession 只派生 Deserialize(CreateWorktree 只有 Deserialize),CreatedSession 只派生 Serialize。
  • P2-11 回调类型:EndListener 改为 Arc<dyn Fn(EndNotice) -> BoxFuture<'static, Result<(), rutis::Error>> + Send + Sync>,调用方示例同步。

自查额外修改(P3 及 A–G):

  • 永久链接重锚到当前 head:SessionSlot、guide 注册、collaboration/request 写事实处。
  • 前向链接改 PR URL;pending 用 inputId/through/includeBlockPresence,history 用 limit;CollaborationTimeline 的 Delivered/Target 加 rename_all_fields。
  • session-access.md A.5 删掉重复段落与已删除的 §9.2 引用。
  • defaults.permission_policy、ObserveRequest、session.state 的 unknown、unavailable Agent 的错误、QuiesceReply 的两种形状、settle 的 closed 都修了。
  • ADR 027 见 按 id 调用:由持有实例的一方选目标(base-1) #2127:需求改为「按 id 路由,实例键不交给调用方」并链 按 id 调用:由持有实例的一方选目标(base-1) #2127。
  • Supersedes 补齐 process-owner-operations、service-faces,并把 Scheduler/Workflow/worktree-management/p6-p7-bindings 记为 docs(design): target contracts for EventHub and Scheduler #2097 等所有者的后续。
  • 绑定附录在临时 example(未提交)里 cargo check -p dim-app-server --example appendix_check 通过(退出码 0),已删除该文件。
  • 客户端可见变更:无。

请评审人复看。

@yyhhyyyyyy yyhhyyyyyy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: Agents and Collaboration owner contracts (round 2)

Scope: refs #2020 and #2015. This PR adds Agents.md, CollaborationSession.md and CollaborationTimeline.md, rewrites Collaboration.md, and replaces the sessions supplement in sessions-service.md and session-access.md with access by id under ADR 027. This round reviews the full main...head at 88e76b6 and the delta over 5582af4.

Verdict: REQUEST_CHANGES

Round-1 status

Fixed in 88e76b6:

  • Lease lifetime: sessions-service.md:8 now states the row-owned lease and cites ADR 027 D5.
  • ADR 027 decision numbers: D3 for the data-face exclusions, D5 for the lease. Verified against ADR 027 at da6f4a950.
  • delete_session: one reply shape, the in_use error kind removed, and the Rpc mapping to session_active stated.
  • observe: the table says null and the appendix returns Result<Option<Observed>, AgentsError>.
  • process-owner-operations.md: sessions.permission is gone and the lease row is row-owned.
  • Delete notices: agent/session-restored, agent/unloaded-session-deleted and agent/session-deleted are all kept; the current consumers still exist.
  • EndListener: the alias now returns Result<(), rutis::Error> and uses Arc, matching rutis 0.23.
  • P3 items: duplicate TimelineTree paragraph, retain_startup requirement, rename_all_fields for Delivered, caller examples, unavailable for create_session, settle error column, and the Supersedes follow-up list.

Partially fixed:

  • Link set: the sessions-service.md anchors are restored, but the other two rewrites still break links. See P2-1.
  • expectedConfig: the paragraph is kept, but its sibling expectedCwd paragraph is still dropped. See P2-2.
  • Request-less reads: fixed in the Agents table and appendix, but the same class remains in CollaborationTimeline and in the permissionDefaults({}) row. See P3.
  • Binding appendix: the import and worktree issues are fixed, but the appendix still does not compile. See P2-4.
  • Permalinks: Agents.md:13 is fixed; CollaborationSession.md:12 and CollaborationTimeline.md:12 still point at the wrong code.
  • Forward links: some now use PR-file URLs; sessions-service.md and the ADR 027 links in Agents.md remain relative.
  • sessions.exists still does not define the unknown answer, and QuiesceReply still always serializes running.

P2

P2-1. The link fix covers only sessions-service.md; the other two rewrites add 42 broken links

Problem: sessions-service.md now keeps its old headings as stubs, which restores the round-1 link set for that page. The session-access.md and Collaboration.md rewrites have no stubs and no inbound link updates. Round 1 checked this class on sessions-service.md only and the fix commit applied stubs only there, so this is the first check of the other two pages. Compared with origin/main, the head adds 42 broken link occurrences in 18 files: 33 missing anchors in 17 files and 9 links to files that exist only in sibling PRs.

Failure scenario: after merge, acp-gateway-implementation.md:452 and session-deletion-and-fork.md:303 send the reader to a missing session-access.md#3-flows; Notifications.md:41, EventHub.md:58,278, Questions.md:52, Modality.md:280 and single-tree.md:108 send the reader to removed session-access.md sections; idle-unload.md:7, native-storage-format.md:110,977, session-classification.md:80 and session-deletion-and-fork.md:179 send the reader to removed Collaboration.md sections. The checked-attach and delegation contracts cannot be followed from their consumers.

Evidence: docs/design/contracts/session-access.md:7-58 has no #3-flows, #7-security, #9-requirements-raised-to-mechanism-owners, #94-optional-parts-per-enabled-plugin or #a1-the-sessions-service. docs/design/plugins/Collaboration.md:61-158 has no #6-delegation-ownership-and-lifetime, #67-stopping-a-member-from-the-client, #7-the-models-a-member-can-run or #task-title. Examples: docs/design/overview.md:104,555, docs/design/plugins/Notifications.md:41, docs/design/plugins/EventHub.md:58,278, docs/design/plugins/Questions.md:52, docs/design/appserver/session-deletion-and-fork.md:179,303, docs/design/appserver/provider-management.md:1151, docs/design/subagent-model-policy.md:34.

Fix: add the same anchor stubs to session-access.md and Collaboration.md, or update every inbound link. The self-link at sessions-service.md:22 should be #3-security. Replace the remaining relative links to ../../adr/027-cross-scope-access-by-id.md, ../plugins/InputQueue.md, ../plugins/Loop.md and ../plugins/TimelineTree.md with PR-file URLs as done elsewhere.

P2-2. session-access.md still drops the expectedCwd contract

Problem: round 1 flagged the deletion of the section that held main's expectedConfig paragraph. The fix keeps expectedConfig in §2 but deletes its sibling expectedCwd paragraph from main. No other document now defines the check.

Failure scenario: an implementer following the target contract has no statement that attach canonicalizes the expected cwd, checks it under the acquire gate before project authorization, restore and plugin activation, and fails without attaching. AcpGateway.md still says load and resume validate expectedCwd through checked attach, but the target contract no longer defines checked attach for cwd, so a reimplementation can attach to a Session whose cwd changed.

Evidence: origin/main:docs/design/contracts/session-access.md:73 has the paragraph; the head docs/design/contracts/session-access.md:24-26 has expectedConfig only. After the PR, expectedCwd remains only in docs/design/plugins/AcpGateway.md:178 and docs/design/acp-gateway-implementation.md:27,452, both as consumers.

Fix: restore the expectedCwd paragraph under §2 Attach expectations and retarget the inbound checked-attach links to #2-attach-expectations.

P2-3. The InputQueue.pending request is stale against the rebased #2102

Problem: Agents.md:226 now says pending({inputId, through?, includeBlockPresence?}), but #2102 at 851f531 defines pending({inputId, publishedCutoff?}) -> {pending}. The same page contradicts itself at line 276, which still says the owner accepts a published-cutoff default.

Failure scenario: a caller that follows this row sends fields the owner does not define, while a caller that follows #2102 sends a different request. Scheduler and Workflow cannot rely on one documented shape to verify a lost input receipt.

Evidence: docs/design/plugins/Agents.md:226,276; docs/design/plugins/InputQueue.md:83,64 at #2102 head 851f531. Round 1 asked for the then-current #2102 shape; that owner PR has since changed to publishedCutoff.

Fix: use pending({inputId, publishedCutoff?}) -> {pending} and align requirement 2. In the same table, sessions.lookup maps to submit with {inputData} while the owner takes {input}; use {input}.

P2-4. The binding appendix still does not compile

Problem: round 1's compile finding is only partly fixed. docs/design/plugins/Agents.md:301 and :304 import PublicService twice, which is E0252, and CreateAgent.profile at :328 still uses crate::protocol::AgentProfile, which the app-server protocol module does not export.

Failure scenario: an implementer cannot copy the binding; the snippet fails before the interface is exercised.

Evidence: docs/design/plugins/Agents.md:301,304,328. crates/dim-app-server/src/agents.rs:15 re-exports dim_agent_types::AgentProfile; crates/dim-app-server/src/protocol.rs has no AgentProfile re-export. The duplicate import fails with error[E0252], reproduced with rustc.

Fix: delete the duplicate import and use the already imported AgentProfile at line 328.

P3

  • Appendix and table shape mismatches. Agents.md:162 says members replies a bare array, while the appendix at :479 returns MembersReply { members: Vec<MemberLink> }. Agents.md:229 defines sessions.exists for deleted, closed and loaded only, although session.state can answer unknown (line 158). Agents.md:487 always serializes running, while the table says {paused: true} or {paused: false, running}. Collaboration.md:173 is externally tagged, so Target::Agent encodes as {"agent":{"agentId":...}}, not the {agentId} or {profile} shape at line 79, and the caller example at line 46 uses a tuple variant that does not match the struct variant.
  • Request-less reads remain in docs/design/plugins/CollaborationTimeline.md:71 (state is shown with a {} request and a closed error, while the appendix state(&self) -> DelegationState takes no request and cannot fail) and docs/design/plugins/CollaborationSession.md:88 (approvalDestination lists invalid_request, while the appendix returns Option). docs/design/contracts/process-owner-operations.md:25 still writes permissionDefaults({}) while Agents.md:144 says it takes no request.
  • Remaining permalinks: docs/design/plugins/CollaborationSession.md:12 still points at plugin key wiring (crates/dim-app-server/src/collaboration.rs:3535-3560); the guide entries register at collaboration.rs:3582. docs/design/plugins/CollaborationTimeline.md:12 still points at the CollaborationSession struct (collaboration.rs:972), not the fact writes.
  • docs/design/appserver/sessions-service.md:87 is a leftover sentence fragment from the section that was stubbed: #32 described the field as client-protocol data that no runtime capability uses. It asked for an idempotency record. It has no terminal punctuation and is followed by another Superseded line. Delete it or finish the sentence.
  • The PR description is stale: it still says one agent/session-deleted notice for EventHub and that both permission reads move to sessions.permission*, while the head keeps three notices and removes sessions.permission. Update it so the merge notes match the contract.

Verification

  • git merge-base origin/main HEAD is 6e86d48c8; git merge-tree origin/main HEAD is clean; GitHub reports mergeable: true.
  • node scripts/adr-check.mjs --base 6e86d48c8361e95575cf8e4425e77f4ec048fc41 passes (12 changed files), run with an isolated HOME/TMPDIR/XDG.
  • CI on 88e76b6: ci-ok success; the docs-only jobs are skipped; the commit status is pending with no external statuses.
  • Link check: 335 Markdown files under docs/, relative links plus GitHub-style heading anchors, compared with origin/main. The head adds 42 broken link occurrences in 18 files. The round-1 sessions-service.md anchors now resolve.
  • Cross-PR merge checks: merge-tree conflicts with #2080, #2094 and #2099 on docs/design/plugins/README.md, with #2091 on resource-owner-operations.md, with #2096 on process-owner-operations.md, with #2097 on sessions-service.md, and with #2102 on session-access.md. The #2102 pending shape is a content conflict, not only a merge conflict; #2096 still carries the old sessions.permission row and must not overwrite the new one when it rebases.

Withdraw or keep

Withdraw as fixed: the round-1 lease, ADR-number, delete-shape, observe-none, sessions.permission, delete-notice and EndListener findings, plus the duplicate paragraph, retain_startup, Delivered casing, examples, unavailable, settle and Supersedes findings.

Keep as partially open: the link set (only sessions-service.md fixed), expectedConfig (fixed, expectedCwd still dropped), request-less reads (Agents fixed, two pages remain), binding appendix (still does not compile), permalinks, forward links, sessions.exists unknown, and quiesce serialization.

| 6 | What does a loaded Session cost? | `xtask measure`, release build, mock model, Apple M4 | About 300 KB of Rust allocations and 43 Tokio tasks per loaded idle Session. Mean creation time is 1.5 ms with 10 Sessions loaded, 4.0 ms with 100 and 57 ms with 1000. The App Server never unloads idle Sessions ([#57](https://github.com/arcships/dim/issues/57)) | Launched Sessions accumulate until restart; idle unload is raised as a follow-up (§8.6) |
| 7 | When can readers see an input? | Code: `Session::input` returns at commit, before publication; protocol v3+ `session.submit` waits for publication | A caller that reads right after `Session::input` can miss its own input | `input` replies after publication, and `lookup` waits for pending publication first (§6.2, §6.3) |
| 8 | Where does lookup by `submissionId` live? | Code | Only in Rpc: `session.input_lookup` scans the published pages, O(n) | Agents owns one lookup and Rpc calls it (§6.3) |
## Superseded anchors

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This stub block restores the sessions-service anchors, but the same fix was not applied to the other two rewritten pages. session-access.md no longer has #3-flows, #7-security, #9-requirements-raised-to-mechanism-owners, #94-optional-parts-per-enabled-plugin or #a1-the-sessions-service, and Collaboration.md no longer has #6-delegation-ownership-and-lifetime, #67-stopping-a-member-from-the-client, #7-the-models-a-member-can-run or #task-title. Against origin/main the head adds 42 broken link occurrences in 18 files, for example overview.md:104,555, plugins/Notifications.md:41, EventHub.md:58,278, session-deletion-and-fork.md:179,303. Failure: those links 404 after merge and the checked-attach and delegation references cannot be followed. Fix: add the same anchor stubs to session-access.md and Collaboration.md, or update every inbound link; the self-link at sessions-service.md:22 should be #3-security.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partially fixed in 3d5ade8. The session-access.md and Collaboration.md headings are back and a docs link check over 335 files finds 0 new broken relative links against main. One stub misdirects: session-access.md:215 (## 3. Flows) says the section is superseded by owners, but main's expectedConfig paragraph stayed in this page at #2-attach-expectations, and session-deletion-and-fork.md:303 still links here. Point the stub at #2-attach-expectations.

| Input source conventions, `SessionConfig` fields, withdrawal and the fixed-prefix read | this document, Appendix A |

The native `session.attach.expectedCwd` capability permits an optional `expectedCwd` on `session.attach`. The boundary canonicalizes that one path and checks the target Session's stored or live cwd by Session ID under its acquire gate, before project authorization, Session restore or plugin activation. A mismatch fails without attaching or running that project's configuration. Omitting it preserves existing callers. Attach already returns cwd and title metadata; a checked attach never lists all Sessions to find its target.
## 2. Attach expectations

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This section keeps main's expectedConfig paragraph but drops its sibling expectedCwd paragraph (origin/main:docs/design/contracts/session-access.md:73). The head has no document that defines canonicalizing the expected cwd, checking it under the acquire gate before project authorization, restore and activation, and failing without attaching; plugins/AcpGateway.md:178 and acp-gateway-implementation.md:452 still refer to checked attach for expectedCwd. Failure: an implementation can attach to a Session whose cwd changed, or order the check after restore, and no target contract forbids it. Fix: restore the expectedCwd paragraph here and point the inbound checked-attach links at #2-attach-expectations.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3d5ade8. session-access.md:26 is byte-identical to origin/main:docs/design/contracts/session-access.md:73, and the checked-attach links now point at #2-attach-expectations.

Comment thread docs/design/plugins/Agents.md Outdated
| `sessions.lookup` | [InputQueue](https://github.com/arcships/dim/pull/2102/files)'s submit re-sent with the caller's `submissionId`: a duplicate answers the existing `{inputId, sequence}` (requirement below); no separate lookup exists |
| `sessions.stop` | [Loop](https://github.com/arcships/dim/pull/2102/files)'s `stop_turn({turnId, reason})` by `(session, line)` id, after reading its published running state for the current turn id; a turn that already ended writes nothing |
| `sessions.withdraw` | [InputQueue](https://github.com/arcships/dim/pull/2102/files)'s `withdraw({inputId, reason})` by `(session, line)` id |
| `sessions.pending` | [InputQueue](https://github.com/arcships/dim/pull/2102/files)'s `pending({inputId, through?, includeBlockPresence?})` by `(session, line)` id; the owner's published head applies when the caller names no `through` |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: These fields are stale against #2102 at 851f531: docs/design/plugins/InputQueue.md:83 defines pending({inputId, publishedCutoff?}) -> {pending}, not {inputId, through?, includeBlockPresence?}. This page also contradicts itself at line 276, which still says the owner accepts a published-cutoff default. Failure: an implementer following this row and one following #2102 send different requests, so a lost input receipt cannot be verified reliably. Fix: use pending({inputId, publishedCutoff?}) -> {pending} and align requirement 2; the submit row should name {input} rather than {inputData}.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3d5ade8. Agents.md:226,276 and the sessions.input row now match #2102 at 44e6419: {inputId, publishedCutoff?} -> {pending} and {input}.

Comment thread docs/design/plugins/Agents.md Outdated
use dim_agent_runtime::{PublicService, SessionConfig};
use dim_agent_types::{AgentProfile, PermissionPolicy, ModelSelection};
use rutis::Ctx;
use dim_agent_runtime::PublicService;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The appendix still does not compile. This line imports PublicService a second time (line 301 already imports it), which is E0252, and CreateAgent.profile at line 328 still uses crate::protocol::AgentProfile, which the app-server protocol module does not export (crates/dim-app-server/src/agents.rs:15 re-exports dim_agent_types::AgentProfile). Failure: copying the binding fails before any caller can use it. Fix: delete the duplicate import and use the imported AgentProfile at line 328.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partially fixed in 3d5ade8. The Agents appendix fixes are in: the duplicate import is removed and CreateAgent.profile uses AgentProfile. Collaboration.md:173 still uses crate::protocol::AgentProfile, which does not exist; the new review covers it.

```rust
#[derive(serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase", rename_all_fields = "camelCase", deny_unknown_fields)]
pub enum Target { Agent { agent_id: String }, Profile { profile: crate::protocol::AgentProfile } }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: Target is externally tagged, so Target::Agent encodes as {"agent":{"agentId":...}} and Profile as {"profile":{"profile":...}}, not the {agentId} or {profile} shapes in the operations table at line 79; the caller example at line 46 also uses a tuple variant Target::Agent(agent_id) that does not match this struct variant. Failure: the binding and the documented request cannot both be implemented. Fix: make the enum #[serde(untagged)] and use Target::Agent { agent_id } in the example, or document the tagged shape.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partially fixed in 3d5ade8. #[serde(untagged)] fixes the tagged encoding, but removing rename_all_fields makes the variant field encode as agent_id instead of the table's agentId, and Profile { profile: crate::protocol::AgentProfile } has a nonexistent path. Use #[serde(untagged, rename_all_fields = "camelCase")] and dim_agent_types::AgentProfile.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partly fixed: untagged is right, but the path and the field casing remain. Collaboration.md:173 still uses crate::protocol::AgentProfile and has no rename_all_fields, so Target::Agent encodes agent_id instead of agentId. See the thread on the same line.

| Caller → owner | Methods and replies |
| --- | --- |
| Permission consumers → Agent directory | `sessions.permission({sessionId,branchId})` and `sessions.permissionDefaults({})` retain the existing policy replies. The first holds the Session lease; the second reads the current default without creating a Session. |
| Permission consumers → Permission and Agents | A line's current policy is Permission's published value, read by `(sessionId, branchId)` id ([ADR 027](https://github.com/arcships/dim/pull/2029/files) D1); there is no `sessions.permission`. `sessions.permissionDefaults({})` reads the current creation default without creating a Session. |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: This row writes sessions.permissionDefaults({}), but the Agents contract at docs/design/plugins/Agents.md:144 and its appendix define permissionDefaults as a value read with no request. Failure: the same request-less read is specified in two shapes again, the class round 1 raised for the Agents table. Fix: write permissionDefaults with no request, or make the Agents binding take an empty request and return Result.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3d5ade8. process-owner-operations.md:25 now writes sessions.permissionDefaults with no request, matching Agents.md:163.

Comment thread docs/design/plugins/Agents.md Outdated
| `sessions.pending` | [InputQueue](https://github.com/arcships/dim/pull/2102/files)'s `pending({inputId, through?, includeBlockPresence?})` by `(session, line)` id; the owner's published head applies when the caller names no `through` |
| `sessions.history` | [TimelineTree](https://github.com/arcships/dim/pull/2092/files)'s `read(line, from, through, limit)` by `(session, line)` id |
| `sessions.defaultBranchId` | [TimelineTree](https://github.com/arcships/dim/pull/2092/files)'s `directory` for the Session; the default line is in the reply |
| `sessions.exists` | `session.state`: `deleted` answers false, `closed` and `loaded` answer true |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: session.state can answer unknown for an id this process never saw (line 158), but this mapping defines only deleted, closed and loaded. Failure: an implementation has no target answer for sessions.exists on an unknown id. Fix: state that unknown answers false, or answer session.state as an error.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partially fixed in 3d5ade8. unknown now has an answer, but false is wrong for an idle-unloaded Session with rows: session has no state for it (line 158), and EventHub treats false as deleted and removes its subscriptions (EventHub.md:224-229). The new review covers the missing state and acquire path.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partly fixed and unchanged since: unknown now answers false, but an idle-unloaded Session with rows is not unknown (Agents.md:158 defines unknown as an id this process never saw), so it must answer true. EventHub.md:227-228 treats false as deleted and removes subscriptions. This is covered by the open P2 on the missing unloaded state and acquire path.

Comment thread docs/design/plugins/Agents.md Outdated

#[derive(serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct QuiesceReply { pub paused: bool, #[serde(default)] pub running: u32 }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: running has no skip_serializing_if, so this reply always serializes it, while the table at line 164 says {paused: true} or {paused: false, running}. Failure: the wire shape differs from the contract for the paused case. Fix: add #[serde(skip_serializing_if = "is_zero")] or change the table.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3d5ade8. QuiesceReply.running now uses skip_serializing_if = "is_zero", matching the {paused: true} shape.

Restore the attach expectations from main, keep the removed anchors on the two
rewritten pages, use InputQueue's publishedCutoff shape, and fix the appendix
imports, quiesce reply and permalinks.
@eric8810

Copy link
Copy Markdown
Collaborator Author

已按评审修改,head 3d5ade808。

逐条处理(本轮新评审):

  • sessions-service.md:42 / session-access.md:24 的锚点:session-access.md 加回 #3-flows、#31-launch-write-wait、#32-withdrawal、#6-interfaces-summary、#7-security、#8-rule-check、#9-requirements-raised-to-mechanism-owners、9.1–9.4、#appendix-a-interface-details、#a1-the-sessions-service、附录 B–E 的标题锚点;Collaboration.md 加回 #1-model-facing-texts、#2-the-guide-entries、#3-policy-at-the-factory-configuration、#task-title、#6-delegation-ownership-and-lifetime、#67-stopping-a-member-from-the-client、#7-the-models-a-member-can-run 等标题锚点,每节一行指向新所有者;sessions-service.md 自查链接改为 #3-security。
  • session-access.md:24 expectedCwd:从 origin/main 恢复 session.attach.expectedCwd 段落(规范化的 cwd、acquire 闸门下、项目授权/恢复/激活之前检查、不匹配不 attach),AcpGateway.md 与 acp-gateway-implementation.md 的 checked-attach 链接改指 #2-attach-expectations。
  • Agents.md:226 pending:按 docs(design): target contracts for the branch turn chain #2102 最新 head 改成 pending({inputId, publishedCutoff?}) → {pending},submit 行改成 {input};需求 2 同步。
  • Agents.md:304 附录:删掉重复的 PublicService 导入,CreateAgent.profile 用导入的 AgentProfile。
  • Collaboration.md:173 Target:改为 #[serde(untagged)],示例改为 Target::Agent { agent_id }。
  • process-owner-operations.md:25:permissionDefaults 改为无请求。
  • Agents.md:229:sessions.exists 的映射写明 unknown 也答 false。
  • Agents.md:487:QuiesceReply.running 加 skip_serializing_if = "is_zero",与 {paused: true} 形状一致。
  • Agents.md:13 永久链接:CollaborationSession.md 的 guide 注册改指 collaboration.rs:3580-3600,CollaborationTimeline.md 的事实写入改指 collaboration.rs:3695-3710,两者都锚到 3d5ade808。
  • session-access.md:18 前向链接:sessions-service.md 剩余的 ADR 027、InputQueue、Loop、TimelineTree 相对链接改为 PR 文件 URL;Agents.md 的 ADR 027 相对链接同样处理。

自查额外发现并修:pending 需求与操作表两处形状不一致(同批改)、Collaboration.md 的 Target 与调用方示例不一致、session-access.md 的 #7-security 自引用、QuiesceReply 的零值省略。

绑定附录编译:临时 example(未提交)cargo check -p dim-app-server --example appendix_check 通过,已删除。

留给第二步(跨 PR):closed_session → session_closed 的错误码拼写;session-access 附录 E 的 InputQueue 绑定已在 ADR 027 下删除,若 #2093 仍引用旧附录需对齐;与 #2102 共享的 pending/withdraw 类型在两边契约的重复定义;ADR 027 D2 编号(本 PR 已按 D3/D5 改正,若 #2029 再改号需同步)。

客户端可见变更:无。请评审人复看。

@yyhhyyyyyy yyhhyyyyyy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: Agents and Collaboration owner contracts (round 3)

Scope: refs #2020 and #2015. This PR adds Agents.md, CollaborationSession.md and CollaborationTimeline.md, rewrites Collaboration.md, and replaces the sessions supplement in sessions-service.md and session-access.md with access by id under ADR 027. This round reviews the full main...head at 3d5ade8 and the delta over 88e76b6.

Verdict: REQUEST_CHANGES

Round-2 status

Fixed in 3d5ade8:

  • expectedCwd: docs/design/contracts/session-access.md:26 is byte-identical to origin/main:docs/design/contracts/session-access.md:73; the expectedConfig paragraph is unchanged; docs/design/acp-gateway-implementation.md:452 points at #2-attach-expectations.
  • pending: docs/design/plugins/Agents.md:226,276 match #2102 at 44e6419: pending({inputId, publishedCutoff?}) -> {pending}, and sessions.input uses {input}.
  • Agents.md appendix: the duplicate PublicService import is gone and CreateAgent.profile uses the imported AgentProfile. I found no remaining compile error in that appendix. QuiesceReply skips the zero running; permissionDefaults takes no request; sessions.exists defines unknown.
  • Anchors: the stubs on session-access.md and Collaboration.md resolve. A link check over 335 docs finds 0 new broken relative links against main (the round-2 set of 42 is gone). The remaining links to ADR 027, InputQueue, Loop and TimelineTree are PR-file URLs.
  • ADR 027 citations D1-D5, the row-owned lease, the three delete notices and the EndListener type remain correct.

Partially fixed or still open:

  • The 3d5ade8 comment says the CollaborationSession and CollaborationTimeline permalinks were re-anchored to collaboration.rs:3580-3600 and 3695-3710, but neither file is in that commit and the head still has the 5a279d6 links (P3).
  • closed_session against session_closed, the request-less state row and the approvalDestination error row remain (P3).
  • The PR body still says one agent/session-deleted notice and both permission reads moving to sessions.permission* (P3).

P2

P2-1. Collaboration's cross-Session calls sit outside ADR 027's caller scopes

Problem: docs/design/contracts/session-access.md:9 states the two caller scopes: a process caller uses sessionId and (sessionId, branchId); a Session caller uses branchId for its own line's owners. ADR 027 D1 (PR #2029 at 9e629e9) and #2127 define exactly those two segments, and #2127's Session-to-branch segment is for this Session only. But CollaborationTimeline is a branch part and CollaborationSession is a Session part, and they call another Session's branch faces by (memberSession, line) and read the leader's collaborationSession value by sessionId (CollaborationTimeline.md:60,93,128; CollaborationSession.md:73,128,174; Agents.md:239). #2127's acceptance covers process-to-Session and Session-to-own-branch only; it has no cross-Session case.

Failure scenario: the leader line cannot write the request input, stop the member's turn or withdraw an unqueued input, and the member's Session part cannot resolve the leader's approval destination. An implementer either invents a route the mechanism does not define or moves these calls to the process Collaboration owner, which contradicts the stated ownership of the writes.

Fix: either state that all cross-Session calls are made by the process owner Collaboration, and give the member part an operation on it, or extend ADR 027 D1 and #2127 to let Session and branch callers address another Session by id, including the visibility rule for which Session a caller may address.

P2-2. An idle-unloaded Session has no state, no exists answer and no acquire path

Problem: Agents.md:158 makes state one of loaded, closed, deleted or unknown, with unknown described as an id this process never saw. An idle-unloaded Session with rows is none of these. Agents.md:229 then maps unknown to false; Agents.md:155 says acquire pins a loaded Session and :191 defines its unknown error as no loaded Session having the id, while ADR 027 D5 and #2127 say a target that is not loaded takes a hold and Agents loads the next generation, and sessions-service.md:8 says the next call restores it.

Failure scenario: a scheduled or event input finds an idle-unloaded target, gets the mechanism's NoSession, takes a lease as #2127 says, and acquire refuses it, so the input is never delivered. Separately, EventHub's reconciliation reads sessions.exists; docs/design/plugins/EventHub.md:224-229 says false means the Session was deleted, a closed restorable Session is true, and false removes its subscriptions. An idle-unloaded Session is restorable, so the new mapping can remove every subscription while the rows remain. Current code answers true for an unloaded Session because the rows remain (crates/dim-app-server/src/agents/sessions.rs:606; crates/dim-app-server/src/agents/sessions/tests.rs:189,207).

Fix: add an unloaded state, or define unknown with stored: true as restorable; answer exists true when rows exist; state that acquire restores an idle-unloaded Session and returns its new generation; keep closed_session for a business close, and reserve unknown for no rows and observe's null for no live generation.

P2-3. delete_session does not state the requireInactive default and would change client deletes

Problem: Agents.md:153 takes requireInactive and :171 says an in-use Session answers {removed:false, inUse:reason}, with no statement about requireInactive: false. Main's client contract says the field defaults to false, and without it the delete closes and removes an in-use Session; only true refuses session_active (docs/design/appserver/session-deletion-and-fork.md:78; crates/dim-app-server/src/connection.rs:1418-1431 calls delete_if_inactive only for true and delete otherwise).

Failure scenario: a client or dimcode session delete ID with no requireInactive that hits a running Session would now receive session_active and remove nothing, contrary to "Client-visible changes: None". The reply for an unknown or already-deleted id (main answers deleted false) is also unstated.

Fix: state that true answers removed:false with inUse, false deletes regardless of use, and an unknown or already-deleted id answers removed:false without inUse; give Rpc's mapping for each.

P2-4. The Collaboration binding appendix still does not compile and lost the camelCase field

Problem: Collaboration.md:173 uses crate::protocol::AgentProfile, which does not exist; crates/dim-app-server/src/protocol.rs exports no AgentProfile, and crates/dim-app-server/src/agents.rs:15 re-exports dim_agent_types::AgentProfile. The same line also lost rename_all_fields = "camelCase" when it became untagged, so Target::Agent { agent_id } encodes as agent_id, not the {agentId} shape in the operations table at line 79 and the page's "camelCase fields" sentence at line 168.

Failure scenario: an implementer copying the enum gets a compile error; one following the table and one following the binding disagree on the wire field, so the member target cannot be decoded.

Fix: use dim_agent_types::AgentProfile and #[serde(untagged, rename_all_fields = "camelCase")], or rename the field explicitly.

P3

  • PR body: it still says one agent/session-deleted notice for EventHub and both permission reads moving to sessions.permission*; the head keeps three delete notices and removes sessions.permission. Update the merge notes.
  • docs/design/appserver/sessions-service.md:87 keeps a body fragment ("#32 described the field as client-protocol data...") after the anchors intro at line 44 says the bodies are deleted. Finish or delete it.
  • docs/design/contracts/session-access.md:215: the ## 3. Flows stub says the section is superseded by owners, but main's expectedConfig paragraph stayed in this page at #2-attach-expectations, and docs/design/appserver/session-deletion-and-fork.md:303 still links #3-flows for the checked fork. Point the stub at #2-attach-expectations.
  • docs/design/contracts/session-access.md:265: the "#5, used by the offline rows" paragraph from main now sits inside the anchors block between two stubs; move it to a kept section or delete it.
  • Permalinks: CollaborationSession.md:12 still points at collaboration.rs:3535-3560 at 5a279d6 (plugin key wiring; the guide registration is at 3585-3598), and CollaborationTimeline.md:12 at 972-1080 (struct and op_turn; the fact writes are elsewhere). The 3d5ade8 comment claims 3580-3600 and 3695-3710, but those files are not in the commit; 3695-3710 is the dispatcher subscription list.
  • closed_session (Agents.md:155,192) is the only closed-session spelling in the docs tree; sessions-service.md:10, the session-access consumers and session-boundary.md use session_closed, and #2127 defines NoSession/SessionClosing. State the Rpc mapping or use the final spelling. The author defers this to step 2.
  • CollaborationTimeline.md:71 gives state a {} request and a closed error while the appendix state(&self) -> DelegationState takes no request and cannot fail; the same class as the Agents value reads fixed in round 2.
  • Agents.md:162 replies a bare array for members, while the appendix returns MembersReply {members} and line 144 says every operation answers one reply object. Make the row {members: [...]}.
  • Agents.md:203 says a caller whose create_session reply is lost finds the Session "by the id it chose", but CreateSession has no caller id, and main's launch contract says a lost reply can leave a Session no caller knows about and no lookup is added (origin/main:docs/design/appserver/sessions-service.md section 6.1). State the accepted limit or add a creation identity.
  • Collaboration.md:100 says forking a member is refused, but the Agents fork_session contract does not list this refusal or raise it in Requirements; an Agents implementer can allow it and produce a member role with no leader. Current code refuses it (crates/dim-app-server/src/agents.rs:1954-1956). Add it to the Agents invalid row or to Collaboration's requirements.
  • Supersedes: Agents.md:288 and Collaboration.md:163 cite service-faces.md §3.1 for the collaborationDirectory removal, but the edited text is in §4.9 (docs/design/service-faces.md:339). Fix the section number.

Verification

  • git merge-base origin/main HEAD is 6e86d48; git merge-tree on origin/main and HEAD is clean; GitHub reports mergeable true.
  • node scripts/adr-check.mjs --base 6e86d48c8 passes (13 changed files), run with an isolated HOME/TMPDIR/XDG.
  • CI on 3d5ade8: ci-ok success; the docs jobs are skipped.
  • Link check: 335 docs, 0 new broken relative links or anchors against main; the round-2 set is resolved. External PR-file URLs are not checked; #2029, #2091-#2097, #2100 and #2102 are open.
  • Cross-PR: #2102's pending shape now matches. #2096 at 7cc7e87 still carries the sessions.permission / permissionDefaults({}) row in process-owner-operations.md:25, and #2097 at 9b87ef9 still has EventHub consume sessions.input, lookup, exists and defaultBranchId (EventHub.md:106,161,220); #2097's sessions-service.md is the old pre-#2098 content. Coordinate the rebase so these rows are not restored.
  • Not run: Rust compilation. The Agents appendix was checked statically against the current exports and derives; the Collaboration appendix has the path error above.

Withdraw or keep

Withdraw as fixed: expectedCwd, the pending shape, the duplicate import and AgentProfile in the Agents appendix, QuiesceReply, request-less permissionDefaults, the Target tagged shape, the anchors across the two pages and the forward relative links, plus the round-2 lease, ADR-number, delete-shape, notice and EndListener items.

Keep as open: the cross-Session caller scope, the idle-unloaded state and acquire path, the requireInactive behavior, the Collaboration appendix, and the P3 list above.


### Session access

This owner holds no line or Session object. A member line's owner is resolved by id and called directly: `(session, line)` reaches any branch-group data face except registration points and lifecycle services, `sessionId` any Session-group data face ([ADR 027](https://github.com/arcships/dim/pull/2029/files) D1, D3). Registering a tool, a method or a guide entry stays in this Session's own scope. An answer it needs from another Session — the leader's destination from the member's part — is the other Session's `collaborationSession` value read by session id. It does not read a line's Timeline to re-derive state another owner folds.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This is not a route ADR 027 D1 or #2127 defines. docs/design/contracts/session-access.md:9 says a Session-scope caller reaches its own line's owners with branchId; ADR 027 D1 (PR #2029 at 9e629e9) and #2127 define only process-to-Session by sessionId and (sessionId, branchId), and Session-to-own-branch by branchId. CollaborationSession and CollaborationTimeline are Session and branch parts, yet they call another Session's branch faces by (memberSession, line) and read the leader's collaborationSession value by sessionId (also CollaborationTimeline.md:60,93,128 and Agents.md:239). Failure: the leader line cannot write, stop or withdraw on the member line, and the member cannot resolve the leader's approval destination; an implementer must invent a route or move the calls to the process owner. Fix: either state that cross-Session calls are made by the process Collaboration owner and give the member part an operation on it, or extend ADR 027 D1 and #2127 to let Session and branch callers address another Session by id, with the visibility rule.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still open in c3acab3. docs/design/contracts/session-access.md:9 still limits a Session-scope caller to its own line, and docs/design/plugins/Agents.md:239 still says a Session-scope owner reaches another Session's collaborationSession value by sessionId; CollaborationSession.md:128,174 and CollaborationTimeline.md:60,93,128 rely on that path. ADR 027 D1 (docs/adr/027-cross-scope-access-by-id.md:24-25) defines only process-to-Session and Session-to-own-branch, and #2093's SessionScope contract states NoSession never reaches a Session part. The new wording and the D1 citation do not add a caller scope. The fix is unchanged: move cross-Session calls to the process Collaboration owner with an operation for the member part, or extend ADR 027 D1 and #2127 with a cross-Session segment and its visibility rule.

| `sessions.pending` | [InputQueue](https://github.com/arcships/dim/pull/2102/files)'s `pending({inputId, publishedCutoff?}) → {pending}` by `(session, line)` id; the owner's published head applies when the caller names no `publishedCutoff` |
| `sessions.history` | [TimelineTree](https://github.com/arcships/dim/pull/2092/files)'s `read(line, from, through, limit)` by `(session, line)` id |
| `sessions.defaultBranchId` | [TimelineTree](https://github.com/arcships/dim/pull/2092/files)'s `directory` for the Session; the default line is in the reply |
| `sessions.exists` | `session.state`: `deleted` and `unknown` answer false, `closed` and `loaded` answer true |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: An idle-unloaded Session has no state here, and mapping unknown to false is wrong for it. state is loaded, closed, deleted or unknown, and unknown is an id this process never saw (line 158), so an idle-unloaded Session with rows is none of them. EventHub reads sessions.exists and treats false as deleted, removing the Session's subscriptions (docs/design/plugins/EventHub.md:224-229); an idle-unloaded Session is restorable and must answer true. acquire also says it pins a loaded Session and its unknown error is "No loaded Session has the id" (lines 155,191), while ADR 027 D5 and #2127 say a target that is not loaded takes a hold and Agents loads the next generation; sessions-service.md:8 says the next call restores it. Current code answers true for an unloaded Session (crates/dim-app-server/src/agents/sessions.rs:606; crates/dim-app-server/src/agents/sessions/tests.rs:189,207). Failure: a scheduled or event input cannot recover an idle-unloaded target through a lease, and EventHub can drop subscriptions of a live restorable Session. Fix: add an unloaded state or treat unknown with stored:true as restorable, answer exists true when rows exist, and state that acquire restores an idle-unloaded Session.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partly addressed: 59e4316 renamed the error to session_closed. The rest is unchanged. Agents.md:155 still says acquire pins a loaded Session, :191 still says unknown means no loaded Session, :158 has no state for an idle-unloaded Session, and :229 still maps unknown to exists false. docs/design/appserver/idle-unload.md:26,210,342 says acquire restores an unloaded Session; origin/main crates/dim-app-server/src/agents.rs:929-984 does restore, and agents/sessions.rs:606 with agents/sessions/tests.rs:149-208 answers exists true for an unloaded Session with rows. EventHub.md:227-228 removes subscriptions on false. Add an unloaded state or treat unknown with stored:true as restorable, answer exists true when rows exist, and state that acquire restores an idle-unloaded Session.


`create_session.model` is a resolved `ModelSelection`. Absent, the owner asks Provider's `resolve` for the Agent profile's model and cwd. The reply carries the policy and model the Session was created with, so a caller records the authority a run got without a second read.

`delete_session` answers an in-use Session as a normal reply, not an error: `{removed: false, inUse: reason}`, which Rpc maps back to its `session_active` error; a delete that removed the Session answers `{removed: true}`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: requireInactive has no stated behavior. The operation takes it (line 153), and this paragraph says an in-use Session answers {removed:false, inUse} without saying whether that depends on the flag. Main's client contract says it defaults to false and without it the delete closes and removes an in-use Session; only true refuses session_active (docs/design/appserver/session-deletion-and-fork.md:78; crates/dim-app-server/src/connection.rs:1418-1431 calls delete_if_inactive only for true). Failure: implementing this literally makes dimcode session delete ID on a busy Session return session_active and remove nothing, contrary to the PR's "Client-visible changes: None". The unknown or already-deleted reply is also unstated. Fix: state true answers removed false with inUse, false deletes regardless of use, and an unknown id answers removed false without inUse, with Rpc's mapping for each.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still open in c3acab3; the delete section is unchanged. Agents.md:153 takes requireInactive, but :171 states only the in-use reply. origin/main:docs/design/appserver/session-deletion-and-fork.md:78 says the field defaults to false and without it the delete closes and removes an in-use Session; crates/dim-app-server/src/connection.rs:1418-1435 calls delete_if_inactive only for true. State true answers removed:false with inUse, false deletes regardless of use, and an unknown or already-deleted id answers removed:false without inUse, with Rpc's mapping to session_active and deleted: true/false.

```rust
#[derive(serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum Target { Agent { agent_id: String }, Profile { profile: crate::protocol::AgentProfile } }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This still does not compile and the untagged change dropped the field casing. crate::protocol::AgentProfile does not exist (crates/dim-app-server/src/protocol.rs has no AgentProfile; crates/dim-app-server/src/agents.rs:15 re-exports dim_agent_types::AgentProfile). With #[serde(untagged)] and no rename_all_fields, Target::Agent { agent_id } encodes as agent_id, not the {agentId} shape in the operations table at line 79 or the page's "camelCase fields" sentence at line 168. Failure: the copied enum fails to compile, and the table and binding disagree on the wire. Fix: use dim_agent_types::AgentProfile and #[serde(untagged, rename_all_fields = "camelCase")], or rename the field.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still open in c3acab3; Collaboration.md is unchanged. Line 173 still uses crate::protocol::AgentProfile, which does not exist (crates/dim-app-server/src/agents.rs:15 re-exports dim_agent_types::AgentProfile), and the untagged enum still has no rename_all_fields, so Target::Agent encodes agent_id instead of the agentId in the table at line 79 and the camelCase rule at line 168.


## 3. Flows

Superseded by the owners in the block table of [§1](#1-cross-scope-access-by-id).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: This stub says old section 3 is superseded by owners, but main's expectedConfig paragraph stayed in this page at section 2 (session-access.md:28), and docs/design/appserver/session-deletion-and-fork.md:303 still links #3-flows for the checked fork. Failure: the fork requirement lands on a stub that points away from its definition. Fix: make this stub link #2-attach-expectations.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still open in c3acab3: session-access.md:215 still says section 3 is superseded by the owners, while expectedConfig remains in section 2 and session-deletion-and-fork.md:303 links #3-flows for the checked fork. Point the stub at #2-attach-expectations.

@eric8810

Copy link
Copy Markdown
Collaborator Author

已按评审修改,head 59e4316d6。

跨 PR 对齐:

验证:node scripts/adr-check.mjs --base origin/main 通过;链接与锚点无新增断链。

@eric8810
eric8810 requested a review from yyhhyyyyyy November 24, 2026 06:14
@eric8810

Copy link
Copy Markdown
Collaborator Author

补充说明,head c3acab356(ADR 027 收回到决定层后):

  • session-access.md §1 的 id 访问引用改为 ADR 027 D1 + #2127,不再写 D2(ADR 027 D2 只用于“必须分清三种情况”)。
  • Agents.md 的 id 访问段改成链接,不再复述 D1/D3 的内容;机制需求段把 D2, D4 改为 D1, D4,路由由 #2127 定义。
  • Supersedes 补两条:session-access.md §7 的 “never exported over RPC entries or rutis links” 和 sessions-service.md 的 “Exposure” 行,均改为 ADR 027 D3 的可达范围。
  • 本 PR 不写 NoSession/SessionClosing/NoLine。

验证:node scripts/adr-check.mjs --base origin/main 通过;链接与锚点无新增断链。

@yyhhyyyyyy yyhhyyyyyy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: Agents and Collaboration owner contracts (round 4)

Scope: refs #2020 and #2015. This PR adds Agents.md, CollaborationSession.md and CollaborationTimeline.md, rewrites Collaboration.md, and replaces the sessions supplement in sessions-service.md and session-access.md with access by id under ADR 027. This round reviews the full main...head at c3acab3 and the delta over 3d5ade8.

Verdict: REQUEST_CHANGES

Round-3 status

Fixed in c3acab3: the closed_session spelling is now session_closed; SessionTitle's creation entry names create_session and links this contract; the two Supersedes clauses for session-access.md section 7 and the sessions-service Exposure row are recorded.

All four prior P2s remain open. The session_closed change is a rename only: docs/design/plugins/Agents.md:155,158,191,229 still define acquire only for a loaded Session and map an id this process never saw to no state and no existence answer. The new c3acab3 citations introduce P2-5, and the full-document read adds P2-6.

P2

P2-1. Collaboration's cross-Session calls still sit outside ADR 027's caller scopes

Problem: docs/design/contracts/session-access.md:9 still gives a Session-scope caller only branchId for its own line's owners. docs/design/plugins/Agents.md:239 says a Session-scope owner reached across Sessions is reached by sessionId, and docs/design/plugins/CollaborationSession.md:128,174 and docs/design/plugins/CollaborationTimeline.md:60,93,128 rely on that path for the leader's collaborationSession value and the member's branch faces. ADR 027 D1 (docs/adr/027-cross-scope-access-by-id.md:24-25) defines process-to-Session with sessionId and (sessionId, branchId), and Session-to-own-branch with branchId; it has no Session-to-other-Session or branch-to-other-Session segment. #2127's acceptance covers the same two segments, and #2093's SessionScope contract states NoSession never reaches a Session part (SessionScope.md:26 at 53961a1).

Failure scenario: the member's Session part cannot resolve the leader's approval destination, and the leader's branch part cannot write, stop or withdraw on the member line. An implementer either invents a route the mechanism does not define or moves the writes to the process Collaboration owner, which contradicts the ownership the three pages state.

Evidence: docs/design/contracts/session-access.md:9; docs/design/plugins/Agents.md:239; docs/design/plugins/CollaborationSession.md:128,174; docs/design/plugins/CollaborationTimeline.md:60,93,128; docs/adr/027-cross-scope-access-by-id.md:24-25; docs/design/plugins/SessionScope.md:26 at 53961a1.

Fix: state that all cross-Session calls are made by the process Collaboration owner and give the member part an operation on it, or extend ADR 027 D1 and #2127 with a cross-Session segment and the visibility rule for which Session a caller may address. The c3acab3 link to D1 does not add that scope.

P2-2. An idle-unloaded Session has no state, no exists answer and no acquire path

Problem: docs/design/plugins/Agents.md:158 defines state as loaded, closed, deleted or unknown, and unknown as an id this process never saw. An idle-unloaded Session with rows is none of these. Agents.md:191 says unknown means no loaded Session has the id, :155 says acquire pins a loaded Session, and :229 maps unknown to sessions.exists false. docs/design/appserver/sessions-service.md:8 says the next call restores an idle Session, and docs/design/appserver/idle-unload.md:26,210,342 says acquire restores it.

Failure scenario: EventHub's reconciliation reads sessions.exists for each stored subscription (docs/design/plugins/EventHub.md:227-228); false means deleted and removes the subscriptions. After a process restart, a durable subscription to a Session with rows but no live instance answers unknown and is removed. Separately, a scheduled or event input that finds NoSession takes a hold as #2127 says, and acquire refuses it, so the input is never delivered.

Evidence: origin/main already implements both behaviors: crates/dim-app-server/src/agents.rs:929-984 restores an unloaded Session in acquire, and crates/dim-app-server/src/agents/sessions.rs:606 with crates/dim-app-server/src/agents/sessions/tests.rs:149-208 answers exists true for an unloaded Session with rows.

Fix: add an unloaded state, or define unknown with stored: true as restorable; answer sessions.exists true when rows exist; state that acquire restores an idle-unloaded Session and returns its new generation; keep session_closed for a business close. This also needs store.sessionConfig in the dependency row at Agents.md:134, which a restore reads today (agents.rs:978-984; #2091 SessionStore defines it at SessionStore.md:114).

P2-3. delete_session still does not state requireInactive's behavior

Problem: docs/design/plugins/Agents.md:153 takes requireInactive, and :171 says an in-use Session answers {removed:false, inUse} without saying whether that depends on the flag. Main's client contract says the field defaults to false, and without it the delete closes and removes an in-use Session; only true refuses session_active (docs/design/appserver/session-deletion-and-fork.md:78; crates/dim-app-server/src/connection.rs:1418-1435 calls delete_if_inactive only for true). An unknown or already-deleted id answers {deleted:false} on main, which the Agents reply does not state.

Failure scenario: a client or dimcode session delete ID with no requireInactive that hits a running Session receives session_active and removes nothing, contrary to the PR's "Client-visible changes: None".

Evidence: docs/design/plugins/Agents.md:153,171; docs/design/appserver/session-deletion-and-fork.md:78 at origin/main; crates/dim-app-server/src/connection.rs:1418-1435.

Fix: state true answers removed:false with inUse, false deletes regardless of use, and an unknown or already-deleted id answers removed:false without inUse; give Rpc's mapping to session_active and to deleted: true/false.

P2-4. The Collaboration binding appendix still does not compile and loses the camelCase field

Problem: docs/design/plugins/Collaboration.md:173 still uses crate::protocol::AgentProfile. crates/dim-app-server/src/protocol.rs exports no AgentProfile; crates/dim-app-server/src/agents.rs:15 re-exports dim_agent_types::AgentProfile. The same line lost rename_all_fields = "camelCase" when it became untagged, so Target::Agent { agent_id } encodes as agent_id, not the {agentId} shape in the operations table at :79 and the camelCase rule at :168.

Failure scenario: a copied enum fails with E0433, and an implementation following the table and one following the binding disagree on the wire field.

Evidence: docs/design/plugins/Collaboration.md:79,168,173; crates/dim-app-server/src/agents.rs:15; crates/dim-app-server/src/protocol.rs exports no AgentProfile.

Fix: use dim_agent_types::AgentProfile and #[serde(untagged, rename_all_fields = "camelCase")], or rename the field explicitly.

P2-5. c3acab3 drops ADR 027 D2 from both routing citations

Problem: docs/design/contracts/session-access.md:9 now cites only D1 for the sentence "The mechanism routes the id ... the instance key never reaches the caller". D1 defines caller scopes; D2 (docs/adr/027-cross-scope-access-by-id.md:28-33) is the runtime routing and instance-key decision. docs/design/plugins/Agents.md:275 changed D2, D4 to D1, D4 for a requirement that says "The mechanism must route ..." and "the instance key never goes to the caller". D1 does not state the instance-key rule.

Failure scenario: an implementer who follows the citations omits D2's runtime index and instance-key constraints, or reads D1 as covering the cross-Session sentence at Agents.md:239, which D1 does not.

Evidence: ADR 027 D2 was not reduced to the three-case rule; the three cases are its last bullet. The prior fix in 88e76b6 cited D1, D2 for this sentence.

Fix: cite D1, D2, and D4 where the requirement also says the call is not a dependency.

P2-6. Collaboration's Team status contradicts the idle-unload contract

Problem: docs/design/plugins/Collaboration.md:91 says "a member that is not loaded is closed". docs/design/appserver/idle-unload.md:355 says the Team status of an unloaded member is idle, "as for any available Session". Collaboration.md:84 defines the status values as working, idle or closed.

Failure scenario: a client or the leader sees an idle-unloaded member as closed, which reads as a business close, while the idle-unload contract says the member is available and restorable. The same missing state as P2-2 makes the implementation unable to produce idle for an unloaded member.

Evidence: docs/design/plugins/Collaboration.md:84,91; docs/design/appserver/idle-unload.md:355.

Fix: report idle for a restorable unloaded member and closed only for a business close, and state how the read distinguishes them.

P3

  • Delete notice contract: docs/design/plugins/Agents.md:235 emits agent/session-deleted "after any other delete", which reads as excluding the unloaded case, while origin/main emits it for every delete that removed rows (crates/dim-app-server/src/agents.rs:1749-1774) and EventHub consumes only that event (docs/design/plugins/EventHub.md:226-227; crates/dim-event-hub/src/lib.rs:225). #2097's EventHub contract at ed43cd9 states the notice is emitted "loaded or unloaded" and uses it for the deletion path (EventHub.md:161), so the Agents sentence would break that consumer. State that an unloaded delete emits both notices. The dependency row at Agents.md:134 also omits store.owner, which fills agentId for a Session this process never loaded (#2091 SessionStore.md:35,112; current agents.rs:1730-1731).
  • Permalinks: CollaborationSession.md:12 still points at crates/dim-app-server/src/collaboration.rs:3535-3560 at 5a279d6, which is the plugin constructor and injections; the guide registration is at 3582-3610. CollaborationTimeline.md:12 points at 972-1080, the CollaborationSession struct and op_turn; the fact writes are elsewhere.
  • Request-less read: CollaborationTimeline.md:71 gives state a {} request and a closed error while the appendix state(&self) -> DelegationState takes no request and cannot fail.
  • Reply shape: Agents.md:162 replies a bare array for members, while Agents.md:144 says every operation answers one reply object and the appendix returns MembersReply { members } at :479.
  • Lost reply: Agents.md:203 says the caller finds a lost create_session reply "by the id it chose", but CreateSession has no caller id. Main's contract accepts that a lost launch reply can leave a Session no caller knows (origin/main:docs/design/appserver/sessions-service.md:232). State the accepted limit.
  • Fork refusal: Collaboration.md:100 refuses forking a member, but the Agents fork_session row at Agents.md:154 does not list that refusal; origin/main refuses it at agents.rs:1956. Add it to the invalid row or to Collaboration's requirements.
  • Section number: Agents.md:289 and Collaboration.md:163 cite service-faces.md §3.1 for the collaborationDirectory.relations removal, which is in §4.9 (service-faces.md:324-343).
  • Duplicate Supersedes bullet: Agents.md:281 and :283 both cover docs/design/appserver/sessions-service.md; merge them.
  • sessions-service.md:87 keeps the body fragment "#32 described the field as client-protocol data..."; it has no terminal punctuation and sits between two stubs. Finish or delete it.
  • session-access.md:215 says section 3 is superseded by the owners, but expectedConfig stayed in section 2 and session-deletion-and-fork.md:303 still links #3-flows for the checked fork; point the stub at #2-attach-expectations. session-access.md:265 keeps the "#5, used by the offline rows" paragraph inside the anchors block; move it to a kept section or delete it.
  • Examples: Agents.md:121 matches a Quiesce enum while the appendix defines QuiesceReply; Agents.md:79 calls collaboration.create_agent and create_session, but those are Agents operations, and no such methods are on the Collaboration interface.
  • PR-file anchors: session-access.md:199 links .../files#errors for the Agents, InputQueue and TimelineTree error tables; GitHub's PR files view has no heading anchors, so the links do not reach the tables. Use file paths once the owner pages land.
  • PR body: still says one agent/session-deleted notice and that both permission reads move to sessions.permission*; the head keeps three notices and removes sessions.permission. It also cites #2091 f7425d5, #2092 d968023 and #2093 4209c44, which are no longer the heads, and says #2093 states no requirement, while #2093 at 53961a1 raises #2127 at line 218.

Cross-PR

  • #2095 at fa2eea2 and #2096 at 9ca30e0 modify docs/design/contracts/process-owner-operations.md but still carry the old sessions rows at lines 12, 25 and 36-40. They must rebase on this contract or resolve by taking the new rows, not by taking the sibling file wholesale.
  • #2102 at 3b48e12 modifies docs/design/contracts/session-access.md and its head still deletes main's session.attach.expectedConfig paragraph and keeps the old sessions.withdraw row in A.4. This PR keeps expectedConfig, so #2102 must rebase; its head is not aligned with the file this PR produces.
  • #2091 at 8f9f5e1 still edits plugins/SessionTitle.md with sessions.launch, and #2099 at 8f440bd replaces the same page with launch wording. The create_session change here is consistent on its own, but the merged result needs one term and one owner for the paragraph.
  • #2097 at ed43cd9 still describes EventHub consuming sessions.input, lookup, exists and defaultBranchId (EventHub.md:106,161), while this PR deletes those names and maps exists to session.state. Either #2097 updates its rows or this PR records the follow-up; the Supersedes list only names Scheduler, Workflow, worktree-management and p6-p7-bindings.
  • process-owner-operations.md:40 assigns Provider a per-line "published adopted startup connection" read, but neither #2096's Provider contract nor #2102's PromptAdoption names the publisher or the value. Confirm with the Provider owner which operation or value is read.

Verification

  • node scripts/adr-check.mjs --base origin/main passes (13 changed files), run with an isolated HOME/TMPDIR/XDG under the review data directory.
  • Docs link check over the full tree: no new broken relative links or heading anchors against origin/main. The only difference is a pre-existing line anchor to a crate README.
  • CI on c3acab3: ci-ok success and changes success; the build, platform and scripts jobs are skipped for this docs change; the commit status is pending with no external statuses.
  • Not run: Rust compilation. The Collaboration appendix failures are verified against the current exports and serde attributes.

Withdraw or keep

Withdraw the round-3 approvalDestination invalid_request P3: the Rust method returns Option, and the HostDispatch layer can answer invalid_request for a malformed request, so the table and appendix are compatible. Withdraw the round-2 tagged Target shape P3: untagged is now right; only the path and the field casing remain in P2-4. Keep the earlier fixed-item withdrawals for expectedCwd, pending, the Agents appendix imports, delete shape, observe, notices, EndListener, Delivered casing, permissionDefaults and QuiesceReply serialization.

Keep as open: P2-1 to P2-6 and the P3 list.

| `SessionConfig` field `interactive` | Session record | Supplement |
| Session facade ([agent.rs](../../../crates/dim-agent-runtime/src/agent.rs), [branch.rs](../../../crates/dim-agent-runtime/src/branch.rs)) | Session, branch | Existing |
| InputQueue | Branch | Change: consumes `input/withdraw`, writes `input/deleted`; withdrawal service |
A process-scope caller reaches any Session-group data face with `sessionId` and any branch-group data face with `(sessionId, branchId)`; a Session-scope caller reaches its own line's owners with `branchId`. The address is not limited to input writes or published-value reads. The mechanism routes the id to the target instance's data-face dispatch; the instance key never reaches the caller, and the caller calls the owner's own operation ([ADR 027](https://github.com/arcships/dim/pull/2029/files) D1; [#2127](https://github.com/arcships/dim/issues/2127)). Nothing forwards by operation name, wraps a request or reply, or restates the owner's error. An unknown, unloaded or closing target ends resolution with the mechanism's own error.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This sentence now cites only D1 for the routing and instance-key rule. ADR 027 D1 defines the caller scopes; D2 (docs/adr/027-cross-scope-access-by-id.md:28-33) is the runtime routing and instance-key decision, and the three-case rule is its last bullet. Failure: a caller that follows D1 alone misses the runtime index and the rule that the instance key never reaches the caller. The same sentence gives a Session-scope caller only its own line, so it also does not cover the cross-Session reads at CollaborationSession.md:128 and CollaborationTimeline.md:60,93. Fix: cite D1 and D2, and state which caller scope may address another Session.


## Requirements raised to mechanism owners

1. **Route by id; the instance key never goes to the caller.** The mechanism must route a call to the Session group's data faces by `sessionId` and to the branch group's data faces by `(sessionId, line)`, so a caller reaches the owner's own operation without a facade, a forwarding object or an instance key ([ADR 027](https://github.com/arcships/dim/pull/2029/files) D1, D4; [#2127](https://github.com/arcships/dim/issues/2127)). Registration points (`sessionMethods`, `toolRegistry`) and lifecycle services are excluded (D3). The path must be available through rutis sessions to language runtimes and leaves, as other data faces are (D3); clients keep using Rpc. This is the same requirement TimelineTree records ([TimelineTree](https://github.com/arcships/dim/pull/2092/files)); Rpc, Provider, Collaboration, Scheduler, Workflow and EventHub depend on it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: D2, D4 became D1, D4, but the requirement's first sentence is D2: the mechanism routes the call and the instance key never goes to the caller. ADR 027 D1 is the caller scopes and D4 is "call by id is not a dependency"; neither states runtime routing or instance-key non-disclosure (docs/adr/027-cross-scope-access-by-id.md:28-33), and D2 was not reduced to the three-case bullet. Failure: an implementer reads the requirement without the index and key rule. Fix: cite D1, D2 and D4.

`close` closes the member Session through Agents' `close_session` and removes the relation. It does not close the leader, delete rows, or stop a turn: the branch part settles the request and stops the member's turn first, so ordering a close against a live turn is the branch's concern.

## 2. The guide entries
`team` reads each member's running state from Agents' `session` value; a member that is not loaded is `closed`, and a loaded member with a running turn is `working`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This conflicts with docs/design/appserver/idle-unload.md:355, which says the Team status of an unloaded member is idle, "as for any available Session". An idle-unloaded member is not loaded but is restorable, so reporting it closed reads as a business close. The same missing state as the Agents session enum (P2-2) prevents the implementation from telling them apart. Fix: report idle for a restorable unloaded member and closed only after a business close, and state the read that distinguishes them.

| Service | Purpose |
| --- | --- |
| The storage engine's private transactions | This owner's Agent and member records: write, delete and the startup sweep of owned Agents. The engine executes the transaction; it answers no business read or write for these rows on any face. |
| `store.create`, `delete`, `fork`, `title`, `hasRecords`, `creationRecord` | Session rows, titles, creation records and the row write of a creation, delete or fork. |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The row omits two store reads the target needs. store.owner fills the agentId of agent/session-deleted and agent/unloaded-session-deleted for a Session this process never loaded (#2091 SessionStore.md:35,112; origin/main crates/dim-app-server/src/agents.rs:1730-1731). store.sessionConfig is what an idle-unloaded restore reads today (agents.rs:978-984; #2091 SessionStore.md:114). Failure: the delete notice cannot name the owner, and acquire cannot rebuild a stored Session. Fix: add owner and sessionConfig to the row and name their uses in delete_session and acquire.


### Execution notices

Three process events stay, because their consumers see state `observe` cannot report: `agent/session-restored {agentId, sessionId, generation}` when a Session is restored for this process, `agent/unloaded-session-deleted {agentId, sessionId}` when a delete removed an unloaded Session's rows, and `agent/session-deleted {agentId, sessionId}` after any other delete removed the rows. Provider reattaches a retained startup connection on the restore event and releases it on the unloaded-delete event; Collaboration re-arms its member watch on the restore event and ends the relation on the unloaded-delete event; EventHub removes the Session's subscriptions on either delete event. They are rutis process events, not Timeline facts, and carry no state a caller folds (`observe` remains the per-generation end notification for callers that need the close/unload distinction).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: "after any other delete" reads as excluding the unloaded case, but origin/main emits agent/session-deleted for every delete that removed rows and also emits agent/unloaded-session-deleted for the unloaded case (crates/dim-app-server/src/agents.rs:1749-1774). EventHub listens only to agent/session-deleted (docs/design/plugins/EventHub.md:226-227; crates/dim-event-hub/src/lib.rs:225), and #2097's EventHub contract at ed43cd9 requires it for loaded and unloaded deletes (EventHub.md:161). Failure: an unloaded delete misses EventHub's notice and its subscriptions stay until a reconciliation read. Fix: state that an unloaded delete emits both notices, or change EventHub's contract to consume the unloaded event too.


| Operation | Intent | Request | Reply | Cancellation | Errors |
| --- | --- | --- | --- | --- | --- |
| `state` | This line's delegations as a value | `{}` | `{open: [{member, delegationId, requestEvent, delivered}], closing}` | None | `closed` |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The request is {} and the error is closed, while the appendix state(&self) -> DelegationState takes no request and cannot fail. This is the same shape mismatch the Agents value reads had in round 1. Failure: the wire and error contract cannot match the binding. Fix: mark the request as none and drop closed, or make the method return Result.

- **Restart.** A restart restores owned Agents as owned and members with their leader. It also recovers requests that have no `collaboration/result` yet: each recovered request is stopped on the line that holds the member input its `collaboration/delivered` fact names, never on the member's current default line; without that evidence recovery stops nothing and logs the skip.
- **Close.** `close` ends the member Session for this process, keeps its records, and ends its relation. A restart loads the member again as an ordinary Session its leader may address; closed is process state and is not stored.
- **Delete.** Deleting a leader ends its Team through Agents' `delete_session`: each member's own delete runs first, then each owned Agent closes and its record goes, then the leader. There is no transaction across the Team: a failure midway leaves the leader with part of its Team gone, and a retry finishes.
- **Fork.** Forking a member is refused: the fork would carry the member's role and Agent but no leader.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: Forking a member is refused here, but the Agents fork_session row (Agents.md:154) does not list the refusal, and origin/main refuses it (crates/dim-app-server/src/agents.rs:1956). Failure: an Agents implementer can allow a fork that carries a member role with no leader. Fix: add the refusal to fork_session's invalid row or to this page's requirements.

| `sessions` | The loaded Sessions' value | — | `{sessions: [{sessionId, agentId, generation, closed, running}]}` | None | — |
| `defaults` | The process Session defaults | — | `SessionConfig` | None | — |
| `instance` | The protocol instance of this generation | — | `{instanceId}` | None | — |
| `members` | The member links this owner recorded | `{leaderSessionId?}` | `[{memberSessionId, leaderSessionId, memberAgentId}]` | None | `closed` |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: This reply is a bare array, while line 144 says every operation answers one reply object and the appendix returns MembersReply { members } at line 479. Failure: the wire reply and the binding disagree. Fix: make the row {members: [...]}.


| Operation | Normal path | Caller cancels | Caller unloads | Owner closes or reloads | Settled by |
| --- | --- | --- | --- | --- | --- |
| `create_session` | Take the process hold, resolve the model, cap the policy, create the worktree, write the rows through SessionStore, build the instance, record the version, answer the ids | Before the rows commit: rows removed, worktree discarded, nothing published | The creation runs as the owner's admitted work and reaches its end; the reply may be lost, and the caller finds the Session by the id it chose or by `sessions` | Admission stops; an admitted creation finishes or is rolled back; a reloaded directory logic serves the next call | Rows by SessionStore; worktree by ManagedWorktrees; instance, slot and version by Agents |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The caller cannot find a lost create_session reply "by the id it chose": CreateSession has no caller-supplied id. Main's contract accepts that a lost launch reply can leave a Session no caller knows (origin/main:docs/design/appserver/sessions-service.md:232). Failure: the contract promises a recovery the request cannot perform. Fix: state the accepted limit, or add a caller creation identity.


- `docs/design/appserver/sessions-service.md`: the `sessions` service, its methods and its decisions D1–D14; the page keeps only the lifecycle, submission-identity and authority facts.
- `docs/design/contracts/session-access.md`: the `sessions` method table (A.1), its errors (A.6), the `sessions` rows of §1 and §6, and the Rust binding (Appendix E). Section 7's "never exported over RPC entries or rutis links" becomes [ADR 027](https://github.com/arcships/dim/pull/2029/files) D3's reach.
- `docs/design/appserver/sessions-service.md`: the "Exposure" row becomes [ADR 027](https://github.com/arcships/dim/pull/2029/files) D3's reach.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: This duplicates the sessions-service.md bullet at line 281. Failure: the Supersedes list names the same document twice and reads as two removals. Fix: merge the Exposure clause into the line 281 bullet.

@eric8810

Copy link
Copy Markdown
Collaborator Author

Closing as part of abandoning the owner-split experiment.

@eric8810 eric8810 closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants