fix(runtime): discover subagent files created after watch attaches - #65
Merged
Conversation
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
Subagents (e.g. Claude Code Task/Explore agents) sometimes never appear in
agtrace watch, even thoughagtrace session showdisplays them correctly.Root cause analysis
Analyzed against a real session where an Explore agent was launched mid-session. Claude Code writes the subagent transcript to
{log_root}/{session_id}/subagents/agent-{id}.jsonl(withisSidechain: trueand the parentsessionIdin the header) after the Task tool call. All the data needed for parsing and spawn-linking is present in the logs.The gap was in
SessionStreamer(agtrace-runtime):session_fileswas a fixed snapshot captured at attach time;handle_fs_eventignored any path not in that list. A subagent file created afterwatchattaches therefore never entered the stream, so the watch TUI never received its child-stream sessions.EventKind::Modifywas handled, so file creation events were dropped as well.This explains the "sometimes" symptom: subagents that already existed before attach were picked up by the initial scan, while any subagent spawned during watching was invisible.
Fix
StreamContextnow owns the session file set and grows it dynamically: on a Create/Modify event for an unknown path, the file is adopted ifdiscovery.probe()matches and its headersession_idequals the watched session.EventKind::Createis now handled alongsideModify.Testing
streamer_subagent.rsreproduces the exact scenario (attach first, createsubagents/agent-*.jsonlafterwards) and asserts aStreamId::Sidechainsession reaches the stream. It fails onmain(timeout) and passes with this fix.mise run verifypasses.session showrenders the sidechain stream with correct spawn context (spawned by Turn #2, Step #2), and console watch attaches and streams live.Known limitation (out of scope)
WorkspaceSupervisorstill intentionally skips sidechain files when emittingSessionUpdated(to avoid session switching), so sidechain-only activity does not bump a session's liveness for auto-attach. The attached-session streaming path — the reported symptom — is fully fixed here.🤖 Generated with Claude Code