Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(pi): async subagents leave Running when their run settles first #39888

Mergedjuliusmarmingemerged 2 commits intomain fromrefs/pull/39888/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

When a Pi async subagent run finished, pi-subagents often reported the run as finished one update before its last member. T3 stopped tracking the run at that point and never recorded the member's final state, so the subagent stayed Running and the thread kept waiting on it. The Pi adapter now keeps tracking a finished run until all of its step members have settled too.

Fixes pingdotgg/t3code#39871

Reproduction on main

Commit 2713570406 (origin/main). Dev server run with T3CODE_DEV_SEED=0 on a fresh database, Pi 1.6.0 with pi-subagents 0.89.1 installed into a separate PI_CODING_AGENT_DIR, Pi provider added in Settings > Providers. In a Pi thread (Claude Haiku 4.5) I asked the agent to launch 6 separate async subagent runs (delegate agent, async: true, one tool call each) and end its turn. Batch 1: in Pi all 6 runs ended 'failed' at about the same moment (the hub rejected the subagents' model); orchestration_v2_projection_subagents showed 5 failed and 1 still 'running' (last update about 3 s after launch). Batch 2 (real sleeps, runs finishing at different times): all 6 completed in T3. Batch 3 (same as batch 1, with the Pi binary wrapped to save its RPC stdout): Pi's status.json said 'failed' for all 6 and T3 left all 6 at 'running'. The saved subagent-async widget snapshots show that for every run, the run state turned 'failed' one snapshot before its step:0 child did (e.g. ('f8a348c4','failed',['running']) then ('f8a348c4','failed',['failed'])), all before the coordinator's agent_end. So Pi sent the final state and T3 dropped it. The test on factory/repro-39871 (adapter.test.ts, 'shows the members of an async pi-subagents workflow as running subagents', plus a snapshot with the run failed and one member still running) fails on main: actual statuses ['failed'], expected ['completed','failed'].

Evidence

Real web app, Chromium 1280×800, light theme; separate fresh databases, Pi 1.6.0 and pi-subagents 0.89.1. Launch six separate native async delegate runs, end the coordinator turn, let all children fail through the hub, then expand their rows.

BeforeAfter
27135704068f3cdc6d37
Before recording frame: two Running rows and Waiting on 2 subagentsAfter recording frame: all six rows Failed and no waiting banner
Before inspection recordingAfter inspection recording

Driver, identical prompt. Sanitized RPC transitions: before, after. Persisted T3 rows: before, after.

Both RPC extracts contain the targeted run-failed/member-running transition followed by member-failed. Base retained two Running rows; head recorded all six Failed. Videos and extracted frames were visually inspected.

Not shown:

  • Successful child completion was not exercised; this proof covers the simultaneous failure path from triage.
  • The recordings cover final-state inspection, not the launch interaction; launches were performed through the uploaded CLI driver and corroborated by recorded Pi RPC transitions.

Tests

  • vp test run src/server/adapter.test.ts -t "async pi-subagents workflow" without the fix: 1 failed (the repro)
  • vp test run src/server/adapter.test.ts with the fix: 172 passed
  • vp run check:changed: format, lint, knip, typecheck (9 packages), tests (2 files, 174 passed) all pass
  • PR CI on 8f3cdc6: all 38 checks passed

Not in this change

  • If pi-subagents never sends a final state for a child, the run stays tracked and the background work stays pending until restart; that was already the case for runs whose own state never settled.
  • A run state of 'paused' (waiting) still counts as settled for the run itself, as before.

Who did the work

  • Written by Claude Opus 5.5, in Claude Code
  • Reviewed by GPT-6.1 Sol, in Codex, and by Claude Opus 5.5, each on its own
  • Proof captured by GPT-6.1 Sol and checked by Claude Opus 5.5

Run by the t3code factory in T3 Code.

    1. tanstack-source added labelsbug

    2. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      CodexLive turn WebSocket decoded21.5 KiB21.5 KiB0 B (0.0%)24.4 KiB✅
      CodexLive turn messages110 (0.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.9 KiB21.9 KiB0 B (0.0%)24.4 KiB✅
      ClaudeLive turn messages110 (0.0%)8✅

      Other scenarios

      All 64 scenario measurements match main.

      All 64 scenario measurements
      ProviderScenarioMetricMain baselineThis PRImpactPR ceiling
      Codexshort turn resumeWebSocket decoded10.5 KiB10.5 KiB0 B (0.0%)12.7 KiB✅
      Codexshort turn resumeWebSocket messages220 (0.0%)2✅
      Codexlong turn running, cold openHTTP decoded281.7 KiB281.7 KiB0 B (0.0%)302.7 KiB✅
      Codexlong turn running, cold openrows75750 (0.0%)75✅
      Codexlong turn running, history pageHTTP decoded92.4 KiB92.4 KiB0 B (0.0%)107.4 KiB✅
      Codexlong turn running, history pagerows75750 (0.0%)75✅
      Codexlong turn finished, cold openHTTP decoded381.5 KiB381.5 KiB0 B (0.0%)410.2 KiB✅
      Codexlong turn finished, cold openrows1511510 (0.0%)151✅
      Codexlong turn finished, socket cold openWebSocket decoded381.6 KiB381.6 KiB0 B (0.0%)410.2 KiB✅
      Codexlong turn finished, socket cold openWebSocket messages220 (0.0%)2✅
      Codexlong turn finished, socket cold openrows1511510 (0.0%)151✅
      Codexlong turn finished, work pageHTTP decoded186.2 KiB186.2 KiB0 B (0.0%)200.2 KiB✅
      Codexlong turn finished, work pagerows1501500 (0.0%)150✅
      Codexidle thread resumeWebSocket decoded65 B65 B0 B (0.0%)200 B✅
      Codexidle thread resumeWebSocket messages110 (0.0%)1✅
      Codexfleet shell snapshotHTTP decoded42.4 KiB42.4 KiB0 B (0.0%)53.7 KiB✅
      Codexfleet shell snapshotrows27270 (0.0%)27✅
      Codexfleet shell subscribeWebSocket decoded65 B65 B0 B (0.0%)200 B✅
      Codexfleet shell subscribeWebSocket messages110 (0.0%)1✅
      Codexfleet shell resume checkHTTP decoded18 B18 B0 B (0.0%)100 B✅
      Codexfleet shell resume checkrows0000✅
      Codexstale shell reloadHTTP decoded42.4 KiB42.4 KiB0 B (0.0%)53.7 KiB✅
      Codexstale shell reloadrows27270 (0.0%)27✅
      Codexstale shell resumeWebSocket decoded140 B140 B0 B (0.0%)400 B✅
      Codexstale shell resumeWebSocket messages220 (0.0%)2✅
      Codexstale todo list cold openHTTP decoded72.4 KiB72.4 KiB0 B (0.0%)83.0 KiB✅
      Codexstale todo list cold openrows75750 (0.0%)75✅
      Codexstale todo list cold opennodes220 (0.0%)4✅
      Codexstale todo list cold opensubagents220 (0.0%)4✅
      Codexstale todo list cold openplans110 (0.0%)2✅
      Codexstale todo list cold openproviderTurns110 (0.0%)2✅
      Codexstale todo list cold opencheckpoints110 (0.0%)2✅
      Claudeshort turn resumeWebSocket decoded10.6 KiB10.6 KiB0 B (0.0%)12.7 KiB✅
      Claudeshort turn resumeWebSocket messages220 (0.0%)2✅
      Claudelong turn running, cold openHTTP decoded283.3 KiB283.3 KiB0 B (0.0%)302.7 KiB✅
      Claudelong turn running, cold openrows75750 (0.0%)75✅
      Claudelong turn running, history pageHTTP decoded93.4 KiB93.4 KiB0 B (0.0%)107.4 KiB✅
      Claudelong turn running, history pagerows75750 (0.0%)75✅
      Claudelong turn finished, cold openHTTP decoded384.2 KiB384.2 KiB0 B (0.0%)410.2 KiB✅
      Claudelong turn finished, cold openrows1511510 (0.0%)151✅
      Claudelong turn finished, socket cold openWebSocket decoded384.3 KiB384.3 KiB0 B (0.0%)410.2 KiB✅
      Claudelong turn finished, socket cold openWebSocket messages220 (0.0%)2✅
      Claudelong turn finished, socket cold openrows1511510 (0.0%)151✅
      Claudelong turn finished, work pageHTTP decoded188.1 KiB188.1 KiB0 B (0.0%)200.2 KiB✅
      Claudelong turn finished, work pagerows1501500 (0.0%)150✅
      Claudeidle thread resumeWebSocket decoded66 B66 B0 B (0.0%)200 B✅
      Claudeidle thread resumeWebSocket messages110 (0.0%)1✅
      Claudefleet shell snapshotHTTP decoded43.0 KiB43.0 KiB0 B (0.0%)53.7 KiB✅
      Claudefleet shell snapshotrows27270 (0.0%)27✅
      Claudefleet shell subscribeWebSocket decoded66 B66 B0 B (0.0%)200 B✅
      Claudefleet shell subscribeWebSocket messages110 (0.0%)1✅
      Claudefleet shell resume checkHTTP decoded18 B18 B0 B (0.0%)100 B✅
      Claudefleet shell resume checkrows0000✅
      Claudestale shell reloadHTTP decoded43.0 KiB43.0 KiB0 B (0.0%)53.7 KiB✅
      Claudestale shell reloadrows27270 (0.0%)27✅
      Claudestale shell resumeWebSocket decoded140 B140 B0 B (0.0%)400 B✅
      Claudestale shell resumeWebSocket messages220 (0.0%)2✅
      Claudestale todo list cold openHTTP decoded73.4 KiB73.4 KiB0 B (0.0%)83.0 KiB✅
      Claudestale todo list cold openrows75750 (0.0%)75✅
      Claudestale todo list cold opennodes220 (0.0%)4✅
      Claudestale todo list cold opensubagents220 (0.0%)4✅
      Claudestale todo list cold openplans110 (0.0%)2✅
      Claudestale todo list cold openproviderTurns110 (0.0%)2✅
      Claudestale todo list cold opencheckpoints110 (0.0%)2✅

      Baseline: 6f5293f · PR result: 8f3cdc6 · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 108.5 KiB
      • Claude decoded thread snapshot: 108.8 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Explain Change →

      No actionable comments were generated in the recent review.

      Walkthrough

      The Pi adapter now keeps an asynchronous run tracked after a terminal run status if a recognized step child is still running or pending. The test adds an intermediate failed snapshot with a running child before the later snapshot completes it.

      Changes: Async Pi subagent settlement

      Layer / File(s)Summary
      Child settlement tracking
      packages/provider-pi/src/server/adapter.ts, packages/provider-pi/src/server/adapter.test.ts
      updateAsyncRun checks whether recognized step children are settled. It retains the run and keeps background work pending while any child is running or pending. The test adds an intermediate failed snapshot with one running child.

      Estimated code review effort: 2 (Simple) | ~10 minutes

      Change: Bug fix · Severity of issue fixed: Medium

      Possibly related PRs

      • pingdotgg/t3code#23786: Changes Pi adapter tracking so detached children remain observable after the parent run fails.
      • pingdotgg/t3code#32079: Adds handling for async subagent widget snapshots and retains runs until they settle.

      Suggested labels: bugfix

      Suggested reviewers: stienswout, maria-rcks, macroscopeapp

      Merge Risk: Minimal · up to 8f3cd

      Async Pi subagents should no longer stay Running after their run finishes, because tracking continues until every step child settles. The remaining edge case, where pi-subagents never sends a child's final state, is stated in the PR and leaves work pending only until restart. Merge risk is minimal.

      Pre-merge checks: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title names the fix (async subagents leaving Running when their run settles first) and the affected package (pi). The changeset adds a settle check in the Pi adapter's updateAsyncRun and a test co…
      Linked Issues checkPassed[#39871] The issue requires async Pi subagents from the subagent-async widget path to leave Running in T3 after they finish in Pi. The PR changes updateAsyncRun in packages/provider-pi/src/server/adap…
      Out of Scope Changes checkPassedThe changes are limited to packages/provider-pi/src/server/adapter.ts (about +4 lines in updateAsyncRun, which adds child-settlement tracking that gates cleanup and the pending: false event) and packa…
      Description checkPassedThe description follows the repository template and covers the required sections. The Problem section explains the bug: a Pi async subagent run reported as finished one update before its last member, …
      Full details: Title check

      Explanation

      The title names the fix (async subagents leaving Running when their run settles first) and the affected package (pi). The changeset adds a settle check in the Pi adapter's updateAsyncRun and a test covering a failed run with a still-running member, so the title matches the main change. It is specific and conventional.

      Full details: Linked Issues check

      Explanation

      [#39871] The issue requires async Pi subagents from the subagent-async widget path to leave Running in T3 after they finish in Pi. The PR changes updateAsyncRun in packages/provider-pi/src/server/adapter.ts. It now tracks whether every recognized step child is settled. When the run status is terminal but a child is still running or pending, the run stays registered and background work stays pending. Cleanup and the pending: false event wait until all step children settle. This targets the failure mode in the PR's reproduction: the run became failed one snapshot before its step:0 child, and T3 dropped the child's final state. The test change adds an intermediate snapshot (run failed, one member running) and asserts the final member statuses. The PR reports that this test fails on main and passes with the fix (adapter.test.ts: 172 passed). The issue's root cause was unverified at filing. The PR's diagnosis is supported by saved snapshots, but the source evidence for the real-app before/after capture is still pending in the PR description. That capture is a non-coding verification item. The stated limit (no final child state from pi-subagents means the run stays pending until restart) is a known residual case, not a requirement of this issue's coding scope. The issue's secondary note about other background work waiting forever is not separately addressed. The PR description does not claim to address it, and the issue states no consistent trigger for it.

      Full details: Out of Scope Changes check

      Explanation

      The changes are limited to packages/provider-pi/src/server/adapter.ts (about +4 lines in updateAsyncRun, which adds child-settlement tracking that gates cleanup and the pending: false event) and packages/provider-pi/src/server/adapter.test.ts (+2 lines, an intermediate failed-run snapshot with one running member). Both directly implement the fix for the linked issue. No unrelated refactoring, dependency change, or unrelated behavior change is reported in the summary. The 'paused' run state behavior is unchanged, as the PR states. The summary does not show any change outside the Pi adapter's async run tracking.

      Full details: Description check

      Explanation

      The description follows the repository template and covers the required sections. The Problem section explains the bug: a Pi async subagent run reported as finished one update before its last member, so T3 stopped tracking it and the subagent stayed Running. The Change section explains the fix: the adapter keeps tracking a finished run until all step members settle. The Scope section links the issue (pingdotgg/t3code#39871) and describes a bug fix, not a feature. The Verification section gives focused test commands with results, a reproduction on main, before/after evidence, and a list of what was not shown. It also names the model and harness that did the work, as the template asks. Minor gaps: the Change section does not name the modified function (updateAsyncRun) or the adapter file, and the Scope section does not say whether a maintainer requested the PR. These gaps are not critical.

      Finishing Touches

      Generate unit tests (beta)

      • Commit to this branch
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Recent review info

      Run configuration

      Commits

      Reviewing files that changed from the base of the PR and between 6f5293fbdca476cddbc37466450983ba1dd2ada2 and 8f3cdc6d37de92471c29614ac5c217a93d45e218.

      Files selected for processing: 2

      • packages/provider-pi/src/server/adapter.test.ts
      • packages/provider-pi/src/server/adapter.ts

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

    4. juliusmarminge merged thisc53ac23

    5. juliusmarminge closed this

Sign in to join this conversation.