From 46358297a4ba7ebf095b63a11ce26c5c30db44dd Mon Sep 17 00:00:00 2001 From: eric8810 Date: Mon, 23 Nov 2026 00:34:07 +0800 Subject: [PATCH 01/12] docs(principles): add owners and operations Add section 7 of the design rules: a plugin is designed from its own responsibility and maintenance boundary; resources stay with their owner, which offers id-based operations; business state is shared through facts or versioned values; one owner has one public surface, judged by cross-language availability, with no forwarding facades. The section adds the three design questions (resources, lifecycle, external operations), operation and owner granularity, errors as part of the contract, and review checks. Refs #2015 --- docs/architecture/rust-agent/principles.md | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/docs/architecture/rust-agent/principles.md b/docs/architecture/rust-agent/principles.md index 55c3b15124..f664b20e78 100644 --- a/docs/architecture/rust-agent/principles.md +++ b/docs/architecture/rust-agent/principles.md @@ -104,3 +104,43 @@ Approval 与 Permission 只管 agent 决策引起的动作(工具调用); ## 6. 验证 需求变化时,旧断言按新需求修改或删除,测试跟随实现。日常行为验证用各 crate 的 `crates/*/tests` 与仓库根的 `tests/integration`(跨包扩展、公开流程)。事件格式样本位于 `crates/dim-agent-types/tests/fixtures/`,是冻结的兼容基线:保留原始公开 wire 样本及其来源,不随实现变更更新;契约测试(`crates/dim-agent-types/tests/*_contract.rs`)对这些样本做反序列化与序列化校验,`cargo run -p dim-agent-types --example compat -- --emit` 输出原生 Rust 样本的 v1 wire 形式供对照。对冻结事件结构的扩展须经设计决定,并在契约测试中登记。 + +## 7. 所有者与操作 + +设计插件先回答"我负责什么、维护到哪里",再回答"别人需要什么"。插件与部件的形状由职责和维护边界决定;外部需求只决定对外提供哪些操作,不决定内部如何组织,也不决定交出什么。需求用来验证职责划分:每个真实需求都应落到某个所有者的某个操作上。落不下去说明划分有缺口;超出职责的需求交给真正的所有者,或新建一个所有者,不在现有插件上开口子。 + +**资源归所有者,别人只能请求它做事;业务状态通过事实或带版本的值共享。** + +| 对象 | 规则 | +| --- | --- | +| 资源(进程、PTY、文件与锁、连接、订阅等需要收尾的 I/O) | 创建、结算、取消、清理都在所有者内部完成;对外只给以 id 标识资源的操作,句柄不离开所有者 | +| 业务状态 | 由事实推出:分支上的 Capability 写入并按序折叠事实(第 4 节);进程级所有者给出值(快照、配置),不进 Timeline(第 4 节规则 9) | + +判据:交出去之后,所有者还要不要为它负责?要,就只能给操作。副本与投影则问:新鲜度由谁负责?持有者接受过期时可以持有;正确性依赖最新值时,向所有者请求或订阅。 + +可以交出的只有:值(快照、配置、身份,带版本)、只读视图,以及同一所有者内部、同一实例生命周期内的东西。不转手:不把别人的资源再交出去,不冒充别人数据的源头;从公开事实折叠出的投影是投影者自己的状态,可以发布,发布者即为它的所有者。 + +**一个所有者一套公开面,不为调用方额外封装。** 公开面就是所有者自身的操作:服务标注在所有者自己的类型上,Rust 在进程内直接调用这些方法,其他语言经 rutis 生成的派发与声明调用同一组操作([Dim 如何使用 rutis](../../design/rutis-usage.md))。公开面以跨语言可用为准:参数、回复与错误是数据,资源以 id 表示([服务面](../../design/service-faces.md)第 1 节)。不为某个调用方另造只转发所有者的门面、命令、控制或宿主对象,同一组操作也不以两套接口存在。需求要的形状在所有者职责内,就成为所有者的一个操作;不在,就归调用方。公开服务上只有 Rust 能用的方法,要么移回所有者内部,要么改成数据操作。 + +### 7.1 设计三问 + +每个所有者在设计文档或插件页面中回答: + +| 问题 | 要回答的内容 | +| --- | --- | +| 资源 | 拥有什么;哪些需要收尾,哪些只是值 | +| 生命周期 | 由谁触发、何时结束、由谁结算;发起方与所有者不在同一作用域时、所有者关闭或重载时、发起方异常退出时如何收尾 | +| 对外业务 | 调用方的意图推出哪些操作与值;每个操作的取消、超时与错误种类 | + +- **操作颗粒度**:一个操作是资源的一次状态迁移或一次一致的读取,所有者能独立完成并收尾。调用方漏调或调错顺序就会破坏所有者状态,说明太细;夹带调用方的决定,或调用方只需要其中一部分,说明太粗。步骤之间以 id 衔接,策略作为数据参数传入。 +- **错误**:错误是操作契约的一部分。种类按调用方下一步能做什么区分(重试、修正输入、不存在、已取消、所有者已关闭、冲突),来自资源的状态机,不泄漏内部错误。取消与超时写明各自停止的是什么。分支上后续决定要依赖的失败写成事实,不只作为返回值。 +- **所有者颗粒度**:在 [ADR 002 D1](../../adr/002-plugin-scope.md) 的作用域划分之内,生命周期不同的资源归不同的所有者;总是一起改动、或只是转发的所有者合并(ADR 002 D2)。上层只通过操作组合下层,不持有下层句柄,也不把下层资源再对外提供。 + +### 7.2 评审检查 + +- 每个跨插件调用都落到某个所有者的一个操作上。 +- 交出去的只有值、只读视图,或同一所有者内部的东西。 +- 没有转手别人的资源,没有冒充别人数据的源头。 +- 所有者只有一套公开面:没有只转发所有者的门面、命令或控制对象,公开服务上没有只供 Rust 调用的方法。 +- 跨作用域的生命周期写明结算权与异常收尾。 +- 公开面不出现资源句柄;公开服务的数据形状见[服务面](../../design/service-faces.md)第 1 节。 From 099df010e97bda38f2274566183fa678bc2d38cd Mon Sep 17 00:00:00 2001 From: eric8810 Date: Mon, 23 Nov 2026 10:16:42 +0800 Subject: [PATCH 02/12] docs: add responsibility split and owner redesign template MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Design rules §7 gains the responsibility split: interfaces use the owner's vocabulary, owner mechanisms such as locks, versions, waits and retries stay inside the owner, and an operation or parameter is added only when callers cannot compose it from existing operations without breaking the owner's invariants. The review checks gain the matching item. docs/templates/owner-redesign.md gives the shape for redesigning an existing owner: a durable design part for docs/design/plugins and a delivery part for the owner's issue. Refs #2015 --- docs/architecture/rust-agent/principles.md | 3 ++ docs/templates/README.md | 1 + docs/templates/owner-redesign.md | 61 ++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 docs/templates/owner-redesign.md diff --git a/docs/architecture/rust-agent/principles.md b/docs/architecture/rust-agent/principles.md index f664b20e78..e6c05f40ba 100644 --- a/docs/architecture/rust-agent/principles.md +++ b/docs/architecture/rust-agent/principles.md @@ -122,6 +122,8 @@ Approval 与 Permission 只管 agent 决策引起的动作(工具调用); **一个所有者一套公开面,不为调用方额外封装。** 公开面就是所有者自身的操作:服务标注在所有者自己的类型上,Rust 在进程内直接调用这些方法,其他语言经 rutis 生成的派发与声明调用同一组操作([Dim 如何使用 rutis](../../design/rutis-usage.md))。公开面以跨语言可用为准:参数、回复与错误是数据,资源以 id 表示([服务面](../../design/service-faces.md)第 1 节)。不为某个调用方另造只转发所有者的门面、命令、控制或宿主对象,同一组操作也不以两套接口存在。需求要的形状在所有者职责内,就成为所有者的一个操作;不在,就归调用方。公开服务上只有 Rust 能用的方法,要么移回所有者内部,要么改成数据操作。 +**职责分界:业务面对更小的复杂度。** 设计接口前先分清所有者的内部职责与调用方的业务职责。接口用所有者自己的词汇表达,不出现调用方的业务概念;锁、版本、等待、重试、结算等所有者的内部机制不推给调用方,调用方只处理有业务含义的结果与异常。业务提出的需求,能用现有操作组合完成且不破坏所有者不变量的,留在业务侧;组合会破坏不变量的,才由所有者提供一个通用操作。每个参数都是复杂度,默认值由所有者决定,只有业务确实需要不同取值时才开放。 + ### 7.1 设计三问 每个所有者在设计文档或插件页面中回答: @@ -142,5 +144,6 @@ Approval 与 Permission 只管 agent 决策引起的动作(工具调用); - 交出去的只有值、只读视图,或同一所有者内部的东西。 - 没有转手别人的资源,没有冒充别人数据的源头。 - 所有者只有一套公开面:没有只转发所有者的门面、命令或控制对象,公开服务上没有只供 Rust 调用的方法。 +- 接口里没有调用方的业务概念,也没有推给调用方的所有者内部机制;每个操作和参数都说明了为什么不能由调用方组合完成。 - 跨作用域的生命周期写明结算权与异常收尾。 - 公开面不出现资源句柄;公开服务的数据形状见[服务面](../../design/service-faces.md)第 1 节。 diff --git a/docs/templates/README.md b/docs/templates/README.md index 49ea5b565b..0c09cff73e 100644 --- a/docs/templates/README.md +++ b/docs/templates/README.md @@ -8,6 +8,7 @@ are in [AGENTS.md](../../AGENTS.md). | ADR | [adr.md](adr.md) | [ADR 008](../adr/008-documentation-ownership.md) | | Feature or plugin design | [design.md](design.md) | [Web](../design/plugins/Web.md) | | Contract | [contract.md](contract.md) | [Session access](../design/contracts/session-access.md) | +| Owner redesign | [owner-redesign.md](owner-redesign.md) | none yet | The [design guide](../design/capability-design-arguments.md) offers help with use, public promises and verification. The [detailed reference](../design/capability-design-reference.md) and [Wait example](../design/examples/wait-argument.md) diff --git a/docs/templates/owner-redesign.md b/docs/templates/owner-redesign.md new file mode 100644 index 0000000000..5ab1c56386 --- /dev/null +++ b/docs/templates/owner-redesign.md @@ -0,0 +1,61 @@ +# Owner redesign + +Use this shape when an existing owner's public surface is redesigned under +[design rules §7](../architecture/rust-agent/principles.md#7-所有者与操作). It has two parts. The design +part is durable and goes into the owner's design document, `docs/design/plugins/.md`, +created from the [design template](design.md) when it does not exist. The delivery part is +temporary and goes into the owner's issue. + +Write conclusions first. Name things directly instead of referring back. Do not restate rules or +describe how the document was produced. Link evidence next to the claim it supports. + +## Design part + +### Use and scope: responsibility split + +- The owner's responsibilities, in the owner's own vocabulary. +- The responsibilities that stay with callers as business logic. +- One row per caller requirement: + +| Requirement | Can callers compose it from existing operations without breaking the owner's invariants? | Handling | +| --- | --- | --- | + +An operation or parameter exists only where the answer is no. + +### Caller example + +The caller code after the change for each main intent. It shows the owner operations it calls and +the errors it handles, and nothing of the owner's internal mechanisms. + +### Own contract + +Each operation: the intent it serves, request and reply data, cancellation, and error kinds named by +what the caller can do next. For each operation that holds a resource or waits, a flow covering the +normal path, the caller cancelling or unloading, and the owner closing or reloading, with the party +that settles each resource. + +### Exceptions with reasons + +One line each. + +### Rule check and requirements raised to mechanism owners + +As in the [design template](design.md). + +### Binding appendix + +The `#[rutis::service]` block on the owner type, and the request, reply and error types. + +## Delivery part + +Written in the owner's issue; it is history once the change lands. + +- **Deletion list**: public methods, types, wrappers and catalog entries that must not exist after the + change. +- **Caller migration**: one row per call site, `caller | current call | target operation`. +- **Implementation task**: rewrite the owner's public surface; do not add an interface beside it. + Read the responsibility split, write the callers' target code as flow tests, make the old public + methods `pub(crate)` and use the compile errors as the migration list, implement the operations, + then migrate every caller. One owner and all of its callers are one change. +- **Acceptance**: the flow tests pass; no cross-crate reference to a deleted name remains; the + catalog has no `internal(reason)` entry for the owner; the diff removes the old surface. From ce840afdb6193442229f99b03136108d7981456e Mon Sep 17 00:00:00 2001 From: eric8810 Date: Mon, 23 Nov 2026 11:18:36 +0800 Subject: [PATCH 03/12] docs(principles): settle section 7 against existing rules Define the owner as the part that holds a resource or state, and state that section 7 is the target rule: current shapes that differ are gaps. Resolve the points where section 7 replaces older practice: - interfaces add concepts, so a new one needs a reason from the owner's boundary, and one set of operations has one interface; - rutis supports Rust-only methods, but Dim public surfaces do not use them; - handing out an object is a last resort and requires a lifecycle design shared by the plugins involved; a hot path is not a reason; - an owner does not serve another owner's resources or data; a performance need redefines ownership; - a plugin area is redesigned in one change, without a compatibility period. Also allow callbacks by reference, require versions only when later decisions depend on them, let each owner design its own error kinds, keep section 4 rule 1 for commands that did not take effect, and cite ADR 002 D2 only for merging forwarding owners. Refs #2015 --- docs/architecture/rust-agent/principles.md | 31 +++++++++++++++------- docs/templates/owner-redesign.md | 7 ++++- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/docs/architecture/rust-agent/principles.md b/docs/architecture/rust-agent/principles.md index e6c05f40ba..d48dc47615 100644 --- a/docs/architecture/rust-agent/principles.md +++ b/docs/architecture/rust-agent/principles.md @@ -107,9 +107,11 @@ Approval 与 Permission 只管 agent 决策引起的动作(工具调用); ## 7. 所有者与操作 +本节是目标规则:现有插件中与它不符的形状是待改的差距,不是例外。**所有者**是持有某类资源或状态的部件;一个插件可以有多个所有者,以下规则以所有者为单位。 + 设计插件先回答"我负责什么、维护到哪里",再回答"别人需要什么"。插件与部件的形状由职责和维护边界决定;外部需求只决定对外提供哪些操作,不决定内部如何组织,也不决定交出什么。需求用来验证职责划分:每个真实需求都应落到某个所有者的某个操作上。落不下去说明划分有缺口;超出职责的需求交给真正的所有者,或新建一个所有者,不在现有插件上开口子。 -**资源归所有者,别人只能请求它做事;业务状态通过事实或带版本的值共享。** +**资源归所有者,别人只能请求它做事;业务状态通过事实或值共享。** | 对象 | 规则 | | --- | --- | @@ -118,15 +120,23 @@ Approval 与 Permission 只管 agent 决策引起的动作(工具调用); 判据:交出去之后,所有者还要不要为它负责?要,就只能给操作。副本与投影则问:新鲜度由谁负责?持有者接受过期时可以持有;正确性依赖最新值时,向所有者请求或订阅。 -可以交出的只有:值(快照、配置、身份,带版本)、只读视图,以及同一所有者内部、同一实例生命周期内的东西。不转手:不把别人的资源再交出去,不冒充别人数据的源头;从公开事实折叠出的投影是投影者自己的状态,可以发布,发布者即为它的所有者。 +可以交出的是:值(快照、配置、身份;后续决定依赖修订时带版本)、只读视图(所有者发布、调用方只能观察的值及其订阅),以及按引用传递的回调(不在提交锁内同步调用,[服务面](../../design/service-faces.md)第 1 节规则 4)。 + +**交对象是最后手段。** id、值与回调都做不到时才交出对象。一旦交出对象,就要在更高一层统一设计相关插件的生命周期与边界:谁创建、谁持有、交接顺序、谁收尾、任何一方关闭或重载时如何处理,写进各方共同引用的设计中。"热路径"本身不是交出对象的理由。 + +**不代查别人的资源。** 一个所有者不替别的所有者返回它的资源或数据,也不替它接收写入;调用方直接请求数据的所有者。有性能需求时重新定义归属,而不是增加代查。从公开事件折叠出的投影是投影者自己的状态,发布它的部件就是它的所有者。 -**一个所有者一套公开面,不为调用方额外封装。** 公开面就是所有者自身的操作:服务标注在所有者自己的类型上,Rust 在进程内直接调用这些方法,其他语言经 rutis 生成的派发与声明调用同一组操作([Dim 如何使用 rutis](../../design/rutis-usage.md))。公开面以跨语言可用为准:参数、回复与错误是数据,资源以 id 表示([服务面](../../design/service-faces.md)第 1 节)。不为某个调用方另造只转发所有者的门面、命令、控制或宿主对象,同一组操作也不以两套接口存在。需求要的形状在所有者职责内,就成为所有者的一个操作;不在,就归调用方。公开服务上只有 Rust 能用的方法,要么移回所有者内部,要么改成数据操作。 +**一套公开面,控制概念数量。** 公开面就是所有者自身的操作:服务标注在所有者自己的类型上,Rust 在进程内直接调用这些方法,其他语言经 rutis 生成的派发与声明调用同一组操作([Dim 如何使用 rutis](../../design/rutis-usage.md))。每多一个接口就多一个概念:新增接口要从所有者的职责与边界说明为什么需要,不因某个调用方的需求增加。同一组操作不以两套接口存在,不为调用方另造只转发的门面、命令、控制或宿主对象。 + +**公开面以跨语言可用为准。** rutis 支持只在 Rust 内可用的方法与服务([Dim 如何使用 rutis](../../design/rutis-usage.md) §3.3);Dim 为了让跨语言插件的能力最大化、让插件的生命周期内聚,公开面不使用这一能力:参数、回复与错误是数据,资源以 id 表示([服务面](../../design/service-faces.md)第 1 节)。只能在 Rust 内使用的方法留在所有者内部。 **职责分界:业务面对更小的复杂度。** 设计接口前先分清所有者的内部职责与调用方的业务职责。接口用所有者自己的词汇表达,不出现调用方的业务概念;锁、版本、等待、重试、结算等所有者的内部机制不推给调用方,调用方只处理有业务含义的结果与异常。业务提出的需求,能用现有操作组合完成且不破坏所有者不变量的,留在业务侧;组合会破坏不变量的,才由所有者提供一个通用操作。每个参数都是复杂度,默认值由所有者决定,只有业务确实需要不同取值时才开放。 +**一个板块一次改完。** 改造一个插件板块的公开面时,新的操作、全部调用方的迁移与旧公开面的删除在同一个改动中完成,不保留新旧并存的兼容期。 + ### 7.1 设计三问 -每个所有者在设计文档或插件页面中回答: +每个所有者在设计文档中回答,形状见 [owner-redesign 模板](../../templates/owner-redesign.md): | 问题 | 要回答的内容 | | --- | --- | @@ -135,15 +145,16 @@ Approval 与 Permission 只管 agent 决策引起的动作(工具调用); | 对外业务 | 调用方的意图推出哪些操作与值;每个操作的取消、超时与错误种类 | - **操作颗粒度**:一个操作是资源的一次状态迁移或一次一致的读取,所有者能独立完成并收尾。调用方漏调或调错顺序就会破坏所有者状态,说明太细;夹带调用方的决定,或调用方只需要其中一部分,说明太粗。步骤之间以 id 衔接,策略作为数据参数传入。 -- **错误**:错误是操作契约的一部分。种类按调用方下一步能做什么区分(重试、修正输入、不存在、已取消、所有者已关闭、冲突),来自资源的状态机,不泄漏内部错误。取消与超时写明各自停止的是什么。分支上后续决定要依赖的失败写成事实,不只作为返回值。 -- **所有者颗粒度**:在 [ADR 002 D1](../../adr/002-plugin-scope.md) 的作用域划分之内,生命周期不同的资源归不同的所有者;总是一起改动、或只是转发的所有者合并(ADR 002 D2)。上层只通过操作组合下层,不持有下层句柄,也不把下层资源再对外提供。 +- **错误**:错误是操作契约的一部分,由每个所有者按调用方下一步能做什么自行设计,不套用通用种类;所有者不会出现的情况不写对应错误,也不泄漏内部错误。取消与超时写明各自停止的是什么。命令没有生效时按第 4 节规则 1 不写事件;已经发生的操作,后续决定依赖其失败的,写成事实。 +- **所有者颗粒度**:在 [ADR 002 D1](../../adr/002-plugin-scope.md) 的作用域划分之内,生命周期不同的资源一般归不同的所有者;只是转发的所有者合并(ADR 002 D2),总是一起改动的所有者合并。上层只通过操作组合下层,不持有下层句柄,也不把下层资源再对外提供。 ### 7.2 评审检查 - 每个跨插件调用都落到某个所有者的一个操作上。 -- 交出去的只有值、只读视图,或同一所有者内部的东西。 -- 没有转手别人的资源,没有冒充别人数据的源头。 -- 所有者只有一套公开面:没有只转发所有者的门面、命令或控制对象,公开服务上没有只供 Rust 调用的方法。 +- 交出去的只有值、只读视图或回调;交出对象的,有更高一层统一设计的生命周期与边界。 +- 没有转手别人的资源,没有代查别人的资源或数据。 +- 同一组操作只有一套接口;每个新增接口都从所有者的职责说明了理由;没有只转发的门面、命令或控制对象。 +- 公开面上没有只能在 Rust 内使用的方法;参数、回复与错误是数据,资源以 id 表示。 - 接口里没有调用方的业务概念,也没有推给调用方的所有者内部机制;每个操作和参数都说明了为什么不能由调用方组合完成。 - 跨作用域的生命周期写明结算权与异常收尾。 -- 公开面不出现资源句柄;公开服务的数据形状见[服务面](../../design/service-faces.md)第 1 节。 +- 一个板块的改造在一个改动中完成,旧公开面同时删除。 diff --git a/docs/templates/owner-redesign.md b/docs/templates/owner-redesign.md index 5ab1c56386..667a56fa0c 100644 --- a/docs/templates/owner-redesign.md +++ b/docs/templates/owner-redesign.md @@ -34,6 +34,10 @@ what the caller can do next. For each operation that holds a resource or waits, normal path, the caller cancelling or unloading, and the owner closing or reloading, with the party that settles each resource. +Ids, values, read-only views and callbacks cross owners. Where an object still has to be handed out, +say why none of those works, and link the design shared by the plugins involved that fixes who +creates, holds, hands over and cleans up the object, and what happens when any side closes or reloads. + ### Exceptions with reasons One line each. @@ -56,6 +60,7 @@ Written in the owner's issue; it is history once the change lands. - **Implementation task**: rewrite the owner's public surface; do not add an interface beside it. Read the responsibility split, write the callers' target code as flow tests, make the old public methods `pub(crate)` and use the compile errors as the migration list, implement the operations, - then migrate every caller. One owner and all of its callers are one change. + then migrate every caller. A plugin area's new operations, every caller and the removal of the old + surface are one change, with no period where old and new coexist. - **Acceptance**: the flow tests pass; no cross-crate reference to a deleted name remains; the catalog has no `internal(reason)` entry for the owner; the diff removes the old surface. From 869ef0d7e439ff97e936164e93f6fb2279d12b15 Mon Sep 17 00:00:00 2001 From: eric8810 Date: Mon, 23 Nov 2026 12:59:11 +0800 Subject: [PATCH 04/12] docs(principles): settle hot paths and registration points in section 7 Calling frequency is no reason to keep a non-data face: a data face leaves Rust's in-process calls unchanged. A name that cannot cross languages is reshaped, made private, or given a coarser operation. Mechanism registration points are not forwarding facades. Owners that only change together are no longer merged by that alone. AGENTS.md and the design template's rule check include the section 7.2 owner checks. --- AGENTS.md | 2 +- docs/architecture/rust-agent/principles.md | 6 +++--- docs/templates/design.md | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 3f8fcc897a..81e810f800 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -118,7 +118,7 @@ Dim's architecture and the way Dim uses rutis are documented apart ([ADR 006](do A rule is stated once, at its layer. The Rust spelling of a rule is a binding, not the rule. See the [architecture overview](docs/architecture/README.md#design-documents) for the full document index. -Before designing or changing a plugin, capability or event, read [design rules §4](docs/architecture/rust-agent/principles.md) (extending behavior through the Timeline), [ADR 002](docs/adr/002-plugin-scope.md) (scope, no wiring modules, configuration, language-neutral contracts) the [plugin contract](docs/design/plugin-contract.md) (how Dim's architecture applies to plugins) and [How Dim uses rutis](docs/design/rutis-usage.md) (how parts are mounted, name services and cross languages). Every plugin design document contains a "Rule check" section that says which parts are Capabilities ([principles §1](docs/architecture/rust-agent/principles.md)) and answers each of these rules (§4 rules 1–9, §1 and ADR 002 D1–D5; or states why one does not apply), and a "Requirements raised to mechanism owners" section in the format of §4 rule 8. Pull requests answer the checklist in the pull request template. +Before designing or changing a plugin, capability or event, read [design rules §4](docs/architecture/rust-agent/principles.md) (extending behavior through the Timeline), [ADR 002](docs/adr/002-plugin-scope.md) (scope, no wiring modules, configuration, language-neutral contracts) the [plugin contract](docs/design/plugin-contract.md) (how Dim's architecture applies to plugins) and [How Dim uses rutis](docs/design/rutis-usage.md) (how parts are mounted, name services and cross languages). Every plugin design document contains a "Rule check" section that says which parts are Capabilities ([principles §1](docs/architecture/rust-agent/principles.md)) and answers each of these rules (§4 rules 1–9, §1, the §7.2 owner checks and ADR 002 D1–D5; or states why one does not apply), and a "Requirements raised to mechanism owners" section in the format of §4 rule 8. Pull requests answer the checklist in the pull request template. 1. A feature is split into parts by the owner of their state, and each part lives in that owner's scope: the process, a Session or a branch ([ADR 002 D1](docs/adr/002-plugin-scope.md)). A part declares every dependency, including those only needed for load order. How a part is mounted and names its dependencies is [How Dim uses rutis](docs/design/rutis-usage.md); the current Rust spelling is below. `apply` acquires resources and registers their cleanup immediately, then registers services and subscriptions. Once `apply` completes, services and subscriptions are available. Input consumption and background work start only after the Session or branch is published (`activated()`); if assembly fails, they never start. They end on `closing()` without waiting for unload, and a Session is closing from the moment its close starts. A process part whose background work depends on the initial process assembly waits for the host-wide `processActivity.activated()` in its own tasks; `apply` does not block on it, and a row reload does not reset it ([plugin contract §7.1](docs/design/plugin-contract.md#71-phases)). 2. Behavior that produces or consumes events with critical effects (affecting a part's execution, or context content and its processing or insertion) writes facts to the Timeline, and the Dispatcher delivers them. Parts coordinate through facts and the named services they declare; direct calls are limited to handles they own. diff --git a/docs/architecture/rust-agent/principles.md b/docs/architecture/rust-agent/principles.md index d48dc47615..b1dd97ab78 100644 --- a/docs/architecture/rust-agent/principles.md +++ b/docs/architecture/rust-agent/principles.md @@ -126,9 +126,9 @@ Approval 与 Permission 只管 agent 决策引起的动作(工具调用); **不代查别人的资源。** 一个所有者不替别的所有者返回它的资源或数据,也不替它接收写入;调用方直接请求数据的所有者。有性能需求时重新定义归属,而不是增加代查。从公开事件折叠出的投影是投影者自己的状态,发布它的部件就是它的所有者。 -**一套公开面,控制概念数量。** 公开面就是所有者自身的操作:服务标注在所有者自己的类型上,Rust 在进程内直接调用这些方法,其他语言经 rutis 生成的派发与声明调用同一组操作([Dim 如何使用 rutis](../../design/rutis-usage.md))。每多一个接口就多一个概念:新增接口要从所有者的职责与边界说明为什么需要,不因某个调用方的需求增加。同一组操作不以两套接口存在,不为调用方另造只转发的门面、命令、控制或宿主对象。 +**一套公开面,控制概念数量。** 公开面就是所有者自身的操作:服务标注在所有者自己的类型上,Rust 在进程内直接调用这些方法,其他语言经 rutis 生成的派发与声明调用同一组操作([Dim 如何使用 rutis](../../design/rutis-usage.md))。每多一个接口就多一个概念:新增接口要从所有者的职责与边界说明为什么需要,不因某个调用方的需求增加。同一组操作不以两套接口存在,不为调用方另造只转发的门面、命令、控制或宿主对象。机制提供的登记点(`sessionMethods`、`managementMethods`、`toolRegistry`,[ADR 002](../../adr/002-plugin-scope.md))不是转发门面。 -**公开面以跨语言可用为准。** rutis 支持只在 Rust 内可用的方法与服务([Dim 如何使用 rutis](../../design/rutis-usage.md) §3.3);Dim 为了让跨语言插件的能力最大化、让插件的生命周期内聚,公开面不使用这一能力:参数、回复与错误是数据,资源以 id 表示([服务面](../../design/service-faces.md)第 1 节)。只能在 Rust 内使用的方法留在所有者内部。 +**公开面以跨语言可用为准。** rutis 支持只在 Rust 内可用的方法与服务([Dim 如何使用 rutis](../../design/rutis-usage.md) §3.3);Dim 为了让跨语言插件的能力最大化、让插件的生命周期内聚,公开面不使用这一能力:参数、回复与错误是数据,资源以 id 表示([服务面](../../design/service-faces.md)第 1 节)。只能在 Rust 内使用的方法留在所有者内部。数据面不改变 Rust 进程内的直接调用,调用频率不是保留非数据面的理由。跨不了语言时按原因处理:参数不是数据就改形状;只服务同一功能内部的移出目录,作为私有名字;要求逐项回调或交出对象的,改操作颗粒度。 **职责分界:业务面对更小的复杂度。** 设计接口前先分清所有者的内部职责与调用方的业务职责。接口用所有者自己的词汇表达,不出现调用方的业务概念;锁、版本、等待、重试、结算等所有者的内部机制不推给调用方,调用方只处理有业务含义的结果与异常。业务提出的需求,能用现有操作组合完成且不破坏所有者不变量的,留在业务侧;组合会破坏不变量的,才由所有者提供一个通用操作。每个参数都是复杂度,默认值由所有者决定,只有业务确实需要不同取值时才开放。 @@ -146,7 +146,7 @@ Approval 与 Permission 只管 agent 决策引起的动作(工具调用); - **操作颗粒度**:一个操作是资源的一次状态迁移或一次一致的读取,所有者能独立完成并收尾。调用方漏调或调错顺序就会破坏所有者状态,说明太细;夹带调用方的决定,或调用方只需要其中一部分,说明太粗。步骤之间以 id 衔接,策略作为数据参数传入。 - **错误**:错误是操作契约的一部分,由每个所有者按调用方下一步能做什么自行设计,不套用通用种类;所有者不会出现的情况不写对应错误,也不泄漏内部错误。取消与超时写明各自停止的是什么。命令没有生效时按第 4 节规则 1 不写事件;已经发生的操作,后续决定依赖其失败的,写成事实。 -- **所有者颗粒度**:在 [ADR 002 D1](../../adr/002-plugin-scope.md) 的作用域划分之内,生命周期不同的资源一般归不同的所有者;只是转发的所有者合并(ADR 002 D2),总是一起改动的所有者合并。上层只通过操作组合下层,不持有下层句柄,也不把下层资源再对外提供。 +- **所有者颗粒度**:在 [ADR 002 D1](../../adr/002-plugin-scope.md) 的作用域划分之内,生命周期不同的资源一般归不同的所有者;只是转发的所有者合并(ADR 002 D2)。上层只通过操作组合下层,不持有下层句柄,也不把下层资源再对外提供。 ### 7.2 评审检查 diff --git a/docs/templates/design.md b/docs/templates/design.md index 2d92b71c4d..d9a89ba8c5 100644 --- a/docs/templates/design.md +++ b/docs/templates/design.md @@ -26,7 +26,7 @@ Run results belong in the issue or PR. ## Rule check -Answer [design rules §4](../architecture/rust-agent/principles.md), §1 and +Answer [design rules §4](../architecture/rust-agent/principles.md), §1, the §7.2 owner checks and [ADR 002](../adr/002-plugin-scope.md) D1–D5 as required by AGENTS.md; explain inapplicable rules. ## Requirements raised to mechanism owners From 658e5a46178d124b2956c8fa4dcca6dc89fd25dd Mon Sep 17 00:00:00 2001 From: eric8810 Date: Mon, 23 Nov 2026 20:27:14 +0800 Subject: [PATCH 05/12] docs(principles): scope section 7 to owners and add ADR 027 Reach owners in an enclosing scope by id through the mechanism instead of Agents' sessions service, superseding that row of ADR 002 D2. Define the change unit as one owner, keep handles behind the object rule, treat registered contributions as the owner's surface, narrow the callback clause to synchronous calls in the commit lock, and route new owners through the design template. --- docs/adr/027-cross-scope-access-by-id.md | 59 ++++++++++++++++++++++ docs/adr/README.md | 1 + docs/architecture/rust-agent/principles.md | 16 +++--- docs/templates/design.md | 2 + docs/templates/owner-redesign.md | 13 +++-- 5 files changed, 79 insertions(+), 12 deletions(-) create mode 100644 docs/adr/027-cross-scope-access-by-id.md diff --git a/docs/adr/027-cross-scope-access-by-id.md b/docs/adr/027-cross-scope-access-by-id.md new file mode 100644 index 0000000000..90472b6f22 --- /dev/null +++ b/docs/adr/027-cross-scope-access-by-id.md @@ -0,0 +1,59 @@ +# 027: 跨作用域访问按 id 直达所有者 + +Decision status: Proposed. + +## Context + +[ADR 002](002-plugin-scope.md) D2 规定,进程插件经 Agents 的 `sessions` 服务访问其他 Session;[Session 访问契约](../design/contracts/session-access.md)据此定义了 `launch`、`input`、`lookup`、`history`、`pending`、`withdraw`、`stop`、`idle`、`delete`。D3 又规定插件只依赖本作用域或外层作用域,所以进程插件不能注入 Session 组或分支组的服务。 + +这些方法的数据和操作不属于 Agents:输入与撤回属于 InputQueue,历史属于 Timeline 的读取所有者,停止属于 Loop。Agents 每个方法都要先取得 Session,再转述对方的结果、错误和新鲜度。新增一种跨 Session 的需求,就要在 `sessions` 上再加一个方法。Session 部件访问本 Session 内分支所有者时,也有同样的问题。 + +[设计规则 §7](../architecture/rust-agent/principles.md#7-所有者与操作) 要求调用方直接请求数据的所有者,不代查,也不设只转发的门面。要满足这条,调用方需要一条能从外层作用域直接到达内层所有者的路径。 + +## Decision + +### D1. 外层作用域的调用方按 id 直达内层所有者 + +- 进程作用域的调用方用 Session id 到达 Session 组的服务,用 `(Session id, line id)` 到达分支组的服务。 +- Session 作用域的调用方用 line id 到达本 Session 分支组的服务。 +- 解析由机制完成,调用方直接调用目标所有者自己的操作。 +- 中间的所有者不按操作名转发,不包一层请求或回复,也不转述目标所有者的错误。 +- 目标不存在、未加载或正在关闭时,解析本身以错误结束,错误种类由机制定义。 + +### D2. 这是按 id 调用,不是依赖 + +- D3 的依赖方向不变:调用方不把内层服务声明为依赖,也不参与内层的装配顺序。 +- 调用方声明要调用的服务名,每次调用时按 id 解析。 +- 解析结果不跨调用保存,也不交给别的部件。 + +### D3. 让目标保持加载属于目标作用域的所有者 + +- 进程调用方需要一个 Session 在多次调用之间保持加载时,向 Agents 取一个绑定调用行的保持。行卸载时,保持随之结算。 +- 保持只决定 Session 是否加载,不提供对 Session 内部的访问。 + +### D4. Agents 只保留自己的操作 + +- Agents 拥有 Agent 与 Session 的实例:创建、关闭、删除,准入值,以及保持。 +- `sessions` 服务中属于其他所有者的方法删除,调用方按 D1 直接调用这些所有者: + - `input`、`lookup`、`pending`、`withdraw` 调 InputQueue; + - `history` 调 Timeline 的读取所有者; + - `stop` 调 Loop。 +- 各方法的去向由 Agents 的契约给出。 + +## Consequences + +- ADR 002 D2 表中「Reach other Sessions」一行由 D1 取代。 +- Session 访问契约的 `sessions` 服务按 D4 收缩,契约由它的所有者修改。 +- Collaboration、Scheduler、Workflow、EventHub、Rpc 的跨 Session 调用都改成 D1 的形状。 +- 机制要提供按 id 解析 Session 组与分支组服务的能力,而且它跨语言可用。 + +## Non-goals + +- 不改变作用域划分(ADR 002 D1)和依赖方向(D3)。 +- 不改变机制登记点:`sessionMethods`、`managementMethods`、`toolRegistry`。 +- 不规定任何语言的写法,写法属于绑定。 +- 不改变客户端协议:客户端仍经 Rpc 的方法表访问 Session。 + +## Supersession + +取代 [ADR 002](002-plugin-scope.md) D2 表中「Reach other Sessions」一行。D2 的其余各行和 D1、D3–D5 不变。 diff --git a/docs/adr/README.md b/docs/adr/README.md index 2da733ce20..c67c5d07e8 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -34,6 +34,7 @@ original text. | [024 — Web 抓取层使用请求库,地址策略在请求之前执行](024-web-fetch-transport.md) | Proposed | Follows 006 D1; replaces the hand-written transport and narrows the address policy to a pre-request check | | [025 — The plugin runtime baseline is rutis 0.23](025-rutis-0-23.md) | Proposed | Follows 015; sets the rutis version baseline and the protocol-5 upgrade rule | | [026 — Verification tiers, test coverage and CI governance](026-verification-tiers-and-ci-governance.md) | Proposed | Extends 008; defines three operational test states, verification tiers (L0–L4), form-only doc checks and CI governance | +| [027 — 跨作用域访问按 id 直达所有者](027-cross-scope-access-by-id.md) | Proposed | Supersedes the "Reach other Sessions" row of 002 D2; follows design rules §7 | Source baseline: [initial foundation parent](https://github.com/arcships/dim/commit/aaaffa5768e031d781abb73e45b1915b05dc2aa0). This baseline includes lifecycle fixes not necessarily present on the default branch. diff --git a/docs/architecture/rust-agent/principles.md b/docs/architecture/rust-agent/principles.md index b1dd97ab78..81ddec478c 100644 --- a/docs/architecture/rust-agent/principles.md +++ b/docs/architecture/rust-agent/principles.md @@ -115,7 +115,7 @@ Approval 与 Permission 只管 agent 决策引起的动作(工具调用); | 对象 | 规则 | | --- | --- | -| 资源(进程、PTY、文件与锁、连接、订阅等需要收尾的 I/O) | 创建、结算、取消、清理都在所有者内部完成;对外只给以 id 标识资源的操作,句柄不离开所有者 | +| 资源(进程、PTY、文件与锁、连接、订阅等需要收尾的 I/O) | 创建、结算、取消、清理都在所有者内部完成;对外只给以 id 标识资源的操作;句柄只按下文「交对象是最后手段」的条件交出 | | 业务状态 | 由事实推出:分支上的 Capability 写入并按序折叠事实(第 4 节);进程级所有者给出值(快照、配置),不进 Timeline(第 4 节规则 9) | 判据:交出去之后,所有者还要不要为它负责?要,就只能给操作。副本与投影则问:新鲜度由谁负责?持有者接受过期时可以持有;正确性依赖最新值时,向所有者请求或订阅。 @@ -124,19 +124,19 @@ Approval 与 Permission 只管 agent 决策引起的动作(工具调用); **交对象是最后手段。** id、值与回调都做不到时才交出对象。一旦交出对象,就要在更高一层统一设计相关插件的生命周期与边界:谁创建、谁持有、交接顺序、谁收尾、任何一方关闭或重载时如何处理,写进各方共同引用的设计中。"热路径"本身不是交出对象的理由。 -**不代查别人的资源。** 一个所有者不替别的所有者返回它的资源或数据,也不替它接收写入;调用方直接请求数据的所有者。有性能需求时重新定义归属,而不是增加代查。从公开事件折叠出的投影是投影者自己的状态,发布它的部件就是它的所有者。 +**不代查别人的资源。** 一个所有者不替别的所有者返回它的资源或数据,也不替它接收写入;调用方直接请求数据的所有者;调用方在外层作用域时,按 id 经机制直达所有者([ADR 027](../../adr/027-cross-scope-access-by-id.md))。有性能需求时重新定义归属,而不是增加代查。从公开事件折叠出的投影是投影者自己的状态,发布它的部件就是它的所有者。 -**一套公开面,控制概念数量。** 公开面就是所有者自身的操作:服务标注在所有者自己的类型上,Rust 在进程内直接调用这些方法,其他语言经 rutis 生成的派发与声明调用同一组操作([Dim 如何使用 rutis](../../design/rutis-usage.md))。每多一个接口就多一个概念:新增接口要从所有者的职责与边界说明为什么需要,不因某个调用方的需求增加。同一组操作不以两套接口存在,不为调用方另造只转发的门面、命令、控制或宿主对象。机制提供的登记点(`sessionMethods`、`managementMethods`、`toolRegistry`,[ADR 002](../../adr/002-plugin-scope.md))不是转发门面。 +**一套公开面,控制概念数量。** 公开面就是所有者自身的操作:Rust 在进程内直接调用,其他语言经 rutis 的派发与声明调用同一组操作([Dim 如何使用 rutis](../../design/rutis-usage.md))。每多一个接口就多一个概念:新增接口要从所有者的职责与边界说明为什么需要,不因某个调用方的需求增加。同一组操作不以两套接口存在,不为调用方另造只转发的门面、命令、控制或宿主对象。机制提供的登记点(`sessionMethods`、`managementMethods`、`toolRegistry`,[ADR 002](../../adr/002-plugin-scope.md))不是转发门面;所有者向登记点登记的方法与工具,是它经该登记点提供的公开面。 -**公开面以跨语言可用为准。** rutis 支持只在 Rust 内可用的方法与服务([Dim 如何使用 rutis](../../design/rutis-usage.md) §3.3);Dim 为了让跨语言插件的能力最大化、让插件的生命周期内聚,公开面不使用这一能力:参数、回复与错误是数据,资源以 id 表示([服务面](../../design/service-faces.md)第 1 节)。只能在 Rust 内使用的方法留在所有者内部。数据面不改变 Rust 进程内的直接调用,调用频率不是保留非数据面的理由。跨不了语言时按原因处理:参数不是数据就改形状;只服务同一功能内部的移出目录,作为私有名字;要求逐项回调或交出对象的,改操作颗粒度。 +**公开面以跨语言可用为准。** rutis 支持只在 Rust 内可用的方法与服务([Dim 如何使用 rutis](../../design/rutis-usage.md) §3.3);Dim 为了让跨语言插件的能力最大化、让插件的生命周期内聚,公开面不使用这一能力:参数、回复与错误是数据,资源以 id 表示([服务面](../../design/service-faces.md)第 1 节)。只能在 Rust 内使用的方法留在所有者内部。数据面不改变 Rust 进程内的直接调用,调用频率不是保留非数据面的理由。跨不了语言时按原因处理:参数不是数据就改形状;只服务同一功能内部的移出目录,作为私有名字;要求在提交锁内同步回调或交出对象的,改操作颗粒度。 **职责分界:业务面对更小的复杂度。** 设计接口前先分清所有者的内部职责与调用方的业务职责。接口用所有者自己的词汇表达,不出现调用方的业务概念;锁、版本、等待、重试、结算等所有者的内部机制不推给调用方,调用方只处理有业务含义的结果与异常。业务提出的需求,能用现有操作组合完成且不破坏所有者不变量的,留在业务侧;组合会破坏不变量的,才由所有者提供一个通用操作。每个参数都是复杂度,默认值由所有者决定,只有业务确实需要不同取值时才开放。 -**一个板块一次改完。** 改造一个插件板块的公开面时,新的操作、全部调用方的迁移与旧公开面的删除在同一个改动中完成,不保留新旧并存的兼容期。 +**一个所有者一次改完。** 改造一个所有者的公开面时,新的操作、全部调用方的迁移与旧公开面的删除在同一个改动中完成,不保留新旧并存的兼容期。一个插件的多个所有者可以分成多个改动,每个改动对它的所有者是完整的。[服务面](../../design/service-faces.md) §2.2 的 `internal(reason)` 记录的就是这类差距,随该所有者的改动一起消除。 ### 7.1 设计三问 -每个所有者在设计文档中回答,形状见 [owner-redesign 模板](../../templates/owner-redesign.md): +每个所有者在设计文档中回答下表(新所有者按[设计模板](../../templates/design.md),重设计已有所有者按 [owner-redesign 模板](../../templates/owner-redesign.md)): | 问题 | 要回答的内容 | | --- | --- | @@ -145,13 +145,13 @@ Approval 与 Permission 只管 agent 决策引起的动作(工具调用); | 对外业务 | 调用方的意图推出哪些操作与值;每个操作的取消、超时与错误种类 | - **操作颗粒度**:一个操作是资源的一次状态迁移或一次一致的读取,所有者能独立完成并收尾。调用方漏调或调错顺序就会破坏所有者状态,说明太细;夹带调用方的决定,或调用方只需要其中一部分,说明太粗。步骤之间以 id 衔接,策略作为数据参数传入。 -- **错误**:错误是操作契约的一部分,由每个所有者按调用方下一步能做什么自行设计,不套用通用种类;所有者不会出现的情况不写对应错误,也不泄漏内部错误。取消与超时写明各自停止的是什么。命令没有生效时按第 4 节规则 1 不写事件;已经发生的操作,后续决定依赖其失败的,写成事实。 +- **错误**:错误是操作契约的一部分,由每个所有者按调用方下一步能做什么自行设计,不套用通用种类;所有者不会出现的情况不写对应错误,也不泄漏内部错误。取消与超时写明各自停止的是什么。指令没有生效时按第 4 节规则 1 不写事件;已经发生的操作,后续决定依赖其失败的,写成事实。 - **所有者颗粒度**:在 [ADR 002 D1](../../adr/002-plugin-scope.md) 的作用域划分之内,生命周期不同的资源一般归不同的所有者;只是转发的所有者合并(ADR 002 D2)。上层只通过操作组合下层,不持有下层句柄,也不把下层资源再对外提供。 ### 7.2 评审检查 - 每个跨插件调用都落到某个所有者的一个操作上。 -- 交出去的只有值、只读视图或回调;交出对象的,有更高一层统一设计的生命周期与边界。 +- 默认只交出值、只读视图或回调;交出对象的,有更高一层统一设计的生命周期与边界。 - 没有转手别人的资源,没有代查别人的资源或数据。 - 同一组操作只有一套接口;每个新增接口都从所有者的职责说明了理由;没有只转发的门面、命令或控制对象。 - 公开面上没有只能在 Rust 内使用的方法;参数、回复与错误是数据,资源以 id 表示。 diff --git a/docs/templates/design.md b/docs/templates/design.md index d9a89ba8c5..6836a29c95 100644 --- a/docs/templates/design.md +++ b/docs/templates/design.md @@ -17,6 +17,8 @@ Identify the parts that are Capabilities. Affected inputs, outputs, events, state, errors and public dependencies. Link the owners' contracts. For changed events, explain their meaning, correlation and compatibility. Describe affected recovery and lifecycle behavior under the existing contracts. Distinguish existing promises from proposed changes. +For each owner, answer the [design rules §7.1](../architecture/rust-agent/principles.md#71-设计三问) +questions: its resources, their lifecycle and the operations callers need. ## Verification diff --git a/docs/templates/owner-redesign.md b/docs/templates/owner-redesign.md index 667a56fa0c..0dca5ea48c 100644 --- a/docs/templates/owner-redesign.md +++ b/docs/templates/owner-redesign.md @@ -3,8 +3,9 @@ Use this shape when an existing owner's public surface is redesigned under [design rules §7](../architecture/rust-agent/principles.md#7-所有者与操作). It has two parts. The design part is durable and goes into the owner's design document, `docs/design/plugins/.md`, -created from the [design template](design.md) when it does not exist. The delivery part is -temporary and goes into the owner's issue. +created from the [design template](design.md) when it does not exist. A plugin with several owners +has one document per owner, each listed in `docs/design/plugins/README.md`. The delivery part is +temporary and goes into the owner's issue. A new owner uses the [design template](design.md) alone. Write conclusions first. Name things directly instead of referring back. Do not restate rules or describe how the document was produced. Link evidence next to the claim it supports. @@ -40,7 +41,9 @@ creates, holds, hands over and cleans up the object, and what happens when any s ### Exceptions with reasons -One line each. +One line each, only for a deviation §7 allows, such as an object handed out with its shared +lifecycle design. A current shape that differs from §7 is a gap for the delivery part, not an +exception. ### Rule check and requirements raised to mechanism owners @@ -48,7 +51,9 @@ As in the [design template](design.md). ### Binding appendix -The `#[rutis::service]` block on the owner type, and the request, reply and error types. +The `#[rutis::service]` block on the owner type for the owner's own face; for what the owner +registers with a mechanism registration point, the registration call instead. Then the request, +reply and error types. ## Delivery part From 07baa8c89f7a11f15cc8763950826fa53df874b2 Mon Sep 17 00:00:00 2001 From: eric8810 Date: Mon, 23 Nov 2026 21:00:51 +0800 Subject: [PATCH 06/12] docs(adr): define the resolvable set and reach of ADR 027 Limit by-id access to the target scope's data faces, excluding registration points and lifecycle services, and make it available to language runtimes and leaves over rutis sessions while clients keep the Rpc method table. Leave the per-method mapping to the Agents contract. Hand out resource handles only as whole ownership transfers, use the owner unit in the review check and template, and link ADR 027 from ADR 002. --- docs/adr/002-plugin-scope.md | 2 + docs/adr/027-cross-scope-access-by-id.md | 58 +++++++++++++--------- docs/architecture/rust-agent/principles.md | 6 +-- docs/templates/owner-redesign.md | 5 +- 4 files changed, 43 insertions(+), 28 deletions(-) diff --git a/docs/adr/002-plugin-scope.md b/docs/adr/002-plugin-scope.md index 3df1092f5c..91d8fb0b79 100644 --- a/docs/adr/002-plugin-scope.md +++ b/docs/adr/002-plugin-scope.md @@ -11,6 +11,8 @@ gone. D4's location of structural configuration is corrected by [ADR 007](007-plugin-configuration.md). +D2's "Reach other Sessions" row is superseded by [ADR 027](027-cross-scope-access-by-id.md). + ## Context Dim assembles plugins at three scopes: the process, a Session, and a branch diff --git a/docs/adr/027-cross-scope-access-by-id.md b/docs/adr/027-cross-scope-access-by-id.md index 90472b6f22..5b871230a6 100644 --- a/docs/adr/027-cross-scope-access-by-id.md +++ b/docs/adr/027-cross-scope-access-by-id.md @@ -4,53 +4,65 @@ Decision status: Proposed. ## Context -[ADR 002](002-plugin-scope.md) D2 规定,进程插件经 Agents 的 `sessions` 服务访问其他 Session;[Session 访问契约](../design/contracts/session-access.md)据此定义了 `launch`、`input`、`lookup`、`history`、`pending`、`withdraw`、`stop`、`idle`、`delete`。D3 又规定插件只依赖本作用域或外层作用域,所以进程插件不能注入 Session 组或分支组的服务。 +[ADR 002](002-plugin-scope.md) D2 规定,进程插件经 Agents 的 `sessions` 服务访问其他 Session。[Session 访问契约](../design/contracts/session-access.md)据此定义了 `sessions` 的方法。ADR 002 D3 又规定插件只依赖本作用域或外层作用域,所以进程插件不能注入 Session 组或分支组的服务。 -这些方法的数据和操作不属于 Agents:输入与撤回属于 InputQueue,历史属于 Timeline 的读取所有者,停止属于 Loop。Agents 每个方法都要先取得 Session,再转述对方的结果、错误和新鲜度。新增一种跨 Session 的需求,就要在 `sessions` 上再加一个方法。Session 部件访问本 Session 内分支所有者时,也有同样的问题。 +`sessions` 的方法分两类: +- `launch`、`exists`、`delete` 是 Agents 自己的操作; +- 其余方法的数据和操作属于 Session 或分支内的所有者,例如输入的撤回与待处理属于 InputQueue,默认分支属于 TimelineTree,停止属于 Loop。 -[设计规则 §7](../architecture/rust-agent/principles.md#7-所有者与操作) 要求调用方直接请求数据的所有者,不代查,也不设只转发的门面。要满足这条,调用方需要一条能从外层作用域直接到达内层所有者的路径。 +对第二类方法,Agents 要先取得 Session,再转述对方的结果、错误和新鲜度。每新增一种跨 Session 的需求,就要在 `sessions` 上加一个方法。Session 部件访问本 Session 内的分支所有者,也有同样的问题。 + +[设计规则 §7](../architecture/rust-agent/principles.md#7-所有者与操作) 要求调用方直接请求数据的所有者,不代查,也不设只转发的门面。这需要一条从外层作用域到内层所有者的路径。rutis 已经按实例键提供数据面的派发:每个 Session 实例和分支实例下,都有该作用域数据面的派发入口([Dim 如何使用 rutis](../design/rutis-usage.md))。 ## Decision -### D1. 外层作用域的调用方按 id 直达内层所有者 +### D1. 外层作用域的调用方按 id 直达内层所有者的数据面 + +- 进程作用域的调用方:用 `sessionId` 到达 Session 组的数据面,用 `(sessionId, branchId)` 到达分支组的数据面。 +- Session 作用域的调用方:用 `branchId` 到达本 Session 分支组的数据面。 +- 机制按实例键解析到目标实例的派发入口,调用方直接调用目标所有者自己的操作。 +- 中间的所有者不按操作名转发,不包装请求或回复,也不转述目标所有者的错误。 +- 目标不存在、未加载或正在关闭时,解析以错误结束,错误种类由机制定义。 + +### D2. 可解析的只有目标作用域的数据面,不含登记点 -- 进程作用域的调用方用 Session id 到达 Session 组的服务,用 `(Session id, line id)` 到达分支组的服务。 -- Session 作用域的调用方用 line id 到达本 Session 分支组的服务。 -- 解析由机制完成,调用方直接调用目标所有者自己的操作。 -- 中间的所有者不按操作名转发,不包一层请求或回复,也不转述目标所有者的错误。 -- 目标不存在、未加载或正在关闭时,解析本身以错误结束,错误种类由机制定义。 +- 可解析的是目标作用域在 catalog 中共享的数据面。 +- 不包括机制登记点:`sessionMethods`、`toolRegistry` 等登记只能在本作用域内进行,因为登记属于登记方自己的 loader row。 +- 也不包括作用域的生命周期服务。 +- 各语言使用同一条路径:Rust 插件在进程内调用;TypeScript、Python 等语言运行时和 leaf 经 rutis 会话调用,与其他数据面相同。它们是宿主运行的可信本地代码,不靠 id 隔离([Dim 如何使用 rutis](../design/rutis-usage.md),AGENTS.md 规则 11)。 +- 哪些 link 能到达这条路径由部署决定([服务面](../design/service-faces.md) §2.1)。客户端不经这条路径,仍经 Rpc 的方法表与 Session 授权访问。 -### D2. 这是按 id 调用,不是依赖 +### D3. 按 id 调用不是依赖 -- D3 的依赖方向不变:调用方不把内层服务声明为依赖,也不参与内层的装配顺序。 +- ADR 002 D3 的依赖方向不变:调用方不把内层服务声明为依赖,也不参与内层的装配顺序。 - 调用方声明要调用的服务名,每次调用时按 id 解析。 - 解析结果不跨调用保存,也不交给别的部件。 -### D3. 让目标保持加载属于目标作用域的所有者 +### D4. 让目标保持加载属于 Agents -- 进程调用方需要一个 Session 在多次调用之间保持加载时,向 Agents 取一个绑定调用行的保持。行卸载时,保持随之结算。 +- 进程调用方需要一个 Session 在多次调用之间保持加载时,向 Agents 取一个保持。 +- 保持属于调用方的 loader row,在调用方释放或该 row 卸载时结算。 - 保持只决定 Session 是否加载,不提供对 Session 内部的访问。 -### D4. Agents 只保留自己的操作 +### D5. Agents 只保留自己的操作 - Agents 拥有 Agent 与 Session 的实例:创建、关闭、删除,准入值,以及保持。 -- `sessions` 服务中属于其他所有者的方法删除,调用方按 D1 直接调用这些所有者: - - `input`、`lookup`、`pending`、`withdraw` 调 InputQueue; - - `history` 调 Timeline 的读取所有者; - - `stop` 调 Loop。 -- 各方法的去向由 Agents 的契约给出。 +- `sessions` 中不属于 Agents 的方法删除,调用方按 D1 直接调用目标所有者。 +- 每个方法的去向由 [Agents 契约](https://github.com/arcships/dim/pull/2098)给出,目标操作由各所有者的契约定义。 ## Consequences - ADR 002 D2 表中「Reach other Sessions」一行由 D1 取代。 -- Session 访问契约的 `sessions` 服务按 D4 收缩,契约由它的所有者修改。 +- [Session 边界契约](../design/contracts/session-boundary.md)附录 F 中「No service lookup by name is added to the Session facade」不变:D1 的路径是机制的派发,不在 Session facade 上加查找。 +- Session 访问契约中 `sessions` 的方法表由 Agents 契约取代,Session 访问契约随 Agents 的契约改动一起修改。 - Collaboration、Scheduler、Workflow、EventHub、Rpc 的跨 Session 调用都改成 D1 的形状。 -- 机制要提供按 id 解析 Session 组与分支组服务的能力,而且它跨语言可用。 +- 机制要按实例键解析 Session 组与分支组的数据面,并且经 rutis 会话对各语言运行时和 leaf 可用。 +- Session 访问契约 §7「never exported over RPC entries or rutis links」随 `sessions` 一起取代:D1 的路径对语言运行时和 leaf 可用,对 RPC 入口不可用。 ## Non-goals -- 不改变作用域划分(ADR 002 D1)和依赖方向(D3)。 -- 不改变机制登记点:`sessionMethods`、`managementMethods`、`toolRegistry`。 +- 不改变作用域划分(ADR 002 D1)和依赖方向(ADR 002 D3)。 +- 不改变机制登记点及其登记方式。 - 不规定任何语言的写法,写法属于绑定。 - 不改变客户端协议:客户端仍经 Rpc 的方法表访问 Session。 diff --git a/docs/architecture/rust-agent/principles.md b/docs/architecture/rust-agent/principles.md index 81ddec478c..83d90479f3 100644 --- a/docs/architecture/rust-agent/principles.md +++ b/docs/architecture/rust-agent/principles.md @@ -115,14 +115,14 @@ Approval 与 Permission 只管 agent 决策引起的动作(工具调用); | 对象 | 规则 | | --- | --- | -| 资源(进程、PTY、文件与锁、连接、订阅等需要收尾的 I/O) | 创建、结算、取消、清理都在所有者内部完成;对外只给以 id 标识资源的操作;句柄只按下文「交对象是最后手段」的条件交出 | +| 资源(进程、PTY、文件与锁、连接、订阅等需要收尾的 I/O) | 创建、结算、取消、清理都在所有者内部完成;对外只给以 id 标识资源的操作;所有者仍要负责的句柄不离开所有者 | | 业务状态 | 由事实推出:分支上的 Capability 写入并按序折叠事实(第 4 节);进程级所有者给出值(快照、配置),不进 Timeline(第 4 节规则 9) | 判据:交出去之后,所有者还要不要为它负责?要,就只能给操作。副本与投影则问:新鲜度由谁负责?持有者接受过期时可以持有;正确性依赖最新值时,向所有者请求或订阅。 可以交出的是:值(快照、配置、身份;后续决定依赖修订时带版本)、只读视图(所有者发布、调用方只能观察的值及其订阅),以及按引用传递的回调(不在提交锁内同步调用,[服务面](../../design/service-faces.md)第 1 节规则 4)。 -**交对象是最后手段。** id、值与回调都做不到时才交出对象。一旦交出对象,就要在更高一层统一设计相关插件的生命周期与边界:谁创建、谁持有、交接顺序、谁收尾、任何一方关闭或重载时如何处理,写进各方共同引用的设计中。"热路径"本身不是交出对象的理由。 +**交对象是最后手段。** id、值与回调都做不到时才交出对象。一旦交出对象,就要在更高一层统一设计相关插件的生命周期与边界:谁创建、谁持有、交接顺序、谁收尾、任何一方关闭或重载时如何处理,写进各方共同引用的设计中。资源句柄只能整体转移:接收方成为它的所有者并负责结算,交出方不再为它负责;交出后仍要交出方收尾的句柄,是待改的差距。"热路径"本身不是交出对象的理由。 **不代查别人的资源。** 一个所有者不替别的所有者返回它的资源或数据,也不替它接收写入;调用方直接请求数据的所有者;调用方在外层作用域时,按 id 经机制直达所有者([ADR 027](../../adr/027-cross-scope-access-by-id.md))。有性能需求时重新定义归属,而不是增加代查。从公开事件折叠出的投影是投影者自己的状态,发布它的部件就是它的所有者。 @@ -157,4 +157,4 @@ Approval 与 Permission 只管 agent 决策引起的动作(工具调用); - 公开面上没有只能在 Rust 内使用的方法;参数、回复与错误是数据,资源以 id 表示。 - 接口里没有调用方的业务概念,也没有推给调用方的所有者内部机制;每个操作和参数都说明了为什么不能由调用方组合完成。 - 跨作用域的生命周期写明结算权与异常收尾。 -- 一个板块的改造在一个改动中完成,旧公开面同时删除。 +- 一个所有者的改造在一个改动中完成,旧公开面同时删除。 diff --git a/docs/templates/owner-redesign.md b/docs/templates/owner-redesign.md index 0dca5ea48c..0b3cd384e2 100644 --- a/docs/templates/owner-redesign.md +++ b/docs/templates/owner-redesign.md @@ -4,7 +4,7 @@ Use this shape when an existing owner's public surface is redesigned under [design rules §7](../architecture/rust-agent/principles.md#7-所有者与操作). It has two parts. The design part is durable and goes into the owner's design document, `docs/design/plugins/.md`, created from the [design template](design.md) when it does not exist. A plugin with several owners -has one document per owner, each listed in `docs/design/plugins/README.md`. The delivery part is +has one document per owner; the plugin's row in `docs/design/plugins/README.md` links each of them. The delivery part is temporary and goes into the owner's issue. A new owner uses the [design template](design.md) alone. Write conclusions first. Name things directly instead of referring back. Do not restate rules or @@ -38,6 +38,7 @@ that settles each resource. Ids, values, read-only views and callbacks cross owners. Where an object still has to be handed out, say why none of those works, and link the design shared by the plugins involved that fixes who creates, holds, hands over and cleans up the object, and what happens when any side closes or reloads. +A resource handle crosses only as a whole transfer: the receiver becomes its owner and settles it. ### Exceptions with reasons @@ -65,7 +66,7 @@ Written in the owner's issue; it is history once the change lands. - **Implementation task**: rewrite the owner's public surface; do not add an interface beside it. Read the responsibility split, write the callers' target code as flow tests, make the old public methods `pub(crate)` and use the compile errors as the migration list, implement the operations, - then migrate every caller. A plugin area's new operations, every caller and the removal of the old + then migrate every caller. The owner's new operations, every caller and the removal of the old surface are one change, with no period where old and new coexist. - **Acceptance**: the flow tests pass; no cross-crate reference to a deleted name remains; the catalog has no `internal(reason)` entry for the owner; the diff removes the old surface. From 2fc4f50b47529e17d51e92b1d7441734771226fc Mon Sep 17 00:00:00 2001 From: eric8810 Date: Mon, 23 Nov 2026 21:08:06 +0800 Subject: [PATCH 07/12] docs(adr): keep ADR 002 text unchanged Record ADR 027's supersession only in ADR 027 and the ADR index. --- docs/adr/002-plugin-scope.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/adr/002-plugin-scope.md b/docs/adr/002-plugin-scope.md index 91d8fb0b79..3df1092f5c 100644 --- a/docs/adr/002-plugin-scope.md +++ b/docs/adr/002-plugin-scope.md @@ -11,8 +11,6 @@ gone. D4's location of structural configuration is corrected by [ADR 007](007-plugin-configuration.md). -D2's "Reach other Sessions" row is superseded by [ADR 027](027-cross-scope-access-by-id.md). - ## Context Dim assembles plugins at three scopes: the process, a Session, and a branch From f91b72b3c6cf13512b488a4d83b0973509918932 Mon Sep 17 00:00:00 2001 From: eric8810 Date: Mon, 23 Nov 2026 21:54:54 +0800 Subject: [PATCH 08/12] docs(adr): name the by-id routing mechanism in ADR 027 The route is a new dim runtime mechanism that keeps instance keys inside their instance, answers NoInstance or Closed, and is raised as a mechanism requirement. Keep the session-access clauses in force until the Agents contract lands, keep Rpc's method table on the facade, and correct the registration and client wording. --- docs/adr/027-cross-scope-access-by-id.md | 63 +++++++++++++++++------- 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/docs/adr/027-cross-scope-access-by-id.md b/docs/adr/027-cross-scope-access-by-id.md index 5b871230a6..c1a10b6c31 100644 --- a/docs/adr/027-cross-scope-access-by-id.md +++ b/docs/adr/027-cross-scope-access-by-id.md @@ -12,7 +12,10 @@ Decision status: Proposed. 对第二类方法,Agents 要先取得 Session,再转述对方的结果、错误和新鲜度。每新增一种跨 Session 的需求,就要在 `sessions` 上加一个方法。Session 部件访问本 Session 内的分支所有者,也有同样的问题。 -[设计规则 §7](../architecture/rust-agent/principles.md#7-所有者与操作) 要求调用方直接请求数据的所有者,不代查,也不设只转发的门面。这需要一条从外层作用域到内层所有者的路径。rutis 已经按实例键提供数据面的派发:每个 Session 实例和分支实例下,都有该作用域数据面的派发入口([Dim 如何使用 rutis](../design/rutis-usage.md))。 +[设计规则 §7](../architecture/rust-agent/principles.md#7-所有者与操作) 要求调用方直接请求数据的所有者,不代查,也不设只转发的门面。这需要一条从外层作用域到内层所有者的路径,而现在没有这样的路径: + +- 每个 Session 实例和分支实例下,都有本作用域数据面的派发入口; +- 但实例键只能在实例内部读取,rutis 拒绝实例外的实例键([Session 边界契约](../design/contracts/session-boundary.md)中的 `Session::instance()` 需求)。 ## Decision @@ -20,51 +23,75 @@ Decision status: Proposed. - 进程作用域的调用方:用 `sessionId` 到达 Session 组的数据面,用 `(sessionId, branchId)` 到达分支组的数据面。 - Session 作用域的调用方:用 `branchId` 到达本 Session 分支组的数据面。 -- 机制按实例键解析到目标实例的派发入口,调用方直接调用目标所有者自己的操作。 -- 中间的所有者不按操作名转发,不包装请求或回复,也不转述目标所有者的错误。 -- 目标不存在、未加载或正在关闭时,解析以错误结束,错误种类由机制定义。 +- 调用方直接调用目标所有者自己的操作。中间的所有者不按操作名转发,不包装请求或回复,也不转述目标所有者的错误。 + +### D2. 路由由 dim 运行时按 id 完成,实例键不离开实例 + +- 这是一个新机制,所有者是 dim 运行时。 +- 运行时维护从 `sessionId`、`(sessionId, branchId)` 到当前存活实例的索引,把调用路由到目标实例内的派发入口。 +- 调用方只给 id 和服务名,拿不到实例键。所以「实例键只在实例内部可读」的约定不变。 +- 解析失败时的错误: + - `NoInstance`:目标没有存活的实例,可能是分支已结束、分支不属于该 Session,或者 Session 未加载。分支的情况不重试。进程调用方对未加载的 Session,先按 D5 取得保持再调用。 + - `Closed`:目标正在关闭,这一代不再服务。需要时向 Agents 重新取保持,调用落到下一代。 -### D2. 可解析的只有目标作用域的数据面,不含登记点 +### D3. 可解析的只有目标作用域的数据面 - 可解析的是目标作用域在 catalog 中共享的数据面。 -- 不包括机制登记点:`sessionMethods`、`toolRegistry` 等登记只能在本作用域内进行,因为登记属于登记方自己的 loader row。 +- 不包括机制登记点(`sessionMethods`、`toolRegistry` 等)。登记属于登记方这一代部件,其他语言的部件属于 bridge 的调用方 row,只能在本作用域内进行。 - 也不包括作用域的生命周期服务。 -- 各语言使用同一条路径:Rust 插件在进程内调用;TypeScript、Python 等语言运行时和 leaf 经 rutis 会话调用,与其他数据面相同。它们是宿主运行的可信本地代码,不靠 id 隔离([Dim 如何使用 rutis](../design/rutis-usage.md),AGENTS.md 规则 11)。 -- 哪些 link 能到达这条路径由部署决定([服务面](../design/service-faces.md) §2.1)。客户端不经这条路径,仍经 Rpc 的方法表与 Session 授权访问。 +- 各语言用同一条路径: + - Rust 插件在进程内调用; + - TypeScript、Python 等语言运行时和 UI leaf 经 rutis 会话调用,与其他数据面相同。它们是宿主运行的可信本地 rutis 节点,不靠 id 隔离([Dim 如何使用 rutis](../design/rutis-usage.md),AGENTS.md 规则 11)。 +- 哪些 link 能到达这条路径由部署决定([服务面](../design/service-faces.md) §2.1)。 +- RPC 客户端不经这条路径,仍经 Rpc 的方法表与 Session 授权访问。 -### D3. 按 id 调用不是依赖 +### D4. 按 id 调用不是依赖 - ADR 002 D3 的依赖方向不变:调用方不把内层服务声明为依赖,也不参与内层的装配顺序。 - 调用方声明要调用的服务名,每次调用时按 id 解析。 - 解析结果不跨调用保存,也不交给别的部件。 -### D4. 让目标保持加载属于 Agents +### D5. 让目标保持加载属于 Agents - 进程调用方需要一个 Session 在多次调用之间保持加载时,向 Agents 取一个保持。 - 保持属于调用方的 loader row,在调用方释放或该 row 卸载时结算。 - 保持只决定 Session 是否加载,不提供对 Session 内部的访问。 -### D5. Agents 只保留自己的操作 +### D6. Agents 只保留自己的操作 - Agents 拥有 Agent 与 Session 的实例:创建、关闭、删除,准入值,以及保持。 - `sessions` 中不属于 Agents 的方法删除,调用方按 D1 直接调用目标所有者。 -- 每个方法的去向由 [Agents 契约](https://github.com/arcships/dim/pull/2098)给出,目标操作由各所有者的契约定义。 +- 每个方法的去向由 Agents 契约给出,目标操作由各所有者的契约定义。Agents 契约在 [#2098](https://github.com/arcships/dim/pull/2098),交付部分在 [#2020](https://github.com/arcships/dim/issues/2020#issuecomment-7093864713) 跟踪。 +- Agents 契约合并之前,Session 访问契约的附录 A.1(`sessions` 方法表)与 §7(安全)仍然有效。 ## Consequences - ADR 002 D2 表中「Reach other Sessions」一行由 D1 取代。 -- [Session 边界契约](../design/contracts/session-boundary.md)附录 F 中「No service lookup by name is added to the Session facade」不变:D1 的路径是机制的派发,不在 Session facade 上加查找。 -- Session 访问契约中 `sessions` 的方法表由 Agents 契约取代,Session 访问契约随 Agents 的契约改动一起修改。 -- Collaboration、Scheduler、Workflow、EventHub、Rpc 的跨 Session 调用都改成 D1 的形状。 -- 机制要按实例键解析 Session 组与分支组的数据面,并且经 rutis 会话对各语言运行时和 leaf 可用。 -- Session 访问契约 §7「never exported over RPC entries or rutis links」随 `sessions` 一起取代:D1 的路径对语言运行时和 leaf 可用,对 RPC 入口不可用。 +- [Session 边界契约](../design/contracts/session-boundary.md)中以下两条不变: + - 附录 F「No service lookup by name is added to the Session facade」:D1 的路径由运行时路由,不在 Session facade 上加查找; + - 「实例键只在实例内部可读」:见 D2。 +- Agents 契约合并时,Session 访问契约随之修改: + - 附录 A.1 由 Agents 契约取代; + - §7「never exported over RPC entries or rutis links」改为 D3 的可达范围。 +- Collaboration、Scheduler、Workflow、EventHub 的跨 Session 调用改成 D1 的形状。 +- Rpc 的方法表派发仍走 Session facade;只有 Rpc 对被删除的 `sessions` 方法的调用改成 D1 的形状。 + +### 向机制所有者提出的需求 + +| 项 | 内容 | +| --- | --- | +| 被挡住的 | 设计规则 §7「不代查」:进程部件与 Session 部件要直接调用内层所有者,但 ADR 002 D3 禁止注入内层服务,Session 边界契约又规定实例键只能在实例内部读取。 | +| 考虑过的现有机制 | 经 Agents 的 `sessions` 转发:违反 §7。Session facade 按名查找:附录 F 已经排除。把实例键交给调用方:违反 D2 中实例键不离开实例的约定。 | +| 需要的通用能力 | 按 `sessionId`、`(sessionId, branchId)` 把对目标作用域某个数据面的调用路由到存活实例;失败时返回 `NoInstance` 或 `Closed`。不带业务含义。 | +| 对序号、批次、中断、重载的影响 | 无:路由不写事件,调用的语义由目标所有者的操作决定。目标重载后,索引指向新的一代。 | +| 所有者与 issue | dim 运行时。Session 到分支一段就是 SessionScope 契约([#2025](https://github.com/arcships/dim/issues/2025#issuecomment-7093412347))中的 `line_owner` 需求;进程到 Session 一段随 Agents 契约(#2020)一起提出。 | ## Non-goals - 不改变作用域划分(ADR 002 D1)和依赖方向(ADR 002 D3)。 - 不改变机制登记点及其登记方式。 - 不规定任何语言的写法,写法属于绑定。 -- 不改变客户端协议:客户端仍经 Rpc 的方法表访问 Session。 +- 不改变客户端协议:RPC 客户端仍经 Rpc 的方法表访问 Session。 ## Supersession From da6f4a950e0079b5f41281a58b305c350638b644 Mon Sep 17 00:00:00 2001 From: eric8810 Date: Tue, 24 Nov 2026 10:56:42 +0800 Subject: [PATCH 09/12] docs(principles): self-check section 7, ADR 027 and the template Track the by-id route in its own mechanism issue, tell business close from idle unload for Closed, cover one-shot calls, take service names at call time instead of composition, list every superseded sessions clause, and state that Rpc does not use sessions. In section 7, relate owner operations to section 4 rule 1 and add whole-transfer handles to the check. In the template, add Supersedes, the client-visible rule and the binding's wire requirements. --- docs/adr/027-cross-scope-access-by-id.md | 28 +++++++++++----------- docs/architecture/rust-agent/principles.md | 8 +++---- docs/templates/owner-redesign.md | 11 ++++++++- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/docs/adr/027-cross-scope-access-by-id.md b/docs/adr/027-cross-scope-access-by-id.md index c1a10b6c31..b16a81d47f 100644 --- a/docs/adr/027-cross-scope-access-by-id.md +++ b/docs/adr/027-cross-scope-access-by-id.md @@ -10,7 +10,7 @@ Decision status: Proposed. - `launch`、`exists`、`delete` 是 Agents 自己的操作; - 其余方法的数据和操作属于 Session 或分支内的所有者,例如输入的撤回与待处理属于 InputQueue,默认分支属于 TimelineTree,停止属于 Loop。 -对第二类方法,Agents 要先取得 Session,再转述对方的结果、错误和新鲜度。每新增一种跨 Session 的需求,就要在 `sessions` 上加一个方法。Session 部件访问本 Session 内的分支所有者,也有同样的问题。 +对第二类方法,Agents 要先取得 Session,再转述对方的结果、错误和新鲜度。每新增一种跨 Session 的需求,就要在 `sessions` 上加一个方法。Session 部件访问本 Session 内的分支所有者时,现在经 `Branch` 门面或交出的分支服务对象,同样绕开了所有者自己的操作。 [设计规则 §7](../architecture/rust-agent/principles.md#7-所有者与操作) 要求调用方直接请求数据的所有者,不代查,也不设只转发的门面。这需要一条从外层作用域到内层所有者的路径,而现在没有这样的路径: @@ -22,7 +22,7 @@ Decision status: Proposed. ### D1. 外层作用域的调用方按 id 直达内层所有者的数据面 - 进程作用域的调用方:用 `sessionId` 到达 Session 组的数据面,用 `(sessionId, branchId)` 到达分支组的数据面。 -- Session 作用域的调用方:用 `branchId` 到达本 Session 分支组的数据面。 +- Session 作用域的调用方:用 `branchId` 到达本 Session 分支组的数据面。`branchId` 就是分支线的 id(line id)。 - 调用方直接调用目标所有者自己的操作。中间的所有者不按操作名转发,不包装请求或回复,也不转述目标所有者的错误。 ### D2. 路由由 dim 运行时按 id 完成,实例键不离开实例 @@ -31,8 +31,8 @@ Decision status: Proposed. - 运行时维护从 `sessionId`、`(sessionId, branchId)` 到当前存活实例的索引,把调用路由到目标实例内的派发入口。 - 调用方只给 id 和服务名,拿不到实例键。所以「实例键只在实例内部可读」的约定不变。 - 解析失败时的错误: - - `NoInstance`:目标没有存活的实例,可能是分支已结束、分支不属于该 Session,或者 Session 未加载。分支的情况不重试。进程调用方对未加载的 Session,先按 D5 取得保持再调用。 - - `Closed`:目标正在关闭,这一代不再服务。需要时向 Agents 重新取保持,调用落到下一代。 + - `NoInstance`:目标没有存活的实例。分支已结束或不属于该 Session 时,不重试。Session 未加载时,进程调用方按 D5 取得保持后再调用。 + - `Closed`:目标实例正在关闭,这个实例不再服务。Session 作用域的调用方收到它,说明自己所在的 Session 正在关闭,结束本次工作。进程调用方需要继续时向 Agents 取保持:业务关闭的 Session 在本进程内不再加载,`acquire` 答 `session_closed`,到此为止;空闲卸载的 Session 由 `acquire` 加载下一代。 ### D3. 可解析的只有目标作用域的数据面 @@ -48,12 +48,13 @@ Decision status: Proposed. ### D4. 按 id 调用不是依赖 - ADR 002 D3 的依赖方向不变:调用方不把内层服务声明为依赖,也不参与内层的装配顺序。 -- 调用方声明要调用的服务名,每次调用时按 id 解析。 +- 调用方在每次调用时给出 id 和服务名,由运行时解析。调用方不在装配时声明内层组的名字:外层装配解析不了内层组的名字。 - 解析结果不跨调用保存,也不交给别的部件。 ### D5. 让目标保持加载属于 Agents -- 进程调用方需要一个 Session 在多次调用之间保持加载时,向 Agents 取一个保持。 +- Session 已加载时,单次调用不需要保持。 +- 进程调用方需要一个 Session 在多次调用之间保持加载,或者目标未加载,向 Agents 取一个保持;单次调用在调用后释放。 - 保持属于调用方的 loader row,在调用方释放或该 row 卸载时结算。 - 保持只决定 Session 是否加载,不提供对 Session 内部的访问。 @@ -62,7 +63,7 @@ Decision status: Proposed. - Agents 拥有 Agent 与 Session 的实例:创建、关闭、删除,准入值,以及保持。 - `sessions` 中不属于 Agents 的方法删除,调用方按 D1 直接调用目标所有者。 - 每个方法的去向由 Agents 契约给出,目标操作由各所有者的契约定义。Agents 契约在 [#2098](https://github.com/arcships/dim/pull/2098),交付部分在 [#2020](https://github.com/arcships/dim/issues/2020#issuecomment-7093864713) 跟踪。 -- Agents 契约合并之前,Session 访问契约的附录 A.1(`sessions` 方法表)与 §7(安全)仍然有效。 +- Agents 契约合并之前,Session 访问契约与 [sessions 服务设计](../design/appserver/sessions-service.md)中关于 `sessions` 的条款仍然有效。被取代的条款以 Agents 契约的「Supersedes」一节为准。 ## Consequences @@ -70,11 +71,10 @@ Decision status: Proposed. - [Session 边界契约](../design/contracts/session-boundary.md)中以下两条不变: - 附录 F「No service lookup by name is added to the Session facade」:D1 的路径由运行时路由,不在 Session facade 上加查找; - 「实例键只在实例内部可读」:见 D2。 -- Agents 契约合并时,Session 访问契约随之修改: - - 附录 A.1 由 Agents 契约取代; - - §7「never exported over RPC entries or rutis links」改为 D3 的可达范围。 -- Collaboration、Scheduler、Workflow、EventHub 的跨 Session 调用改成 D1 的形状。 -- Rpc 的方法表派发仍走 Session facade;只有 Rpc 对被删除的 `sessions` 方法的调用改成 D1 的形状。 +- Agents 契约合并时,`sessions` 的条款随之修改: + - Session 访问契约:附录 A.1 方法表、附录 A.6 错误、§1 与 §6 中的 `sessions` 行、附录 E 绑定由 Agents 契约取代;§7「never exported over RPC entries or rutis links」改为 D3 的可达范围; + - sessions 服务设计:`sessions` 服务、它的方法与决定由 Agents 契约取代,「Exposure」一行改为 D3 的可达范围。 +- `sessions` 的使用方 Collaboration、Scheduler、Workflow、EventHub 改成 D1 的形状。Rpc 不使用 `sessions`,它的方法表派发仍走 Session facade。 ### 向机制所有者提出的需求 @@ -82,9 +82,9 @@ Decision status: Proposed. | --- | --- | | 被挡住的 | 设计规则 §7「不代查」:进程部件与 Session 部件要直接调用内层所有者,但 ADR 002 D3 禁止注入内层服务,Session 边界契约又规定实例键只能在实例内部读取。 | | 考虑过的现有机制 | 经 Agents 的 `sessions` 转发:违反 §7。Session facade 按名查找:附录 F 已经排除。把实例键交给调用方:违反 D2 中实例键不离开实例的约定。 | -| 需要的通用能力 | 按 `sessionId`、`(sessionId, branchId)` 把对目标作用域某个数据面的调用路由到存活实例;失败时返回 `NoInstance` 或 `Closed`。不带业务含义。 | +| 需要的通用能力 | 按 `sessionId`、`(sessionId, branchId)` 把对目标作用域某个数据面的调用路由到存活实例;失败时返回 `NoInstance` 或 `Closed`。不带业务含义,也不把实例键交给调用方。 | | 对序号、批次、中断、重载的影响 | 无:路由不写事件,调用的语义由目标所有者的操作决定。目标重载后,索引指向新的一代。 | -| 所有者与 issue | dim 运行时。Session 到分支一段就是 SessionScope 契约([#2025](https://github.com/arcships/dim/issues/2025#issuecomment-7093412347))中的 `line_owner` 需求;进程到 Session 一段随 Agents 契约(#2020)一起提出。 | +| 所有者与 issue | dim 运行时,两段都在 [#2127](https://github.com/arcships/dim/issues/2127) 跟踪。使用方:Session 到分支一段是 SessionScope 与 TimelineTree 契约中的 `line_owner`([#2025](https://github.com/arcships/dim/issues/2025)、[#2024](https://github.com/arcships/dim/issues/2024));进程到 Session 一段是 Agents 契约([#2020](https://github.com/arcships/dim/issues/2020))。 | ## Non-goals diff --git a/docs/architecture/rust-agent/principles.md b/docs/architecture/rust-agent/principles.md index 83d90479f3..8b2964972e 100644 --- a/docs/architecture/rust-agent/principles.md +++ b/docs/architecture/rust-agent/principles.md @@ -124,11 +124,11 @@ Approval 与 Permission 只管 agent 决策引起的动作(工具调用); **交对象是最后手段。** id、值与回调都做不到时才交出对象。一旦交出对象,就要在更高一层统一设计相关插件的生命周期与边界:谁创建、谁持有、交接顺序、谁收尾、任何一方关闭或重载时如何处理,写进各方共同引用的设计中。资源句柄只能整体转移:接收方成为它的所有者并负责结算,交出方不再为它负责;交出后仍要交出方收尾的句柄,是待改的差距。"热路径"本身不是交出对象的理由。 -**不代查别人的资源。** 一个所有者不替别的所有者返回它的资源或数据,也不替它接收写入;调用方直接请求数据的所有者;调用方在外层作用域时,按 id 经机制直达所有者([ADR 027](../../adr/027-cross-scope-access-by-id.md))。有性能需求时重新定义归属,而不是增加代查。从公开事件折叠出的投影是投影者自己的状态,发布它的部件就是它的所有者。 +**不代查别人的资源。** 一个所有者不替别的所有者返回它的资源或数据,也不替它接收写入;调用方直接请求数据的所有者。调用所有者的操作不是替它决定:所有者在操作内自己决定,结果事件由它按第 4 节规则 1 写。调用方在外层作用域时,按 id 经机制直达所有者([ADR 027](../../adr/027-cross-scope-access-by-id.md))。有性能需求时重新定义归属,而不是增加代查。从公开事件折叠出的投影是投影者自己的状态,发布它的部件就是它的所有者。 **一套公开面,控制概念数量。** 公开面就是所有者自身的操作:Rust 在进程内直接调用,其他语言经 rutis 的派发与声明调用同一组操作([Dim 如何使用 rutis](../../design/rutis-usage.md))。每多一个接口就多一个概念:新增接口要从所有者的职责与边界说明为什么需要,不因某个调用方的需求增加。同一组操作不以两套接口存在,不为调用方另造只转发的门面、命令、控制或宿主对象。机制提供的登记点(`sessionMethods`、`managementMethods`、`toolRegistry`,[ADR 002](../../adr/002-plugin-scope.md))不是转发门面;所有者向登记点登记的方法与工具,是它经该登记点提供的公开面。 -**公开面以跨语言可用为准。** rutis 支持只在 Rust 内可用的方法与服务([Dim 如何使用 rutis](../../design/rutis-usage.md) §3.3);Dim 为了让跨语言插件的能力最大化、让插件的生命周期内聚,公开面不使用这一能力:参数、回复与错误是数据,资源以 id 表示([服务面](../../design/service-faces.md)第 1 节)。只能在 Rust 内使用的方法留在所有者内部。数据面不改变 Rust 进程内的直接调用,调用频率不是保留非数据面的理由。跨不了语言时按原因处理:参数不是数据就改形状;只服务同一功能内部的移出目录,作为私有名字;要求在提交锁内同步回调或交出对象的,改操作颗粒度。 +**公开面以跨语言可用为准。** rutis 支持只在 Rust 内可用的方法与服务([Dim 如何使用 rutis](../../design/rutis-usage.md) §3.3);Dim 为了让跨语言插件的能力最大化、让插件的生命周期内聚,公开面不使用这一能力:参数、回复与错误是数据,资源以 id 表示([服务面](../../design/service-faces.md)第 1 节)。只能在 Rust 内使用的方法留在所有者内部。数据面不改变 Rust 进程内的直接调用,调用频率不是保留非数据面的理由。跨不了语言时按原因处理:参数不是数据就改形状;只服务同一功能内部的移出 catalog,作为私有名字;要求在提交锁内同步回调或交出对象的,改操作颗粒度。 **职责分界:业务面对更小的复杂度。** 设计接口前先分清所有者的内部职责与调用方的业务职责。接口用所有者自己的词汇表达,不出现调用方的业务概念;锁、版本、等待、重试、结算等所有者的内部机制不推给调用方,调用方只处理有业务含义的结果与异常。业务提出的需求,能用现有操作组合完成且不破坏所有者不变量的,留在业务侧;组合会破坏不变量的,才由所有者提供一个通用操作。每个参数都是复杂度,默认值由所有者决定,只有业务确实需要不同取值时才开放。 @@ -145,13 +145,13 @@ Approval 与 Permission 只管 agent 决策引起的动作(工具调用); | 对外业务 | 调用方的意图推出哪些操作与值;每个操作的取消、超时与错误种类 | - **操作颗粒度**:一个操作是资源的一次状态迁移或一次一致的读取,所有者能独立完成并收尾。调用方漏调或调错顺序就会破坏所有者状态,说明太细;夹带调用方的决定,或调用方只需要其中一部分,说明太粗。步骤之间以 id 衔接,策略作为数据参数传入。 -- **错误**:错误是操作契约的一部分,由每个所有者按调用方下一步能做什么自行设计,不套用通用种类;所有者不会出现的情况不写对应错误,也不泄漏内部错误。取消与超时写明各自停止的是什么。指令没有生效时按第 4 节规则 1 不写事件;已经发生的操作,后续决定依赖其失败的,写成事实。 +- **错误**:错误是操作契约的一部分,由每个所有者按调用方下一步能做什么自行设计,不套用通用种类;所有者不会出现的情况不写对应错误,也不泄漏内部错误。取消与超时写明各自停止的是什么。指令没有生效时按第 4 节规则 1 不写结果事件;已经发生的操作,后续决定依赖其失败的,写成事实。 - **所有者颗粒度**:在 [ADR 002 D1](../../adr/002-plugin-scope.md) 的作用域划分之内,生命周期不同的资源一般归不同的所有者;只是转发的所有者合并(ADR 002 D2)。上层只通过操作组合下层,不持有下层句柄,也不把下层资源再对外提供。 ### 7.2 评审检查 - 每个跨插件调用都落到某个所有者的一个操作上。 -- 默认只交出值、只读视图或回调;交出对象的,有更高一层统一设计的生命周期与边界。 +- 默认只交出值、只读视图或回调;交出对象的,有更高一层统一设计的生命周期与边界;资源句柄只整体转移。 - 没有转手别人的资源,没有代查别人的资源或数据。 - 同一组操作只有一套接口;每个新增接口都从所有者的职责说明了理由;没有只转发的门面、命令或控制对象。 - 公开面上没有只能在 Rust 内使用的方法;参数、回复与错误是数据,资源以 id 表示。 diff --git a/docs/templates/owner-redesign.md b/docs/templates/owner-redesign.md index 0b3cd384e2..d4a4434e28 100644 --- a/docs/templates/owner-redesign.md +++ b/docs/templates/owner-redesign.md @@ -40,6 +40,14 @@ say why none of those works, and link the design shared by the plugins involved creates, holds, hands over and cleans up the object, and what happens when any side closes or reloads. A resource handle crosses only as a whole transfer: the receiver becomes its owner and settles it. +The client protocol and user-visible behavior stay as they are. List any change with its reason and +the affected clients. + +### Supersedes + +The clauses of other designs that define this owner's surface, each replaced by a link to this +contract or removed in the same change. Other owners' clauses stay. + ### Exceptions with reasons One line each, only for a deviation §7 allows, such as an object handed out with its shared @@ -54,7 +62,8 @@ As in the [design template](design.md). The `#[rutis::service]` block on the owner type for the owner's own face; for what the owner registers with a mechanism registration point, the registration call instead. Then the request, -reply and error types. +reply and error types. Error types serialize to the codes in the error table, callbacks are +direct parameters, and an operation bound to the calling row takes the caller. ## Delivery part From a3c7c4d8a2f2d288a18071bc8c1c51df88b87bf9 Mon Sep 17 00:00:00 2001 From: eric8810 Date: Tue, 24 Nov 2026 13:22:30 +0800 Subject: [PATCH 10/12] docs(adr): split ADR 027 route errors by Session and line Resolve the Session before the line: NoSession, SessionClosing and NoLine, each with the caller's next step. A closing line no longer reads as a closing Session. The owner-redesign template keeps an owner's design in its existing document in either plugin tree. --- docs/adr/027-cross-scope-access-by-id.md | 9 +++++---- docs/templates/owner-redesign.md | 8 +++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/docs/adr/027-cross-scope-access-by-id.md b/docs/adr/027-cross-scope-access-by-id.md index b16a81d47f..b70db6f6ec 100644 --- a/docs/adr/027-cross-scope-access-by-id.md +++ b/docs/adr/027-cross-scope-access-by-id.md @@ -30,9 +30,10 @@ Decision status: Proposed. - 这是一个新机制,所有者是 dim 运行时。 - 运行时维护从 `sessionId`、`(sessionId, branchId)` 到当前存活实例的索引,把调用路由到目标实例内的派发入口。 - 调用方只给 id 和服务名,拿不到实例键。所以「实例键只在实例内部可读」的约定不变。 -- 解析失败时的错误: - - `NoInstance`:目标没有存活的实例。分支已结束或不属于该 Session 时,不重试。Session 未加载时,进程调用方按 D5 取得保持后再调用。 - - `Closed`:目标实例正在关闭,这个实例不再服务。Session 作用域的调用方收到它,说明自己所在的 Session 正在关闭,结束本次工作。进程调用方需要继续时向 Agents 取保持:业务关闭的 Session 在本进程内不再加载,`acquire` 答 `session_closed`,到此为止;空闲卸载的 Session 由 `acquire` 加载下一代。 +- 运行时先解析 Session,再解析分支。解析失败时的错误: + - `NoSession`:Session 没有存活的实例,可能是空闲卸载、已关闭或不存在。只有进程调用方会收到。需要继续时按 D5 向 Agents 取保持:Agents 加载下一代后重新调用;Agents 答该 Session 已关闭或不存在,就到此为止。 + - `SessionClosing`:Session 实例正在关闭。目标是该 Session 内的分支时也答这个错误。Session 作用域的调用方收到它,说明自己所在的 Session 正在关闭,结束本次工作。进程调用方按 `NoSession` 处理。 + - `NoLine`:Session 存活,但分支没有存活的实例:分支实例正在关闭或已关闭、还没发布,或者不属于该 Session。对这个分支是最终结果,不取保持,不重试。分支写入 `branch/end` 之后、实例关闭之前,路由仍然到达分支的所有者,所有者按自己的契约回答。 ### D3. 可解析的只有目标作用域的数据面 @@ -82,7 +83,7 @@ Decision status: Proposed. | --- | --- | | 被挡住的 | 设计规则 §7「不代查」:进程部件与 Session 部件要直接调用内层所有者,但 ADR 002 D3 禁止注入内层服务,Session 边界契约又规定实例键只能在实例内部读取。 | | 考虑过的现有机制 | 经 Agents 的 `sessions` 转发:违反 §7。Session facade 按名查找:附录 F 已经排除。把实例键交给调用方:违反 D2 中实例键不离开实例的约定。 | -| 需要的通用能力 | 按 `sessionId`、`(sessionId, branchId)` 把对目标作用域某个数据面的调用路由到存活实例;失败时返回 `NoInstance` 或 `Closed`。不带业务含义,也不把实例键交给调用方。 | +| 需要的通用能力 | 按 `sessionId`、`(sessionId, branchId)` 把对目标作用域某个数据面的调用路由到存活实例;先解析 Session 再解析分支,失败时返回 `NoSession`、`SessionClosing` 或 `NoLine`(D2)。验收覆盖每个错误:空闲卸载后取保持再调用成功;业务关闭后取保持被拒;Session 关闭期间按 `branchId` 调用答 `SessionClosing`;Session 存活时分支关闭答 `NoLine`,Session 不受影响。不带业务含义,也不把实例键交给调用方。 | | 对序号、批次、中断、重载的影响 | 无:路由不写事件,调用的语义由目标所有者的操作决定。目标重载后,索引指向新的一代。 | | 所有者与 issue | dim 运行时,两段都在 [#2127](https://github.com/arcships/dim/issues/2127) 跟踪。使用方:Session 到分支一段是 SessionScope 与 TimelineTree 契约中的 `line_owner`([#2025](https://github.com/arcships/dim/issues/2025)、[#2024](https://github.com/arcships/dim/issues/2024));进程到 Session 一段是 Agents 契约([#2020](https://github.com/arcships/dim/issues/2020))。 | diff --git a/docs/templates/owner-redesign.md b/docs/templates/owner-redesign.md index d4a4434e28..ca5e2a5142 100644 --- a/docs/templates/owner-redesign.md +++ b/docs/templates/owner-redesign.md @@ -2,9 +2,11 @@ Use this shape when an existing owner's public surface is redesigned under [design rules §7](../architecture/rust-agent/principles.md#7-所有者与操作). It has two parts. The design -part is durable and goes into the owner's design document, `docs/design/plugins/.md`, -created from the [design template](design.md) when it does not exist. A plugin with several owners -has one document per owner; the plugin's row in `docs/design/plugins/README.md` links each of them. The delivery part is +part is durable and goes into the owner's existing design document: under +`docs/architecture/rust-agent/plugins/` for a plugin indexed in that tree's README, otherwise under +`docs/design/plugins/`. An owner without a design document gets `docs/design/plugins/.md`, +created from the [design template](design.md). A plugin with several owners has one document per +owner; the plugin's row in the index of the tree holding its design links each of them. The delivery part is temporary and goes into the owner's issue. A new owner uses the [design template](design.md) alone. Write conclusions first. Name things directly instead of referring back. Do not restate rules or From 9e629e9a6c67b821b60f10caca3c4cc8298c5f00 Mon Sep 17 00:00:00 2001 From: eric8810 Date: Tue, 24 Nov 2026 13:41:04 +0800 Subject: [PATCH 11/12] docs(adr): keep ADR 027 at the decision layer D2 states only that a failed resolution distinguishes a missing Session, a closing Session and a missing line. Error names, caller steps and acceptance belong to the mechanism owner in #2127; the superseded sessions clauses are listed by the Agents contract. --- docs/adr/027-cross-scope-access-by-id.md | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/docs/adr/027-cross-scope-access-by-id.md b/docs/adr/027-cross-scope-access-by-id.md index b70db6f6ec..d10747350e 100644 --- a/docs/adr/027-cross-scope-access-by-id.md +++ b/docs/adr/027-cross-scope-access-by-id.md @@ -30,10 +30,7 @@ Decision status: Proposed. - 这是一个新机制,所有者是 dim 运行时。 - 运行时维护从 `sessionId`、`(sessionId, branchId)` 到当前存活实例的索引,把调用路由到目标实例内的派发入口。 - 调用方只给 id 和服务名,拿不到实例键。所以「实例键只在实例内部可读」的约定不变。 -- 运行时先解析 Session,再解析分支。解析失败时的错误: - - `NoSession`:Session 没有存活的实例,可能是空闲卸载、已关闭或不存在。只有进程调用方会收到。需要继续时按 D5 向 Agents 取保持:Agents 加载下一代后重新调用;Agents 答该 Session 已关闭或不存在,就到此为止。 - - `SessionClosing`:Session 实例正在关闭。目标是该 Session 内的分支时也答这个错误。Session 作用域的调用方收到它,说明自己所在的 Session 正在关闭,结束本次工作。进程调用方按 `NoSession` 处理。 - - `NoLine`:Session 存活,但分支没有存活的实例:分支实例正在关闭或已关闭、还没发布,或者不属于该 Session。对这个分支是最终结果,不取保持,不重试。分支写入 `branch/end` 之后、实例关闭之前,路由仍然到达分支的所有者,所有者按自己的契约回答。 +- 解析失败时,调用方要能分清三种情况:Session 不在、Session 正在关闭、分支不在。分支结束不等于 Session 关闭:Session 仍然存活时,分支不在对这个分支是最终结果,不影响同一 Session 的其他调用。错误的名字、每种错误下调用方的下一步和验收,由机制所有者在 [#2127](https://github.com/arcships/dim/issues/2127) 定义。 ### D3. 可解析的只有目标作用域的数据面 @@ -63,8 +60,7 @@ Decision status: Proposed. - Agents 拥有 Agent 与 Session 的实例:创建、关闭、删除,准入值,以及保持。 - `sessions` 中不属于 Agents 的方法删除,调用方按 D1 直接调用目标所有者。 -- 每个方法的去向由 Agents 契约给出,目标操作由各所有者的契约定义。Agents 契约在 [#2098](https://github.com/arcships/dim/pull/2098),交付部分在 [#2020](https://github.com/arcships/dim/issues/2020#issuecomment-7093864713) 跟踪。 -- Agents 契约合并之前,Session 访问契约与 [sessions 服务设计](../design/appserver/sessions-service.md)中关于 `sessions` 的条款仍然有效。被取代的条款以 Agents 契约的「Supersedes」一节为准。 +- 每个方法的去向和被取代的条款由 Agents 契约([#2098](https://github.com/arcships/dim/pull/2098))给出,目标操作由各所有者的契约定义。 ## Consequences @@ -72,9 +68,7 @@ Decision status: Proposed. - [Session 边界契约](../design/contracts/session-boundary.md)中以下两条不变: - 附录 F「No service lookup by name is added to the Session facade」:D1 的路径由运行时路由,不在 Session facade 上加查找; - 「实例键只在实例内部可读」:见 D2。 -- Agents 契约合并时,`sessions` 的条款随之修改: - - Session 访问契约:附录 A.1 方法表、附录 A.6 错误、§1 与 §6 中的 `sessions` 行、附录 E 绑定由 Agents 契约取代;§7「never exported over RPC entries or rutis links」改为 D3 的可达范围; - - sessions 服务设计:`sessions` 服务、它的方法与决定由 Agents 契约取代,「Exposure」一行改为 D3 的可达范围。 +- [Session 访问契约](../design/contracts/session-access.md)与 [sessions 服务设计](../design/appserver/sessions-service.md)中的 `sessions` 服务由 Agents 契约取代,两份文档中关于可达范围的条款改为 D3。 - `sessions` 的使用方 Collaboration、Scheduler、Workflow、EventHub 改成 D1 的形状。Rpc 不使用 `sessions`,它的方法表派发仍走 Session facade。 ### 向机制所有者提出的需求 @@ -83,7 +77,7 @@ Decision status: Proposed. | --- | --- | | 被挡住的 | 设计规则 §7「不代查」:进程部件与 Session 部件要直接调用内层所有者,但 ADR 002 D3 禁止注入内层服务,Session 边界契约又规定实例键只能在实例内部读取。 | | 考虑过的现有机制 | 经 Agents 的 `sessions` 转发:违反 §7。Session facade 按名查找:附录 F 已经排除。把实例键交给调用方:违反 D2 中实例键不离开实例的约定。 | -| 需要的通用能力 | 按 `sessionId`、`(sessionId, branchId)` 把对目标作用域某个数据面的调用路由到存活实例;先解析 Session 再解析分支,失败时返回 `NoSession`、`SessionClosing` 或 `NoLine`(D2)。验收覆盖每个错误:空闲卸载后取保持再调用成功;业务关闭后取保持被拒;Session 关闭期间按 `branchId` 调用答 `SessionClosing`;Session 存活时分支关闭答 `NoLine`,Session 不受影响。不带业务含义,也不把实例键交给调用方。 | +| 需要的通用能力 | 按 `sessionId`、`(sessionId, branchId)` 把对目标作用域某个数据面的调用路由到存活实例;失败时区分 Session 不在、Session 正在关闭、分支不在(D2)。不带业务含义,也不把实例键交给调用方。 | | 对序号、批次、中断、重载的影响 | 无:路由不写事件,调用的语义由目标所有者的操作决定。目标重载后,索引指向新的一代。 | | 所有者与 issue | dim 运行时,两段都在 [#2127](https://github.com/arcships/dim/issues/2127) 跟踪。使用方:Session 到分支一段是 SessionScope 与 TimelineTree 契约中的 `line_owner`([#2025](https://github.com/arcships/dim/issues/2025)、[#2024](https://github.com/arcships/dim/issues/2024));进程到 Session 一段是 Agents 契约([#2020](https://github.com/arcships/dim/issues/2020))。 | From ff3298ff5787cd57e735457c05cc1eebd4da5b90 Mon Sep 17 00:00:00 2001 From: eric8810 Date: Tue, 24 Nov 2026 14:06:57 +0800 Subject: [PATCH 12/12] docs(templates): route an owner redesign to the document holding its design A plugin whose architecture page links a design under docs/design/plugins keeps its design there. --- docs/templates/owner-redesign.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/templates/owner-redesign.md b/docs/templates/owner-redesign.md index ca5e2a5142..b47ff1afa8 100644 --- a/docs/templates/owner-redesign.md +++ b/docs/templates/owner-redesign.md @@ -2,9 +2,11 @@ Use this shape when an existing owner's public surface is redesigned under [design rules §7](../architecture/rust-agent/principles.md#7-所有者与操作). It has two parts. The design -part is durable and goes into the owner's existing design document: under -`docs/architecture/rust-agent/plugins/` for a plugin indexed in that tree's README, otherwise under -`docs/design/plugins/`. An owner without a design document gets `docs/design/plugins/.md`, +part is durable and goes into the document that holds the owner's design. When the plugin's page +under `docs/architecture/rust-agent/plugins/` links a design under `docs/design/plugins/`, the +linked design is that document. Otherwise it is the plugin's architecture page, or its page under +`docs/design/plugins/` when it has no architecture page. An owner with neither gets +`docs/design/plugins/.md`, created from the [design template](design.md). A plugin with several owners has one document per owner; the plugin's row in the index of the tree holding its design links each of them. The delivery part is temporary and goes into the owner's issue. A new owner uses the [design template](design.md) alone.