Skip to content

docs(adr): let the holder of an instance choose it by id in ADR 027 - #2200

Merged
eric8810 merged 5 commits into
mainfrom
dim/2127-adr027-holders
Nov 25, 2026
Merged

eric8810 merged 5 commits into
mainfrom
dim/2127-adr027-holders

Conversation

@eric8810

Copy link
Copy Markdown
Collaborator

ADR 027 原来要求运行时另建一个路由机制和索引。这一版改成:由持有实例的一方,按 id 选出目标。

为什么改

  • 跨语言的调用只能传数据,不能传对象。rutis 是外部依赖,不向它提需求(§4 规则 8)。
  • 部件只能注入本实例和外层实例的服务(ADR 002 D3)。
  • 所以往里调用一层,只能由持有子实例的一方按 id 选出目标:Agents 选 Session,Session 选自己的线。
  • 单独建一个路由对象,等于多一层转发;另建一份索引,等于和持有者手里的表重复。

改了什么

  • D1:禁止的是"每个操作各开一个转发方法"。按 id 选目标的调用不带业务含义,请求和回复原样传递,不算转发。
  • D2:由持有者用已有的表选出目标,选中后调用目标所有者在 catalog 中的操作本身,所有者不用登记。
  • D3:Rust 用同一组数据操作,没有按类型取对象的入口。
  • D5:经 sessions 的一次调用,Agents 在调用期间保持 Session 加载,和现在的 sessions 方法、Rpc 一样。
  • D6:Agents 的职责加上"按 sessionId 选 Session";方法的去向改为链接 所有者扫描:Agent 目录与协作 #2020。
  • 删掉"向机制所有者提出的需求"一节。
  • 不做的事里补一条:sessionMethods 继续只服务客户端协议。
  • principles §7 里引用 ADR 027 的那句,按新写法改了措辞。

写法和错误在 #2127 定义,实现在 #2174。

Refs #2127
Refs #2015

Cross-language calls carry data only, and a part cannot inject the services of
an inner instance. So each step inward is taken by whoever already holds the
inner instances: Agents chooses a Session, a Session chooses its own line. No
routing object or extra index is added, and the call reaches the target
owner's own catalog operation.

- D1: a per-operation forwarder is what is ruled out; the addressed call is not one.
- D2: the holders choose by id from the tables they already keep.
- D5: a call through sessions keeps the Session loaded for its duration.
- D6: Agents also owns choosing a Session by id.
- The mechanism requirement section is removed; sessionMethods stays as it is.

Refs #2127
Refs #2015

@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: #2200 docs(adr): let the holder of an instance choose it by id in ADR 027

Reviewed head 1c3ad6d9 against origin/main c8417f1f; merge base 3f83c159. The diff is 2 files, +26/-30. Verdict: REQUEST_CHANGES.

The ADR replaces the proposed runtime router and its index with holder-based selection: Agents selects a Session by sessionId from its session table, and a Session selects its own line by branchId from its branch table. The change also updates the principles §7 pointer and removes the mechanism-owner requirements section. The direction matches the maintainer decision recorded in #2127. The §4 rule 8 citation is correct: docs/architecture/rust-agent/principles.md:70-76 says rutis is an external dependency and no requirement is raised to it. The two tables exist: AgentIndex::session (crates/dim-app-server/src/agents.rs:626) and the Session line directory (crates/dim-agent-runtime/src/agent.rs:641-647), resolved by id at crates/dim-agent-runtime/src/route.rs:197-207. #2020's 2026-11-25 decision comment contains the method-to-removal table.

Three P2s remain. The first two are direct contradictions with the linked implementation #2174 at f5d21296; the third is a rules-text contradiction.

P2: D3 forbids a Rust typed entry that the linked implementation still exposes

Problem: D3 says Rust uses the same data operations and has no separate type-based object entry (docs/adr/027-cross-scope-access-by-id.md:46), and D2 says the caller gets no object (:37). #2174 exposes both: crates/dim-agent-runtime/src/route.rs:255-264 defines LineHandle::get<T>() -> Routed<Arc<T>> and :269-274 defines session_face<T>() -> Routed<Arc<T>>. #2174's PR body also lists line(&scope, lineId).get::<InputQueue>()?.withdraw(id) and session_face::<T>(&scope)? as the Rust shapes.

Failure scenario: a Rust caller keeps the typed entry, so the same owner operation has a second public path that returns a live Arc<T> instead of passing data through the selected data face. D3's one-entry rule is bypassed: a plugin can reach the owner object without going through the data face, and the cross-language path and the Rust path no longer use the same operations. This is the deviation the #2127 decision was meant to remove, not a binding detail.

Fix: remove LineHandle::get and session_face from #2174 and have Rust build the operation's request args and decode the reply, as D3 says; or change D2/D3 if the typed entry is intended. The PR body says the implementation is in #2174, so the two cannot stay different.

P2: D5 requires loading an unloaded Session, but #2174 answers NoSession

Problem: D5 says a sessions call keeps the target Session loaded for the call and loads it first if it is not loaded, so only a Session that does not exist is absent (docs/adr/027-cross-scope-access-by-id.md:59). #2174's AgentIndex::call uses self.live(&id) and returns NoSession when it is missing (crates/dim-app-server/src/agents.rs:1645-1650); live looks up the owner and calls host.agent.get_session(id) (:1686-1690), and its doc says a single call needs no hold because the Session is either live now or not. #2174's "Still open" also records that the hold is approximated by Agent::restore_session until #2020.

Failure scenario: a process caller calls sessions.call for an idle-unloaded Session. The call returns NoSession, which D5 reserves for a Session that does not exist; the caller stops or creates a new Session instead of retrying after the load. The current behavior and the ADR cannot both be right.

Fix: implement the load and call-time keep in #2174's sessions.call, as the #2127 decision says, or state in D5 that this part is not implemented yet and #2174 remains a target. If D5 is the decision, #2174 is the side to change.

P2: The new generic dispatch still conflicts with principles §7

Problem: The changed sentence in principles §7 says a caller outside the scope reaches the owner through the holder by id (docs/architecture/rust-agent/principles.md:127). The next paragraph still says no forwarding-only facade, command, control or host object is created for callers (:129). The decided shape adds sessionScope.call and sessionScope.lineCall, and sessions.call, generic data faces whose only job is to select a target by id and invoke another owner's operation (crates/dim-agent-runtime/src/route.rs:165-184, :214-244; crates/dim-app-server/src/agents.rs:1641-1672). ADR 027 D1 says these are not forwarding (docs/adr/027-cross-scope-access-by-id.md:27), but §7 does not contain that exception. #2174's sessionScope is also a new service, so D2's no-new-route-object sentence (:35) reads as true only if the new service is classified as the holder's data face.

Failure scenario: a future owner design follows §7 literally, rejects sessionScope and sessions.call as forwarding facades, and removes the path #2174 uses; or a reviewer accepts the ADR's label and misses that the generic face is a second interface for the same operations. The design set gives two answers.

Fix: add the D1 carve-out to §7, for example forbid per-operation forwarding facades and state that an id-selection data face on the holder is the holder's operation, with a pointer to ADR 027. One sentence in §7 is enough. The current split between the rule and the ADR is the defect.

P3 notes (optional)

  1. #2127 still owns the mechanism in its title and body: the title says the runtime routes by id and the body says the owner is the dim runtime and calls this mechanism base-1. This ADR removes the runtime mechanism and says no new mechanism is added (docs/adr/027-cross-scope-access-by-id.md:35, :78). The PR body points to #2127 for the shape and errors. Update the issue title and body to the holder shape, or add a note in the ADR that the issue body predates this decision. Otherwise the linked contract gives the opposite ownership.
  2. docs/design/contracts/session-access.md:7 still lists the sessions methods and says process plugins reach Sessions through the public Session interface; :533 uses Session::service::<InputQueue>(branch). docs/design/appserver/sessions-service.md:33, :52 and :614 still say withdraw and delete forward. The Consequences section says these documents are superseded by the Agents contract and their reach clauses change to D3 (docs/adr/027-cross-scope-access-by-id.md:76), but neither document says so. Add a superseded banner or land the #2020 edits; until then the old access path is still the only written one.
  3. D1's carve-out says the selection call passes requests and replies through (docs/adr/027-cross-scope-access-by-id.md:27), but not errors. #2174 returns sessions.call failures as SessionsError::Routed { routing, name, message } (crates/dim-app-server/src/agents/sessions.rs:296-306). If the owner's failure is meant to travel as data, state that here and point to the #2127 error shape; otherwise the not-forwarding carve-out and the error envelope still disagree.
  4. D2 names the optional line id branchId (docs/adr/027-cross-scope-access-by-id.md:33), while #2174's request field is lineId (crates/dim-app-server/src/agents/sessions.rs:27-40) and the PR body uses lineId. D1 says branchId is the line id, but the wire name is not stated. Use one name or state the binding name; a caller following D2 can send branchId and be rejected by deny_unknown_fields.

Verification

  • node scripts/adr-check.mjs --base origin/main: ADR freeze passed for 2 changed files.
  • git diff --check origin/main...HEAD: clean.
  • Relative links and anchors in both changed files resolve; the linked ADR, contract and design files exist.
  • CI at this head: ci-ok and changes pass; every other job is skipped for the docs-only change.
  • Worktree clean at 1c3ad6d9; no local services or processes.

Cross-PR

  • #2174 is an open draft at f5d21296; the implementation claims above are against that head.
  • #2020's 2026-11-25 decision comment gives the method-to-removal table; the older table in the issue body is not the current one.
  • #2200 has no reviews and no review threads at this head.

Unverified

  • #2174 was read at f5d21296 but not built or run; the code-line claims are static. A later #2174 head may change them.
  • The #2020 documentation edits are not in this PR; note 2 is a follow-up.

- 也不包括作用域的生命周期服务。
- 各语言用同一条路径:
- Rust 插件在进程内调用;
- Rust 插件在进程内调用,用的是同一组数据操作,不另有按类型取对象的入口;

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.

D3 forbids the Rust typed entry that the linked implementation still exposes. At #2174 f5d21296, crates/dim-agent-runtime/src/route.rs:255-264 defines LineHandle::get<T>() -> Routed<Arc<T>> and :269-274 defines session_face<T>() -> Routed<Arc<T>>; #2174's PR body lists both as the Rust shape. That is the type-based object entry this line rules out and the object D2 says the caller cannot get. Remove both from #2174, or change D2/D3 if they are intended. P2.

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.

Not fixed in f837bd63a1: #2174 is still at f5d21296, and both entries remain. LineHandle::get<T> is at crates/dim-agent-runtime/src/route.rs:255-264; session_face<T> is at :269-274. The #2174 comments request their removal, but the head has not changed. D3 is correct; this stays open until #2174 changes.

- 进程调用方需要一个 Session 在多次调用之间保持加载,或者目标未加载,向 Agents 取一个保持;单次调用在调用后释放。
- 保持属于调用方的 loader row,在调用方释放或该 row 卸载时结算。
- 保持只决定 Session 是否加载,不提供对 Session 内部的访问。
- 进程调用方经 `sessions` 的一次调用,由 Agents 在调用期间保持目标 Session 加载:Session 未加载时先加载,调用结束后释放。所以只有 Session 不存在时才是「Session 不在」。这与现在的 `sessions` 方法和 Rpc 相同。

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.

D5 is not implemented in the linked #2174 at f5d21296. crates/dim-app-server/src/agents.rs:1645-1650 uses self.live(&id) and returns NoSession when the Session is not loaded; live looks up the owner and calls host.agent.get_session(id) (:1686-1690), and its doc says a single call needs no hold. An idle-unloaded Session therefore answers NoSession, while this line says Agents loads it first. Implement the load and call-time keep, or state that D5 is not implemented yet. P2.

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.

Not fixed in f837bd63a1: the new D5 sentence adds the closed and unloadable case, which matches #2127, but AgentIndex::call still uses self.live(&id) and returns NoSession for an idle-unloaded Session (crates/dim-app-server/src/agents.rs:1645-1650; live at :1686). It does not load. The ADR text is right; #2174 must change.

**交对象是最后手段。** id、值与回调都做不到时才交出对象。一旦交出对象,就要在更高一层统一设计相关插件的生命周期与边界:谁创建、谁持有、交接顺序、谁收尾、任何一方关闭或重载时如何处理,写进各方共同引用的设计中。资源句柄只能整体转移:接收方成为它的所有者并负责结算,交出方不再为它负责;交出后仍要交出方收尾的句柄,是待改的差距。"热路径"本身不是交出对象的理由。

**不代查别人的资源。** 一个所有者不替别的所有者返回它的资源或数据,也不替它接收写入;调用方直接请求数据的所有者。调用所有者的操作不是替它决定:所有者在操作内自己决定,结果事件由它按第 4 节规则 1 写。调用方在外层作用域时,按 id 经机制直达所有者([ADR 027](../../adr/027-cross-scope-access-by-id.md))。有性能需求时重新定义归属,而不是增加代查。从公开事件折叠出的投影是投影者自己的状态,发布它的部件就是它的所有者。
**不代查别人的资源。** 一个所有者不替别的所有者返回它的资源或数据,也不替它接收写入;调用方直接请求数据的所有者。调用所有者的操作不是替它决定:所有者在操作内自己决定,结果事件由它按第 4 节规则 1 写。调用方在外层作用域时,经持有目标实例的一方按 id 直达所有者([ADR 027](../../adr/027-cross-scope-access-by-id.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.

The changed sentence points at the holder path, but the next paragraph still forbids forwarding-only facades (docs/architecture/rust-agent/principles.md:129). #2174's sessionScope.call and lineCall, and sessions.call, are generic data faces whose only job is to select by id and invoke another owner's operation (crates/dim-agent-runtime/src/route.rs:165-184, :214-244; crates/dim-app-server/src/agents.rs:1641-1672). ADR 027 D1 calls them not forwarding, but §7 does not. Add the carve-out here, or remove the generic faces. P2.

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 f837bd63a1. docs/architecture/rust-agent/principles.md:129 now says a holder's id-selection data face is not a forwarding facade, and only per-operation forwarders are forbidden. ADR 027 D1 says the same. One optional follow-up: section 7.2's checklist at :156 still reads absolute.

…DR 027

- §7 states that an id-selection data face on the holder is not a forwarding
  facade; a per-operation forwarder still is.
- D1: the owner's errors pass through unchanged; the field naming the line is
  the binding's, defined in #2127.
- D2: the Session-side selection is the Session's own data face.
- D5: a closed Session that cannot load again is also absent.

Refs #2127
@eric8810

Copy link
Copy Markdown
Collaborator Author

感谢评审。改动在 f837bd6,逐条说明如下。

P2-1 Rust 按类型取的入口:成立,要改的是 #2174。ADR 的 D2、D3 就是决定本身,#2174 还没跟上。已经在 #2174 要求删掉 LineHandle::get 这类按类型取的入口(评论 1、评论 2),#2127 的已定决定里也写了。session_face::<T> 属于同一类,一并删掉。#2174 还是 draft,合并前要和 ADR 一致。

P2-2 D5 加载:成立,同样要改的是 #2174。sessions.call 在调用期间用 Agents 现有的 acquire 加载并保持 Session,见上面评论 2 的第 2 项。

P2-3 §7 没有写例外:成立,已改。§7「一套公开面」一段加了一句:持有实例的一方按 id 选目标、再调用目标所有者自己操作的数据面,不是转发门面;禁止的是为某个操作单独开的转发方法。D2 也补了一句:Session 一侧的调用属于 Session 自己的数据面,Session 自己的读取也由它提供(#2025),所以它不是只做路由的对象。

P3-1 #2127 的标题和正文:已改。标题改为「按 id 调用:由持有实例的一方选目标(base-1)」。正文改成持有者的写法,错误、调用方的下一步和验收也按 D5 改了:空闲卸载以后会先加载,不再回答 NoSession。

P3-2 Session 访问契约和 sessions 服务设计:成立,在 #2020 改。这两份文档要等 Agents 契约落地时一起改,一个所有者在一个改动里完成。#2020 的已定决定已经写明:那个 PR 要在两份文档开头注明被取代,可达范围改为 D3。

P3-3 错误:已改。D1 写明目标所有者的错误原样传递,只有选不中时才由持有者回答三种错误,错误的形状在 #2127 定义。#2174 的 Routed { routing, name, message } 保留了所有者错误的名字和内容,和这一点一致。

P3-4 branchId 和 lineId:已改。ADR 按惯例只用 branchId 这个词,调用里的字段名由绑定决定,D1 写明在 #2127 定义。#2127 定的是 lineId。

自查:node scripts/adr-check.mjs --base origin/main 通过,git diff --check 没有问题。

@zerob13 zerob13 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.

Holder-based selection is the right direction, and the revised §7 distinction is clear. The ADR still needs three observable contract boundaries before the implementations adopt it:

  1. D2, branch visibility: During branch opening, a runtime entry can exist before the branch is published. Specify the publication boundary: process-scoped and Session-scoped calls must agree on whether the branch is selectable, without a second directory acquiring an independent lifecycle. The choice of implementation is not prescribed.
  2. D5, existing holds: The blanket statement that no caller needs a hold between operations conflicts with current Collaboration requests and RPC attachments. Scope the per-call lease to the new call path. An outstanding Collaboration request must still keep the member loaded until settlement, and an attached client until detach. Changing either is a separate product decision.
  3. D1/D2, admission errors: An Agents reload or a stored Session failing to restore is not a permanently absent target. Define the caller-visible outcomes, here or in the referenced contract, so reload can be retried, restore failure can be surfaced, and only genuine absence is final. No target operation should dispatch on these errors.

The docs checks passed. The linked draft’s typed helpers and load-on-call implementation are tracked there, not separate blockers for this ADR.

…ds in ADR 027

- D2: a branch is selectable once published and not after it ends, the same for
  both paths; an Agents reload or a failed restore is not an absent Session, and
  is answered before the target operation runs.
- D5: the per-call keep applies to the new call path only; Collaboration
  requests and client attachments keep their holds.

Refs #2127
@eric8810

Copy link
Copy Markdown
Collaborator Author

@zerob13 感谢评审,三点都成立。改动在 6a186a6。

1. 分支什么时候能被选中:D2 加了一条:分支发布之后才能被选中,结束之后就选不中了。还在建立、尚未发布的分支,进程调用方和 Session 部件看到的都是「分支不在」,两条路径看的是同一份发布状态。
#2174 里 SessionAssembly 新加的 lines 表,在线发布之前就能查到线(assembly.rs:1566),正是你说的第二张表。已在 #2127 写明要去掉它,改查 TimelineTree 的 published。

2. 已有的保持:D5 原来那句「现在没有调用方需要」是错的,已删掉。现在 D5 只规定新调用路径上的保持。Collaboration 的请求(结果写回之前)和客户端 attach(detach 之前)原有的保持都不变,要改它们是另外的产品决定。

3. 加载失败:D2 加了一条:加载失败不等于 Session 不在。Agents 重载时可以重试;恢复失败时,把原因交给调用方。只有不存在或已关闭才是最终结果。这些情况都在调用目标操作之前回答。
具体错误写在 #2127:新增 SessionReloading(稍后重试)和 SessionUnavailable { reason }(报告原因,不重试),并写了 acquire 各种失败分别对应哪个错误,以及对应的验收。

adr-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: #2200 docs(adr): let the holder of an instance choose it by id in ADR 027

Reviewed head f837bd63a1 against origin/main c8417f1f. The PR is 2 files, +28/-31; this round adds +5/-4. Verdict: REQUEST_CHANGES.

The direction is right and unchanged: Agents selects a Session by sessionId, the Session selects its own line by branchId, and an id-selection data face on the holder is not a per-operation forwarding method. The new principles section 7 carve-out and the D1 error text close the round-1 rules-text contradiction. One P2 remains, and the linked draft still does not match the ADR in several places.

P2: D5 still denies the holds that current callers use

The earlier review's P2 is correct. docs/adr/027-cross-scope-access-by-id.md:62 says no caller needs a hold between calls, but an open Collaboration request holds its leader until its result is written (crates/dim-app-server/src/collaboration.rs:9-10, :869-875, :2253-2257) and an RPC attachment holds a SessionUse until detach (crates/dim-app-server/src/connection/subscription.rs:19-24; crates/dim-app-server/src/agents.rs:195-196). If this sentence is the contract, a later change removes those holds and idle unload ends a leader with an open request or a Session with an attached client. Scope the per-call lease to the new call path and keep the existing multi-call holds, or delete the blanket sentence. P2.

P3: D1 says owner errors pass through, but #2174 flattens them

Problem: D1 (:27) now says the owner's error passes through unchanged. At #2174 f5d21296, sessions.call maps every RouteError to SessionsError::Rejected { message: format!("{}: {error}", error.code()) } (crates/dim-app-server/src/agents/sessions.rs:925-930); SessionsError::Routed (:300-307) is never constructed. The author's reply says Routed carries the owner's name; that is not true at this head. The scheduler test asserts error.code == "rejected" and message substrings (crates/dim-agent-scheduler/tests/data_faces_flow.rs:828-870), and Rejected.retryable() is false (sessions.rs:338-343), so an owner Reloading failure becomes permanent.

Failure scenario: a process caller cannot recover the owner's error name or retry policy. Fix: construct Routed from RouteError::Owner in #2174, or use the #2127 shape, and state where the wire shape is defined. The ADR text is correct. P3 for the linked draft.

P3: D2 says no new index, but #2174 adds one

Problem: D2 (:36) says each layer reads the holder's existing table and no new index is built. #2174 adds SessionAssembly.lines: Mutex<HashMap<String, Weak<TimelineContext>>> (crates/dim-agent-runtime/src/assembly.rs:1143-1145), fills it in register_line (:1166-1169) at :1566, and resolves lines from it (:1176). Session::branches() returns Vec<TimelineInfo> (crates/dim-agent-runtime/src/agent.rs:641-647), so this is not the existing directory. The entry is registered before TimelineContext::activate (crates/dim-agent-runtime/src/timeline_context.rs:234-238), so the table is also the one behind the opening boundary the earlier review raised.

Failure scenario: a reviewer applying D2 literally rejects the map #2174 needs; or the map stays undocumented and its entry lifetime is undefined. Fix: name the map as the Session's own line table and state when an entry is selectable, or have #2174 use the existing directory. Reword "existing table, no new index" if a new map is intended. P3.

P3: small consistency points

  1. Section 7.2's checklist (docs/architecture/rust-agent/principles.md:156) still says no forwarding facade without the per-operation exception now at :129.
  2. docs/adr/027-cross-scope-access-by-id.md:28 refers to plain #2127 while the other references are links. Link it.
  3. D5 (:60) says this is the same as the current sessions methods and Rpc, but exists never loads (docs/design/appserver/sessions-service.md:46-48). Scope the sentence to the selection path.
  4. docs/design/contracts/session-access.md:7 and :533 and docs/design/appserver/sessions-service.md:30-33, :52-53, :614-615 still describe the old path. Tracked in #2020; not resolved here.

Carried round-1 P2s: no ADR text change needed

  • D3 typed entry: docs/adr/027-cross-scope-access-by-id.md:47 is correct and unchanged. #2174 still exposes LineHandle::get<T>() -> Routed<Arc<T>> (crates/dim-agent-runtime/src/route.rs:255-264) and session_face<T>() -> Routed<Arc<T>> (:269-274). Remove both before #2174 leaves draft.
  • D5 load: docs/adr/027-cross-scope-access-by-id.md:60 now matches #2127. #2174 AgentIndex::call still uses self.live(&id) and returns NoSession for an idle-unloaded Session (crates/dim-app-server/src/agents.rs:1645-1650; live at :1686). The ADR needs no change; #2174 does.

Verification

  • node scripts/adr-check.mjs --base origin/main: ADR freeze passed for 2 changed files.
  • git diff --check origin/main...HEAD: clean.
  • Relative links and anchors in both changed files resolve.
  • Head f837bd63a1; PR open and not draft. CI: ci-ok and changes pass; every other job is skipped for the docs-only change.

Cross-PR

  • #2174 is an open draft at f5d21296. Its typed helpers, live-only lookup, and Rejected error mapping are static claims at that head. #2127 now matches D1, D2, and D5. #2020 owns the superseded-document banners. No conflict with main.

Unverified

  • #2174 was read at f5d21296, not built or run. The code-line claims are static; a later head may change them.
  • The #2020 and #2127 edits are outside this PR.

Withdraw / keep

  • Withdrawn: round-1 P2-3 (fixed in f837bd63a1), P3-1 (#2127 updated), P3-3 (D1 now covers errors), P3-4 (field name now stated), and the round-1 claim that the Session line directory is an existing line-to-context table.
  • Keep P2-1 and P2-2 against #2174, not as text changes to #2200.
  • P3-2 remains the tracked #2020 follow-up.

- Session 作用域的调用方:用 `branchId` 到达本 Session 分支组的数据面。`branchId` 就是分支线的 id(line id)。
- 调用方直接调用目标所有者自己的操作。中间的所有者不按操作名转发,不包装请求或回复,也不转述目标所有者的错误。
- 调用方直接调用目标所有者自己的操作。中间不为某个操作单独开转发方法(例如 `sessions` 现在的 `withdraw`、`pending`),不改写请求或回复,也不转述目标所有者的错误。
- D2 中按 id 选目标的调用不算转发:它不带业务含义,对每个操作都一样,请求、回复和目标所有者的错误原样传递;只有选不中时,才由持有者回答 D2 的三种错误。错误的形状在 [#2127](https://github.com/arcships/dim/issues/2127) 定义。

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.

D1 now says the owner's error passes through unchanged, but #2174 at f5d21296 maps every route failure to SessionsError::Rejected { message: format!("{}: {error}", error.code()) } (crates/dim-app-server/src/agents/sessions.rs:925-930); SessionsError::Routed (:300-307) is never constructed. The scheduler test asserts error.code == "rejected" and a no_session message for an absent Session, and no_session or no_line message substrings for a closed Session and a missing line (crates/dim-agent-scheduler/tests/data_faces_flow.rs:828-870). Rejected.retryable() is false (sessions.rs:338-343), so an owner Reloading failure becomes permanent. #2174's own docs/design/contracts/runtime-owner-operations.md:35-40 says errors pass through. Fix #2174, or name the flattening in #2127 or #2020. The ADR text is correct. P3 for the linked implementation.

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 at #2174 f5d2129: sessions.call maps every RouteError to SessionsError::Rejected (crates/dim-app-server/src/agents/sessions.rs:925-930); Routed (:300-307) is never constructed and Rejected.retryable() is false (:338-343). The ADR text is correct; fix #2174.

### D3. 可解析的只有目标作用域的数据面
- Session 由 Agents 持有:进程调用方经 Agents 的 `sessions`,按 `sessionId` 选 Session,可选再带 `branchId`。
- 分支由它所在的 Session 持有:Session 部件经本 Session 自己的数据面,按 `branchId` 选本 Session 的分支。它不能指定别的 Session。这个数据面是 Session 这个持有者自己的操作,不是只做路由的对象;Session 自己的读取也由它提供([#2025](https://github.com/arcships/dim/issues/2025))。
- 每一层查的是持有者已有的表:Agents 的 Session 表、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.

D2 says each layer reads an existing table and no index is added. #2174 adds SessionAssembly.lines: Mutex<HashMap<String, Weak<TimelineContext>>> (crates/dim-agent-runtime/src/assembly.rs:1143-1145), fills it in register_line (:1166-1169) at :1566, and resolves lines from it (:1176). Session::branches() only returns Vec<TimelineInfo> (crates/dim-agent-runtime/src/agent.rs:641-647). The entry is registered before TimelineContext::activate (crates/dim-agent-runtime/src/timeline_context.rs:234-238), so a line can be selected during opening, before it is published, and D2 does not say whether that is a selection miss or an owner result. Define the entry lifetime (for example selectable from Active until Closing) and reword "existing table, no new index" if the map is intended. P3.

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.

ADR side fixed in 6a186a6c5: D2 now requires publication before selection and one shared published state. #2174 at f5d2129 still resolves through SessionAssembly.lines, registered before activate (crates/dim-agent-runtime/src/assembly.rs:1166, :1566; route.rs:197-209), so #2174 must drop the map and use TimelineTree::published plus the is_closing check. No further ADR change.

…sion

- §7.2's review check carries the holder's id-selection exception.
- D5 compares only with sessions methods that take the Session; exists does
  not load it.
- Link #2127 in D1.

Refs #2127
@eric8810

Copy link
Copy Markdown
Collaborator Author

这一轮评审看的是 f837bd6。D5 和线的表这两点,已经在之后推送的 6a186a6 里改了,见上一条回复。

P2 D5 已有的保持:6a186a6c5 已改。原来那句话已删掉,D5 现在只规定新调用路径上的保持,并写明 Collaboration 的请求和客户端 attach 原有的保持都不变。

P3 线的表:6a186a6c5 已改,选的是"#2174 去掉这张表"。D2 写明分支发布之后才能被选中、结束之后选不中,两条路径看的是 Session 分支表的同一份发布状态。#2174 改为查 TimelineTree 的 published,它返回的 Branch 里带着 TimelineContext,所以不需要新的表。已在 #2174 说明,"不另建索引"这句保留。

P3 错误被压平:成立,我上一条回复说 Routed 保留了所有者错误的名字,这是错的,更正。#2174 现在把所有错误都压成了 Rejected。ADR 的写法不变,改的是 #2174:五种选不中和加载不了的错误各用自己的错误码,所有者的错误用 Routed 返回,是否可重试跟着错误走。已写进 #2127 的已定决定,并在 #2174 说明。

P3 小问题(487bb6945):

  1. §7.2 的检查项补上了例外,指向「一套公开面」那一段。
  2. D1 里的 按 id 调用:由持有实例的一方选目标(base-1) #2127 改成了链接。
  3. D5 只和"会取得 Session 的 sessions 方法"相比,并写明 exists 不加载 Session,也不走这条路径。
  4. 两份旧文档仍由 所有者扫描:Agent 目录与协作 #2020 跟进。

沿用的两个 P2(按类型取的入口、调用时加载):同意,等 #2174 改完。

adr-check 通过。

@zerob13 zerob13 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.

All three ADR acceptance points are satisfied: process and Session calls share the published-branch boundary; per-call holds do not shorten Collaboration settlement or RPC attachment lifetimes; and admission distinguishes retryable reload, restore failure and true absence before dispatch, with exists staying non-loading. The exact docs CI passed. Approving the ADR; the runtime implementation remains a separate review in #2174.

@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: #2200 docs(adr): let the holder of an instance choose it by id in ADR 027

Reviewed head 487bb6945e5abdcb411ecafafe6d1805143e69ba against origin/main c8417f1f2fcb413b7f3e43e79ae89e9e3d1f1dce. The PR is 2 files, +32/-32; this round adds +8/-5 in 6a186a6c5 and 487bb6945. Verdict: REQUEST_CHANGES, one P2.

The direction is right and unchanged: the holder selects the target from the table it already owns, and the holder's data face is not a per-operation forwarder. The earlier review's three points are answered in the text: the publication bound at line 37, the existing long-lived holds at line 65, and the load failures at line 41. The round-2 P2 is closed; the P2 below comes from the new line 41.

P2: D2 says only a missing or closed Session is final, contradicting line 40 and #2127

Problem: line 41 says that only a Session that does not exist or has closed is a final result. The bullet before it says that a missing branch is final for that branch (docs/adr/027-cross-scope-access-by-id.md:40-41). #2127 makes NoLine, SessionClosing and SessionUnavailable no-retry outcomes; only SessionReloading is retryable.

Failure scenario: a caller or implementer follows line 41 and treats NoLine, SessionClosing or SessionUnavailable as temporary, for example retrying a call to a line that ended or waiting on a Session that is closing. #2127 says those end the call or the line; only SessionReloading is retried. An implementer can also mark them retryable and fail #2127's acceptance.

Evidence: docs/adr/027-cross-scope-access-by-id.md:40-42; #2127's five errors and their next steps. D5 line 63 already has the precise form: only a Session that does not exist, or has closed and cannot load, is "Session absent". The rest of the new D2 text matches AgentIndex::acquire (crates/dim-app-server/src/agents.rs:929-1049): a failed activity hold is Reloading, an unavailable or unowned stored Session is Storage, and a missing or closed one is Closed.

Fix: scope the sentence to absence, as D5 does: only a Session that does not exist or has closed is "Session absent". Line 40's NoLine finality and #2127's no-retry outcomes then stand. Related, D1 line 27's "three errors of D2" now sits beside D2's five outcomes; "the three selection misses" would keep the count accurate. The error names and next steps stay in #2127.

Closed: the round-2 P2 on D5 holds

Fixed in 6a186a6c5. D5 line 65 leaves the existing long-lived holds in place. Verified: a Collaboration request stores _usage: SessionUse and _hold: SessionHold until its result is written (crates/dim-app-server/src/collaboration.rs:9-10, :867-872, :2253-2262); an attachment stores _usage until detach (crates/dim-app-server/src/connection/subscription.rs:19-24); SessionUse pins the loaded instance and idle unload skips Sessions with uses > 0 (crates/dim-app-server/src/agents.rs:195-226, :1078-1086). D5 line 63 also matches the current per-call behavior: the sessions methods that obtain a Session call acquire (for example crates/dim-app-server/src/agents/sessions.rs:551, :605, :666, :691, :731, :768, :791), exists does not (:629-655), and Rpc's Session method acquires (crates/dim-app-server/src/connection.rs:580).

P3 for #2200, target for #2174: D2's published-only bound

Problem: line 37 says a branch is selectable only after publication and both paths read the same published state. At #2174 f5d21296, SessionScope::line_context resolves through SessionAssembly::line (crates/dim-agent-runtime/src/route.rs:197-209); register_line inserts the entry before TimelineContext::activate (crates/dim-agent-runtime/src/assembly.rs:1166, :1566; crates/dim-agent-runtime/src/timeline_context.rs:234-238). Both paths therefore see a line during opening that is not published. TimelineTree::published returns UnknownBranch before the ready result and BranchEnded after the line is removed (crates/dim-agent-capabilities/src/timeline_tree.rs:3202-3216).

Line 36 also says no new index. The map is a second line table, so the new sentence makes it nonconforming rather than redefining "existing table". #2127's decision comment already says to remove the map and use TimelineTree::published, so the ADR text stands.

Failure scenario: a call during branch opening reaches a line and dispatches to its owner, while the ADR says both paths answer "branch not present". The behavior the ADR rules out is the one #2174 ships.

Fix: in #2174, drop SessionAssembly.lines and resolve through TimelineTree::published, keeping the is_closing check: published still returns a line while it is closing, and #2127 wants NoLine there. The ADR needs no change. This closes the entry-lifetime P3 from the last review.

P3 for #2200, P2 in #2174: D5 load and keep is still not implemented

Problem: D5 line 63 requires the call to load an idle-unloaded Session and keep it for the call. #2174's AgentIndex::call uses self.live(&id) and answers NoSession for an idle-unloaded Session (crates/dim-app-server/src/agents.rs:1645-1650; live at :1686). live's own doc says a single call needs no hold.

Failure scenario: a process caller calls sessions.call for an idle-unloaded Session and gets the permanent NoSession that D5 reserves for a missing or closed Session, so it stops instead of retrying after the load.

Fix: #2174 loads and keeps through AgentIndex::acquire, as #2127's decision comment says. The ADR text is the target.

P3 for #2200, P2 in #2174: D3's ban on a type-based entry is still not implemented

Problem: D3 line 50 rules out a type-based object entry. #2174 still exposes LineHandle::get<T>() -> Routed<Arc<T>> (crates/dim-agent-runtime/src/route.rs:255-264) and session_face<T>() -> Routed<Arc<T>> (:269-274).

Failure scenario: a Rust caller keeps the typed entry and reaches the owner object without going through the data face, so the same owner operation has a second public path.

Fix: remove both from #2174. The ADR text is correct.

P3 for #2200, P3 in #2174: D1 owner errors are still flattened

Problem: D1 line 27 says the owner's error passes through unchanged. #2174 maps every RouteError to SessionsError::Rejected with the routing code in the message (crates/dim-app-server/src/agents/sessions.rs:925-930); SessionsError::Routed (:300-307) is never constructed and Rejected.retryable() is false (:338-343).

Failure scenario: an owner Reloading failure becomes a permanent rejected, and the caller cannot recover the owner's error name or retry policy.

Fix: construct Routed from RouteError::Owner in #2174. The ADR text is correct.

P3 (follow-up): the old contracts still describe the old path

docs/design/contracts/session-access.md:7, :533 and docs/design/appserver/sessions-service.md:30-33, :52-53, :614-615 still list the forwarding sessions methods. The Consequences section supersedes them, but the files do not say so. #2020 owns the banners; not resolved here.

Verification

  • node scripts/adr-check.mjs --base origin/main: ADR freeze passed for 2 changed files.
  • git diff --check origin/main...HEAD: clean.
  • All relative links and anchors in both changed files resolve.
  • CI at this head: ci-ok and changes pass; every other job is skipped for the docs-only change.
  • Worktree clean at 487bb694; no local services or processes.

Cross-PR

  • #2174 is an open draft at f5d21296; its code claims are static at that head and may change.
  • #2127's 2026-11-25 decision comment defines the five errors, the acquire mapping, removing the lines table and Routed; the ADR agrees with it.
  • #2020 owns the old-document banners; #2025 owns sessionScope.describe.
  • No conflict with origin/main.

Withdraw / keep

  • Withdrawn: the round-2 P2 that D5 denies existing holds, fixed in 6a186a6c5; the P3 that the opening boundary is unspecified, fixed in 6a186a6c5; the P3s on section 7.2, the D1 link and the D5 exists scope, fixed in 487bb6945; the earlier claim that the Session line directory is an existing line-to-context table.
  • Keep the #2174 P2s (typed entry, load on call) and P3s (owner errors, line table) against #2174, not as ADR changes. Keep the #2020 follow-up.
  • New this round: the P2 on line 41.

Unverified

  • #2174 was read at f5d21296, not built or run.
  • TimelineTree::published alone still returns a line while it is closing; #2174 must add the is_closing check when it moves off the map. This was checked by reading the node lifetime, not by running it.
  • The #2020 and #2025 edits are outside this PR.

- 选中目标之后,调用的是目标所有者在 catalog 中的操作本身。所有者不为此登记,也不写代码。
- 调用方只给 id、服务名、方法名和参数,拿不到实例键,也拿不到对象。所以「实例键只在实例内部可读」的约定不变。
- 选不中时,调用方要能分清三种情况:Session 不在、Session 正在关闭、分支不在。分支结束不等于 Session 关闭:Session 仍然存活时,分支不在对这个分支是最终结果,不影响同一 Session 的其他调用。
- 加载失败不等于 Session 不在:Agents 正在重载时,调用方可以稍后重试;存储的 Session 恢复失败时,原因要交给调用方。只有 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.

D2 says only a missing or closed Session is a final result, but the bullet above says a missing branch is final for that branch (docs/adr/027-cross-scope-access-by-id.md:40-41), and #2127 makes NoLine, SessionClosing and SessionUnavailable no-retry outcomes (only SessionReloading is retryable). A caller or implementer reading this line will retry a closed line or a closing Session. Scope it to absence, as D5 line 63 does: only a Session that does not exist or has closed is 'Session absent'. D2's load outcomes otherwise match AgentIndex::acquire (crates/dim-app-server/src/agents.rs:929-1049). P2.

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 7f96aa5c. D2 line 41 now defines only "Session absent"; D1 line 27 names three selection misses plus load failures, matching the five #2127 outcomes and D5 line 63.

D2 said only a missing or closed Session is final, which read as if a missing
branch or a closing Session could be retried. It now says that only those two
cases are "Session absent"; D1 names the selection misses and load failures
instead of three errors.

Refs #2127
@eric8810

Copy link
Copy Markdown
Collaborator Author

P2 第 41 行:成立,已改(7f96aa5c1)。

  • 第 41 行改为:只有 Session 不存在或已经关闭,才是「Session 不在」。和 D5 的写法一致,不再说"只有这两种是最终结果"。所以 NoLine 对这条线仍是最终结果,按 id 调用:由持有实例的一方选目标(base-1) #2127 里各种错误的下一步也不受影响。
  • D1 里"D2 的三种错误"改为"D2 中的情况(三种选不中,以及加载失败)"。

is_closing 检查:已补进 #2127 的已定决定。#2174 改查 published 时,要保留 is_closing 检查,正在关闭的线答 NoLine。

#2174 的各项改动等本 PR 合并后一次完成,见 #2174 的暂停说明。adr-check 通过。

@eric8810
eric8810 requested a review from yyhhyyyyyy November 25, 2026 16:40

@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: #2200 docs(adr): let the holder of an instance choose it by id in ADR 027

Reviewed head 7f96aa5c against origin/main c8417f1f; merge base 3f83c159. The PR is 2 files, +32/-32; this round adds +2/-2 in 7f96aa5c. Verdict: APPROVE.

The ADR replaces the proposed runtime router with holder-based selection. Agents selects a Session by sessionId from its Session table, a Session selects its own line by branchId from its branch table, and the holder's id-selection data face is not a per-operation forwarder. The PR also updates the principles §7 pointer and carve-out, and removes the mechanism-requirements section. The direction is the maintainer decision recorded in #2127.

The P2 from 487bb69 is closed

Line 41 no longer says that only a missing or closed Session is a final result. It now says that only a Session that does not exist or has closed is "Session absent" (docs/adr/027-cross-scope-access-by-id.md:41). Line 40's branch-final rule stands: a branch that is not selectable is final for that branch while the Session survives. #2127's no-retry NoLine, SessionClosing and SessionUnavailable outcomes are no longer contradicted.

D1 line 27 now names the three selection misses plus load failures (:27). That is the five #2127 outcomes: NoSession, SessionClosing and NoLine are the selection misses; SessionReloading and SessionUnavailable are the load failures. D2 line 41 names both load-failure situations (reload, restore failure); #2127 also puts an unavailable Agent under SessionUnavailable, which is the same category. D5 line 63 uses the same absence definition: only a Session that does not exist, or has closed and cannot load, is "Session absent".

The Session-level outcomes match the current AgentIndex::acquire failures: Reloading, Storage, and Closed (crates/dim-app-server/src/agents.rs:929-1049); #2127 maps them to SessionReloading, SessionUnavailable, and NoSession. close_session records that a closed Session does not load again in this process (crates/dim-app-server/src/agents.rs:673-680), so D2 line 41 and D5 line 63 state the same condition.

No contradiction with D2's five outcomes, D5 line 63, or #2127. The earlier review's three points (publication bound, existing long-lived holds, admission errors) remain satisfied at this head.

Carried to #2174, not ADR blockers

The linked draft #2174 is still at f5d21296. These are #2174 changes, not gaps in the ADR text:

  • Selection before publication. Problem: SessionScope::line_context resolves through SessionAssembly::line (crates/dim-agent-runtime/src/route.rs:197-209), and register_line fills that map before TimelineContext::activate (crates/dim-agent-runtime/src/assembly.rs:1145, :1566). Failure scenario: a call during opening reaches a line and dispatches to its owner, while D2 line 37 says both paths answer "branch absent" for an unpublished line. Fix: drop the map and resolve through TimelineTree::published with the is_closing check.
  • Load on call. Problem: AgentIndex::call uses self.live(&id) and answers NoSession for an idle-unloaded Session (crates/dim-app-server/src/agents.rs:1643-1686). Failure scenario: the caller receives the permanent NoSession that D5 line 63 reserves for a missing or closed Session, so it stops instead of retrying after the load. Fix: use AgentIndex::acquire.
  • Typed object entries. Problem: LineHandle::get<T>() and session_face<T>() still return Arc<T> (crates/dim-agent-runtime/src/route.rs:255-274). Failure scenario: a Rust caller reaches the owner object without the data face, so the same owner operation has a second public path. Fix: remove both and have callers build the request args and decode the reply.
  • Owner errors flattened. Problem: sessions.call maps every RouteError to SessionsError::Rejected with a message prefix (crates/dim-app-server/src/agents/sessions.rs:925-930); Routed (:302-306) is never constructed and Rejected.retryable() is false (:338-343). Failure scenario: an owner Reloading failure becomes a permanent rejected, so the caller cannot retry when the owner finishes reloading. Fix: construct Routed from the owner failure.

P3 follow-up

The old contracts still describe the old path: docs/design/contracts/session-access.md:7, :533; docs/design/appserver/sessions-service.md:30-33, :52-53, :614-615. ADR 027 Consequences line 80 says they are superseded by the Agents contract, and #2020's decided comment adds the banners and changes reach to D3. Tracked there, not an ADR defect.

Verification

  • node scripts/adr-check.mjs --base origin/main: ADR freeze passed for 2 changed files.
  • git diff --check origin/main...HEAD: clean.
  • Relative links and anchors in both changed files resolve.
  • CI at this head: ci-ok and changes pass; the other jobs are skipped for the docs-only change.
  • Worktree clean at 7f96aa5c; no local services or processes.

Cross-PR

  • #2174 is an open draft at f5d21296; its code claims are static at that head.
  • #2127's five errors and next steps match D1, D2, and D5.
  • #2020 owns the banners for the two old contracts; #2025 owns the Session data-face reads.
  • No other open PR touches docs/adr/027-cross-scope-access-by-id.md or docs/architecture/rust-agent/principles.md.

Withdraw

  • Withdraw the P2 on line 41: fixed in 7f96aa5c.
  • Keep the #2174 changes (typed entries, load on call, publication bound, owner errors) against #2174; keep the #2020 banner follow-up.

Unverified

  • #2174 was read at f5d21296, not built or run.
  • The old-contract banners and the #2025 reads are outside this PR.

@zerob13 zerob13 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.

The wording change closes the remaining ambiguity: absence is distinct from branch misses, closing, and unavailable Sessions, and only reload is retryable. The shared published-branch boundary and existing Collaboration and RPC hold lifetimes remain intact. Exact-head docs CI passed. No ADR blockers; runtime behavior remains a separate review in #2174.

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.

3 participants