Skip to content

docs(design): target contracts for the branch turn chain - #2102

Closed
eric8810 wants to merge 11 commits into
mainfrom
dim/2027-loop-contract
Closed

eric8810 wants to merge 11 commits into
mainfrom
dim/2027-loop-contract

Conversation

@eric8810

@eric8810 eric8810 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Target contracts for the branch turn chain (#2027), following the owner-redesign template in #2029 and the cross-cutting decisions in #2015.

Owners: Loop, ContextPreparation, ContextUsage, ModelProvider, Prompt adoption, PromptSourcesBranch, InputQueue, WaitBranch.

The delivery part — deletion list, caller migration, implementation task and acceptance — is the delivery comment on #2027.

Refs #2027
Refs #2015

Dependencies and merge order: #2029 (§7) → #2080 → #2091/#2092/#2093 (ContextProjection, ContextFacts, SummaryStrategy, RequestSettings) → #2100 (ToolBinding) and #2103 (PromptGuide, PromptSources, InputMethods, Wait). Links to files added by those PRs use the PR URL and say "target"; shared files touched here change only this owner's rows. After the merge order is fixed, rebase onto the owners' latest heads and re-check the names.

The binding appendix compiles in a temporary crate (workspace dim-agent-types and dim-agent-runtime plus rutis 0.23) with cargo check; the crate is not committed.

Merge order

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

Sibling heads this change is aligned with: #2091 f7425d55c, #2092 d96802349, #2100 437266bff, #2103 59a77a3d1. A paragraph that depends on a sibling names that PR; its head is the one above.

@eric8810

Copy link
Copy Markdown
Collaborator Author

评审(head 5413efde1):需改 3 处;Loop、ModelProvider、ContextUsage、PromptAdoption、WaitBranch 其余部分符合。

  1. Loop 在两个所有者之间搬运数据。 Loop 先调 ContextProjection 的 rendered_stream,再把投影作为参数交给 ContextPreparation 的 prepare。改成 ContextPreparation 在 prepare 内按同一截止自己读投影,Loop 只传 cutoff。
  2. InputQueue 自相矛盾。 职责分界和调用方示例写「由 operator entry 跑 submit checks,再调 withdraw」,例外写「withdraw 自己跑 submit checks」。按例外的理由(只有队列能原子替换),统一成 withdraw 自己跑,调用方示例只调 withdraw。
  3. 一个所有者三份文档。 Prompt.md 只改了一行状态,仍是旧设计;输入指南已由 docs(design): target contracts for the Session registries and tools #2103 的 PromptGuide.md 接手,分支采用由 PromptAdoption.md 定义。删掉 Prompt.md 里被取代的内容,或者改成只指向这两份契约。

@eric8810

Copy link
Copy Markdown
Collaborator Author

已按评审修改,head 27d97f30f。

  1. ContextPreparation 的 prepare 自己读投影。 prepare 在操作内按 source 的 cutoff 通过 ContextProjection 读并消费投影;Loop 只传 cutoff,PrepareRequest 去掉 projection 字段。职责分界、操作表、调用方示例、错误、流程、Verification、§7 行、绑定与交付评论同步。
  2. InputQueue 统一为 withdraw 自己跑 submit checks。 职责分界与调用方示例改为:operator entry 只做操作者内容校验,然后调 withdraw;checks、条件决定与原子替换都在 withdraw 内,例外理由保留一处。操作表、错误与交付评论同步。
  3. Prompt.md 只留指针。 输入指南移交 docs(design): target contracts for the Session registries and tools #2103 的 PromptGuide.md,分支采用由 PromptAdoption.md 定义;旧正文删除。旧章节标题保留为指向两份契约的锚点,代码注释引用的 #2-the-entry-route、#33-one-composition-two-paths、#61-the-plugin-bridge 等仍然有效;README 索引改指 PromptGuide.md。

检查:node scripts/adr-check.mjs --base origin/main 通过(10 changed files);cargo run --locked -p xtask-check 通过(含 101 个注释链接)。

@eric8810

Copy link
Copy Markdown
Collaborator Author

自查完成,head 56348699f。按 A–G:

  • A 绑定:所有错误类型改为 {code, message, ...} 形状(tag = "code"、snake_case、字段 camelCase),线上 code 与错误表一致;Loop/ModelProvider 的订阅改为直接参数 observe(&self, caller: &Ctx, listener),删除 Observe/Lease 请求结构;stopTurn/state/progress 改为同步写后返回;示例与签名一致;跨文档同名的 Listener/Lease/Observe 已消除;删掉 Loop 附录未用的 import。
  • B 一致性:submit 补 cancelled,configure 补 source_failed;compact 写明命令在第一个 await 前写入,取消或丢弃只停等待;各操作的错误表覆盖流程结局;事实的单一写入方在职责、流程、例外与 Rule check 中一致(context/configured 归 Prompt,compaction 事实归 ContextPreparation,输入结果归 InputQueue)。
  • C 取代:每份契约新增 Supersedes;只改描述本板块所有者的段落——runtime-owner-operations.md 的 agentLoop/contextPreparation/prompt/inputQueue 行、service-faces.md §3.5 与 §3.4/§4.8、session-access.md §2/A.4/绑定、session-boundary.md、timeline-branches.md §6、ContextCompaction.md §1/§1.1/§2.1;Prompt.md 只指向 PromptAdoption 与 PromptGuide,旧正文删除。
  • D 客户端:ModelProvider.md 增加 Client-visible changes:session.model.progress 增加 requestId、textCharacters、thinkingCharacters 三个增量字段;其余 RPC、通知、错误码与用户可见行为不变。
  • E 读取:没有新增 open/read/close 会话式读。
  • F 引用:PromptGuide 与 Wait(docs(design): target contracts for the Session registries and tools #2103 新增)改用 PR URL;README 的索引行与 By scope 同步;不引用 §7 标题,不列已关闭 issue。
  • G 按 id 访问:示例与需求写 line_owner::<T>(line);可调用分支组任何数据面,登记点与生命周期服务除外。

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

@yyhhyyyyyy yyhhyyyyyy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Scope: Target contracts for the branch turn chain (#2027), part of the owner-operations documentation series refs #2027 and #2015. The PR adds owner contracts for Loop, ContextPreparation, ContextUsage, ModelProvider, Prompt adoption, PromptSourcesBranch, InputQueue and WaitBranch, and rewires the surrounding contracts and indexes.

Verdict: REQUEST_CHANGES

P1

1. Manual compaction still has two owners

Problem: The new summary at ContextCompaction.md:21, items 4-5 at lines 44-45 and the §2.1 note at line 108 give the command, the single-flight slot and the step to ContextPreparation. The rest of the same file still assigns them to Loop and AgentLoop: the §2 diagram (line 92), §2.2 (line 127), §3 (line 150), §4.1 (line 170), §4.3 (line 233), §5.3 (line 807), §5.4-§5.5, §5.8 (line 1006) and the rule check (line 1260). ContextPreparation.md:14 gives the command and slot to ContextPreparation, and its Supersedes list at line 128 names only §1 items 4-5, §1.1 and §2.1. The header at ContextCompaction.md:5 also still declares Session parts plus supplements to Loop and ContextPreparation, while README.md:23 now calls the document a policy detail with no parts.

Failure scenario: An implementer following ContextCompaction writes context/compact from AgentLoop and keeps the Loop slot, while the Session RPC is routed to contextPreparation.compact. The two designs cannot both run, and a manual compaction requested during a request has no single sequencer or cancellation owner.

Fix: Keep ContextPreparation as the owner, update the listed sections, and extend the Supersedes list to §3, §4.1, §4.3, §5.3-§5.5, §5.8, §10 and §12. If the Loop should own the step instead, revert the lines that moved it.

P2

2. ContextUsage changes the wire values of baselineSource

Problem: The appendix at ContextUsage.md:152-157 defines BaselineSource with Counted and ProviderMeasured, serialized by camelCase as counted and providerMeasured. The repository already has dim_agent_types::BaselineSource at crates/dim-agent-types/src/model.rs:333-337 with wire values provider_baseline and full_estimate; ContextCompaction.md:166 still documents those values, and the CLI reads provider_baseline at crates/dim-cli/src/session_host.rs:607-608.

Failure scenario: Implementing this contract changes session.context.usage from provider_baseline or full_estimate to counted or providerMeasured. A provider-baselined read then renders as "estimated" in the CLI, and any client matching the old strings misreads the baseline.

Fix: Reuse dim_agent_types::BaselineSource and keep the existing wire values, or state a versioned breaking change and update every reader. Do not add a second type for the same data; the module's use dim_agent_types::* also makes the name shadow the existing type.

3. InputQueue's pending and withdraw shapes conflict with the existing read and #2103

Problem: The current session.input.pending (docs/design/input-state-read.md:3-16) returns a page {branchId, through, inputs, next} from TimelineTree.query. PR #2103's InputMethods keeps that page (InputMethods.md:80, 102) and states that it needs no InputQueue operation. This PR's InputQueue.pending (InputQueue.md:83) takes one inputId and returns {pending}, and InputQueue.md:154 says session.input.pending becomes its caller. Withdraw uses WithdrawRequest and publication_unknown here, while #2103 uses WithdrawInput and interrupted (InputMethods.md:63, 79).

Failure scenario: The Session entry cannot produce the client's page from a single-id bit, so the queued-messages inventory either loses its page or falls back to N+1 calls. If the owner's error is publication_unknown, the Session entry in #2103 maps a different code.

Fix: Keep the page read on TimelineTree and scope the owner pending to the single-id membership check, or add a paged owner operation and update #2103. Align the withdraw request type and the publication error name with the caller contract.

4. Prompt adoption's configure shape conflicts with #2103

Problem: #2103's PromptSources calls prompt.configure(ConfigureRequest::Initial(..)), ConfigureRequest::Loaded { sources: vec![entry] } and LanguageUpdate { version } (PromptSources.md:51-66), and compares adopted.version. This PR's ConfigureRequest is a single struct with (PromptSourceTarget, Option<PromptEntry>) pairs (PromptAdoption.md:186-193), AdoptedEntries has no version, and the configure row lists source_failed even though the request already carries loaded entries and the use/scope assigns loading to callers.

Failure scenario: The Session callers in #2103 cannot call this owner shape, and source_failed has no path. The two contracts cannot both land.

Fix: Align the configure request with #2103 or update #2103 in the same series; state who loads sources; remove source_failed or give it a request path.

5. Loop requires ToolBinding operations that #2100 does not define

Problem: Loop.md:67 lists bind, claim, transfer, retain_only and release, and line 145 asks for all five as data operations. PR #2100's ToolBinding defines bind, adopted, claim and transfer, and settles records and claims from the line's facts (ToolBinding.md:131-136, 154-155); it has no retain_only or release operation for Loop.

Failure scenario: Following Loop.md, the Loop calls operations that the ToolBinding owner does not provide; the two target contracts cannot both land.

Fix: Update Loop.md to bind, adopted, claim and transfer, or add retain_only and release to #2100 with a stated settlement rule.

6. ContextUsage's persistence contract is not specified and contradicts itself

Problem: ContextUsage.md:5 says the saved formats are decided in ADR 023, but ADR 023's Non-goals exclude snapshot formats, table structure and write transactions. The previous text carried the v5 and covered shapes; the new text says "at the version the format decides" (line 12) without naming an owner. Separately, line 12 says a context-usage/covered extension is written for a checked no-effect tail, line 71 says a no-effect source only advances in-memory state, line 109 says no new record, and the current code writes COVERED (crates/dim-agent-capabilities/src/context_usage.rs:115).

Failure scenario: Implementers have no format contract for recovered or covered, and they cannot tell whether a no-effect tail is persisted. Recovery and compatibility work will diverge.

Fix: State the recovered and covered format here or link the page that owns it; decide whether the covered record is written and state it once.

7. The projection handover contradicts ContextPreparation.md and #2093

Problem: ContextUsage.estimate takes a StreamedContext (ContextUsage.md:181) from ContextPreparation, but ContextPreparation.md:12 says no projection object crosses an owner and the preparation projects internally. PR #2093's ContextProjection contract says Loop builds the projection and hands it to ContextPreparation, and makes StreamedContext serde (ContextProjection.md:25, 164-180).

Failure scenario: The same projection has three owners: Loop renders it, ContextPreparation says it renders it, and ContextUsage receives it. Implementers cannot tell which call owns the cutoff and which value crosses the owner boundary.

Fix: Settle one handover. If the projection is a value, update ContextPreparation.md and say where it is rendered; if it stays inside ContextPreparation, estimate must take an id, cutoff or already-counted contributions.

8. ContextPreparation writes facts owned by Loop and ModelProvider

Problem: ContextPreparation.md:98 says prepare writes context/prepare and step/model-output-end on a host or budget failure. Loop.md:14 lists context/prepare among Loop's own turn and step facts; ModelProvider.md:13 and 86 say ModelProvider owns step/model-output-end. The current code writes context/prepare from AgentLoop (crates/dim-agent-capabilities/src/agent_loop.rs:1342) and the terminal from ModelProvider (crates/dim-agent-capabilities/src/model_provider.rs:145).

Failure scenario: Two owners write the same terminal fact, or recovery folds a preparation terminal that ModelProvider does not know about. The first-fact-wins and failure-chain rules become ambiguous.

Fix: Assign each fact one writer; if ContextPreparation must settle a request that never reached ModelProvider, state that exception in ModelProvider's contract and in both rule checks.

9. A committed cancelled compaction has no outcome

Problem: ContextPreparation.compact's reply is completed, skipped or failed, and its only cancellation error means "the wait stopped; the step continues" (ContextPreparation.md:96). A committed cancelled compaction has no variant, while ContextCompaction.md:176-177 and crates/dim-agent-capabilities/src/context_methods.rs:173 expose compaction_cancelled.

Failure scenario: A client waiting on an interrupted step cannot distinguish compaction_cancelled from operation_interrupted, and the documented reply is unreachable.

Fix: Add cancelled {reason} to CompactionOutcome, or define the mapping from the committed cancelled fact to the Session error code.

10. Broken relative links in service-faces.md

Problem: docs/design/service-faces.md uses ../plugins/InputQueue.md (line 149), ../plugins/Loop.md (lines 173-174), ../plugins/PromptAdoption.md (175, 180, 181), ../plugins/ContextPreparation.md (176), ../plugins/ContextUsage.md (177) and ../plugins/PromptSourcesBranch.md (320). From docs/design, this prefix resolves to docs/plugins, which does not exist.

Failure scenario: Every new link to the owner contracts returns 404, so the catalog cannot be followed.

Fix: Use plugins/InputQueue.md and the same form in all nine places.

11. Prompt.md removes anchors that five documents still link

Problem: The rewrite keeps only headings 2, 3.3, 4, 5, 6.1 and 6.3. Inbound links now point to missing anchors: ContextCompaction.md:2077 (#31-the-frame), EventHub.md:257 (#34-adopted-when-its-writer-loads), Scheduler.md:386, ShellInput.md:187 and Workflow.md:360 (#62-the-writers). Prompt.md:8 says the old sections remain as pointers so comments keep their anchors, but only some anchors remain.

Failure scenario: The five documents link to headings that no longer exist; a reader or code comment that follows one lands nowhere.

Fix: Keep a stub heading for every removed anchor, or update the five linkers and narrow the sentence at line 8 to the anchors that remain.

12. InputQueue documents line_ended but the error enum has no variant

Problem: InputQueue.md:81 and 92 list line_ended for submit; the appendix enum at lines 213-226 has Invalid, InputBlocked, PublicationUnknown, Cancelled and Closed.

Failure scenario: The submit path cannot return the documented error, and a caller matching line_ended gets a different variant or an internal error.

Fix: Add LineEnded, or remove the error from the operation and the Errors table.

13. adoptedConfiguration drops the revision the Intent promises

Problem: PromptAdoption.md:97 says the reply is the adopted settings and their revision, but the reply is {settings?} and the Adopted appendix at line 212 has only settings. Current Prompt::adopted_configuration returns (Option<ModelConfiguration>, u64) (crates/dim-agent-capabilities/src/prompt.rs:1074), and the App Server reports that cutoff (crates/dim-app-server/src/connection/tree.rs:609).

Failure scenario: session.agent.get and model_get lose the cutoff they currently return; a read at the returned state cannot be expressed, and existing callers break.

Fix: Add through or a revision to Adopted, or state which operation supplies the cutoff to the Session entry.

14. The unchanged model.progress notice cannot be built from the new Progress value

Problem: ModelProvider.md:92 says the notice keeps its field names and gains requestId, textCharacters and thinkingCharacters. requestId already exists (crates/dim-app-server/src/tree_protocol.rs:373). The new Progress value (lines 152-165) has counts, part ids and a different retry shape, but the notice keeps text, textOffset, thinking, thinkingOffset and tools, and rule check line 128 removes StateCell<ModelProgress>.

Failure scenario: After the state cell is removed, the notice's text and tool fields have no source; either the client-visible notice changes or an unstated second source remains.

Fix: State where the notice is built or extend Progress with the fields it needs; correct the additive-field list and reconcile the retry shape.

15. runtime-owner-operations keeps host APIs the new contracts replace

Problem: The Compaction row at line 31 is updated, but lines 69-75 still define PrepareModelHost, PrepareContextHost, ContextModelHost, CompactionStrategyHost and prepare(...) -> ModelRequest. Loop.md uses RequestSettings, GuideEntries and ContextPreparation.prepare; ContextPreparation.md:166 says ContextFacts and SummaryStrategy replace contextModelHost and compactionStrategyHost; ContextPreparation.prepare returns {} and the projection does not cross.

Failure scenario: Two contracts describe the same operations, and an implementer wires the old host ports that the new owner contracts no longer use.

Fix: Update lines 69-75, or state explicitly that they remain #2025's target and link the sibling contract; remove the old prepare return shape.

P3

16. Stale catalog rows and references

Problem:

  • service-faces.md:130 still lists promptSourcesBranch, while PromptSourcesBranch.md:111 says the service is removed. service-faces.md:185-187 still list prepareModelHost, contextModelHost and compactionStrategyHost as "to migrate", while Loop.md and ContextPreparation.md consume the new owners.
  • ContextCompaction.md:5 still declares Session parts plus supplements to Loop and ContextPreparation, and §4.4 still installs ProductSummaryStrategyPlugin and ContextMethodsPlugin; README.md:23 now calls the document a policy detail with no parts.
  • Recall.md:538 and docs/zh/design/plugins/Recall.md:303 still say compaction runs "as a Loop step"; ContextPreparation.md:14 moves the manual step to ContextPreparation.
  • Loop.md:109 says it supersedes the compaction row that assigns the manual command to agentLoop, but runtime-owner-operations.md:31 already assigns it to contextPreparation. PromptAdoption.md:132 lists initialCompletion, which runtime-owner-operations.md:61 no longer has.

Failure scenario: Readers follow stale rows and references after the new contracts land.

Fix: Update or remove them in this PR.

17. Appendix hygiene

Problem:

  • Unused imports remain in ContextUsage.md:150 (rutis::Ctx), ContextPreparation.md:178, PromptAdoption.md:182, InputQueue.md:165, WaitBranch.md:130 and several PublicService imports; the last commit removed the same class of import only from Loop.md.
  • ContextUsage.md:161 defines Usage in a module that does use dim_agent_types::* (crates/dim-agent-capabilities/src/context_usage.rs:10), and crates/dim-agent-capabilities/src/context_usage/sources.rs:39 uses the model Usage through use super::*; the new name shadows the existing type.
  • ContextPreparation's CompactionRequest { manual: bool } is always true and its Default is false, which the operation does not define; WaitRequest derives Default with timeout_ms 0, outside the documented 1 through cap range.

Failure scenario: The appendices do not compile as copied, and callers can construct invalid requests.

Fix: Remove unused imports and duplicate names; use a unit request or make the flag meaningful; do not derive Default for a request with a required positive timeout.

18. Examples and cross-PR type names

Problem:

  • PromptSourcesBranch.md:40 calls entries.get on a Vec and cancelled.child_token on CancelledFn.
  • #2103's Wait.md uses a WaitReply struct and a Reason enum (Wait.md:36-48), while WaitBranch.md:142 defines WaitOutcome as an internally tagged enum. Use the owner's type in the tool contract, or define one type for both.
  • #2096's Provider.md:53 uses line_owner::<PromptAdoption>, while this PR and #2103 use Prompt. Align the type name.
  • InputQueue.submit(SubmitRequest) and WaitBranch.wait(WaitRequest) change the generated TypeScript signatures at npm/branch-services.d.ts:225 and 711; the contract does not state the migration.

Failure scenario: Cross-language callers and sibling documents use different names and shapes.

Fix: Align the names and state the caller migration.

19. Session error mapping for ContextUsage

Problem: ContextUsage.md:73-84 defines not_configured, not_ready, unsupported, unknown, cancelled and closed, but the existing Session method maps the owner's failures to context_usage_unavailable, context_not_configured and context_model_failed (crates/dim-agent-capabilities/src/context_methods.rs:196-208). The contract should state the mapping, as InputQueue.md does for session.input.withdraw.

Failure scenario: A client that handles the existing codes gets a different error.

Fix: Add the mapping or preserve the existing codes.

20. Forward references and merge risk

Problem: The new docs cite #2103 (Prompt guide and Wait), #2029 (ADR 027), #2093 (line_owner and ContextProjection), #2096 (Provider) and #2100 (ToolBinding), all unmerged. The PR also touches shared files that the siblings edit (runtime-owner-operations.md, service-faces.md, session-access.md), so the series will conflict. The self-check commit did not catch the ownership text, the broken links or the unused imports.

Failure scenario: The contracts cannot be validated end to end, and the merge order changes the text.

Fix: State the dependency and merge order, rebase after the owning contracts land, and reconcile the self-check claims with the remaining issues.


The Loop runs the manual compaction step itself, in a tracked task, by calling
`ContextPolicy::compact_step`. It does not drive ContextPreparation through an event. The reasons:
The manual command and the step are ContextPreparation's; see [ContextPreparation](ContextPreparation.md). This section's earlier account of the Loop holding the step is superseded. The reasons it gave:

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.

Only §2.1 is marked superseded, but this document still assigns the manual command and step to Loop in the §2 diagram (line 92), §2.2 (line 127), §3 (line 150), §4.1 (line 170), §4.3 (line 233), §5.3 (line 807), §5.4-§5.5, §5.8 (line 1006) and the rule check (line 1260). ContextPreparation.md:14 gives the command, the single-flight slot and the step to ContextPreparation, and its Supersedes list at line 128 covers only §1 items 4-5, §1.1 and §2.1. Failure scenario: an implementer following this document writes the command and slot in the Loop while the Session RPC is routed to contextPreparation.compact, so the two designs cannot both run. Fix: keep ContextPreparation as the owner, update the sections above, and extend the Supersedes list to §3, §4.1, §4.3, §5.3-§5.5, §5.8, §10 and §12.

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 851f531. The command, the single-flight slot and the step are ContextPreparation's in the normative sections: ContextCompaction.md:5, 22, 95, 149-152, 234-236, 852-858, 912-944, 998-1008, 1260-1272; ContextPreparation.md:129-133 extends Supersedes to sections 2, 2.1, 2.2, 3, 4.1, 4.3, 5.3-5.5, 5.8, 10 and 12. The section 2 diagram and the section 4.1 route now name ContextPreparation. Two stale references remain and are in the new body as P3-4: the section 5.4 diagram still says Loop consumes k, and section 8 at 1238 still lists Loop as the supplement.

Comment thread docs/design/plugins/ContextUsage.md Outdated
Scope: branch. Issue: #2027.

## 1. 决定与边界
ContextUsage owns the numbers of a line's effective context: what each source contributed, the cumulative totals, the compaction cuts and the provider's measured baseline. The counting rules and the saved formats are decided in [ADR 023](../../adr/023-context-usage.md); the compaction interaction is [ContextCompaction §5](ContextCompaction.md#5-usage-and-the-compaction-cut). This document is the owner's target contract.

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 023 does not decide saved formats: its Non-goals explicitly exclude snapshot formats, table structure and write transactions. The previous ContextUsage text carried the v5 and covered shapes; this contract now says "at the version the format decides" (line 12) without naming an owner. Failure scenario: recovery and compatibility work has no format contract. Fix: state the recovered and covered format here or link the page that owns it. The link ContextCompaction.md#5-usage-and-the-compaction-cut also has no matching heading; §5 is Flows.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Partially fixed in 851f531. The formats are now stated: ContextUsage.md:12, 72, 101 give recovered v5, covered v1 and the handoff rule. What remains: the same line still links ContextCompaction.md#5-usage-and-the-compaction-cut, which has no heading (section 5 is Flows, and the usage state is section 5.7). The new body files it as P3-1.

Comment thread docs/design/plugins/ContextUsage.md Outdated
| `confirm` | Save the contributions for a request that was sent with the estimate's projection | `{requestId}` | `{}` | None; the owner completes the save | `unknown` (no estimate for the id), `closed` |

只将数字和来源截止交给 Usage 的按序任务,正文在请求准备结束后释放。初始化保存一份当前数字,不补建更早位置;与新来源按固定截止串接,不能漏计或重复累加。之后沿既有请求关联接收首轮 provider 基准。正常首次请求读取1遍、消息计数1遍,恢复读取0条历史正文。请求专有附加消息或不支持可组合计数的模型仍走实际请求计数合同,不把该总量保存成 Timeline 内容统计。
`read` answers at `through`, or at the branch's current sequence when absent. `estimate` is idempotent for one request id and projection: a repeated call answers the same numbers. `confirm` makes those numbers the request's contribution; without it the estimate is discarded at the next request or at close. A saved result is written only for a source that actually changed the numbers; a processed but no-effect source only advances the in-memory position.

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.

This says a no-effect source only advances the in-memory position, but line 12 promises a context-usage/covered extension for a checked no-effect tail, line 109 says no new record, and the current code writes COVERED (crates/dim-agent-capabilities/src/context_usage.rs:115). Failure scenario: implementers either drop the covered position and lose recovery state or write it against the verification. Fix: decide whether the covered record is written and state it once.

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 851f531. ContextUsage.md:12, 72 and 101 now say a checked no-effect tail at a fixed read or turn-end handoff extends the covered record, and any other no-effect source only advances the in-memory position. The three statements agree, and the code's cover path matches the handoff rule.

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

#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum BaselineSource {

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.

BaselineSource already exists at crates/dim-agent-types/src/model.rs:333 with wire values provider_baseline and full_estimate; ContextCompaction.md:166 still documents those, and crates/dim-cli/src/session_host.rs:607 reads provider_baseline. This new enum serializes as counted and providerMeasured, so session.context.usage changes values and a provider-baselined read renders as estimated. Failure scenario: existing clients silently misread the baseline. Fix: reuse the existing type or document a versioned break and update every reader. Naming this reply Usage also shadows dim_agent_types::Usage through the module glob.

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 851f531. ContextUsage.md:5 says the saved formats are this contract's, 40 and 153 import dim_agent_types::BaselineSource with provider_baseline and full_estimate, and the reply type is renamed UsageRead (157, 212), so the model Usage is no longer shadowed.

Comment thread docs/design/plugins/ContextUsage.md Outdated
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct EstimateRequest {
pub request_id: String,
pub projection: crate::history::StreamedContext,

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.

This makes ContextPreparation hand its projection to ContextUsage, but ContextPreparation.md:12 says no projection object crosses an owner and the preparation projects internally. Sibling PR #2093's ContextProjection contract also says Loop hands the projection to ContextPreparation and makes StreamedContext serde. Failure scenario: the three documents disagree about who projects and where the value crosses. Fix: settle one handover; if the projection is a value, update ContextPreparation.md; if it stays inside ContextPreparation, pass an id, cutoff or contributions here.

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 851f531. estimate now takes {requestId, through} (ContextUsage.md:69, 98, 175-178) and no longer receives a StreamedContext; ContextPreparation.md:12 and 42-45 render the projection and pass it once as a value. The remaining old handover in ContextCompaction section 15 is a separate P2 in the new body (P2-5).

| Fault producers and Session observers → `sessionLifecycle` | `reportFault(error) → void`, `failure({}) → SessionFault or null`, `observeFault(listener) → id`, `release(id) → boolean`. The listener receives the current failure (initially null) and subsequent reports. Caller unload releases the observation. The first fault wins until a storage failure supersedes it; the first storage failure wins. |
| Check providers and input admission → SubmitChecks | `register(name, check) → void`; `check({entry, branchId, user?, mode}, cancelled) → proceed{blocks, warnings} or block{message}`. Run in name order through the first block. Interrupted checks write nothing. |
| Compaction, stop and activity callers → `agentLoop` | `agentLoop.compact({}) → sequence`, `stopTurn({turnId, reason}) → sequence or null`; `agentLoop.state({}) → {phase, turnId?}`, `observe(listener)` delivers that snapshot. |
| Compaction → `contextPreparation`; stop and activity callers → `agentLoop` | `contextPreparation.compact(..)`; `agentLoop.stopTurn/state/observe`; see [Loop](../plugins/Loop.md) and [ContextPreparation](../plugins/ContextPreparation.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 Compaction row is updated, but lines 69-75 still define PrepareModelHost, PrepareContextHost, ContextModelHost, CompactionStrategyHost and prepare(...) -> ModelRequest. Loop.md uses RequestSettings, GuideEntries and ContextPreparation.prepare; ContextPreparation.md:166 says ContextFacts and SummaryStrategy replace the two hosts; ContextPreparation.prepare returns {}. Failure scenario: two contracts for the same operations and callers wire the old hosts. Fix: update lines 69-75 or state that they stay with #2025 and link the sibling target.

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 851f531. runtime-owner-operations.md:69-76 now lists RequestSettings, ContextFacts, SummaryStrategy, ContextProjection and the new ContextPreparation operations; the old PrepareModelHost, ContextModelHost and CompactionStrategyHost rows are gone.

Comment thread docs/design/plugins/InputQueue.md Outdated
| --- | --- | --- | --- | --- | --- |
| `submit` | Admit one input into the line, once per submission id | `{input}` | `{inputId, sequence}`; a repeated submission id answers the committed input | The caller cancels before the append; nothing is written | `invalid` (the input fails its own shape or scope), `line_ended` (the line has ended), `cancelled`, `closed` |
| `withdraw` | Withdraw one held input, optionally replacing it with a checked Steer | `{inputId, reason?, steer?}` | `{status}`: `deleted{sequence}` or `notHeld` | The caller cancels the wait; a committed withdrawal stands and a later call answers `notHeld` | `input_blocked` (a submit check refused the Steer), `invalid` (a malformed Steer candidate), `publication_unknown` (committed but publication unconfirmed), `cancelled`, `closed` |
| `pending` | Whether an input is held and unapplied at a cutoff | `{inputId, through?, includeBlockPresence?}` | `{pending}` | The caller cancels the wait for the cutoff; nothing changes | `closed`, `cancelled` |

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.

Two conflicts with the existing read and sibling PR #2103's InputMethods. The current session.input.pending (docs/design/input-state-read.md:3-16) returns a page of inputs through TimelineTree.query; #2103 InputMethods:80 and 102 keep that page and say it needs no InputQueue operation. This pending {inputId} reply {pending} cannot serve it, yet line 154 says the Session entry calls it. Withdraw also uses WithdrawRequest here and publication_unknown, while #2103 uses WithdrawInput and interrupted (InputMethods.md:63 and 79). Failure scenario: the client's queued-messages read loses its page, or the Session entry calls operations that do not answer its shape. Fix: keep the page on TimelineTree and scope pending to a single-id check, or add a paged operation and update #2103; align the withdraw type and error name.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Partially fixed in 851f531. The page read stays on TimelineTree (InputQueue.md:29, 85, 125, 154) and pending is a single-id membership check (83, 191-195). withdraw now uses WithdrawInput (174). What remains: the owner error is interrupted (82, 94, 212-213), while #2103's current InputMethods declares publication_unknown (79, 92) and session-access.md:234 keeps publication_unknown; session-access.md:533 also still binds the removed InputQueue::pending(input_id) -> bool. The new body files both as P2-2 and P2-6.

Comment thread docs/design/plugins/Loop.md Outdated
| --- | --- | --- |
| RequestSettings (#2025) | `settings` | The Session's default model settings before a configuration is adopted. |
| ContextPreparation | `prepare` | Build the request at the source's cutoff, project the history there and publish the handoff facts. |
| ToolBinding (#2028) | `bind`, `claim`, `transfer`, `retain_only`, `release` | Pin the request's tool handlers and release them when the request can no longer run. |

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.

PR #2100's ToolBinding defines bind, adopted, claim and transfer, and settles records and claims from facts without a caller release. retain_only and release are not operations there. Failure scenario: Loop calls operations the owner does not provide and the two target contracts cannot both land. Fix: update this row and line 145 to bind, adopted, claim, transfer, or get the two operations added to #2100.

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 851f531 for the named operations: Loop.md:67 and 145 use bind, adopted, claim and transfer, which #2100 defines. One new conflict remains: #2100's current ToolBinding defines release and retain_only for Loop's budget-recovery and rebuild (ToolBinding.md:37-38, 141-142, 176), while Loop.md:145 says the Loop calls no release or retain operation. The new body files it as P2-4.

let mut changed = Vec::new();
for target in checked {
let current = prompt_host.load(target.clone(), cancelled.child_token()).await?;
if current != entries.get(&target) {

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.

AdoptedEntries.entries is Vec<(PromptSourceTarget, PromptEntry)> (PromptAdoption.md:227), so entries.get(&target) does not compile. The same example calls cancelled.child_token(), but the documented cancellation type is CancelledFn (crates/dim-agent-capabilities/src/host.rs:1169), not a CancellationToken. Failure scenario: the example cannot be copied. Fix: use a map or a lookup over the Vec, and name the cancellation type.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Partially fixed in 851f531. CancelledFn replaces child_token (PromptSourcesBranch.md:38-40) and the example no longer calls entries.get. What remains: entries is Vec<(PromptSourceTarget, PromptEntry)> (PromptAdoption.md:213-214), so entry.source, entry.scope and entry.version at PromptSourcesBranch.md:41-42 are fields of a tuple, not of the entry; the example still does not compile. The new body files it as P3-2.

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

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct SubmitRequest {

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 current data face is submit(input: InputMessageData) (npm/branch-services.d.ts:225). Wrapping it in SubmitRequest { input } changes the wire to {input: ...} and breaks existing TypeScript callers; WaitBranch's wait(WaitRequest) does the same to wait(taskId, timeoutMs) (npm/branch-services.d.ts:711). Failure scenario: external plugin calls break with no migration note. Fix: state the shape change and the caller migration, or keep the existing parameter shape.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Fixed in 851f531. submit keeps the direct InputMessageData parameter (InputQueue.md:222), and WaitBranch adds the client-visible migration note for the request object (WaitBranch.md:76-78).

@eric8810

eric8810 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator Author

已按评审与自查标准修改,head 44e641995。

P1

  1. 手动压缩归 ContextPreparation。 ContextCompaction.md 中分给 Loop/AgentLoop 的命令、单飞槽位与步骤全部改掉:§2 图、§2.2 机制行、§3 所有者表、§4.1 方法、§4.3 事件表、§5.3 手动步骤、§5.4 调度与去重、§5.5(改为「What ContextPreparation gains」)、§5.8 表、§9 Rule check、§10、§12 与实现注记;Loop 只保留「步骤运行时不开始请求」。ContextPreparation.md 的 Supersedes 列全 §1 items 4–5、§1.1、§2、§2.1、§2.2、§3、§4.1、§4.3、§5.3–5.5、§5.8、§10、§12。ContextCompaction.md 头改为策略文档;§4.4 注明部件属于各所有者。

P2

  1. baselineSource 冻结。 删除本契约的 BaselineSource,复用 dim_agent_types::BaselineSource(provider_baseline/full_estimate);Usage 改名 UsageRead,避免与 use dim_agent_types::* 的同名类型冲突。
  2. InputQueue 与 docs(design): target contracts for the Session registries and tools #2103 对齐。 session.input.pending 的页读留在 TimelineTree,不调 InputQueue;所有者的 pending 只答单个 input 的成员判断,请求 {inputId, publishedCutoff?}(docs(design): target contracts for the Agents and Collaboration owners #2098 的 sessions.pending 用它)。withdraw 改用 WithdrawInput,发布失败错误码改 interrupted。
  3. Prompt configure 与 docs(design): target contracts for the Session registries and tools #2103 对齐。 ConfigureRequest 改为 Initial(ConfigureUpdate) / Loaded { sources } / LanguageUpdate { version } / Tools;Adopted 增加 through。加载路径写明:Initial 由所有者经 PromptSources 加载,Loaded 由调用方加载;source_failed 只属于 Initial。
  4. ToolBinding 操作与 design(tools): target contracts for the branch tool chain #2100 对齐。 Loop 只依赖 bind、adopted、claim、transfer;结算随 step/tool-result 与 turn/end,不再要求 retain_only/release。
  5. ContextUsage 持久化。 写明 context-usage/recovered v5、context-usage/covered v1;covered 只在固定读或 turn-end 交接处为已检查的无效果尾部写入,其他无效果源只推进内存位置。格式变更留作单独决定。
  6. 投影交接。 按 docs(design): target contracts for the Session scope and its host ports #2093 的最新 head,Loop 在 cutoff 渲染投影并把值交给 prepare;estimate 改为 {requestId, through},不再接收投影。
  7. 事实单一写入方。 Loop 写 context/prepare;prepare 写 model/call,或对未到达 ModelProvider 的请求写 step/model-output-end(作为 ModelProvider 契约声明的唯一例外),两个 Rule check 都写明。
  8. 已提交的取消压缩有结果。 CompactionOutcome 增加 cancelled { reason };Session 映射为 compaction_cancelled。
  9. service-faces 链接。 九处 ../plugins/ 改为 plugins/。
  10. Prompt.md 锚点。 增加 #31-the-frame、#34-adopted-when-its-writer-loads、#62-the-writers,保留 2/3.3/4/5/6.1/6.3;五份文档的链接不再落空。
  11. InputQueue line_ended。 错误枚举补 LineEnded。
  12. adoptedConfiguration 的 revision。 Adopted 增加 through,App Server 的 cutoff 仍由它返回。
  13. model.progress 不变。 复用 dim_agent_runtime::ModelProgress,notice 逐字段构建;删除「新增三个字段」的 Client-visible changes;session.turn.get 由 text_offset + text.len() 等字段计算。
  14. runtime-owner-operations 主机 API。 69–75 行改为 RequestSettings / ContextFacts / SummaryStrategy / ContextProjection(docs(design): target contracts for the Session scope and its host ports #2093 target)与 PrepareContextHost(保留的模型 profile 宿主端口),并更新 prepare、ContextUsage、ToolBinding 行。

P3

  1. 陈旧行。 promptSourcesBranch 行标记已删除;prepareModelHost/contextModelHost/compactionStrategyHost 行改为指向 docs(design): target contracts for the Session scope and its host ports #2093;ContextCompaction 头与 §4.4、Recall.md 与 zh 版、Loop 的 Supersedes 措辞、PromptAdoption 的 initialCompletion 项都改掉。
  2. 附录卫生。 删除未用 import;Usage 改名;CompactionRequest 改为空结构、不再有 Default 的 manual;WaitRequest 去掉 Default。
  3. 示例与类型名。 PromptSourcesBranch 示例改为 promptSources.load 与 configure(Loaded);WaitBranch 采用 docs(design): target contracts for the Session registries and tools #2103 的 WaitReply { reason, task_ids, waited_ms } 与 Reason;Provider 的 line_owner::<PromptAdoption> 已在 所有者扫描:模型与服务商 #2019 留评论要求改为 Prompt;wait 数据面的请求对象化在 Client-visible changes 写明迁移。inputQueue.submit 保持位置参数,生成签名不变。
  4. ContextUsage 的 Session 映射。 写明 not_configured → context_not_configured、not_ready → context_usage_unavailable、unsupported/unknown → context_model_failed。
  5. 依赖与合并顺序。 PR 描述与交付评论写明 docs(principles): add owners and operations #2029 → design(fileStorage): target contract #2080 → docs(storage): define the session storage owners' target contracts #2091/docs(design): define the line directory owner contract #2092/docs(design): target contracts for the Session scope and its host ports #2093 → design(tools): target contracts for the branch tool chain #2100/docs(design): target contracts for the Session registries and tools #2103;未合并文件用 PR URL 标 target;合并顺序确定后按所有者最新 head rebase。

自查额外修改

  • 绑定附录放进临时 crate(workspace 的 dim-agent-types、dim-agent-runtime + rutis 0.23)跑 cargo check 通过;错误类型统一 Debug, serde::Serialize, thiserror::Error 与 tag = "code", rename_all = "snake_case"。
  • Prompt.md 同时改为只指向 PromptGuide(docs(design): target contracts for the Session registries and tools #2103)与 PromptAdoption;旧正文删除、旧标题留锚点。
  • 共享文件只改本板块所有者的行:runtime-owner-operations.md、service-faces.md、session-access.md、session-boundary.md、timeline-branches.md、ContextCompaction.md、Recall.md/zh、PromptSourcesBranch。

客户端可见变更

  • session.model.progress 逐字段不变(复用 ModelProgress);session.context.usage 的 baselineSource 取值不变(复用 dim_agent_types::BaselineSource)。
  • wait 数据面的请求从位置参数改为 WaitRequest;TypeScript 调用方迁移为 wait({taskId?, timeoutMs}, cancelled),回复与错误码不变。
  • 其余 RPC、通知、错误码与用户可见行为不变。

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

@yyhhyyyyyy yyhhyyyyyy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Round 2 review: target contracts for the branch turn chain

Scope: target contracts for the branch turn chain (#2027): Loop, ContextPreparation, ContextUsage, ModelProvider, Prompt adoption, PromptSourcesBranch, InputQueue and WaitBranch, plus the surrounding owner indexes and the compaction and prompt rewires. Reviewed the full main...head at 851f531 (merge base 5a279d6), not only the delta.

Verdict: REQUEST_CHANGES

Round status

Round-1 finding Status
1. P1 manual compaction has two owners Fixed
2. BaselineSource wire values Fixed
3. InputQueue pending and withdraw vs the page and #2103 Partially fixed: error code name still conflicts with #2103; the session-access pending row is stale
4. Prompt adoption configure vs #2103 Partially fixed: this contract is an enum, #2103's current head still calls the old struct
5. Loop requires ToolBinding operations #2100 does not define Fixed for the named operations; a new release/retain_only conflict with #2100 remains (P2-4)
6. ContextUsage persistence contract Fixed
7. Projection handover has three owners Fixed for ContextUsage and ContextPreparation; the old handover in ContextCompaction section 15 remains (P2-5)
8. ContextPreparation writes facts owned by Loop and ModelProvider Fixed: the writers are named and the ModelProvider exception is stated; the prepare failure reply is a P3 gap
9. A committed cancelled compaction has no outcome Fixed
10. Broken service-faces links Fixed
11. Prompt.md removed anchors Fixed
12. line_ended missing from the enum Fixed
13. adoptedConfiguration drops the revision Fixed
14. model.progress notice has no source Fixed
15. runtime-owner-operations keeps old host APIs Fixed
16. Stale catalog rows and references Fixed
17. Appendix hygiene Fixed except a duplicate PublicService line (P3-3)
18. Examples and cross-PR type names Partially fixed: the PromptSourcesBranch example still does not compile; Provider.md still names PromptAdoption
19. Session error mapping for ContextUsage Fixed
20. Forward references and merge risk Open as a merge-order note (P3-7)

The round-1 P1 is resolved as an ownership contract. The command, the single-flight slot and the step are ContextPreparation's in the normative sections, and ContextPreparation.md:129-133 extends Supersedes to ContextCompaction sections 2, 2.1, 2.2, 3, 4.1, 4.3, 5.3-5.5, 5.8, 10 and 12. The remaining findings are two cross-PR caller mismatches, sibling API drift, one unclosed projection handover and one stale Rust binding. No round-1 opinion was a false positive; the fixed items can be withdrawn.

P2

P2-1. #2103's PromptSources cannot call the new ConfigureRequest

Problem: This PR changes ConfigureRequest to a tagged enum with Initial, Loaded { sources: Vec<PromptEntry> }, LanguageUpdate { version } and Tools (PromptAdoption.md:174-179), and Adopted has through but no version (198-202). #2103's current head 734d364 still calls the old struct shape ConfigureRequest { sources: Some(vec![(target, Some(entry))]), model: None, tools: None } in both the periodic check and the language update, and compares adopted.version (PromptSources.md:56-60, 72-75). PromptSources.md:198 says those types are Prompt adoption's.

Failure scenario: The two PRs cannot both land. The Session language update and the periodic source check cannot compile against this owner, and the Loaded variant has no caller. A client or plugin following #2103 sends {sources, model, tools} where this contract expects {kind, data}.

Evidence: docs/design/plugins/PromptAdoption.md:89, 174-179, 198-202; #2103 PromptSources.md:56-60, 72-75, 198 at head 734d364.

Fix: Update #2103's examples in the same series, or keep the struct request shape and express the variants as a versioned wire union. State the dependency and the merge order either way.

P2-2. InputQueue's interrupted conflicts with #2103's publication_unknown

Problem: withdraw now answers interrupted for a committed but unconfirmed withdrawal (InputQueue.md:82, 94, 212-213). #2103's current InputMethods declares publication_unknown for session.input.withdraw and never mentions interrupted (InputMethods.md:79, 92). PromptAdoption.md:85 and 98 use publication_unknown for the same condition, and session-access.md:234 keeps publication_unknown on the sessions method.

Failure scenario: The Session entry must invent a mapping from the owner's interrupted to its declared publication_unknown, or the client sees an undeclared code. A client that handles publication_unknown treats a committed withdrawal as a generic failure and may retry it.

Evidence: docs/design/plugins/InputQueue.md:82, 94, 212-213; #2103 InputMethods.md:63, 79, 92 at head 734d364; docs/design/plugins/PromptAdoption.md:85, 98; docs/design/contracts/session-access.md:234.

Fix: Keep publication_unknown here, or state the mapping in both contracts and update #2103. Do not add a third name for the same state.

P2-3. ContextUsage requires ToolRegistry operations that #2103 does not define

Problem: ContextUsage's dependency names definitions and toolSourcesView.get (ContextUsage.md:61, 142). #2103's current ToolRegistry exposes declarations and sources, and retires toolSourcesView (ToolRegistry.md:95, 110-112, 177). #2100's ToolBinding also says definitions is removed (ToolBinding.md:215).

Failure scenario: The path with no tools named in the adopted configuration calls operations the Session owner does not provide. An implementer either wires the removed toolSourcesView cell or cannot serve the no-tools case, and the two contracts cannot both land.

Evidence: docs/design/plugins/ContextUsage.md:61, 142; #2103 ToolRegistry.md:95, 110-112, 177 at head 734d364; #2100 ToolBinding.md:215 at head 038e60c.

Fix: Use toolRegistry.declarations() and sources() (or sources/observe_sources) and update the requirement bullet.

P2-4. Loop and #2100 disagree about release and retain_only

Problem: Loop's dependency lists only bind, adopted, claim and transfer, and its requirements say the Loop calls no release or retain operation because settlement follows step/tool-result and turn/end (Loop.md:67, 145). #2100's current ToolBinding defines release and retain_only, and says they exist for Loop's budget-recovery and rebuild steps (ToolBinding.md:37-38, 141-142, 176, 215). runtime-owner-operations.md:76 also omits both.

Failure scenario: On a rebuild, either the Loop follows this contract and leaves stale records until the owner closes, or it follows #2100 and calls an operation this contract forbids. The two target contracts cannot both land as written.

Evidence: docs/design/plugins/Loop.md:67, 145; docs/design/contracts/runtime-owner-operations.md:76; #2100 ToolBinding.md:37-38, 141-142, 176, 215 at head 038e60c.

Fix: Add release and retain_only where the Loop needs them, or get #2100 to make the owner settle a rebuild itself and say so in both contracts.

P2-5. ContextCompaction section 15 still describes the old projection handover and Usage save

Problem: The request-local projection handoff says the Loop passes the projection to ContextPreparation before publishing context/prepare, ContextPreparation retains one pending projection bound to the request object, and Usage computes and saves contributions when the final request still uses the original cutoff (ContextCompaction.md:2127-2143). ContextPreparation.md:12 and 162 say the projection crosses once as a value and the crate-private projection slot is removed. ContextUsage.md:70-72 and 93 say only confirm saves, after estimate. Section 15 is not in either contract's Supersedes list.

Failure scenario: An implementer builds a pending projection slot and a Usage save without confirm, while the new contracts remove the slot and require the confirm. The projection has two handovers and the saved contributions can be written twice or never.

Evidence: docs/design/plugins/ContextCompaction.md:2127-2143; docs/design/plugins/ContextPreparation.md:12, 103, 162; docs/design/plugins/ContextUsage.md:70-72, 93.

Fix: Add section 15 to ContextPreparation's and ContextUsage's Supersedes lists, or rewrite it to the value handover and the estimate/confirm pair.

P2-6. session-access Appendix E binds types and a method the InputQueue contract removes

Problem: The withdraw row binds line_owner::<InputQueue>(line)?.withdraw(WithdrawRequest { input_id, reason, steer }) (session-access.md:532), but the owner type is WithdrawInput (InputQueue.md:174-180). The next row still binds InputQueue::pending(input_id) -> bool and Session::service::<InputQueue> (session-access.md:533), while the owner contract removes the pending Rust method and defines pending(PendingRequest) -> Pending (InputQueue.md:146, 191-195, 224).

Failure scenario: The Rust binding names a type and a method that do not exist. An implementer following Appendix E cannot compile, and the Session page read is wired to the removed shape.

Evidence: docs/design/contracts/session-access.md:532-533; docs/design/plugins/InputQueue.md:146, 174-180, 191-195, 224.

Fix: Use WithdrawInput and line_owner::<InputQueue>(line)?.pending(PendingRequest { .. }) -> Pending, or add both rows to InputQueue's Supersedes.

P3

P3-1. ContextUsage's compaction link has no heading

Problem: ContextCompaction.md#5-usage-and-the-compaction-cut has no matching heading. Section 5 is Flows, and the usage state is section 5.7.

Failure scenario: The intro link 404s for a reader looking for the compaction interaction.

Evidence: docs/design/plugins/ContextUsage.md:5; docs/design/plugins/ContextCompaction.md:516, 979.

Fix: Link #5-flows or #57-compaction-state-for-clients.

P3-2. PromptSourcesBranch's lookup still indexes a tuple

Problem: entries is Vec<(PromptSourceTarget, PromptEntry)> (PromptAdoption.md:213-214), so the closure parameter is a tuple reference and entry.source, entry.scope and entry.version do not exist (PromptSourcesBranch.md:41-42).

Failure scenario: The example cannot be copied or compiled.

Evidence: docs/design/plugins/PromptSourcesBranch.md:41-42; docs/design/plugins/PromptAdoption.md:213-214.

Fix: entries.iter().find(|(source, _)| source == &target.source) then use .1.version, or return a keyed map.

P3-3. Appendix duplicates and a lost heading

Problem: ContextCompaction.md:177 duplicates the cancelled mapping already at 178, and lines 494-495 declare impl PublicService for ContextPreparation {} twice. WaitBranch.md:76 replaced the ## Exceptions with reasons heading with ## Client-visible changes, leaving the two exception bullets at 82-83 under the migration note.

Failure scenario: The appendix does not compile as copied, the map has two identical entries, and the exception list reads as part of the client-visible changes.

Evidence: docs/design/plugins/ContextCompaction.md:177-178, 494-495; docs/design/plugins/WaitBranch.md:76-83.

Fix: Delete the duplicate line and the duplicate impl, and restore the ## Exceptions with reasons heading.

P3-4. Compaction still has stale Loop ownership references

Problem: ContextCompaction.md:928 says the Loop's next_model starts a pending step, 1238 still lists Loop as the compaction supplement, and 952 says ContextPreparation injects CompactionStrategyHost while the target contract uses SummaryStrategy (ContextPreparation.md:89-90, 172). The overview still calls compaction a Loop step (overview.md:229), and the Chinese ContextCompaction still assigns the command, slot and step to Loop (docs/zh/design/plugins/ContextCompaction.md:100, 117, 157).

Failure scenario: A reader in these sections keeps the step start or the old port in the Loop, the same split the P1 described, even though the normative sections moved the owner.

Evidence: docs/design/plugins/ContextCompaction.md:928, 952, 1238; docs/design/overview.md:229; docs/zh/design/plugins/ContextCompaction.md:100, 117, 157.

Fix: Update these references or add them to the Supersedes lists. The Chinese page can be a follow-up, but it should not contradict the English owner contract.

P3-5. PromptHost and the Provider type name are stale

Problem: PromptAdoption.md:20 and PromptSourcesBranch.md:11, 63, 109, 121 still name PromptHost, which #2103 removes in favor of PromptSources (PromptSources.md:198). #2096's current Provider.md:53 and 65 still call line_owner::<PromptAdoption>, while this contract's type is Prompt.

Failure scenario: An implementer wires the removed PromptHost service or a nonexistent PromptAdoption type.

Evidence: docs/design/plugins/PromptAdoption.md:20; docs/design/plugins/PromptSourcesBranch.md:11, 63, 109, 121; #2103 PromptSources.md:198; #2096 Provider.md:53, 65 at head 13f9b94.

Fix: Use PromptSources and Prompt in the examples and the dependency rows.

P3-6. Operation-shape nits

Problem: prepare's reply is {} once model/call is committed, but the pre-ModelProvider failure path writes step/model-output-end and the errors list has no over_budget for prepare (ContextPreparation.md:99, 103, 105-109). runtime-owner-operations.md:72 says SummaryStrategy's compact returns cancelled, while #2093 returns completed, skipped or failed and makes cancelled an error (SummaryStrategy.md:72, 82 at head a4f2377).

Failure scenario: A Loop implementer waits for a model/call that the failure terminal replaced, and a SummaryStrategy caller handles a variant that never arrives.

Evidence: docs/design/plugins/ContextPreparation.md:99, 103, 105-109; docs/design/contracts/runtime-owner-operations.md:72; #2093 SummaryStrategy.md:72, 82.

Fix: Say prepare returns {} once model/call or its failure terminal is committed, or add over_budget to its errors; drop or cancelled from the SummaryStrategy row or name the two layers.

P3-7. Merge order is still unstated

Problem: This PR and the series edit the same shared files: runtime-owner-operations.md, service-faces.md, session-access.md and session-boundary.md. The cross-PR mismatches above are symptoms of the missing order.

Failure scenario: The series merges in a different order and the later PR restores an old shape or a stale row.

Evidence: the shared files in this PR's file list; the sibling edits in #2103, #2100 and #2093.

Fix: State the dependency and merge order, and rebase after the owning contracts land.

Verification

  • node scripts/adr-check.mjs --base 5a279d69 passes: ADR freeze passed, 19 changed files.
  • A link and anchor check over the 19 changed files finds ContextUsage.md -> ContextCompaction.md#5-usage-and-the-compaction-cut broken. ContextCompaction.md -> model-configuration.md#model-parameters and timeline-branches.md -> appserver/session-deletion-and-fork.md#62-why-main-only are pre-existing and not raised here.
  • This PR is docs only; no code tests were run. CI reports changes and ci-ok success, the other jobs skipped. mergeStateStatus is BLOCKED with reviewDecision CHANGES_REQUESTED.

Comment thread docs/design/plugins/ContextUsage.md Outdated
Scope: branch. Issue: #2027.

## 1. 决定与边界
ContextUsage owns the numbers of a line's effective context: what each source contributed, the cumulative totals, the compaction cuts and the provider's measured baseline. The counting rules are decided in [ADR 023](../../adr/023-context-usage.md); the saved formats are this contract's (below). The compaction interaction is [ContextCompaction §5](ContextCompaction.md#5-usage-and-the-compaction-cut). This document is the owner's target contract.

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.

Problem: [ContextCompaction section 5](ContextCompaction.md#5-usage-and-the-compaction-cut) has no matching heading. Section 5 is Flows, and the usage state is section 5.7.

Failure scenario: The intro link 404s for a reader looking for the compaction interaction.

Evidence: docs/design/plugins/ContextUsage.md:5; docs/design/plugins/ContextCompaction.md:516, 979.

Fix: Link #5-flows or #57-compaction-state-for-clients.

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 44e6419. ContextUsage.md:5 now links ContextCompaction.md#57-compaction-state-for-clients, which matches the heading at ContextCompaction.md:977.


#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(tag = "kind", content = "data", rename_all = "camelCase")]
pub enum ConfigureRequest {

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.

Problem: #2103's current head 734d364 still calls the old struct shape ConfigureRequest { sources: Some(vec![(target, Some(entry))]), model: None, tools: None } and compares adopted.version (PromptSources.md:56-60, 72-75), while this enum has Initial, Loaded, LanguageUpdate and Tools and Adopted has no version (198-202). PromptSources.md:198 says these types are Prompt adoption's.

Failure scenario: The two PRs cannot both land. The Session language update and the periodic source check cannot compile against this owner, and the Loaded variant has no caller.

Evidence: docs/design/plugins/PromptAdoption.md:89, 174-179, 198-202; #2103 PromptSources.md:56-60, 72-75, 198 at head 734d364.

Fix: Update #2103's examples in the same series, or keep the struct request shape and express the variants as a versioned wire union.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Partially fixed in 44e6419. #2103 at 69071dd now calls ConfigureRequest::Initial, Loaded { sources } and LanguageUpdate (PromptSources.md:52, 57, 68) and says the enum is #2102's (190), so the configure shapes agree. What remains is #2103 PromptSources.md:56, which still compares adopted.version; this contract's Adopted has settings? and through (PromptAdoption.md:198-202), and adoptedEntries returns (target, entry) pairs (213-214), so the example should call adoptedEntries. Filed as an optional P3 in the round-3 body.

Comment thread docs/design/plugins/InputQueue.md Outdated
| Operation | Intent | Request | Reply | Cancellation | Errors |
| --- | --- | --- | --- | --- | --- |
| `submit` | Admit one input into the line, once per submission id | `{input}` | `{inputId, sequence}`; a repeated submission id answers the committed input | The caller cancels before the append; nothing is written | `invalid` (the input fails its own shape or scope), `line_ended` (the line has ended), `cancelled`, `closed` |
| `withdraw` | Withdraw one held input, optionally replacing it with a Steer | `{inputId, reason?, steer?}` | `{status}`: `deleted{sequence}` or `notHeld` | The caller cancels the wait; a committed withdrawal stands and a later call answers `notHeld` | `input_blocked` (a submit check refused the Steer), `invalid` (a malformed Steer candidate), `interrupted` (committed but publication unconfirmed), `cancelled`, `closed` |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Problem: withdraw answers interrupted for a committed but unconfirmed withdrawal, but #2103's current InputMethods declares publication_unknown for session.input.withdraw and never mentions interrupted (InputMethods.md:79, 92 at head 734d364). PromptAdoption.md:85 and 98 use publication_unknown for the same condition, and session-access.md:234 keeps publication_unknown.

Failure scenario: The Session entry must invent a mapping, or the client sees an undeclared code and treats a committed withdrawal as a generic failure.

Evidence: docs/design/plugins/InputQueue.md:82, 94, 212-213; #2103 InputMethods.md:63, 79, 92; docs/design/plugins/PromptAdoption.md:85, 98; docs/design/contracts/session-access.md:234.

Fix: Keep publication_unknown here, or state the mapping in both contracts and update #2103.

Comment thread docs/design/plugins/ContextUsage.md Outdated
| Owner | Operation | Use |
| --- | --- | --- |
| ContextFacts (#2025, Session) | `describe`, `contributions`, `estimate` | The additive counter, the fixed contribution and one contribution's size. |
| ToolRegistry (#2026, Session) | `definitions`, `toolSourcesView.get` | The current tool declarations when the adopted configuration names no tools. |

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.

Problem: The dependency names toolRegistry.definitions and toolSourcesView.get, but #2103's current ToolRegistry exposes declarations and sources and retires toolSourcesView (ToolRegistry.md:95, 110-112, 177 at head 734d364). #2100's ToolBinding also says definitions is removed (ToolBinding.md:215).

Failure scenario: The path with no tools named in the adopted configuration calls operations the owner does not provide, so the two contracts cannot both land.

Evidence: docs/design/plugins/ContextUsage.md:61, 142; #2103 ToolRegistry.md:95, 110-112, 177; #2100 ToolBinding.md:215 at head 038e60c.

Fix: Use toolRegistry.declarations() and sources() (or sources/observe_sources) and update the requirement bullet.

Comment thread docs/design/plugins/Loop.md Outdated
| --- | --- | --- |
| RequestSettings (#2025) | `settings` | The Session's default model settings before a configuration is adopted. |
| ContextPreparation | `prepare` | Build the request at the source's cutoff from the projection and publish the handoff facts. |
| ToolBinding (#2028) | `bind`, `adopted`, `claim`, `transfer` | Pin the request's tool generation, read its declarations, register the calls' claims and move the record to a retry; settlement follows the line's facts. |

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.

Problem: The row lists only bind, adopted, claim and transfer, and line 145 says the Loop calls no release or retain operation, but #2100's current ToolBinding defines release and retain_only for Loop's budget-recovery and rebuild steps (ToolBinding.md:37-38, 141-142, 176, 215 at head 038e60c).

Failure scenario: On a rebuild, either the Loop follows this contract and leaves stale records until the owner closes, or it follows #2100 and calls an operation this contract forbids.

Evidence: docs/design/plugins/Loop.md:67, 145; docs/design/contracts/runtime-owner-operations.md:76; #2100 ToolBinding.md:37-38, 141-142, 176, 215.

Fix: Add release and retain_only where the Loop needs them, or get #2100 to make the owner settle a rebuild itself and say so in both contracts.

in-flight compaction.
- It maps the outcome: `completed` → `{status: "completed", sequence}`;
`skipped` → `{status: "skipped", reason}`; `failed` → `compaction_failed`;
`cancelled` → `compaction_cancelled`;

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.

Problem: The mapping now lists cancelled -> compaction_cancelled twice (177 and 178).

Failure scenario: The mapping is ambiguous and the copied text is wrong.

Evidence: docs/design/plugins/ContextCompaction.md:177-178.

Fix: Delete one.

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 44e6419. The duplicate cancelled -> compaction_cancelled line is gone; ContextCompaction.md:174-177 now has one mapping.

-> Result<ContextUsage, ContextOpError>; }
impl ContextPreparation { pub async fn compact(&self, request: CompactionRequest, cancelled: CancelledFn)
-> Result<CompactionOutcome, PreparationError>; }
impl PublicService for ContextPreparation {}

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.

Problem: impl PublicService for ContextPreparation {} appears twice (494-495).

Failure scenario: The appendix does not compile as copied.

Evidence: docs/design/plugins/ContextCompaction.md:494-495.

Fix: Delete one.

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 44e6419. The duplicate declaration is gone; the appendix has one impl PublicService for ContextPreparation {} at ContextCompaction.md:493.




- A reload ends an accepted wait with an error rather than replaying an arrival: a cancelled background task emits no wake, and an arrival from the previous generation is not a wake the model can still act on.

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.

Problem: The ## Exceptions with reasons heading was replaced by ## Client-visible changes, so these two exception bullets (82-83) sit under the migration note.

Failure scenario: The contract's exception list has no heading and reads as part of the client-visible changes.

Evidence: docs/design/plugins/WaitBranch.md:76-83.

Fix: Restore the ## Exceptions with reasons heading before the bullets.

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 44e6419. WaitBranch.md:80 restores the ## Exceptions with reasons heading before the two bullets at 82-83.

| Loop → RequestSettings | `settings() → settings`; the model profile's defaults before an adoption ([#2093](https://github.com/arcships/dim/pull/2093), target). |
| ContextPreparation → PrepareContextHost | The model profile's request builder stays the host port `prepare` calls; the owner contract is [ContextPreparation](../plugins/ContextPreparation.md). |
| Context accounting and compaction → ContextFacts | `describe`, `count`, `contributions`, `estimate`; ContextFacts is the owner ([#2093](https://github.com/arcships/dim/pull/2093), target). |
| ContextPreparation → SummaryStrategy | `describe(model facts) → {name, replacementSize}`; `compact(input, cancelled) → completed, skipped, failed or cancelled` with StrategyDiagnostics; SummaryStrategy is the owner ([#2093](https://github.com/arcships/dim/pull/2093), target). |

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.

Problem: This row says SummaryStrategy's compact returns cancelled, but #2093's current SummaryStrategy returns completed, skipped or failed and makes cancelled an error (SummaryStrategy.md:72, 82 at head a4f2377). Only ContextPreparation's CompactionOutcome adds a cancelled outcome.

Failure scenario: A caller handles a variant that never arrives and misses the error.

Evidence: docs/design/contracts/runtime-owner-operations.md:72; #2093 SummaryStrategy.md:72, 82.

Fix: Drop or cancelled or name the two layers.

while one is outstanding is skipped (§5.4).
4. **Boundaries.**
- `next_model` (except with a budget-retry source) and `turn/end` start a pending step instead
- The Loop's `next_model` (except with a budget-retry source) and `turn/end` start a pending step instead

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.

Problem: This still says the Loop's next_model starts a pending compaction step, while ContextPreparation owns the step and its flow says the owner runs it at the boundary (ContextPreparation.md:14, 122). Section 8 at 1238 still lists Loop as the compaction supplement.

Failure scenario: An implementer keeps the step start in the Loop for the boundary path, the same split the P1 described.

Evidence: docs/design/plugins/ContextCompaction.md:928, 1238; docs/design/plugins/ContextPreparation.md:14, 122, 129-133.

Fix: Say the Loop signals the boundary or the owner observes it, and update section 8 to ContextPreparation.

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 44e6419. ContextCompaction.md:850-853 and 866-867 now say ContextPreparation consumes the command and starts the pending step, and 925-927 says the Loop does not advance across the boundary. Section 8's Loop row now only says it starts no request (1236). The round-3 body notes one optional detail: name the boundary facts ContextPreparation observes.

@eric8810

Copy link
Copy Markdown
Collaborator Author

已按评审修改,head 44e641995。

本轮处理

  • ContextCompaction §5.4/§8:两处 Loop consumes k 图上文字改为 ContextPreparation 消费命令;§5.4 的 Boundary 与 §5.5 的 Boundaries 写明 ContextPreparation 在边界启动步骤、Loop 不越过;§8 的 Loop 行改为「步骤运行时不开始请求」,ContextPreparation 行补命令、单飞槽与步骤。
  • ContextCompaction 重复:删除重复的 cancelled → compaction_cancelled 映射与重复的 impl PublicService for ContextPreparation {}。
  • ContextUsage 链接:ContextCompaction.md#5-usage-and-the-compaction-cut 改为 #57-compaction-state-for-clients。
  • WaitBranch:恢复被 ## Client-visible changes 覆盖的 ## Exceptions with reasons 标题。
  • PromptSourcesBranch:示例按 Vec<(PromptSourceTarget, PromptEntry)> 解构,取 .1.version,不再访问 tuple 的字段。
  • session-access 绑定:WithdrawRequest 改为 WithdrawInput;pending 行改为 line_owner::<InputQueue>(line)?.pending(PendingRequest { .. }) -> Pending。
  • ContextPreparation prepare:回复改为「model/call 或失败终态提交后答 {}」,失败终态路径有答复。

自查发现

  1. 当前断言按评审给出的路径核对;除评审列举项外,发现 §5.4 第二处 Loop consumes k、§8 的 Loop supplement 行、§5.4 Boundary 的启动归属、重复映射与重复 impl,已一并修正。
  2. 现有文档冲突在本 PR 内改完:ContextCompaction、service-faces、runtime-owner-operations、session-access、session-boundary、timeline-branches、Recall(en/zh)、PromptSources 的 branch 段。
  3. 一词一概念:本 PR 内 WithdrawInput、Withdrawal、WaitReply/Reason、UsageRead、CompactionOutcome 一致;跨 PR 拼写列在下面。
  4. 内部一致:prepare 的回复与失败终态一致;WaitBranch 例外标题恢复;ContextCompaction 映射唯一。
  5. 每个结局写明调用方下一步:prepare 的失败终态是已提交事实、返回 {};compact 的 cancelled{reason};wait 的 interrupted;submit 的 line_ended;withdraw 的 interrupted。
  6. 重命名/删除后全仓 grep:Loop consumes k、重复 PublicService、InputQueue::pending(input_id) 已清;WithdrawRequest 只保留在 session-access 的 sessions.withdraw RPC 类型(非本所有者绑定)。
  7. 规则不带 Rust 拼写;未合并文件用 PR URL 标 target;不引用扫描 issue。
  8. 新写句子按 1–5 复核(§8 行、Boundary 句、ContextUsage 链接、WaitBranch 标题、PromptSourcesBranch 示例、session-access 行)。
  9. 按 docs(design): target contracts for the Session registries and tools #2103 734d364、design(tools): target contracts for the branch tool chain #2100 038e60c、docs(design): target contracts for the Session scope and its host ports #2093 a4f2377 的最新 head 核对,跨 PR 项如下。

留给第二步(left for step 2)

检查:node scripts/adr-check.mjs --base origin/main 与 cargo run --locked -p xtask-check 通过;绑定附录临时 crate cargo check 通过(未提交)。请重新评审。

@eric8810
eric8810 requested a review from yyhhyyyyyy November 24, 2026 05:31

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

Round 3 review: target contracts for the branch turn chain

Scope: target contracts for the branch turn chain (#2027), covering Loop, ContextPreparation, ContextUsage, ModelProvider, Prompt adoption, PromptSourcesBranch, InputQueue and WaitBranch, plus the compaction and prompt rewires and the shared owner indexes. Reviewed the full main...head at 44e6419 (merge base 5a279d6) against origin/main c819cfd, not only the 851f531 to 44e6419 delta.

Verdict: REQUEST_CHANGES

Round status

Round-2 finding Status
P2-1 #2103 configure shape Fixed for this contract: #2103 at 69071dd calls ConfigureRequest::Initial, Loaded { sources } and LanguageUpdate (PromptSources.md:52, 57, 68) and says the enum is this PR's (190). P3 residual: #2103 PromptSources.md:56 still compares adopted.version.
P2-2 InputQueue interrupted Still open, now P2-2 below.
P2-3 ToolRegistry definitions and toolSourcesView Still open, now P2-3 below.
P2-4 Loop release and retain_only Still open, now P2-4 below.
P2-5 ContextCompaction section 15 Still open, now P2-5 below.
P2-6 session-access Appendix E Fixed in 44e6419: the rows now use WithdrawInput and pending(PendingRequest) (session-access.md:532-533, InputQueue.md:174-180, 191-195, 224). Optional follow-up below: the default for published_cutoff: None is unstated.
P3-1 ContextUsage compaction link Fixed: ContextUsage.md:5 links #57-compaction-state-for-clients, matching ContextCompaction.md:977.
P3-2 PromptSourcesBranch tuple lookup Partially fixed, see the P3 list.
P3-3 duplicate lines and heading Fixed: one cancelled mapping (ContextCompaction.md:174-177), one PublicService impl, and the ## Exceptions with reasons heading is back at WaitBranch.md:80.
P3-4 stale Loop references Partially fixed: sections 5.4, 5.5 and 8 now name ContextPreparation; ContextCompaction.md:950 still names CompactionStrategyHost, and section 5.6 is not superseded (ContextPreparation.md:133).
P3-5 PromptHost names Still open, see the P3 list.
P3-6 prepare reply and SummaryStrategy cancelled Partially fixed: ContextPreparation.md:99 now names the failure terminal; runtime-owner-operations.md:72 still lists cancelled.
P3-7 merge order Addressed in the PR body: it now states #2029, #2080, #2091/#2092/#2093, #2100 and #2103 in order.

All round-1 findings remain as assessed in round 2. No round-1 opinion was a false positive.

P2 (blocking)

P2-1 (round 3). PrepareRequest carries the internal StreamedContext, so #2093's renderedStream reply cannot reach prepare

Problem: PrepareRequest derives serde and declares pub projection: crate::history::StreamedContext (ContextPreparation.md:184-189). That is the internal type, pub struct StreamedContext { pub history: Vec<HistoryEntry>, ... } with only #[derive(Debug, Clone)] and no serde derive (crates/dim-agent-capabilities/src/history.rs:729-740 on origin/main). #2093 at a4f2377 changes renderedStream's reply to a wire StreamedContext with history: Vec<Entry>, owned values and serde, and keeps the internal type unchanged (ContextProjection.md:166-198, 297). The field is a non-serde internal type inside a serde request for a cross-language operation, which the contract's own §7 cross-language rule forbids (ContextPreparation.md:163).

Failure scenario: Loop calls contextProjection.renderedStream, receives #2093's wire StreamedContext, and passes it to prepare. The request field expects the internal Vec<HistoryEntry> value, which has no Serialize or Deserialize, so the serde derive on PrepareRequest cannot compile. Even in process, the wire value and the field type differ, and the conversion is nowhere defined. The same mismatch applies to the handoff text in ContextCompaction section 15 (P2-5).

Evidence: ContextPreparation.md:184-189; crates/dim-agent-capabilities/src/history.rs:728-740; #2093 ContextProjection.md:166-198, 297 at a4f2377. This was noted on #2093 at ContextProjection.md:168 and is still unfixed here.

Fix: Use #2093's exported wire type for this field (and state its import path in #2093), or state the one conversion and where it runs. Do not put a non-serde internal type in a data-face request.

P2-2 (round 3). interrupted still conflicts with #2103's and session-access's publication_unknown

Problem: withdraw answers interrupted for a committed but unconfirmed withdrawal (InputQueue.md:82, 94, 212-213). #2103 at 69071dd still declares publication_unknown for session.input.withdraw and never mentions interrupted (InputMethods.md:79, 92). session-access.md:234 keeps publication_unknown, and this PR's PromptAdoption.md:85 and 98 use it for the same condition.

Failure scenario: The Session entry in #2103 must invent a mapping or pass through an undeclared code. A client that handles publication_unknown treats a committed withdrawal as a generic failure and may retry it; a client matching interrupted cannot receive it through the declared session.input.withdraw shape.

Evidence: docs/design/plugins/InputQueue.md:82, 94, 212-213; #2103 InputMethods.md:79, 92 at 69071dd; docs/design/contracts/session-access.md:234; docs/design/plugins/PromptAdoption.md:85, 98.

Fix: Keep publication_unknown here, or state the mapping in both contracts and update #2103 and session-access.md. Do not keep two names for one state.

P2-3 (round 3). ContextUsage still requires ToolRegistry operations that #2103 retires

Problem: ContextUsage's dependency and requirement name definitions and toolSourcesView.get (ContextUsage.md:61, 142). #2103 at 69071dd exposes declarations and sources, retires toolSourcesView (ToolRegistry.md:95, 110-111, 177), and #2100 says definitions is removed (ToolBinding.md:215).

Failure scenario: The path with no tools named in the adopted configuration calls operations the Session owner does not provide. An implementer either wires the retired toolSourcesView or cannot serve the no-tools case, so the two target contracts cannot both land.

Evidence: docs/design/plugins/ContextUsage.md:61, 142; #2103 ToolRegistry.md:95, 110-111, 177 at 69071dd; #2100 ToolBinding.md:215 at a68b322.

Fix: Use toolRegistry.declarations() and sources() (or observe_sources) and update the requirement bullet.

P2-4 (round 3). Loop forbids release and retain_only that #2100 defines for it

Problem: Loop's dependency lists only bind, adopted, claim and transfer, and its requirement says the Loop calls no release or retain operation (Loop.md:67, 145). #2100 at a68b322 defines release and retain_only and says they exist for Loop's budget-recovery and rebuild steps (ToolBinding.md:18, 37-38, 141-142, 176). runtime-owner-operations.md:76 also omits both.

Failure scenario: On a rebuild, the Loop either follows this contract and leaves stale records until the owner closes, or follows #2100 and calls an operation this contract forbids. Budget recovery has the same split. The two target contracts cannot both land as written.

Evidence: docs/design/plugins/Loop.md:67, 145; docs/design/contracts/runtime-owner-operations.md:76; #2100 ToolBinding.md:18, 37-38, 141-142, 176 at a68b322.

Fix: Add release and retain_only where the Loop needs them, or get #2100 to settle a rebuild itself and say so in both contracts.

P2-5 (round 3). ContextCompaction section 15 still describes the old projection handoff and Usage save, and neither owner supersedes it

Problem: Section 15's Request-local projection handoff still says Loop passes the projection before publishing context/prepare, ContextPreparation retains at most one pending projection bound to the original request object, the value is not serialized, and Usage computes and saves contributions when the final request keeps the original cutoff (ContextCompaction.md:2127-2141). The owner contracts say the projection crosses once as a value in prepare (ContextPreparation.md:12, 103), the crate-private slot is removed (ContextPreparation.md:162), estimate does not take a StreamedContext (ContextUsage.md:144), and only confirm saves (ContextUsage.md:70-72, 93). ContextPreparation's Supersedes (ContextPreparation.md:133) and ContextUsage's Supersedes (ContextUsage.md:103-106) do not include section 15.

Failure scenario: An implementer builds the pending projection slot and a Usage save without confirm, while the owner contracts remove the slot and require confirm. The projection has two handovers, and contributions can be written twice or never.

Evidence: docs/design/plugins/ContextCompaction.md:2127-2141; docs/design/plugins/ContextPreparation.md:12, 103, 133, 162; docs/design/plugins/ContextUsage.md:70-72, 93, 103-106, 144.

Fix: Add section 15, at least the Request-local projection handoff subsection, to both Supersedes lists, or rewrite it to the value handover and the estimate/confirm pair.

P3 (optional)

  • PromptSourcesBranch's lookup still does not compile (P3-2 residual). PromptSourcesBranch.md:41-45 compares source == &target.source, where source is &PromptSourceTarget ({source: String, scope: PromptScope} at crates/dim-agent-runtime/src/contracts.rs:91-94) and target.source is String; it also drops the scope comparison. Use source.source == target.source && source.scope == target.scope, or source == &target.
  • The ContextUsage rewrite drops two anchors that unchanged docs still link. docs/design/owner-state-indexed-reads.md:115 links plugins/ContextUsage.md#6-恢复切点和查询范围, and docs/design/appserver/native-storage-format.md:1614 links #61-统计版本与旧数据. The old file had those headings (5a279d6:ContextUsage.md:92, 104); the new one does not. Keep stub headings as Prompt.md:8 does, or update the two linkers.
  • The delta makes ContextPreparation start a pending step at a Loop boundary (ContextCompaction.md:889-891, 926-927), but section 5.5's subscription list still names only context/compact, context/compaction-start and context/compaction (917-919). Hypothesis: an implementer registers only those facts, so a command consumed while a request is in flight has no trigger at step/tool-result or turn/end. Name the boundary facts, or state that the Loop signals the boundary.
  • session-access.md:533 says the owner applies its published-cutoff default, but InputQueue.md never defines what published_cutoff: None means (83, 191-195). State the default, or pass the captured cutoff in the row.
  • runtime-owner-operations.md:72 still lists cancelled as a SummaryStrategy outcome; #2093 at a4f2377 returns completed, skipped or failed and makes cancelled an error (SummaryStrategy.md:72, 82).
  • ContextCompaction.md:950 still says ContextPreparation injects CompactionStrategyHost; section 5.6 is not in the Supersedes list (ContextPreparation.md:133).
  • overview.md:229 still calls compaction "a Loop step", and docs/zh/design/plugins/ContextCompaction.md:100, 117 and 157 still assign the command, slot and step to Loop.
  • PromptHost names remain (PromptAdoption.md:20; PromptSourcesBranch.md:11, 66, 112, 124) while #2103 PromptSources.md:169-170 retires promptHost.
  • #2103 PromptSources.md:56 still compares adopted.version; this contract's Adopted has settings? and through, and adoptedEntries returns (target, entry) pairs (PromptAdoption.md:198-202, 213-214). Use adoptedEntries in #2103's example.

Verification

  • node scripts/adr-check.mjs --base 5a279d69 passes with 19 changed files.
  • A link and anchor check over the 19 changed files and their inbound links finds only the two ContextUsage anchors above. ContextCompaction.md:528 and the aimux and session-deletion anchors are pre-existing and not raised.
  • CI: ci-ok passed and the other jobs were skipped (docs only). mergeStateStatus is BLOCKED with reviewDecision CHANGES_REQUESTED. No code tests were run.

#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct PrepareRequest {
pub source: ContextPrepareData,
pub projection: crate::history::StreamedContext,

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.

Problem: PrepareRequest derives Serialize and Deserialize, but this field is the internal crate::history::StreamedContext, which has only #[derive(Debug, Clone)] and no serde derive, and holds Vec<HistoryEntry> (crates/dim-agent-capabilities/src/history.rs:729-740 on origin/main). #2093 at a4f2377 makes renderedStream's reply a wire StreamedContext with history: Vec<Entry> and serde (docs/design/plugins/ContextProjection.md:166-198, 297).

Failure scenario: Loop receives #2093's wire value and cannot pass it to prepare. The field type has no serde, so the PrepareRequest derive cannot compile, and even in process the wire value and the field type differ with no conversion defined. The prepare path cannot be built from both contracts.

Evidence: this line and ContextPreparation.md:184-189; crates/dim-agent-capabilities/src/history.rs:728-740; #2093 ContextProjection.md:166-198 at a4f2377. This was noted on #2093 at ContextProjection.md:168 and is still unfixed here.

Fix: Use #2093's exported wire type for the field (and state its import path there), or define the one conversion and where it runs.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Still open in 3b48e12. PrepareRequest.projection is still crate::history::StreamedContext (ContextPreparation.md:188), the internal type with no serde derive (crates/dim-agent-capabilities/src/history.rs:728-740). #2093 at c8f1812 still defines contextProjection::StreamedContext, Entry and History and says #2102 must align its import (ContextProjection.md:150). See P2-1 in the round-4 body.

Comment thread docs/design/plugins/InputQueue.md Outdated
| Operation | Intent | Request | Reply | Cancellation | Errors |
| --- | --- | --- | --- | --- | --- |
| `submit` | Admit one input into the line, once per submission id | `{input}` | `{inputId, sequence}`; a repeated submission id answers the committed input | The caller cancels before the append; nothing is written | `invalid` (the input fails its own shape or scope), `line_ended` (the line has ended), `cancelled`, `closed` |
| `withdraw` | Withdraw one held input, optionally replacing it with a Steer | `{inputId, reason?, steer?}` | `{status}`: `deleted{sequence}` or `notHeld` | The caller cancels the wait; a committed withdrawal stands and a later call answers `notHeld` | `input_blocked` (a submit check refused the Steer), `invalid` (a malformed Steer candidate), `interrupted` (committed but publication unconfirmed), `cancelled`, `closed` |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Problem: interrupted is the owner's name for a committed but unconfirmed withdrawal (also 94, 212-213). #2103 at 69071dd still declares publication_unknown for session.input.withdraw (docs/design/plugins/InputMethods.md:79, 92), session-access.md:234 keeps publication_unknown, and this PR's PromptAdoption.md:85 and 98 use it for the same condition.

Failure scenario: The Session entry maps the owner's code to its declared one, or the client sees an undeclared code. A client that handles publication_unknown may retry a withdrawal that already committed.

Evidence: InputQueue.md:82, 94, 212-213; #2103 InputMethods.md:79, 92 at 69071dd; docs/design/contracts/session-access.md:234; docs/design/plugins/PromptAdoption.md:85, 98.

Fix: Keep publication_unknown, or state the mapping in both contracts and update #2103 and session-access.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.

Partially fixed in 3b48e12. The operation table (InputQueue.md:82) and error row (94) now use publication_unknown, matching #2103 at 59a77a3 (InputMethods.md:173-174) and session-access. What remains is the binding appendix: InputQueueError::Interrupted (InputQueue.md:213) still serializes as interrupted. Rename it or add a serde rename; see P2-2 and the inline comment at line 213.

Comment thread docs/design/plugins/ContextUsage.md Outdated
| Owner | Operation | Use |
| --- | --- | --- |
| ContextFacts (#2025, Session) | `describe`, `contributions`, `estimate` | The additive counter, the fixed contribution and one contribution's size. |
| ToolRegistry (#2026, Session) | `definitions`, `toolSourcesView.get` | The current tool declarations when the adopted configuration names no tools. |

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.

Problem: This names definitions and toolSourcesView.get, and line 142 repeats the requirement. #2103 at 69071dd exposes declarations and sources and retires toolSourcesView (docs/design/plugins/ToolRegistry.md:95, 110-111, 177); #2100 says definitions is removed (docs/design/plugins/ToolBinding.md:215).

Failure scenario: The path with no tools named in the adopted configuration calls operations the Session owner does not provide. An implementer either wires the retired toolSourcesView or cannot serve the no-tools case, so the two target contracts cannot both land.

Evidence: ContextUsage.md:61, 142; #2103 ToolRegistry.md:95, 110-111, 177 at 69071dd; #2100 ToolBinding.md:215 at a68b322.

Fix: Use toolRegistry.declarations() and sources() (or observe_sources) and update the requirement at line 142.

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 3b48e12. The dependency row (ContextUsage.md:61) and requirement (142) now use declarations, and #2103 at 59a77a3 defines declarations with request {} and reply {tools, sources} (ToolRegistry.md:110, 281). Withdrawn.

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

## Requirements raised to mechanism owners

- #2028 (ToolBinding): Loop needs `bind`, `adopted`, `claim` and `transfer` as data operations; settlement follows `step/tool-result` and `turn/end`, so the Loop calls no release or retain operation.

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.

Problem: This says the Loop calls no release or retain operation, and the dependency at line 67 lists only bind, adopted, claim and transfer. #2100 at a68b322 defines release and retain_only and says they exist for Loop's budget-recovery and rebuild steps (docs/design/plugins/ToolBinding.md:18, 37-38, 141-142, 176). docs/design/contracts/runtime-owner-operations.md:76 also omits both.

Failure scenario: On a rebuild, the Loop either follows this contract and leaves stale records until the owner closes, or follows #2100 and calls an operation this contract forbids. Budget recovery has the same split. The two target contracts cannot both land as written.

Evidence: Loop.md:67, 145; docs/design/contracts/runtime-owner-operations.md:76; #2100 ToolBinding.md:18, 37-38, 141-142, 176 at a68b322.

Fix: Add release and retain_only where the Loop needs them, or get #2100 to settle a rebuild itself and state that in both contracts.

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 3b48e12. Loop.md:67, 145 and runtime-owner-operations.md:76 now list release and retain_only, matching #2100 at 437266b: release({requestId}) and retain_only({requestId}) (ToolBinding.md:140-141, 299-300), Loop is the caller (18, 176), settlement stays with the line's facts (14, 169), and ToolBinding keeps records across a Loop reload (171, 194). Withdrawn.

@eric8810

Copy link
Copy Markdown
Collaborator Author

已按评审修改,head 823124c7b。

跨 PR 对齐:

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

@eric8810

Copy link
Copy Markdown
Collaborator Author

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

  • 七处 “ADR 027's id-to-instance step resolves … except registration points and lifecycle services” 的复述删掉,改为 ADR 027 D1 加 #2127 的链接;契约不再复述路由机制的内容。

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

@yyhhyyyyyy yyhhyyyyyy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Round 4 review: target contracts for the branch turn chain

Scope: target contracts for the branch turn chain (#2027), covering Loop, ContextPreparation, ContextUsage, ModelProvider, Prompt adoption, PromptSourcesBranch, InputQueue and WaitBranch, plus the compaction and prompt rewires and the shared owner indexes. Reviewed the full main...head at 3b48e12 (merge base 5a279d6), not only the 44e6419 to 3b48e12 delta. Sibling heads checked: #2100 437266b, #2103 59a77a3, #2093 c8f1812 (the head moved from 53961a1; ContextProjection is unchanged), #2098 c3acab3, #2097 ed43cd9.

Verdict: REQUEST_CHANGES

Round status

Prior finding Status
P2-1 PrepareRequest projection Still open, see P2-1.
P2-2 withdraw code Partially fixed: the table and error row now use publication_unknown (InputQueue.md:82, 94), but the binding still emits interrupted, see P2-2.
P2-3 ContextUsage ToolRegistry Fixed in 823124c: ContextUsage.md:61, 142 now use declarations, and #2103 at 59a77a3 defines declarations with request {} and reply {tools, sources} (ToolRegistry.md:110, 281). Withdraw the prior opinion.
P2-4 Loop release and retain_only Fixed in 823124c: Loop.md:67, 145 and runtime-owner-operations.md:76 now match #2100 at 437266b: release({requestId}) and retain_only({requestId}) (ToolBinding.md:140-141, 299-300), Loop is the caller (18, 176), settlement stays with the line's facts (14, 169), and ToolBinding keeps records across a Loop reload (171, 194). Withdraw the prior opinion.
P2-5 ContextCompaction section 15 Still open, see P2-5.

Withdraw P2-3 and P2-4 as fixed. Narrow P2-2 rather than withdrawing it. P2-1 and P2-5 stand. No prior opinion is withdrawn as a false positive.

The round-2 and round-3 P3 residuals are unchanged and remain optional: ContextCompaction.md:947-950 still names CompactionStrategyHost and section 5.6 is not superseded; the two ContextUsage anchors remain absent at owner-state-indexed-reads.md:115 and appserver/native-storage-format.md:1614; PromptSourcesBranch.md:41-45 still compares &PromptSourceTarget with &String and drops the scope; runtime-owner-operations.md:72 still lists cancelled as a SummaryStrategy outcome while #2093 SummaryStrategy.md:13, 82 makes it an error; #2103 PromptSources.md:56 still compares adopted.version; and InputQueue.md:83 does not state what publishedCutoff: None means while session-access.md:533 and #2098 Agents.md:226, 276 say the owner's published head applies.

P2 (blocking)

P2-1. PrepareRequest still carries the internal StreamedContext, not #2093's wire type

Problem: PrepareRequest derives serde and declares pub projection: crate::history::StreamedContext (ContextPreparation.md:186-189). That is the internal dim-agent-capabilities type, #[derive(Debug, Clone)] with pub history: Vec<HistoryEntry> and no serde derive (crates/dim-agent-capabilities/src/history.rs:728-740 on origin/main). #2093 at c8f1812 defines the wire types contextProjection::StreamedContext, contextProjection::Entry and contextProjection::History and explicitly says #2102 must align its import (ContextProjection.md:150, 161-198, 299). The caller example passes rendered_stream's wire reply into prepare (ContextPreparation.md:39-50), and runtime-owner-operations.md:74 repeats prepare({source, projection}).

Failure scenario: The serde derive on PrepareRequest cannot compile with a field type that has no Serialize or Deserialize. Even in process, Loop's wire value and the internal field type differ, and no conversion is defined. The prepare path cannot be built from both contracts.

Evidence: docs/design/plugins/ContextPreparation.md:186-189; crates/dim-agent-capabilities/src/history.rs:728-740 at decc589; #2093 docs/design/plugins/ContextProjection.md:150, 161-198, 299 at c8f1812; docs/design/contracts/runtime-owner-operations.md:74.

Fix: Use #2093's wire type for the field and name its import, or define the one conversion and where it runs. Do not put a non-serde internal type in a serde request.

P2-2. InputQueue's binding still emits interrupted for a committed withdrawal

Problem: The operation table and error row now use publication_unknown (InputQueue.md:82, 94), and PromptAdoption.md:85, 98 and session-access.md:234, 446 use the same code. But the binding appendix still declares Interrupted under #[serde(tag = "code", rename_all = "snake_case")] (InputQueue.md:203-213), so the compiled wire code is interrupted. #2103 at 59a77a3 declares PublicationUnknown (InputMethods.md:173-174), and origin/main's withdraw maps AgentError::PublicationUnknown to the sessions code publication_unknown (crates/dim-agent-capabilities/src/input_queue.rs:333-336; crates/dim-agent-capabilities/src/methods.rs:146).

Failure scenario: An implementer copies the binding and the owner emits interrupted while the same document's table, #2103 and session-access declare publication_unknown. The Session entry must invent a mapping, and a client that handles publication_unknown treats a committed withdrawal as an unknown failure and may retry it.

Evidence: docs/design/plugins/InputQueue.md:82, 94, 203-213; #2103 docs/design/plugins/InputMethods.md:173-174 at 59a77a3; docs/design/contracts/session-access.md:234, 446; crates/dim-agent-capabilities/src/input_queue.rs:333-336 and methods.rs:146 at decc589.

Fix: Rename the variant to PublicationUnknown, or add #[serde(rename = "publication_unknown")]. Keep one name.

P2-5. ContextCompaction section 15 still describes the old projection handoff and Usage save, and no owner supersedes it

Problem: Section 15's Request-local projection handoff still says Loop passes the projection before publishing context/prepare, ContextPreparation retains at most one pending projection bound to the original request object, the value is not serialized, and Usage computes and saves contributions when the final request keeps the original cutoff (ContextCompaction.md:2125-2141). The owner contracts say the projection crosses once as a value in prepare (ContextPreparation.md:12, 99, 103), the crate-private slot is removed (ContextPreparation.md:162), estimate does not take a StreamedContext (ContextUsage.md:144), and only confirm saves (ContextUsage.md:70-72, 93). ContextPreparation's Supersedes list omits section 15 (ContextPreparation.md:129-134), and ContextUsage's Supersedes omits it too (ContextUsage.md:103-106).

Failure scenario: An implementer builds the pending projection slot and a Usage save without confirm, while the owner contracts remove the slot and require confirm. The projection gets two handovers, and contributions can be written twice or never.

Evidence: docs/design/plugins/ContextCompaction.md:2125-2141; docs/design/plugins/ContextPreparation.md:12, 99, 103, 129-134, 162; docs/design/plugins/ContextUsage.md:70-72, 93, 103-106, 144.

Fix: Add section 15's Request-local projection handoff subsection to the Supersedes lists, or rewrite it to the value handover and the estimate/confirm pair.

P2-6. InputQueue.submit has no publication_unknown that #2097's EventHub requires

Problem: #2097 at ed43cd9 writes EventHub's guide through line_owner::<InputQueue>(line)?.submit (EventHub.md:199) and its error table and requirement say the owner's submit answers publication_unknown when the guide committed but its publication is unconfirmed (EventHub.md:141, 220). #2102's submit errors are only invalid, line_ended, cancelled and closed (InputQueue.md:81), and its flow answers after the append, not after publication (InputQueue.md:104). origin/main's sessions.input waits for publication (crates/dim-app-server/src/agents/sessions.rs:529, 562-568), so the owner submit is the path that lacks the signal.

Failure scenario: EventHub cannot distinguish a committed but unpublished guide from a failed or delayed one. It either stores the subscription and replies its id while the guide may never publish, or treats a storage failure as a normal receipt. The two target contracts cannot both land.

Evidence: #2097 docs/design/plugins/EventHub.md:141, 199, 220 at ed43cd9; docs/design/plugins/InputQueue.md:81, 104; crates/dim-app-server/src/agents/sessions.rs:529, 562-568 at decc589.

Fix: Either add publication_unknown to submit and state the publication wait, or state that submit returns at commit and change #2097 to confirm publication separately.

ADR 027 citations

The seven changed citations (ContextPreparation.md:174, ContextUsage.md:145, InputQueue.md:155, Loop.md:147, ModelProvider.md:134, PromptAdoption.md:161, WaitBranch.md:122) cite ADR 027 D1 for the caller-to-owner route and #2127 for the tracked mechanism. ADR 027 D1 (docs/adr/027-cross-scope-access-by-id.md:22-26 at decc589) owns the by-id access rule, and D2 (28-33) owns runtime routing and instance-key non-disclosure. None of the changed sentences restates D2, so no citation regression was found. The three sentences that previously said "except registration points and lifecycle services" now leave D3 to the linked ADR; the calls they describe are data-face operations, so no concrete failure follows. If the author wants the caveat back, cite D3.

Verification

  • node scripts/adr-check.mjs --base 5a279d69 passes with 19 changed files.
  • The link and anchor check over the 19 changed files reports two pre-existing problems: ContextCompaction.md:528 to model-configuration.md#model-parameters, and timeline-branches.md:576 to appserver/session-deletion-and-fork.md#62-why-main-only. Both are unchanged from 5a279d6.
  • CI: ci-ok passed and the other jobs were skipped (docs only). mergeStateStatus is BLOCKED with reviewDecision CHANGES_REQUESTED. No code tests were run.
  • All 60 review comments are from yyhhyyyyyy; there are no other-author review threads.
  • Unverified: #2100, #2103 and #2093 are target contracts, so no origin/main code exists for release, retain_only or declarations; the PR body's temporary-crate compile claim was not reproduced, and it does not cover #2093's wire type.

#[error("line ended")]
LineEnded,
#[error("publication unconfirmed")]
Interrupted,

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.

Problem: The table and error row now use publication_unknown (InputQueue.md:82, 94), but this binding still declares Interrupted under #[serde(tag = "code", rename_all = "snake_case")], so the owner emits interrupted.

Failure: An implementer following the binding returns a code that #2103 at 59a77a3 (InputMethods.md:173-174) and session-access.md:234 do not declare. The Session entry must invent a mapping, and a client that handles publication_unknown may retry a committed withdrawal.

Evidence: this line; InputQueue.md:82, 94; #2103 InputMethods.md:173-174 at 59a77a3; session-access.md:234; origin/main crates/dim-agent-capabilities/src/input_queue.rs:333-336 returns AgentError::PublicationUnknown and methods.rs:146 emits publication_unknown.

Fix: Rename the variant to PublicationUnknown, or add #[serde(rename = "publication_unknown")].


| Operation | Intent | Request | Reply | Cancellation | Errors |
| --- | --- | --- | --- | --- | --- |
| `submit` | Admit one input into the line, once per submission id | `{input}` | `{inputId, sequence}`; a repeated submission id answers the committed input | The caller cancels before the append; nothing is written | `invalid` (the input fails its own shape or scope), `line_ended` (the line has ended), `cancelled`, `closed` |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Problem: submit lists only invalid, line_ended, cancelled and closed, and its flow answers after the append (line 104). #2097 at ed43cd9 has EventHub call line_owner::<InputQueue>(line)?.submit (EventHub.md:199) and requires it to answer publication_unknown when the guide committed but publication is unconfirmed (EventHub.md:141, 220).

Failure: EventHub cannot distinguish a committed but unpublished guide from a failed write. It either stores the subscription while the guide may never publish, or treats a storage failure as a normal receipt. The two target contracts cannot both land.

Evidence: this line; InputQueue.md:104; #2097 EventHub.md:141, 199, 220 at ed43cd9; origin/main crates/dim-app-server/src/agents/sessions.rs:529, 562-568 waits for publication.

Fix: Add publication_unknown to submit and state the publication wait, or state that submit returns at commit and change #2097 to confirm publication separately.

@eric8810

Copy link
Copy Markdown
Collaborator Author

Closing as part of abandoning the owner-split experiment.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants