Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

fix(capabilities): settle a closing line's queued inputs as deleted - #2586

Draft
yyhhyyyyyy wants to merge 7 commits into
mainfrom
hui/issue-2146-contract-6
Draft

yyhhyyyyyy wants to merge 7 commits into
mainfrom
hui/issue-2146-contract-6

Conversation

@yyhhyyyyyy

@yyhhyyyyyy yyhhyyyyyy commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

An input still queued when its line ended had no terminal outcome: close interrupted the line and unloaded it while the input had neither input/applied, input/consumed nor input/deleted, so a held input had no fact at all and an applied one stayed pending with no turn left to consume it.

docs/design/contracts/session-access.md now states that a closing line settles every input it did not consume and that this settlement is the only deletion that may follow an application, with input/consumed and input/deleted still mutually exclusive (docs/design/contracts/session-access.md:L125); its timing table and appendix B record branch/end < input/deleted < branch/ended, never consumed and never pending (docs/design/contracts/session-access.md:L132, docs/design/contracts/session-access.md:L472); the result-fact and after-apply rows say when InputQueue writes the fact and that a closing line deletes an applied input (L348, L355); appendix C item 5 carries the rule (L498); the Chinese mirror states the same at L121, L128, L339, L346, L402 and L428.

docs/design/timeline-branches.md adds the settlement batch to close step 5 (docs/design/timeline-branches.md:L412) and to restore, which settles a stored line's unconsumed inputs before fixing its head (docs/design/timeline-branches.md:L424); the Chinese mirror follows at L387 and L399. docs/design/input-state-read.md says an ended line's inputs are no longer pending (L21). InputQueue.md states when the queue releases nothing and settles (L139), and Loop.md states that an ending generation starts no turn and that a branch-scope interrupt is not a durable interrupt (L45).

Live close: InputQueue consumes branch/end and marks the line ending; after branch/end, turn/end or stop/interrupt, once no turn runs and none is about to start, it writes one atomic input/deleted batch for every entry it still holds (crates/dim-agent-capabilities/src/input_queue.rs:L183). The input the final turn end releases is applied and deleted in that batch, the other held inputs are deleted without a new application, and all of it lands before branch/ended. Loop marks the generation ending on branch/end and on a scope: branch interrupt without writing a durable interrupt (crates/dim-agent-capabilities/src/agent_loop.rs:L1449), so a turn end cannot open another turn. BranchRuntime drains dispatch to the committed sequence before it cancels the driver (crates/dim-agent-runtime/src/timeline_context.rs:L857), so the settlement is published before the close finishes.

Restore: settle_stored_line selects a stored line's inputs without a terminal fact and appends one atomic input/deleted batch before the parent's branch/ended and before the line's head is fixed (crates/dim-agent-capabilities/src/input_queue/recovery.rs:L505); restore calls it from its descendant and own-end paths (crates/dim-agent-capabilities/src/timeline_tree.rs:L1159, L3304, L3342). It reads fields only, writes nothing when nothing is unsettled, and the existing one-page restore test still reads zero ranges from a store that refuses range reads (L2161).

Readers: the CLI projection drops the pending row on input/deleted (crates/dim-cli/src/projection.rs:L436), and the client window carries InputDeleted across page continuations (crates/dim-client/src/window.rs:L270).

Existing tests: five expectations in crates/dim-agent-capabilities/tests/branch_flow.rs move by one because each end now carries one more input fact, +1 at L1143, L1157, L1323 and L2164, and +2 at L1326 for the line whose own result and settlement both extend it; each place asserts that the added event is that input's InputDeleted. New flow tests cover a tool end with a held input (crates/dim-agent-capabilities/tests/branch_flow.rs:L1381), a close that applies and then deletes an input before the parent records the end (crates/dim-agent-capabilities/tests/branch_flow.rs:L1475), and a restore that settles a stored end's inputs before its result (crates/dim-agent-capabilities/tests/branch_flow.rs:L1563).

Design rule checklist

  • Scope: each new part is placed by the owner of its state and lifecycle (process / Session / branch); no wiring module. No part or wiring module is added: the close settlement stays in the branch's InputQueue (input_queue.rs:L183), the ending flag in the branch's Loop (agent_loop.rs:L1449), and restore calls the queue's own settlement because a closed line is not opened (recovery.rs:L505).
  • Commands and results: changes to another module's state are command events; the owner writes the result; a command with no effect writes no event and the caller's reply says so. branch/end and stop/interrupt stay the commands; InputQueue decides from its own held entries and writes input/deleted as its result, a close that settles nothing writes no event, and no other owner's state is written (session-access.md:L132).
  • Handover: every handover point is an explicit event; nothing is revoked after handover. The handover fact is still input/applied, and the only fact that may follow it is the close settlement defined in the contract, which records that an ending line will not consume the input; it does not return the input to the queue (session-access.md:L125).
  • n/a: Timeline before callbacks. No before callback is added or changed; the settlement runs from InputQueue's ordered consumption and from the restore's own store read, not inside a write callback.
  • Infrastructure (Timeline, Dispatcher, event envelope, assembly and lifecycle, Session and branch facades) is unchanged, or the change comes from and closes within the infrastructure itself. The only runtime change is a generic drain in BranchRuntime::close that waits until dispatch reaches the committed sequence before the driver stops (timeline_context.rs:L857); it has no feature branch and stays inside the branch lifecycle.
  • Core mechanisms and consumers gain no plugin-specific handling. The drain is generic, the Loop and InputQueue behavior stays in those parts, and the CLI and client readers consume the existing input/deleted event (projection.rs:L436, window.rs:L270).
  • Batch: facts that take effect together are written in one batch, with the deciding event last. The close settlement writes every held input's input/deleted as one atomic batch, after the last turn end's application, and restore appends one batch before it fixes the head (input_queue.rs:L188, recovery.rs:L505).
  • Context: only handed-over, consumed facts reach the model context. The settlement writes terminal facts only: a deleted input's raw and keyed blocks never reach the model context, and the change adds no context input path (session-access.md:L498).
  • No reading another plugin's internal state or deciding for it. InputQueue decides from its own held entries and its own selection query (recovery.rs:L505); restore only calls that selection at the point it fixes a closed line's head (timeline-branches.md:L424).
  • Cross-language faces: new public services use data faces, existing dependencies state their current face, and a leaf injects and provides only data faces (service faces). No service is added: inputQueue stays a branch data face and its declaration changes only in the documented comment (branch-services.d.ts:L812); no injects or provides changes.
  • Business configuration stays out of loader rows; contracts are language-neutral. No configuration is added: the settlement is stated in the language-neutral input contract and carried by the existing events (session-access.md:L132).
  • Missing mechanism capabilities are raised as requirements (problem, why existing mechanisms fail, generic capability, ordering impact, owner/issue). None raised: the settlement fits the existing events and the queue's own state, and the one lifecycle gap, dispatch not drained before the driver stops, is closed inside the runtime (timeline_context.rs:L857).
  • Timeline holds only facts later decisions use; UI-only changes go through Session broadcast notices; process-level state is changed through its owner's typed write operation, not the Timeline. input/deleted is the terminal fact later decisions read (pending reads, restore and clients), and no UI-only state enters the Timeline (session-access.md:L125).

Documentation

  • No accepted ADR is modified or deleted; a changed decision is a new ADR, and a link or typo fix uses adr-erratum (ADR 008). No ADR is modified; the input contract and the branch, InputQueue and Loop design pages state the settlement (session-access.md:L125).
  • No other module's design is changed; a cross-module requirement is stated for its owner. The Session and InputQueue contract states the final state and its timing (session-access.md:L132), and each part's page states its own consumption (InputQueue.md:L139, Loop.md:L45).
  • Delivery status is not added to an ADR, index or roadmap; binding details are in a binding appendix. No delivery status or history is added to any ADR, index or roadmap.

Verification on this head: cargo fmt --all -- --check --config error_on_line_overflow=true passed; cargo clippy --workspace --all-targets --locked -- -D warnings passed; cargo test -p dim-agent-capabilities --test capabilities_flow --locked passed 783 with 1 ignored; cargo test -p dim-agent-runtime --lib --test agent_runtime_flow --locked passed 14 and 34; cargo test -p dim-cli --locked passed 959; cargo test -p dim-client --locked passed 2 and 4; cargo run --locked -p xtask -- check passed; node scripts/adr-check.mjs --base origin/main passed.

Fixes #2146

A line that ends stops accepting input but could leave an applied or held input pending forever, because the at-most-one rule for input/applied and input/deleted could not express a deletion after application. The contract now chooses input/deleted as the closing settlement, written by InputQueue for every input the line did not consume, after branch/end and before branch/ended; consumed and deleted stay mutually exclusive. The branch close and restore sections describe the settlement and the fixed head it extends, and the InputQueue and Loop pages record the new consumption rules.
InputQueue consumes branch/end, releases nothing more, and writes one atomic input/deleted batch for the entries it still holds once no turn runs or is about to start, so an applied input can settle as deleted only through this close settlement. Loop consumes branch/end and input/deleted, keeps a branch-scope interrupt in this generation's memory, and starts no turn for an ending line; the close drains dispatch to the committed head before the driver stops. Restore settles a stored line through an InputQueue selection before it fixes the line's head and records branch/ended, and the CLI and client projections clear a deleted input's pending row.
The flow tests pin a tool end that keeps a consumed input and settles a held queue input without starting a turn, a close that settles an applied input after its application and before the parent records the end, and a restore that settles a stored end before its result. The restart fixtures expect the settled event in their ended heads.
…ttlement

The InputQueue interface in the generated TypeScript declarations carries the new branch/end and close settlement paragraph its Rust owner documents.
…g flag

Build the recovery state in one initializer so clippy's field-reassign-with-default lint stays clean.
The Loop page names the live path for a non-tool source's unopened turn, and the InputQueue page names the facts whose handling checks the ending, quiet state.
@yyhhyyyyyy
yyhhyyyyyy requested a review from eric8810 December 4, 2026 12:44
@eric8810

eric8810 commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator

This is a draft, and #2146 is still P3: the contract fork it raises (whether an input applied by a closing line stays pending or settles as deleted) has not been accepted yet, so this PR is not merge-eligible under the issue gate. The rule proposed here — a closing line writes input/deleted for every input it did not consume, including one it applied — is the decision #2146 asked for, and it needs to be confirmed in the Session/InputQueue contract before #2146 can move to P2. Until that is settled, keep this as a draft; once #2146 is accepted the PR can be reconsidered. Implementation review stays with the reviewers.

This branch has not been deployed

No deployments
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.

InputQueue: an input queued when its line ends has no defined outcome

2 participants