Skip to content

feat(core): make a background subagent's activity live, and show it - #689

Merged
mohitranka merged 1 commit into
mainfrom
feat/subagent-live-activity
Sep 15, 2026
Merged

mohitranka merged 1 commit into
mainfrom
feat/subagent-live-activity

Conversation

@mohitranka

Copy link
Copy Markdown
Contributor

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_message was meant to answer "what is this agent doing", 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 entire run internally. During the window the field exists to describe, it was None. Rendering it would have added a line nobody could ever see.

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 watch its own run. run_user_message now delegates to it unchanged.
  • ActivityProbe drains that stream on a thread — StreamEventTx is a std::sync::mpsc sender, and std receivers cannot be awaited — accumulating assistant text as it arrives and writing running bash… on a ToolCallStart, because what the model asked for is more useful than the prose it wrote.
  • A done flag plus a receive timeout keeps finish bounded, 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 -- --check and cargo clippy --workspace --all-targets --locked -- -D warnings clean.
  • New tests: the probe follows text and tool calls; tail truncation; activity collapses to one line; the request outranks the activity; a row with nothing to report reserves no line; height counts 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_failure fails on this machine with the turn parked in Waiting instead of Completed. It never touches a subagent, and its only session call goes through run_user_message, which is byte-identical before and after this change (it now delegates with None). Its own comment notes that a HITL pause parks the turn in Waiting, 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.

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.
@mohitranka
mohitranka merged commit bd9d12d into main Sep 15, 2026
3 checks passed
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