Skip to content

fix(runtime): discover subagent files created after watch attaches - #65

Merged
zawakin merged 1 commit into
mainfrom
feature/watch-live-subagent-discovery
Jul 13, 2026
Merged

fix(runtime): discover subagent files created after watch attaches#65
zawakin merged 1 commit into
mainfrom
feature/watch-live-subagent-discovery

Conversation

@zawakin

@zawakin zawakin commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Problem

Subagents (e.g. Claude Code Task/Explore agents) sometimes never appear in agtrace watch, even though agtrace session show displays 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 (with isSidechain: true and the parent sessionId in 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):

  1. session_files was a fixed snapshot captured at attach time; handle_fs_event ignored any path not in that list. A subagent file created after watch attaches therefore never entered the stream, so the watch TUI never received its child-stream sessions.
  2. Only EventKind::Modify was 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

  • StreamContext now owns the session file set and grows it dynamically: on a Create/Modify event for an unknown path, the file is adopted if discovery.probe() matches and its header session_id equals the watched session.
  • Files confirmed to belong to another session are negatively cached to avoid re-reading headers on every poll tick; unreadable/empty files are retried on later events.
  • EventKind::Create is now handled alongside Modify.

Testing

  • New integration test streamer_subagent.rs reproduces the exact scenario (attach first, create subagents/agent-*.jsonl afterwards) and asserts a StreamId::Sidechain session reaches the stream. It fails on main (timeout) and passes with this fix.
  • mise run verify passes.
  • Manually verified against the real session logs: session show renders 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)

WorkspaceSupervisor still intentionally skips sidechain files when emitting SessionUpdated (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

@zawakin zawakin self-assigned this Jul 13, 2026
@zawakin
zawakin merged commit 29796f7 into main Jul 13, 2026
8 checks passed
@zawakin
zawakin deleted the feature/watch-live-subagent-discovery branch July 13, 2026 06:45
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.

1 participant