Drive Claude subagent mirror lifecycle from the Subagent item, not the parent turn - #443
Merged
Merged
Conversation
…e parent turn Background Agent tasks outlive the parent turn, so closing every mirror on the parent's TurnCompleted (and treating the async_launched tool_result as completion) left mirrors showing not-running and turned every later child item into a zero-length synthetic turn. - Runtime: mirror turn opens while the Subagent item is InProgress, closes on its terminal status; SessionClosed interrupts still-running mirrors. - Agent: async_launched keeps the item InProgress until task_notification; terminal snapshots wait for the transcript tail's final flush; PreferPath no longer replays a discovered transcript; stdout/tail child items are deduped. Co-Authored-By: Claude <noreply@anthropic.com>
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
Claude Code background Agent tasks outlive the parent turn. tcode closed every native-subagent mirror on the parent's
TurnCompleted, and also treated theasync_launchedtool_result as the subagent's completion. Result: the mirror never showed running, and every later child transcript item became its own zero-length synthetic turn (a wall of1:42 PM · 0sfooters).Fix
Mirror lifecycle is owned by the Subagent item's own status end to end.
InProgress, closes on its terminal status. ParentTurnCompletedno longer touches mirrors.SessionClosedmarks still-running mirrorsInterrupted. Per-item open+close hack removed; stragglers fold into the last turn.async_launchedtool_result keeps the itemInProgressuntiltask_notification(parent row now spins until the agent really finishes and shows the real summary). Terminal Subagent snapshots are held until the transcript tail acks Stop after its final read, so child items always precede the terminal update.PreferPathonly seeds a reader when discovery found nothing (no replay from byte 0). Child items from the stdoutparent_tool_use_idfeed and the tail feed are deduped.subagent_background_trace.jsonl.Tests
native_mirror_turn_lifecycle_outlives_parent_turn,..._session_closed_interrupts,..._late_item(fail on main, pass here)background_subagent_terminal_waits_for_tail_flush_and_dedupes_feeds,subagent_tail_prefer_path_does_not_replay_a_discovered_transcriptcargo clippy --workspace --all-targets -D warningsclean;cargo test -p agent -p tcode-runtimegreen.Not verified: a live GUI run against a real background Agent.
Co-Authored-By: Claude noreply@anthropic.com