Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): emit terminal task rows for subagents that survive a stop sweep #7585

Closedspiky02plateau(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/7585/headopened View on GitHub

Interrupting 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 refused stopTask still yields a terminal stopped row after interrupt; a nested task keeps its owning-agent linkage on the settled row; stopSession emits terminal rows before session.exited.
  • tsgo --noEmit: no errors.
  • vp lint on 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.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 287aa51cebbc173b6862c48449a289e558951751. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Emit terminal task rows for subagents that survive a stop sweep in interruptTurn and stopSession

  • Introduces settleLiveTasks in ClaudeAdapter.ts, which drains liveTaskIds and emits a synthesized task.completed event with status 'stopped' for each remaining live task.
  • interruptTurn now calls settleLiveTasks after attempting stopTask and invoking query.interrupt, guaranteeing terminal task rows even when individual stopTask calls reject or time out.
  • stopSessionInternal calls settleLiveTasks before completing the turn, ensuring task rows are emitted with the current turnId before session.exited.
  • Adds tests covering: stopTask rejection, nested task termination with agent linkage preserved, and correct ordering of task events before session.exited.
Macroscope summarized 287aa51.
    1. Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: 658869f1-a1c9-44a4-a078-104f2a465540

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      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
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. 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).
    4. 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.

Sign in to join this conversation.