Repository navigation
perf(runtime): avoid scanning diagnostics for opening progress - #1997
Conversation
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
Review: perf(runtime): avoid scanning diagnostics for opening progress
Verdict: APPROVE
I reviewed the full main...head diff at 9b9d93f against How Dim uses rutis A3, single-tree assembly, and the rutis 0.23.0 identity, diagnostics and event code. The removed diagnostics call is off the report path, so the performance claim is plausible; I did not rerun xtask measure. The opening contract is preserved.
Correctness
- Identity is the same key on both sides.
Ctx::instance()returns the fiber'sInstanceId(rutis-0.23.0/src/ctx.rs:1203-1205), andRuntimeDiagnosticspublishes that samefiber.instance(rutis-0.23.0/src/ctx.rs:1345-1346).InstanceIdis process unique and never reused (rutis-0.23.0/src/key.rs:10-38), so the string key cannot alias a different row. - Membership is still resolved before the instance lookup.
by_instancefilters snapshot rows tomembersby plugin id and only then matchesplugin.instance(crates/dim-agent-runtime/src/assembly.rs:155-161), andsubtreestill walks the snapshot's parent links (crates/dim-agent-runtime/src/assembly.rs:2275-2293). A report from a sibling, another Session, a row outside the roots, or a row that left the snapshot before the deadline is ignored, as before. The old code also failed to count a removed row becausememberscame from the same deadline snapshot. - Nested and required-part rows stay covered. The required-part mount path is
ctx.plugin(crates/dim-agent-runtime/src/assembly.rs:1976-1979), which records the mounting fiber as parent, and nested loader instances attach the same way, so a live descendant resolves throughsubtree. I also ran an uncommitted nested probe (parentapplymounts a reporting child,wait_activeon the parent with a 150 ms interval while the child works for 360 ms) and it passed, which confirms the child's instance report renews the parent's opening. - Dispatch and receipt reports keep their plugin id.
TimelineContextemitsOpeningAdvanced::Plugin(inner.view.id)during Loading (crates/dim-agent-runtime/src/timeline_context.rs:187-193) and receipt completion emitsOpeningAdvanced::Plugin(scope)with the branch view id (crates/dim-agent-runtime/src/config.rs:382-385). The branch opening's roots are exactly that view id (crates/dim-agent-runtime/src/timeline_context.rs:117), so those reports still match. The enum variants are distinct, so a plugin id cannot be read as an instance id. - Deadline behavior is preserved. First activation still renews once through the
HashMap::entrycheck (crates/dim-agent-runtime/src/assembly.rs:80-95), a second activation after a row restart still does not renew by itself, a report from outside the subtree still does not renew, and a missing row or an ended future still produces the same timeout. The newcancellation_tokengate tightens rather than loosens this: a cancelled generation reports nothing, which matches A3's "Restarting the same row does not renew it". - Cancellation and rollback error retention are untouched: the guard is before the emit only, and no future, receipt or error path changed.
Notes, not blocking
crates/dim-agent-runtime/src/assembly.rs:45-46: the///contract still describes only the no-live-fiber case, but the new gate also suppresses reports from a live fiber whose generation was cancelled (rollback, restart, reload). That is the more common case and worth stating so callers do not expect a report to renew a failing opening.crates/dim-agent-runtime/tests/opening_progress.rs:39-45: the new sibling case covers root-level filtering, and the first test covers the instance path for a directly registered root plugin. The production callerInputQueuerecovery runs under a branch, and theSlowAssemblyRowfixture intransport_flowdoes callopening_advancedfrom a required row, but that test uses the default 10 s startup interval and asserts the note counter, not renewal of a shorter interval. No committed test callsopening_advancedfrom a nested row while a shorter interval is running, and the base flows cited in the PR body do not call it, so they do not cover the new identity mapping. A nested variant of this test would pin it, as noted above.
Verification
cargo test --locked -p dim-agent-runtime --test agent_runtime_flow: 33 passed, including bothopening_progresstests andlifecycle_review.cargo clippy --locked -p dim-agent-runtime --all-targets -- -D warnings: clean.cargo fmt --all -- --check: clean.nested_instances_preserve_optional_rows_and_cleanup_across_create_restore_and_failureinintegration_flow: passed on the head, so the nested-instance create, restore and rollback path still works.- All builds and tests used an isolated HOME, TMPDIR and XDG directories with
CARGO_TARGET_DIRunder the review data directory; no product home was touched and no processes were left running.
Merge and CI
The head is a descendant of the given origin/main (e4d981b) and git merge-tree --write-tree origin/main HEAD is clean. Open PR #1905 also touches assembly.rs and still merges cleanly at tree level; #1911 is already conflicting with main independently of this change. At review time the PR is MERGEABLE with verify (linux) still running and macos-native passing; the other jobs were skipped by path filters. I did not wait for CI.
| if let Some(id) = id { | ||
| let _ = ctx.emit(OpeningAdvanced(id)); | ||
| if !ctx.cancellation_token().is_cancelled() { | ||
| let _ = ctx.emit(OpeningAdvanced::Instance(ctx.instance().to_string())); |
There was a problem hiding this comment.
The new cancellation_token().is_cancelled() guard is a caller-visible behavior change that the /// above does not state. A live fiber whose generation was cancelled (rollback, restart, reload) still appears in diagnostics, so before this change its opening_advanced call emitted and could renew an inactivity interval; now it reports nothing. I agree with the guard because it matches A3's "Restarting the same row does not renew it", and the no-live-fiber sentence above remains true because a destroyed fiber yields a pre-cancelled token. The missing case is the cancelled generation. Failure scenario: a caller keeps reporting during teardown, when the row is still live, and now silently loses those reports with no hint in the contract that cancellation gates them. Fix: extend the sentence to say that a context whose generation was cancelled reports nothing. Not blocking.
| gap: Duration::from_millis(60), | ||
| reports, | ||
| }); | ||
| if !reports { |
There was a problem hiding this comment.
The new sibling case covers filtering for a root-level sibling, and opened(true) covers the instance path for a directly registered root plugin. No committed test calls opening_advanced from a mounted or loader-created nested row while a shorter inactivity interval is running. The SlowAssemblyRow fixture in the_startup_note_reports_assembly_progress_until_the_server_opens does call it from a required row, but that test uses the default 10 s startup interval and asserts the note counter, not renewal of a shorter interval; InputQueue recovery under a branch is the production caller, and the rows whose identity this change resolves through snapshot.plugins are nested. The base tests cited in the PR body (nested_instances_preserve_optional_rows_and_cleanup_across_create_restore_and_failure, a_row_cancelled_while_its_child_waits_ends_the_wait) do not call opening_advanced, so they do not cover this path. Failure scenario: a regression that resolves the instance key incorrectly for loader-created rows would make an opening whose only progress comes from such a row time out after one interval, and no test would fail. Fix: add a nested variant of this test, for example a parent apply that mounts a reporting child and calls wait_active on the parent with a 150 ms interval while the child works for 360 ms. I ran that variant locally and it passes. Not blocking.
eric8810
left a comment
There was a problem hiding this comment.
Reviewed at head 9b9d93f.
The change removes a real cost from a hot path for a stated reason: an opening progress report was building a full diagnostics snapshot just to learn its own plugin id, and the assembly path now reports identity directly and resolves subtree membership at the deadline check it already takes. if !ctx.cancellation_token().is_cancelled() guarding the emit is the right pairing — a cancelled assembly should not renew anyone's opening. Widening active to the identity enum and opening the deadline read over members keeps the "one snapshot, one read" shape.
Blocking: none from the change's own design.
verify (linux) and ci-ok failed on this head, in three places, none of which this PR's files reach:
managed_oauth_flow::managed_provider_selection_http_recovery_and_restart_flow
agents::sessions::tests::exists_answers_loaded_unloaded_closed_and_deleted
goal_product_flow::goal_evaluator_judge_creates_an_evaluator_and_completes_on_done
125 passed; 1 failed (and two more suites)
Those three are timeout-shaped, and two of them (managed_oauth_flow, goal_product_flow) have failed on unrelated heads in this same window, so I am not reading them as a regression here. Not approving while a required check is red.
Non-blocking:
crates/dim-agent-runtime/src/assembly.rs—OpeningAdvancedis#[serde(untagged)]overPlugin(PluginId)andInstance(String). If both serialize as strings, a deserialize can only ever producePlugin, so anInstanceidentity silently becomes a plugin id on any round trip. The enum distinguishes two identity spaces in memory and loses that distinction on the wire; if the event never crosses a wire the untagged marker and the visitor cost both earn nothing, and if it does, the variant that was added cannot survive the trip.
Verification: not run — I read the four changed files' diffs and three of the failing test names; I did not read the new opening_progress.rs bodies or the rutis CtxHost side.
…ing-progress-scan
`BranchLifecycle::opening_budget` (a service-skip) and `BranchLifecycle::admit_opening_with` (a Rust-only method) come from main (#1997/#2198 era, `fbd65fa82` and `b802a3f7d`), not from this branch; they are in the allowlist now so the check can run against the merged tree. Entries: 171 -> 173, both from main. Refs #2015 Refs #2127
`BranchLifecycle::opening_budget` (a service-skip) and `BranchLifecycle::admit_opening_with` (a Rust-only method) come from main (#1997/#2198 era, `fbd65fa82` and `b802a3f7d`), not from this branch; they are in the allowlist now so the check can run against the merged tree. Entries: 171 -> 173, both from main. Refs #2015 Refs #2127
Summary
On current main, a progress report from InputQueue recovery builds a full rutis diagnostics snapshot to find the reporting fiber. The native sample during the 1,000-Session run showed
InputQueue::rebuild → opening_advanced → CtxHost::diagnosticson the creation hot path. The loader's live row query already uses subtree indexes in the published 0.23.0 release adopted by Dim. rutis #1312 · Dim #1941Report the context's instance identity directly and resolve its subtree membership when the inactivity deadline is checked, using the diagnostics snapshot that check already takes. Dispatch and receipt reports that already know the branch group keep using its plugin ID. The existing live member reads continue to cover nested instances created during required-part startup. Startup progress contract · Assembly lifecycle
Fixes #594
Verification
Apple M4, Rust 1.100.0, locked release build with thin LTO, two Tokio workers, mock model, in-memory Sessions and an isolated
DIMCODE_HOME. Compared maine4d981bd2with9b9d93f36usingxtask measure. Each batch keeps its Sessions and main branches live until after the query probe. The probe measures the last Session and its main branch with 100 warm-up calls and 1,000 timed calls per scope.The 1-Session batch includes first-use initialization. Each timed query returned three Session-subtree rows or one main-branch row. At 1,000 Sessions the PR meets the 20 ms creation target, and Agent shutdown returned to zero live Tokio tasks. Target in #367
agent_runtime_flow'sopening_progressandlifecycle_reviewgroups. They cover genuine progress past the deadline, sibling progress isolation, required-row failure, cancellation and rollback error retention.git diff --check. The temporary query probe stays outside the commit.Design rule checklist
before, batch, context and facts. N/A because the notification is on the rutis bus and the change never writes the Timeline.Documentation