fix(runtime): keep subagent mirror turns balanced across eviction and late items - #328
Merged
Merged
Conversation
… late items Mirror sessions for provider-native subagents synthesize their turn boundaries, and the open/closed decision was read from the resident mirror's timeline. Once the mirror was evicted (or its timeline was still loading) every rerouted child item appended another turn_started and no turn_completed could ever follow, so mirrors kept a stale working dot and their event logs held dozens of open turns. A child item arriving after the Subagent item had completed reopened the mirror for good, and the parent's own turn end did not close its mirrors. Track the synthetic turn state on AppState so it survives eviction, wrap a late child item in its own start/complete pair, and close every mirror when the parent turn completes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Observed in a live run with real Codex native subagents after #324. Mirror session event logs held e.g. 11
turn_startedand 0turn_completed(37 vs 5 across eight mirrors) and the sidebar kept a blue working dot on those mirrors after everything had finished.Three defects in
crates/runtime/src/app/subagents.rs:sync_mirror_turndecided open/closed from the resident mirror'stimeline.turn_running. Once the mirror was evicted (or its timeline still loading),resident()isNone, so every rerouted child item appended a newTurnStartedand aTurnCompletedcould never be emitted.TurnCompleteddid not close its mirrors; onlySessionCloseddid.Fix
Track the synthetic turn state in a small
AppStatemap that survives eviction; a late child item gets its own start/item/complete sequence so it still renders inside a turn; the parent'sTurnCompletednow runs the mirror cleanup. Mirror creation no longer pre-setsturn_in_flight.Tests
Five new runtime tests (written first, three failed before the fix): resident, evicted, async metadata reload, late item, and parent-turn-end variants, all asserting exactly one start/completion pair in the persisted log and a non-working final status.
cargo fmt --all --check,cargo clippy --workspace --all-targets -- -D warnings,cargo build,cargo test --workspacepass locally.