Skip to content

feat(appserver): read a line's adopted configuration - #1970

Merged
yyhhyyyyyy merged 11 commits into
mainfrom
hui/session-model-get
Nov 22, 2026
Merged

yyhhyyyyyy merged 11 commits into
mainfrom
hui/session-model-get

Conversation

@yyhhyyyyyy

@yyhhyyyyyy yyhhyyyyyy commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A non-root line's adopted model is not reachable through a bounded read. session.attach answers the root's configuration, a transcript window excludes context/configured, and session.history is a single-line stream whose cursor cannot mix an ancestor's adoption with the line's own sequence. A client therefore cannot restore the model a child line adopted without scanning history, and the history-based attempt was refused by the server's fixed-position check.

docs/design/clients.md requires the adopted model to come from an owner read with a branch cutoff, not from a transcript window: https://github.com/arcships/dim/blob/main/docs/design/clients.md

docs/adr/021-reads-follow-the-state-owner.md states the same rule for current state outside a window: https://github.com/arcships/dim/blob/main/docs/adr/021-reads-follow-the-state-owner.md

Method

session.model.get {sessionId, branchId, through?} answers {branchId, through, configuration: {model: {providerId, modelId}, capabilitySnapshot?, modelPreferences?} | null}.

branchId is required; through pins an earlier committed cutoff of that line and is omitted to read its head.

The method is listed in the built-in hello.features and admitted by session_execution, like session.attach; it is not part of LOCAL_EXECUTION_METHODS, so --mock-model and non-product sessions can call it.

configuration is the value the line's latest context/configured carries, with modelPreferences derived exactly as the event projection derives them.

Watermark

The returned through is always the requested line's own committed cutoff; it is never the sequence of an ancestor's context/configured.

A child line numbers its own facts from 1, so a client that took a parent's adoption sequence as the cutoff would drop every later change on the child.

The cutoff reported by an open line is the cutoff of the state it answers from, so a pinned read at that value always answers the same configuration. A read that waits for the Dispatcher to reach the committed head answers at that head, or at the sequence of a later source fact the owner has already applied instead. A line whose own end is committed answers from the tree at its published head: a fact whose publication is still pending is not visible to any read, so the line does not answer past it.

Clients apply only that line's Configuration events whose sequence > through and refresh by calling the method again without through.

Owner

An open line reads from Prompt, the owner of its adopted configuration: the read advances the Dispatcher to the committed head first, so a context/configured committed just before the call is included rather than missed, and it takes the configuration and the projection's applied cutoff under one lock, so the pair cannot come from two different states.

A line whose own branch/end is committed does not read through the owner, even while the owner is still mounted. It reads through TreeCommands with the same Chain + context/configured + Last query that Prompt::load uses, bounded by each ancestor's inherited cut. That covers an ended line, a caller-supplied cutoff, and a closing line whose recovery would otherwise wait for a prompt-state/recovered publication the close may be holding back; the read is bounded by the published head and answers it as through.

The owner's configuration read never writes. A read that has passed its phase check and meets a close before it advances answers the existing cancellation at that second check, at the same point that would otherwise choose recovery, and the App Server turns it into the same tree read at the published head. The shared opening and mutation path keeps its recovery unchanged; only the configuration read takes the active-only advance, so a close that lands between the checks cannot turn the read into a recovery write.

An active line whose services are reloading has no committed end and keeps its reload error instead of being answered from the tree.

An ended line reads its fixed head and is not reopened; an unknown line answers session_invalid_input for UnknownBranch.

The App Server only routes the call and projects the capability read; it owns no configuration state. Lock order is unchanged and no lock is held across an await.

Tests

crates/dim-app-server/tests/transport_flow/model_get.rs covers a root with configuration A and a child line with B, over a root head far above the child's sequence range so a borrowed ancestor cutoff would be visible.

The child's own cutoff stays below its branch point, and its later adoption is above the earlier cutoff.

It also covers an ended line at its fixed head and at an earlier cutoff without reopening it, an unknown line, and a closing line whose end the parent has not recorded yet.

Two controlled interleavings pin the pair, with no sleeps: a read held after it captures the head while a later adoption is applied, and the Dispatcher held before a committed adoption while the read reports it has to wait. Each asserts that a pinned read at the returned cutoff answers the returned configuration.

A read that has passed its phase check while its line starts closing answers the adopted model, and a pinned read at the returned cutoff answers the same model; the test also asserts that the line's committed sequence did not move, so the read appended no recovery checkpoint. Before the change the read replayed the pending source and moved the sequence.

A closing line is read while the publication of its close interrupt is held, with the owner still mounted: the unpinned read answers the adopted model, the returned cutoff succeeds in a pinned read, and that read answers the same model.

A closing line is also read while the publication of its recovery checkpoint is held. The close is stopped after its phase became Closing and before its Timeline closes, the change is injected above the line's own end, and the owner writes the checkpoint the hold stops; every setup wait and the read have an upper bound. The unpinned read answers the adopted model with a pinned read at the returned cutoff answering the same model.

A live read that waits for a recovery result is then followed by the Session close that closes its line: the read ends and answers from the tree.

A reload of a Session row, held before the replacement starts, shows an active line answering service_reloading while it stays unloaded.

The hello.features entry is asserted on a mock-model server, and the same server answers the method without a product home.

Compatibility

Old servers do not advertise session.model.get. The attach reply describes the root's configuration even when its defaultBranch names another line, so a client uses it for the root alone and reports the limitation for every other line instead of presenting the root's configuration as another line's.

No client changes are included here; the client use of this method follows in #1963.

Also narrows #1989

This PR narrows the window of the goal evaluator failure tracked by #1989, which failed the Linux verify job on this branch and is unrelated to session.model.get. That issue stays open: the continuation append is still not conditional on the head the decision covered.

Goal::do_turn_end decided a continuation from the fold it had read, then waited for the write guard and for the ending turn's tool-call query. A report input that committed in one of those windows was folded only after that decision. The stale continuation was written behind the report turn, drove a turn of its own, and that turn end wrote another continuation after the completion request. The evaluator had already been created, so the flow test failed only on the assertion that no continuation follows the request.

The change waits, after the decision, until the Dispatcher has delivered every fact committed at that call, and decides again from the fold under the state lock. An open turn, a driving input, an interrupt or a newer turn end makes the old decision none. The wait has no timeout: it covers facts already committed, ends on the same cancellation as the existing write-guard wait, and runs in Goal's own task, so it cannot block the Dispatcher.

The second decision and the continuation write are separate steps, and the write awaits before it commits. The state lock is released before the continuation input commits, and the continuation carries a submission ID, so the append looks that submission up before it takes the commit lock. A report input that commits during the lookup makes the loop refresh its deduplication cutoff and retry, which does not refresh Goal's decision, so the continuation can still be appended behind that input. The window therefore spans that lookup.

https://github.com/arcships/dim/blob/main/crates/dim-goal/tests/goal_product_flow.rs holds Goal after the first decision and before the second one, starts the report turn, then releases the hold, and asserts that no continuation follows the request; the test fails before this change and passes after it. It does not reach the interleaving at the append itself.

A separate race is reachable when a queued user input starts the next turn at the report turn's end before Goal's decision for that turn end runs: the request is then never evaluated. It is tracked in #1998 and is not changed by this PR.

A line's adopted model had no bounded, branch-qualified read: attach answers
the root, a transcript window omits `context/configured`, and
`session.history` cannot mix an ancestor's adoption with the line's own
sequence.

`session.model.get {sessionId, branchId, through?}` answers the line's
configuration at its own committed cutoff. An open line reads from Prompt,
advancing the Dispatcher to the committed head so an adoption committed just
before the call is included; an ended line, or an explicit cutoff, reads the
same `Chain + context/configured + Last` query from the tree and is not
reopened. The returned `through` is always the requested line's own cutoff,
never an ancestor's sequence.

The method is listed in `hello.features` with `session_execution` admission,
not in `LOCAL_EXECUTION_METHODS`. Contract tests cover a root and a child
line, an ended line, an unknown line and a configuration committed
immediately before the read; the branch design document is updated in both
languages.

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The branch-qualified read is the right boundary for #1963. It avoids deriving current configuration from the transcript, and the historical path returns the selected line’s cutoff rather than an ancestor’s sequence.

[P2] The live result can pair a newer configuration with an older through. Prompt::adopted_configuration (crates/dim-agent-capabilities/src/prompt.rs:1071–1081) captures T from timeline.committed(), awaits advance(T), then clones the current projection. prompt/recovery.rs:1383–1410 only waits for the dispatcher to reach at least T; meanwhile the independent event handler can apply a later context/configured under the projection lock (prompt.rs:903–927). The result can therefore contain model B from U > T but say through: T. An explicit read at T still returns A. This violates the snapshot contract and lets a client replay events that the returned snapshot already contains, potentially rolling its model back if more than one adoption is queued.

Please read the owner’s configuration at an exact captured cutoff, or capture the corresponding projection watermark and configuration coherently under the same synchronization. If using an exact query after waiting, preserve the existing publication/closing semantics. The current pre-committed-adoption test covers the old-config/new-cutoff direction; add a controlled interleaving that pauses the read, publishes another adoption, and checks that the head reply agrees with a pinned read at its returned through. Static paths checked; I did not run the Rust suite.

@zerob13 zerob13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P2] Read the adopted configuration while a child is closing. crates/dim-app-server/src/connection/tree.rs:599–621 falls back to TimelineTree only after the child is marked ended. A child can already have lost the Prompt service before the parent’s branch/ended fact is published (crates/dim-agent-capabilities/src/timeline_tree.rs:2182–2233). In a controlled local transport test, I held that publication after the child scope closed. The unpinned session.model.get returned service_reloading twice, while a pinned read for the same child and committed cutoff returned its adopted model. Use the TimelineTree owner read for this closing transition and keep genuine reload errors for an active branch.

Documentation follow-up: In docs/design/clients.md:167–184, limit the session.attach fallback to root configuration. The projection in connection/subscription.rs:564–600 can name a non-root default while its model fields still describe root; a client cannot infer that child's model from the fallback.

The three existing transport tests passed on this head. I also reproduced the already-reported configuration/through mismatch; see review #6003097268 for that separate finding.

A live `session.model.get` could pair a newer configuration with an older `through`: the owner read captured the committed head, waited for the Dispatcher, then cloned the projection, so an adoption applied in between came back at the previous cutoff. The read now takes the configuration and the projection's applied cutoff under one lock and reports that cutoff, never below the head it waited for, so a pinned read at the returned value always answers the returned configuration.

A line can also lose its scope before its parent records `branch/ended`: an unpinned read then answered `service_reloading` while a pinned read of the same cutoff answered its adopted model. The owner read now answers from the tree when the line's own `branch/end` is committed, through a new Rust-only `TreeCommands::end_committed`, and an active line that is reloading keeps its reload error instead.

Three controlled interleavings pin the behaviour without sleeps: a read held after it captures the head while a later adoption is applied, the Dispatcher held before a committed adoption while the read reports that it must wait, and a closing line held between the close of its scope and the parent's record of its end. A Session row reload shows an active line answering the reload error.

The branch design document states the reported cutoff, the closing transition and the attach fallback, in both languages; the clients document limits that fallback to the root's configuration.
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

#1970 (review)

Thanks - the pairing was wrong, and the fix takes your second option: the owner answers the configuration and the cutoff together, under one lock.

Prompt::adopted_configuration still waits for the Dispatcher to reach the committed head first, so an adoption committed just before the call is included. It then holds the projection lock once and returns the adopted configuration together with the projection's applied cutoff. The projection applies each source fact and moves that cutoff inside the same critical section, so the two cannot disagree: an adoption applied while the read waits is included and answered at that adoption's sequence or a later applied source fact's, and one applied after the lock is released stays above the returned cutoff.

The cutoff is still the requested line's own sequence. A line's projection is restored at its own committed cutoff and applies only that line's facts, so the value never comes from an ancestor, and it is never below the head the read waited for.

I kept the owner's pair rather than adding an exact chain query after the wait: the reply then describes the state the line is actually running with, it needs no second store read on the open path, and nothing new can drift from the owner's own recovery query. The tree read stays for the ended line and an explicit through.

Two controlled interleavings pin both directions, with no sleeps:

  • a_live_read_answers_the_adoption_it_reports_as_its_cutoff holds the read after it captures the head, commits and applies a later adoption while it is held, then lets it continue. The reply must answer that adoption, and a pinned read at the returned through must answer the same configuration.
  • a_live_read_waits_for_a_committed_adoption_the_dispatcher_has_not_reached holds the Dispatcher before a committed adoption and holds the read after it captures the head. A read that answers while the Dispatcher is still held fails the test; once the read reports that it has to wait, the hold is released and the reply must include the committed adoption at its cutoff. Removing the wait makes the test answer the previous configuration at the newer cutoff, which fails.

The holds are two hooks behind the capabilities crate's testing feature (pause the read after it captures its cutoff, and report that the read is waiting for the Dispatcher) plus a test part that holds the Dispatcher. A production build carries none of them.

@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

#1970 (review)

Thanks - both points are in.

For the closing transition, an unpinned read now asks the tree whether the line's own branch/end is committed. A line records that fact before its scope closes, and its parent's branch/ended only afterwards, so the committed end is exactly the boundary in your reproduction: while it is set the line's facts answer at its head, and while it is not, the lookup error is returned unchanged. An active line that is genuinely reloading has no committed end, so it keeps service_reloading instead of being answered from the tree.

Two tests cover both sides, each held at a known point with no sleeps:

  • a_closing_line_answers_its_adopted_configuration holds the parent's record of a child's end after the child's scope has closed, then reads the child: the unpinned read answers the adopted model at the child's cutoff, a pinned read at that same cutoff answers it too, and the line still answers once its end is recorded.
  • a_reloading_active_line_keeps_its_error reloads a Session row with the replacement's start held, so the line stays unloaded while the read runs: the read answers service_reloading.

The check is a new Rust-only read on the tree's service, TreeCommands::end_committed; it is not part of the cross-language service face.

For the documentation, the clients design document now says the attach reply's model fields describe the root even when its defaultBranch names another line, and that without session.model.get a client uses that reply for the root alone and reports the limitation for every other line. No Chinese section mirrors that paragraph, so only the English document changed.

@zerob13 zerob13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The previous closed-scope fallback and configuration/cutoff findings are fixed. One earlier close phase remains: connection/tree.rs:599–626 only falls back for terminal errors when Prompt is still mounted. In two isolated lifecycle checks, reading during normal close while its interrupt publication was pending returned session_invalid_input / future timeline sequence; a read at the published cutoff still returned the adopted model. Use a valid published cutoff (or wait for it) when the branch is closing but Prompt remains mounted. All six existing model-get cases passed locally; exact hosted Linux was pending at the independent review.

@yyhhyyyyyy
yyhhyyyyyy changed the base branch from hui/branch-default-routing to main November 21, 2026 16:44

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

Reviewed at head b5d632d.

The read is placed correctly and for the stated reason. session.model.get answers from the owner — Prompt::adopted_configuration() on the line itself when it is open — and falls back to the tree's chain read at the line's fixed head when the line has ended, is closing, or an explicit through was asked for. The comment on the method says the App Server owns none of the answer, and the code matches it: the transport resolves a session and a line, then delegates. That is ADR 021's shape rather than a transcript scan or a window.

configuration_query is the part worth keeping: Chain scope, through cutoff, pick: Last, selecting only data, documented as shared with Prompt's recovery read so the two cannot disagree about what a line adopted. One query shape used by both readers is exactly the "one type per kind of data" rule applied to a read, and it makes "what did this line adopt" unanswerable two ways.

Mapping BranchEnded/Cancelled/Closed to the fixed-head read rather than an error is a decision with a business meaning — a closed line's adoption is still a fact — not a swallowed failure, and the alternative would have made an ended line's model unreadable.

verify (linux) and ci-ok failed on this head, in the CLI update machinery, which no file of this PR reaches:

crates/dimcode/tests/cli_flow/staged_update.rs:88
staged_update::an_update_that_installs_nothing_keeps_the_installed_command
  install updater at "…/node_modules/dimcode-alpha/bin/dimcode": exit status: 1
214 passed; 15 failed
update_entry::update_reports_a_source_build_and_sends_no_input
161 passed; 1 failed

Fifteen staged_update cases plus one update-entry case, all failing at the point where the fixture installs the updater — an environment or fixture failure in the npm-install path, and that area has been red on main repeatedly this week. Nothing here touches it.

Not approving while a required check is red.

Non-blocking: none.

A normal close commits its interrupt before the store publishes it. An unpinned `session.model.get` of that line took the last assigned sequence as its cutoff after the branch phase had become closing; the owner's recovery read at that sequence was refused as a future sequence, so the call answered `session_invalid_input` while a pinned read at the published head still answered the adopted model.

The owner read now clamps its cutoff to the line's published head when the branch is not active and reports the cutoff it used. The configuration and the cutoff still come from one projection lock, so a pinned read at the returned value always answers the returned configuration. Active lines keep the wait for the Dispatcher, and an active line under reload keeps its reload error.

A new flow test holds the publication of the close interrupt with a store hook (feature `testing`) while the line is closing and its owner is still mounted, then reads without a cutoff, reads again at the returned cutoff, and gets the adopted model both times. The branch design document now names the published head for a closing line and describes the reported cutoff as the last applied source fact's sequence, in both languages.

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

Reviewed at head 313dbfc.

This head carries 46 commits since the one I read, and none of them touch this PR's own change: connection/tree.rs, protocol.rs, transport.rs, the timeline_tree read and the model_get test are all unchanged from b5d632d1. The delta is main merged in — the TypeScript service faces, InputQueue face, os_string and the regenerated catalog. So my finding at b5d632d1 stands as written: the read answers from the owner (Prompt::adopted_configuration() on an open line) and falls back to the tree's chain read at the fixed head, with configuration_query shared with Prompt's recovery read so the two cannot disagree about what a line adopted. That is ADR 021's shape, not a transcript scan.

verify (linux) and ci-ok failed on this head, in one TUI frame test this PR cannot reach:

crates/dimcode/tests/support/cli_harness.rs:893
staged_update::tui_update::update_now_falls_back_to_manual_command_for_an_old_daemon
  Terminal did not show "To update, exit DimCode and run: dima update"
228 passed; 1 failed

Worth noting what changed for the better: the previous head failed fifteen staged_update cases at the point where the fixture installs the updater; this head fails one, and it fails at a terminal frame assertion rather than at an install step. That is the update_now/TUI-frame cluster that has been red across many heads, not an install-path break, and the "Did not show" message is the frame not having settled inside the harness's wait.

Not approving while a required check is red.

Non-blocking: none.

@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

#1970 (review)

Fixed: a closing line now answers session.model.get at its own published head.

The failure came from the owner read, not from the protocol. While the line's scope is closing, Prompt::adopted_configuration captured the Timeline's last assigned sequence, which could still include the close interrupt whose store publication had not completed. The recovery read at that sequence was refused as future timeline sequence, and the call answered session_invalid_input.

The owner read now takes the line's published head as its cutoff when the branch is not active, and reports that cutoff. The configuration and the cutoff are still read together under the projection lock, so the reply's through is valid for a pinned read and a pinned read at it answers the same configuration. Active lines keep the wait for the Dispatcher, and an active line under reload still keeps its service_reloading error.

New coverage: model_get::a_closing_line_answers_at_its_published_cutoff holds the publication of the close interrupt while the line is closing and the owner is still mounted, then asserts that the unpinned read answers the adopted model, that the returned through succeeds in a pinned read, and that the pinned read answers the same model. It fails before the change with session_invalid_input and future timeline sequence 19, and passes with it.

The design text now says that a closing line answers at its published head, and the parenthetical about the reported cutoff names the sequence of the last applied source fact.

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

Re-reviewed at 8d918e48. Clamping to the published head fixes the pending-interrupt sequence error, and the new test checks that the returned through can be read back while that interrupt is still held.

[P2] Do not make a closing configuration read wait for a Prompt recovery write. The closing path in prompt/recovery.rs:1388–1392 clamps the lookup, but recover_sources still unconditionally waits for projection.written_result at :1505–1508. That sequence is not bounded by the published cutoff. The replay can also create it itself: a published prompt/changed source can reach step during the read and append a prompt-state/recovered checkpoint (:1491–1497, :748–787, :893). If the writer is still holding an older close interrupt, this checkpoint cannot publish, so a read that has enough committed data to answer waits for the very close publication it is meant to be independent of. The new regression uses an idle Prompt, so it does not exercise a pending checkpoint. The active path has a similar final wait after the dispatcher loop, where a close does not select the existing cancellation fallback.

Please keep the closing lookup read-only and bounded to the published cutoff, e.g. use the existing TimelineTree configuration query once the branch is closing, while preserving the active owner read and genuine reload error. A regression can hold prompt-state/recovered publication and assert that the closing lookup and a pinned read return the same model while the hold is still armed. This remaining path is a source finding; I did not run that interleaving. Exact CI was in progress at review time.

yyhhyyyyyy added a commit that referenced this pull request Nov 21, 2026
The CLI, the TUI, the ACP gateway and the Web read a line's adopted configuration through the branch-qualified read added by #1970, at the cursor the attach reply or the window carries, and apply only that line's later configuration events. The reads that paged the line's history backwards with a fixed cutoff and a page cursor together are gone; the App Server refuses that combination as a cursor past the fixed position, so a real daemon never answered them. A server that does not advertise the read no longer has the root's configuration shown for a line: the line reports the limitation and the bar carries no model, and the Web no longer falls back to the directory row's model, which is the root's.

The Web takes a move's generation only once the server accepts it, so a move the server refuses cannot discard the completion of a move it accepted; the earlier move still reaches the page, whose centre then matches the server's default branch.
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

#1970 (review) and #1970 (review)

The first run (b5d632d1a, 44924260195) failed 15 staged_update:: tests and update_entry::update_reports_a_source_build_and_sends_no_input at the same fixture: install_updater reported install updater at "...": exit status: 1, and the job log records the installer's actual error as install: cannot install ... Disk quota exceeded (os error 122) while copying the test binary to a home under /tmp. update_entry then failed on the same exhausted resource with Os { code: 122, kind: QuotaExceeded }. This is an environment failure in the shared test fixture, not a staged-update assertion, and it appeared on a different runner than the same fixture failure in another pull request's run. Tracked in #1987.

The next run (313dbfcc5, 44927803492) did not repeat the installer failure; it failed only staged_update::tui_update::update_now_falls_back_to_manual_command_for_an_old_daemon, which waited for To update, exit DimCode and run: dima update but saw the Home screen with no update dialog. The following run (8d918e486, 44933001434) failed staged_update::tui_update::update_now_stops_an_idle_daemon_and_restarts_on_the_same_session, which waited for Update now and likewise saw no dialog. The second is the resumed-startup update-offer race tracked in #1975: the update check starts before the Session is attached, and the following resumed switch drops the offer before it is shown. #1982 fixes that path. The first shows the same symptom, a resumed start with no update dialog, and most likely has the same cause; that is not confirmed from the log.

The same run (8d918e486, 44933001434) also failed update_uses_the_installed_package_and_prefix_without_a_daemon at cli_daemon_flow.rs:447, where terminal.wait().success() did not match !fail: a fail = false case exited non-zero. That assertion does not print the terminal transcript and the job log does not record the command's output, so the cause of that exit is not known from the log; the test runs the update subcommand through its own npm fixture and does not use the resumed update dialog. It is not explained by the installer failure (that run has no quota error and its staged-update tests passed).

This pull request changes the adopted-configuration read in the App Server, session prompt and timeline-tree code, its transport tests, and the related design pages; none of the failing tests or their fixtures is in that set.

A closing configuration read went through Prompt's recovery, whose final wait does not end when the line closes. The publication it waits for can sit behind the close's own interrupt, and the owner can write a recovery checkpoint while the read runs, so the read waited for the close it must not depend on.

Route a line whose own end is committed to the tree's configuration query, and end an owner read's publication wait when the line closes or its scope unloads. The owner path refuses to replay once the phase is closing.

Tests hold a recovery checkpoint's publication while a line is ending and while a live read waits on it; both fail before this change.
The committed-end check and the owner lookup are two calls, and a line's end can commit between them. Its scope then unloads before session.service returns, so the read reported the reload or ended error that the committed-end route already answers from the tree.

Keep the committed-end check and fall back to the tree when the owner lookup fails and the line's own end is committed; an active line that is reloading still returns its error. Also correct the assertion message of the test's upper bound, which claimed the read ended.
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

#1970 (review)

Fixed: a closing line no longer reads its configuration through the owner's recovery, and an owner read that waits for a recovery result now ends that wait when the line closes.

The closing path still replayed sources through the mounted owner. Its final wait was ConfigurationPublisher::await_published(written_result), which the published cutoff does not bound: the owner writes a prompt-state/recovered checkpoint while applying a published prompt/changed, and when the writer is stopped at the close's own interrupt that checkpoint cannot publish, so the read waited for the close publication it must not depend on.

session.model.get now checks the line's own committed branch/end before touching the owner. A line that committed its own end reads through TreeCommands::adopted_configuration, the same Chain + context/configured + Last query configuration_query uses, so the read neither replays sources nor waits for a write; its through is the line's published head, and a pinned read at it answers the same configuration. An active line still reads from the owner. If the line starts closing after that check, the owner read refuses once the phase reaches Closing, and both of its publication waits select the branch's closing signal and the owner's cancellation token, so the call falls through to the tree instead of waiting.

An active line under reload keeps service_reloading; only a committed end answers from the tree.

New coverage in crates/dim-app-server/tests/transport_flow/model_get.rs, without sleeps: model_get::a_closing_line_answers_without_waiting_for_its_recovery_checkpoint holds the publication of prompt-state/recovered, ends the line, publishes a prompt/changed above that end so the owner writes the checkpoint, and reads while the hold is armed; it answers the adopted model, and a pinned read at the returned through answers the same model. Before the change the read timed out on the held checkpoint's publication. model_get::a_live_read_ends_when_its_line_starts_closing holds the same publication, starts a live read, lets the owner write the checkpoint above the read's captured cutoff, and then starts the Session close that closes the line; the read ends and answers from the tree, where before the change it stayed in the publication wait until the test's own upper bound.

The route adds no protocol method or field, changes no attach reply, and keeps the lock order: the owner path takes no lock across a wait, and the tree read only queries the store at the published head.

@yyhhyyyyyy
yyhhyyyyyy requested a review from eric8810 November 21, 2026 21:33

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

Re-reviewed f961b52a. Checking the line's own end before touching Prompt and cancelling an already-waiting live read address the held-publication hang from my previous review. The recheck after a failed service lookup also closes that lookup race.

  1. [P2] Keep the live read out of recovery if the line starts closing between the two phase checks. Prompt::adopted_configuration checks at prompt.rs:1078, then calls advance, which checks again at prompt/recovery.rs:1405–1409 and enters recover_sources if it now sees Closing. That path can append a recovery checkpoint and expired-context inputs (:750–786) before its final cancellation check. Branch close sets its phase before making the Timeline non-appendable (`timeline_context.rs:736–781)), so the second check can still turn this read into a writer during close. There is no longer a publication hang in that path, but the extra write can delay settlement. Have the model read use an active-only variant that decides at the same phase check that chooses recovery, leaving the shared opening/mutation recovery path intact.
  2. [P2] Gate the closing fixture before it can pass through Ending. In tests/transport_flow/model_get.rs:776–812 the new regression test spawns an idle branch end and polls for the transient Ending state before injecting the source change. Nothing holds the close at that state; it can reach Ended before the poll sees it, or close the Timeline between the poll and the injection. The checkpoint hold cannot prevent that because it only takes effect after the change. The 10s timeout starts after all those waits. Gate the close after its own end is committed but before the Timeline closes, then inject the change, and bound the setup waits.

These are source findings. Exact CI was still running.

@zerob13 zerob13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-reviewed f961b52a91407e448a787abe0dea9159ab036da9. The earlier invalid cutoff and wait during closing are fixed. The ownership boundary still has a gap: a configuration lookup admitted just before close can enter write-capable Prompt recovery after the branch phase changes.

The getter checks the phase before calling advance, whose non-active path still replays sources. Cancellation at the publication wait is too late to prevent that replay from enqueueing a recovery checkpoint. An isolated normal-close lifecycle test returned the correct configuration but advanced the committed sequence from 20 to 21; all nine committed model-get tests passed.

Keep the configuration getter on a read-only path at this transition: return the existing cancellation outcome and let TimelineTree answer at its published cutoff, rather than using the non-active recovery path. This is an ownership fix, not a request for another phase check or broader compatibility logic. Exact CI passed macOS, Web and scripts; Linux was still running when checked.

@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

#1970 (review)

Fixed: a configuration read whose line starts closing between the phase checks no longer enters the recovery path, so it cannot append a checkpoint or expire context inputs while the close settles.

Prompt::adopted_configuration still refuses a line that is already closing before it advances. The advance now uses Prompt::advance_active, which answers the existing cancellation at the same phase check that chooses recovery instead of calling recover_sources; the shared opening and mutation path keeps Prompt::advance and its non-active recovery unchanged. session.model.get turns that cancellation into the TreeCommands read at the line's published cutoff, so the answer and its pinned read still agree.

New coverage: model_get::a_read_whose_line_starts_closing_before_it_advances_commits_nothing holds a live read after its phase check, starts the close, and releases the read once the close's own interrupt is committed and its publication is held; it asserts the adopted model, a pinned read at the returned through answering the same configuration, and that the committed sequence did not move. With the previous advance path and only the test hook added, the same test fails with the committed sequence moving from 19 to 20.

The closing fixture of model_get::a_closing_line_answers_without_waiting_for_its_recovery_checkpoint no longer polls for the transient Ending state. A testing hook stops the close after its phase became Closing and before the Timeline closes, the change is injected there, and every setup wait and the read have an upper bound.

@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

#1970 (review)

Fixed: a configuration lookup admitted before a close no longer reaches the write-capable recovery path after the branch phase changes.

The getter's advance is Prompt::advance_active: it makes the same phase check that would choose recovery, and a line that is not active answers the existing cancellation there, before any source replay. The read therefore appends no prompt-state/recovered checkpoint and expires no context input, and session.model.get answers the line from TimelineTree at its published cutoff. Opening and mutation callers keep Prompt::advance and its recovery unchanged.

model_get::a_read_whose_line_starts_closing_before_it_advances_commits_nothing reproduces the normal-close window deterministically: the read is held after its phase check, the close runs to the commit of its interrupt, the read is released, and the test asserts the returned configuration, a pinned read at the returned cutoff answering the same configuration, and the committed sequence staying put. With the previous advance path and only the test hook added, the committed sequence moves from 19 to 20.

The closing fixture of model_get::a_closing_line_answers_without_waiting_for_its_recovery_checkpoint now stops the close after its phase became Closing and before the Timeline closes instead of polling for Ending, and bounds every setup wait.

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

Reviewed at head 971bde8.

The delta since 313dbfcc is one refinement and its tests. end_committed now decides up front whether the line committed its own end, and such a line is read from the tree at the published head without replaying or waiting. The comment gives the reason and it is the right one: a closing scope may still hold its owner, and that owner may be waiting on a publication the close holds back, so a read that went through the closing scope could wait on the very close it is observing. Checking before the call rather than catching the resulting error is the difference between avoiding the wait and surviving it, and the doc comment on the method now says "fixed, published or requested head" to match.

The test side gained the ability to hand each branch's Timeline to the test and to commit prompt-change facts directly, which is what makes the published-head case reachable without a producer — the kind of coverage this behaviour needs, since a line that has not committed its end is the case that would hang rather than fail.

verify (linux) and ci-ok failed on this head, in the CLI update machinery, which no file of this PR reaches:

update_uses_the_installed_package_and_prefix_without_a_daemon
update_entry::update_reports_a_source_build_and_sends_no_input
staged_update::a_command_another_package_owns_is_never_taken
160 passed; 2 failed

That suite has been red on and off across many heads this week; the counts differ each run (fifteen failing cases, then one, now these), which is what a fixture that installs an updater looks like when the environment misbehaves rather than a regression in a specific path. Nothing here touches it.

Not approving while a required check is red.

Non-blocking: none.

Copy link
Copy Markdown
Collaborator

One CI detail on 971bde8f: the exact Linux job also reports four model_get failures, including the new read-commits-nothing case. All four stop during fixture setup with SqliteStorage: disk I/O error, before their assertions. Six other model_get cases passed. The wider job reports disk-quota errors, but the SQLite setup messages do not themselves establish that cause. The new close assertions therefore still need a clean run on this head.

`do_turn_end` decides a continuation from the fold, then waits on the
write guard and on the ending turn's tool-call query. A report input
that commits in those windows is folded only after the decision, so
the stale continuation is written behind the report turn, drives a
turn of its own, and that turn end writes another continuation after
the completion request. The evaluator was already created, which is
why only the no-continuation assertion failed.

After the decision, wait until the Dispatcher has delivered every fact
committed at that call and decide again from the fold under the state
lock. An open turn, a driving input, an interrupt or a newer turn end
makes the old decision none.

The wait is the one `write_guard` already makes before a state record.
It has no timeout: it is bounded by the facts committed before the
call, ends on the same cancellation as that existing wait, and cannot
block the Dispatcher because it holds neither the state lock nor a
lock the Dispatcher takes, and `do_turn_end` runs in Goal's own task
rather than in a Dispatcher handler.

The regression test holds the set turn's continuation at its write,
starts the report turn, then releases it, and asserts that no
continuation follows the request.

Fixes #1989
Goal's `testing` hook is enabled by its own dev-dependency, like the
hooks of the other crates, so the generated crate graph gains the
self edge `dim-goal -> dim-goal`.

Regenerated with `cargo run -p xtask -- graph`.
The #1989 flow waited on HeldWrite::arrived without a limit, so a
regression that never writes the continuation hung until the job
timeout instead of failing the test. Bound the wait to the 15s the
test's other waits use.

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

Re-reviewed b909eb51. The model-read close fixes from 971bde8f are unchanged: the read no longer enters write-capable recovery when close wins, and the fixture gates the closing phase instead of polling for it. The new Goal change catches the case where the report turn commits before the second decision.

[P2] Keep #1989 open until the continuation precondition holds at append. The remaining race is not just a few instructions. After the second fold check, Goal calls write(input).await. The continuation carries a submission ID, so Timeline::input_checked awaits a submission lookup before taking the commit lock. If another input commits during that await, the loop refreshes its deduplication cutoff and retries; it never refreshes Goal's decision. A report input can therefore still overtake a continuation on this head, particularly if the store lookup is delayed. The new fixture holds the decision before the recheck, so it can't detect this interleaving.

Please make the continuation append conditional on the head the decision covered, and re-evaluate (rather than unconditionally retrying) if that head has changed. A focused regression should gate after the final decision, before append, and then commit the report input. If this PR is intended to ship only the narrower mitigation, please separate it from the configuration read and leave #1989 open. This is distinct from #1998's missed evaluator.

The remaining append race is a source finding, not a locally reproduced failure. Exact CI was still running when checked.

@yyhhyyyyyy
yyhhyyyyyy merged commit 5583244 into main Nov 22, 2026
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

#1970 (review)

I accept the finding: the remaining window is between Goal's second decision and the continuation append, and it is wider than a few instructions. The continuation carries a submission ID, so Timeline::input_checked awaits a submission lookup before it takes the commit lock. A report input that commits during that await makes the loop refresh its deduplication cutoff and retry, and the retry keeps the decision from before that input.

This PR was merged with the narrower mitigation, and the append race is tracked in #1989, which stays open. The regression in this PR holds the decision before the recheck and does not cover that interleaving.

@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

#1970 (comment)

The quota and disk I/O error messages did not reappear in the two later attempts of run 44962245397, and all ten model_get tests passed on Linux in those attempts: https://github.com/arcships/dim/actions/runs/44962245397/job/137056724423 and https://github.com/arcships/dim/actions/runs/44962245397/job/137061938685

Those attempts were still red on goal_product_flow::goal_evaluator_judge_creates_an_evaluator_and_completes_on_done, which is unrelated to session.model.get. Commits after them change when Goal re-evaluates a continuation at a turn end, which narrows that failure's window, and the remaining append race stays open in #1989.

This does not claim the quota messages as a confirmed cause of the first attempt.

A clean verify (linux) run of the new head b909eb5: https://github.com/arcships/dim/actions/runs/44984276369/job/137091378798

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants