fix(server): emit terminal task rows for subagents that survive a stop sweep #7585
main fromrefs/pull/7585/head·opened View on GitHubInterrupting a turn can leave a spawned subagent's row in the agents panel showing "running" forever: blue dot, duration counting up against the wall clock for the life of the thread. Observed with a nested agent (spawned from inside another subagent), but any task whose stop confirmation goes missing gets stranded the same way.
The interrupt path stops live tasks best-effort: stopTask per task with a 3s timeout, and only an acknowledged stop got a synthesized terminal task.completed. Every failure mode (refusal, timeout, the id already gone) returned silently, and nothing downstream can recover: completeTurn and stopSessionInternal never sweep liveTaskIds, the client's coordinator cascade only reaches workflow members keyed by parentAgentId (which nested agents never carry), and the client's dead-session sweep only fires when the session disconnects, which a turn interrupt does not cause.
I checked whether the SDK offers a roster to reconcile against, since a comment in the adapter called the background_tasks control request "the reconciliation source". It is not: per the installed SDK's types, Query.backgroundTasks backgrounds in-flight tasks (the Ctrl+B equivalent) and returns a boolean; BackgroundTaskSummary[] only appears on stop-hook inputs. There is no on-demand liveness query.
So the fix makes T3's own bookkeeping honest. A shared settleLiveTasks drains liveTaskIds and emits one synthesized task.completed { status: "stopped" } with the task's linkage per remaining id. The interrupt path's stop loop collapses to a pure best-effort sweep (same 3s/10s bounds), then interrupt(), then settle: once the interrupt lands the turn is dead and T3 has no remaining liveness signal for anything still marked live. stopSessionInternal settles before completeTurn (rows keep their turnId) and before session.exited, where it is unambiguous since the session process is going away. A turn that ends normally still leaves backgrounded tasks live on purpose. The stale comment now says what background_tasks actually does.
Left alone, for scope: the client's uncapped 1s duration interval (any future row missing its terminal event still counts up), and the client cascades that cannot reach nested agents. With the server now settling, those are defense-in-depth concerns.
Verification#
In apps/server:
vp test run src/provider/Layers/ClaudeAdapter.test.ts: 73 passed (73). Three new tests: a refusedstopTaskstill yields a terminal stopped row after interrupt; a nested task keeps its owning-agent linkage on the settled row;stopSessionemits terminal rows beforesession.exited.tsgo --noEmit: no errors.vp linton both files: one pre-existing warning elsewhere in the file, nothing new.vp fmt --check: clean.
Change made by Claude Opus via Claude Code.
Note
Medium Risk Changes interrupt and session teardown paths in the Claude adapter; incorrect settlement could misreport agent state, but scope is bounded to live-task bookkeeping and is covered by new tests.
Overview
Fixes agent panel rows that stay running forever after Stop when the Claude SDK never confirms subagent shutdown (refused stopTask, timeout, or missing task_notification).
settleLiveTasks drains liveTaskIds and emits synthesized task.completed with status: "stopped" and existing task linkage. interruptTurn still best-efforts stopTask (same timeouts), then interrupt(), then always settles remaining live tasks instead of only synthesizing completion when stopTask succeeded. stopSessionInternal settles live tasks before completeTurn and session.exited.
Comments on background_tasks_changed are corrected: the SDK control is not a roster query. Tests cover refused stopTask, nested agentId on settled rows, and shutdown event ordering.
Note
Emit terminal task rows for subagents that survive a stop sweep in interruptTurn and stopSession#
- Introduces
settleLiveTasksin ClaudeAdapter.ts, which drainsliveTaskIdsand emits a synthesizedtask.completedevent with status'stopped'for each remaining live task. interruptTurnnow callssettleLiveTasksafter attemptingstopTaskand invokingquery.interrupt, guaranteeing terminal task rows even when individualstopTaskcalls reject or time out.stopSessionInternalcallssettleLiveTasksbefore completing the turn, ensuring task rows are emitted with the currentturnIdbeforesession.exited.- Adds tests covering:
stopTaskrejection, nested task termination with agent linkage preserved, and correct ordering of task events beforesession.exited.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — This bug fix modifies runtime event emission behavior in the ClaudeAdapter's task cleanup paths. While the change is well-scoped and well-tested, it affects core session lifecycle logic in a file the author hasn't previously contributed to, warranting human review.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Note
🤖 GPT-5.6 Sol responding on behalf of Theo
We're closing this PR as we clean up the T3 Code backlog. Thank you for taking the time to put this together.
Current main already contains the terminal-task-row behavior for subagents that survive a stop sweep. This branch has no distinct repair left to review.
If you believe we closed this in error, please reopen the PR and leave a comment explaining what we missed.
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
658869f1-a1c9-44a4-a078-104f2a465540You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share