Repository navigation
feat(core): make a background subagent's activity live, and show it - #689
Merged
Merged
Conversation
The strip could say a subagent was running but not what it was doing. `latest_message` was supposed to answer that, and did not: `drive_subagent` wrote it at exactly three points — start, after a HITL resume, and end — and the one that looks live (after `run_agent_turns` returns) fires once the run is over, because that call drives the whole run internally. During the window the field exists to describe it was `None`, so rendering it would have drawn an empty line. The fix is one layer down. `run_user_message_with_stream` is the existing `run_user_message` with the sender it was hardcoding as `None`, so a subagent can now watch its own run. `ActivityProbe` drains that stream on a thread — `StreamEventTx` is a `std::sync::mpsc` sender, which cannot be awaited — accumulating assistant text as it arrives and writing `running bash…` on a tool call, since what the model asked for is more useful than the prose it wrote. A done flag plus a receive timeout keeps `finish` from blocking if a future change ever retains a sender past the call. The strip renders it as a second line on active subagent rows, in secondary text. A blocked row keeps the warning hue for its pending request, so the two never read alike; the request outranks the activity, and the states are mutually exclusive anyway. Fixes a bug this exposed: the widget advanced exactly one line per row, so a row's second line was drawn where the next row's first line goes and got overwritten. The blocked-request line has been invisible whenever another row followed it since #685; the tests only ever drew one-row strips. Height is now `BackgroundStrip::height`, which counts second lines and is what the renderer asks the layout for. Tests: the probe follows text and tool calls; tail truncation; activity collapses to one line; the request outranks it; a row with nothing to report reserves no line; height counts second lines; and the regression test that a second line survives the row below it.
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.
Follows the finding that the P5 "cheap slice" would have rendered an empty line. This makes the field it depends on actually live, then shows it.
Why the obvious version was not worth shipping
BackgroundTaskSnapshot.latest_messagewas meant to answer "what is this agent doing", and did not.drive_subagentwrote it at exactly three points — start, after a HITL resume, and end — and the one that looks live (afterrun_agent_turnsreturns) fires once the run is over, because that call drives the entire run internally. During the window the field exists to describe, it wasNone. Rendering it would have added a line nobody could ever see.The fix is one layer down
run_user_message_with_streamis the existingrun_user_messagewith the sender it was hardcoding asNone, so a subagent can watch its own run.run_user_messagenow delegates to it unchanged.ActivityProbedrains that stream on a thread —StreamEventTxis astd::sync::mpscsender, and std receivers cannot be awaited — accumulating assistant text as it arrives and writingrunning bash…on aToolCallStart, because what the model asked for is more useful than the prose it wrote.finishbounded, so a future change that retains a sender past the call cannot hang the agent loop.The strip side
Active subagent rows draw a second line with that activity in secondary text. A blocked row keeps the warning hue for its pending request, so the two never read alike. The request outranks the activity, and the two states are mutually exclusive anyway.
A bug this exposed
The widget advanced exactly one line per row, so a row's second line was drawn where the next row's first line goes and was overwritten by it. The blocked-request line from #685 has therefore been invisible whenever another row followed it — the existing tests only ever drew one-row strips, which is why they passed. Height is now
BackgroundStrip::height(), counting second lines, and that is what the renderer asks the layout for.Verification
cargo fmt --all -- --checkandcargo clippy --workspace --all-targets --locked -- -D warningsclean.heightcounts second lines; and a regression test that a second line survives the row below it.One local test failure to flag:
app::tests::chrome::completed_turn_renders_unfinished_checks_without_claiming_failurefails on this machine with the turn parked inWaitinginstead ofCompleted. It never touches a subagent, and its only session call goes throughrun_user_message, which is byte-identical before and after this change (it now delegates withNone). Its own comment notes that a HITL pause parks the turn inWaiting, which points at the host refusing to apply the tool sandbox — the same environment class as the other known-local failures. CI is the arbiter; I have not assumed it away.