Skip to content

fix(runtime): report Session restore progress and name its timeout phase - #2055

Merged
yyhhyyyyyy merged 11 commits into
mainfrom
hui/session-restore-timeout
Nov 23, 2026
Merged

yyhhyyyyyy merged 11 commits into
mainfrom
hui/session-restore-timeout

Conversation

@yyhhyyyyyy

@yyhhyyyyyy yyhhyyyyyy commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #2038.

A Session restore can run long after every row is already Active: the store reads and line builds happen while the opening's inactivity bound has nothing to observe. A silent restore then fails the opening at initialization timed out: , naming neither a row nor a phase.

crates/dim-agent-capabilities/src/timeline_tree.rs: every finished restore step reports opening progress after it, so the inactivity bound follows real work. The steps are the default fact read, each line's terminal, lifecycle and own-end reads, the interrupted-end completion and final delivery, the creation check and its source, and the line's build. The report uses a dim_agent_runtime::OpeningReporter that the tree resolves on the first finished step and reuses, so a restore costs one process diagnostics snapshot for the tree instead of one per step, and a Session that never restores resolves none.

The PR adds one public type, dim_agent_runtime::OpeningReporter; its only public methods are new and report (a testing-only accessor names the fiber for the flow test), and the OpeningAdvanced event stays pub(crate). The type exists because a restore reports at many steps and needs a reporter scoped to one task that resolves its reporting identity once.

crates/dim-agent-runtime/src/assembly.rs: OpeningReporter::new resolves the plugin id once and report reuses it; opening_advanced keeps its one-shot behavior for the other opening waits. When a restore's opening lapses with no pending row in the wait, the message names the phase still running: initialization timed out: no pending row in this wait; still running: restore. The other opening waits keep the message they had, and a stuck required row keeps the message listing its name, state and unmet dependencies, which session_create_rejects_trace_and_rolls_back_a_failed_main_branch in transport_flow.rs asserts.

The bound covers only the gaps between steps. An individual store read the restore awaits is still awaited under the same interval, and the branch-directory read precedes the first report, so the restore has no wall-clock bound of its own.

No production timeout, bound or threshold changes; the restore's behavior and step order are unchanged. #2030 reports progress from a silent store upgrade the same way, and #2031 names inactive process rows in its own message; neither touches these functions.

The tests in crates/dim-app-server/tests/storage_flow.rs use a testing restore-step delay keyed by Session. a_silent_restore_times_out_naming_the_restore_phase fails without the phase fallback, ending at initialization timed out: ; a_slow_restore_reports_progress_and_keeps_the_opening_alive fails without the progress reports, timing out while every step stayed shorter than the bound and their total outlasted it. a_restore_resolves_its_reporting_identity_once restores a stored Session and asserts that its tree resolved the reporting identity exactly once, a count rather than a duration. each_tree_generation_resolves_its_own_reporting_identity closes the Session and restores it again, asserting that the two trees resolved different fibers and that the second one is the new tree's live fiber. a_row_reload_resolves_the_new_tree_reporting_identity reloads the TimelineTree feature row for a Session that is already open and asserts the same for the reloaded tree, with the disposed copy's fiber no longer Active. All five pass at a4b7ec46a9446a3c469663e00e18585e43383301.

A Session restore runs its store reads and line builds after every row is already Active, so the opening's inactivity bound saw no progress: a slow store made the Session fail to open, and the error ended at `initialization timed out: ` with neither a row nor a phase to act on (Refs #2038).

Every TimelineTree restore step now reports opening progress with `opening_advanced` after it finishes, so a read or a line's build that runs long renews the bound instead of looking idle. When the bound still lapses with no non-Active row, the message names the phase that was running: `initialization timed out: no row pending; still running: restore`.

The startup bound and the restore's behavior and step order are unchanged. A stuck required row keeps the message that lists its name, state and unmet dependencies.

The tests in storage_flow cover a silent restore that names its phase and a slow restore whose steps each stay inside the bound while their total outlasts it.
The timeout fallback named a phase for every opening wait, but only the restore has a scenario that emits it; the instance-creation, row-activation and new-Session waits now keep their previous message, so each new text in this change is reached by a test.

The fallback covers the rows the wait actually watches: a restore can be building a line that the wait does not include, so the message says "no pending row in this wait" instead of claiming nothing is pending. Only the restore passes a phase, `restore`, and the silent-restore test asserts the whole clause.

The design document now says a restore of the lines a plugin owns may report opening progress, the same as its own long `apply`.
@yyhhyyyyyy
yyhhyyyyyy requested a review from eric8810 November 22, 2026 20:11

@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 phase fallback preserves the existing pending-row diagnostic, and renewing the interval after completed work is preferable to an unconditional heartbeat.

[P2] Avoid rebuilding the process diagnostics snapshot for every restore step. step_finished runs after multiple reads per stored line (including already-ended lines) and again after mounting a line. Each call goes through opening_advanced, which builds a complete Rutis diagnostics snapshot to find this same plugin ID. In pinned Rutis 0.23.0, that walks from the process root, resolves each fiber's dependency diagnostics and snapshots registry bindings before find runs. The new synchronous work therefore scales as restore steps × live process rows, including unrelated Sessions, and becomes quadratic in the number of lines when those lines are being mounted. The two-line fixture cannot expose that cost.

Resolve the reporting identity once for the restore or tree generation (or provide a cheap scoped reporter from the runtime), and reuse it at the same real-work boundaries. Keep subtree filtering and shutdown semantics. A scan-count assertion or a many-line restore test would make it easier to guard the cost.

Separately, the change narrows between-step inactivity gaps. An individual stalled store read is still awaited during cleanup, and the initial branch-directory read precedes this wait. Please keep that limitation explicit rather than implying the whole restore now has a wall-clock bound. Source review only; exact CI was still running.

`opening_advanced` builds a complete Rutis diagnostics snapshot to find the plugin id it reports under, and `TimelineTree::step_finished` called it after each restore step. The tree now resolves the id once on its first finished step through `OpeningReporter` and reuses it at every step, so a restore costs one snapshot per tree instead of one per step, and a Session that never restores costs none.

The new flow test restores a stored Session and asserts that its tree resolved the identity exactly once, a count that does not depend on timing. The design documents state that progress reporting bounds only the gaps between steps, not a single store read.
The restore identity test restored a stored Session under a ten-second opening bound that no other restore test uses. It now passes the same one-second bound as the silent and the slow restore tests, so restore tests share one opening bound and the file gains no new duration.
…nly the gaps between steps

The Chinese guide now carries the sentence its English counterpart already has: a report bounds the gap since the previous one, not any single await, so work that stalls without reporting still times out.
The Chinese guide was missing the English clause about a restore of the lines a plugin owns, so a plugin whose restore runs long had no stated way to report that it advanced.
Both guides named only `opening_advanced`, which resolves the reporting identity on every call. They now say that a multi-step process such as a restore resolves it once with `OpeningReporter::new` and reports through the same reporter at every step, taking one process diagnostics snapshot instead of one per step.
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

Fixed in 8557ee4: TimelineTree resolves its OpeningReporter on the first finished restore step and reuses it, so step_finished emits a progress event instead of building a process diagnostics snapshot for every step. This is the cheap scoped reporter from the runtime that the review suggested: dim_agent_runtime::OpeningReporter exposes only new and report, and the tree holds one reporter for its restore. A Session that never restores resolves none.

a_restore_resolves_its_reporting_identity_once restores a stored Session and asserts that its tree resolved that identity exactly once; the same restore resolved it seven times before the change. The assertion is a count, not a duration.

The PR body and the design documents now state that the progress bound covers only the gaps between steps: a single stalled store read is still awaited, and the branch-directory read precedes the first report.

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

@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 restore reporter now resolves its identity lazily once per tree instead of rebuilding a diagnostics snapshot at every progress step. Progress still follows completed work, the existing inactivity interval is unchanged, and the timeout identifies the restore phase without hiding pending-row details. Exact CI run 45071756753 passed all three restore regressions on Linux and passed macOS native, static checks and the CI gate.

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

The diagnosis is the same shape as the storage-upgrade fix and it belongs at the same place: a restore runs long while every row is already Active, so the opening's inactivity bound has nothing to observe and fails with initialization timed out: naming neither a row nor a phase. Reporting after each finished restore step — the default fact read, each line's terminal, lifecycle and own-end reads, the interrupted-end completion and its delivery, the creation check and its source, the line's build — makes the bound follow real work instead of silence.

The OpeningReporter is the right abstraction and the right size: new and report, the id resolved once so a restore costs one diagnostics snapshot rather than one per step, OpeningAdvanced left pub(crate) so the event does not become public surface, and a Session that never restores resolving nothing. Keeping the existing opening_advanced helper as a thin wrapper over it means the row-level path does not diverge from the restore path.

Checks are green at this head.

Blocking: none.

Non-blocking:

  • crates/dim-agent-capabilities/src/timeline_tree.rs:398 — reporter: OnceLock<Option<OpeningReporter>> resolves the plugin id once for the life of the tree. The report is dropped when no live fiber has that instance, which is what makes the wrapper safe today; but if this row is ever reloaded while the tree survives — the plugin contract has process parts survive a row reload — the cached id would name a fiber that no longer exists, every later report would be dropped, and the restore would time out again with the same silent message this PR fixes. Either say that the tree is rebuilt with the row, or resolve again when a report finds no live fiber.

Each tree resolves the reporting identity its reports are attributed to when it first reports, and the copy that creates the tree is the one that closes it: the owning row's unload withdraws the part registration, disposes every copy, and only then does the next generation apply and create its own tree. A row reload therefore rebuilds the tree and its cached identity together instead of leaving a stale one behind.

The flow test restores a stored Session, closes it, restores it again, and pins that the two trees resolved different fibers and that the second one is live, so each tree reports under its own generation and no report is attributed to a fiber that has gone.

The suite cannot reload the row while a Session stays open. Restarting the feature row withdraws its registration and disposes the tree copy, and a tree mounted into an open Session is never restored, so no report follows. The test moves between generations by restoring the Session, and the row-reload path is stated by the code that creates and disposes the tree.

The capabilities testing feature now enables the runtime testing feature: the identity hook reads the reporter's resolved fiber through the runtime API that only exists in testing builds, and the library must compile when its testing feature is on by itself.
`a_row_reload_resolves_the_new_tree_reporting_identity` reloads the `TimelineTree` feature row of a host whose Session is already open. A test-only Session part declares the tree's name, so it reloads with the row and captures the tree each generation mounts. The flow restores the stored branch directory on the reloaded tree, then asserts that the two generations resolved different fibers, that the second one is the reloaded tree's live `TimelineTree` fiber, and that the disposed copy's fiber is no longer Active.

The restore-generation test and its comment stay; the comment no longer claims that restoring the Session is the only way the suite can reach another tree. The plugins page lists both tests.
The row reload test wraps every wait in `settled` and opens under the default Session bound, so it needs no bound of its own; the removed one-second bound served no assertion and was a new limit.
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

The row reload is covered by a test now. a_row_reload_resolves_the_new_tree_reporting_identity opens the stored Session, reloads the TimelineTree feature row with Loader::restart, and captures the tree each generation mounts through a test-only Session part that declares the tree's name, so it reloads with the row. The flow then reads the stored branch directory with TimelineStore::branches and restores it on the reloaded tree with TimelineTreeControl::restore. It asserts that the two generations resolved a fiber each, that the fibers differ, that the second one is the reloaded tree's TimelineTree fiber in Active state in the Session's diagnostics, and that the disposed copy's fiber is no longer Active. With the reporter held across generations the same test fails at the generation count, one resolution instead of two, so it pins the reload and not only the restore.

The boundary for a Session that is already open is unchanged, and the claim that nothing else owns the copy is gone. Reloading this row disposes the old copy, so its tree is closed, and the reporter resolved under it reports into a fiber that is gone; the new copy applies with a new tree. The Session handle keeps the disposed tree (SessionInner in crates/dim-agent-runtime/src/agent.rs), so its facade addresses the closed copy's lines rather than the new tree's. A restore that is in flight when the row reloads keeps running on the disposed tree: its progress reports are dropped, so a restore that still runs when that copy closes fails with AgentError::Closed("TimelineTree"), whose message names the tree rather than the phase, and only a restore that stays silent past the opening's bound times out with the message this PR fixes, initialization timed out: no pending row in this wait; still running: restore. No product entry restarts this row: RunningServer::restart accepts only the names in RESTARTABLE (Rpc, Connection, Transport, Agents, Mcp), plugin.reload refuses built-in plugins and reloads only that plugin's own row, and no other production code calls the loader's row restart or a fiber restart. This PR therefore does not change that behaviour; an entry that reloads this row later has to move the open Session to the new tree first.

The plugins page and the PR body list both generation tests, the restore-generation one and the row-reload one.

Fixed in 51eb213.

@yyhhyyyyyy
yyhhyyyyyy requested a review from eric8810 November 22, 2026 23:26

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

The three commits since the head I approved at 2920490d answer the question I could not settle from the code at that time, and they answer it with a test rather than a sentence. My note was that reporter: OnceLock<Option<OpeningReporter>> resolves the plugin id once for the life of the tree, so a row reload that outlived the tree would leave every later report naming a dead fiber and the restore would time out again with the same silent message. The identity hook now records the fiber ids a Session's trees resolved instead of counting them, and a_row_reload_resolves_the_new_tree_reporting_identity asserts the reloaded tree resolves its own fiber "not the disposed copy's", with each_tree_generation_resolves_its_own_reporting_identity covering the same property across generations. That turns my suspicion into a stated invariant with an assertion behind it, which is the outcome I wanted.

The other two commits keep the change honest in the same spirit: dropping the row reload test's own one-second opening bound because every wait is already wrapped in settled removes a limit that served no assertion, which is the ablation the conventions ask for.

Blocking: none.

Checks are green at this head. I read the delta against 2920490d — the hook, the doc lines, the commit messages and the two test names — and relied on the reading recorded at the previous head for the rest; I did not read the 179 lines of new tests line by line, and ran nothing.

Non-blocking: none.

@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 follow-up leaves production restore progress and timeout behavior unchanged. The registry disposes the old tree before the replacement is created, and the new regression test exercises row reload and verifies that the replacement resolves the new reporter identity. The exact merge passed Linux, including the reload and slow-restore cases, as well as the selected macOS, static, and dependency checks: https://github.com/arcships/dim/actions/runs/45083214362.

… bound

`a_restore_resolves_its_reporting_identity_once` and `each_tree_generation_resolves_its_own_reporting_identity` assert identity counts and plugin ids, not time, so the one-second opening bound they passed served no assertion and was a new limit. They now open under the Session's default bound, with their assertions and the bounds of the two tests that measure the restore's inactivity unchanged.
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

Fixed in a4b7ec4: the two tests that count reporting-identity resolutions assert no duration, so their one-second opening bound served no assertion. They open under the Session's default bound now, and their assertions are unchanged.

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

The single commit since the head I approved at 51eb213b touches only storage_flow.rs (10/7), and the substance I approved there stands: each restore step reports after it finishes, OpeningReporter resolves the plugin id once per task so a restore costs one diagnostics snapshot rather than one per step, OpeningAdvanced stays pub(crate), and the reload case I raised is now pinned by a test asserting the reloaded tree resolves its own fiber rather than the disposed copy's.

verify (linux) and ci-ok failed on this head, in a suite this PR cannot reach:

Node bindings: session_typescript::node_session_typescript_tools_methods_and_generation_lifetimes
94 passed; 1 failed

That is the public Node bindings generation-lifetime test, not restore progress and not this branch's file. Not approving while a required check is red.

Non-blocking: none — I have nothing to add to a change I already read twice, and inventing a point to fill the section would waste the author's time.

Verification: not run. I re-read the delta against 51eb213b (one test file) and the failing test's name; the rest of the review is the reading recorded at the earlier heads.

…imeout

# Conflicts:
#	crates/dim-agent-runtime/src/assembly.rs
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

Merged main into the branch at head 9dd9066. The only conflict was in crates/dim-agent-runtime/src/assembly.rs, against #1997: main now attributes a per-call opening report to the context's instance without a diagnostics snapshot, while this branch added OpeningReporter so a multi-step restore resolves its identity once, and the merge keeps both (opening_advanced reports by instance as on main, OpeningReporter::report emits the plugin id it resolved).

The process assembly timeout message main gained in #2039, including its limit on the rows it lists, merged without a conflict and is unchanged.

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

Approving now that the checks are green, citing my review at 51eb213b. The head moved by merging origin/main: I listed the 65 commits since that head and every one of them is another PR's commit or a merge — none changes this branch's own files. The own-file diffs the comparison shows (timeline_tree.rs, assembly.rs, storage_flow.rs) come from main's side of the merge, not from the author.

That review found no blocking issue. The restore now reports after each finished step so the opening's inactivity bound follows real work instead of silence; OpeningReporter resolves the plugin id once per task so a restore costs one diagnostics snapshot rather than one per step; OpeningAdvanced stays pub(crate) while the reporter is the public surface; and the reload case is pinned by tests asserting each tree generation resolves its own fiber rather than the disposed copy's.

When I reviewed it, verify (linux) was red on session_typescript::node_session_typescript_tools_methods_and_generation_lifetimes; it is green at this head.

Verification: not run. This approval rests on the reading recorded at 51eb213b, the confirmation that no author commit follows it, and the current green checks.

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

Reviewed 9dd9066. The assembly merge preserves snapshot-free instance attribution and credits cached restore progress only to the watched subtree. The pending-row diagnostic and restore-phase fallback are unchanged. Exact CI checked out this head merged with current main: all five restore regressions, sibling progress isolation and pending-row rollback passed on Linux; macOS native and the gate passed. Windows CLI and macOS packaging were skipped.

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.

A Session restore that stays silent past the opening bound fails without naming anything

3 participants