fix(pi): async subagents leave Running when their run settles first #39888
main fromrefs/pull/39888/head·merged by juliusmarminge View on GitHubWhen 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.
| Before | After |
|---|---|
| 2713570406 | 8f3cdc6d37 |
![]() | ![]() |
| Before inspection recording | After 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.tswith the fix: 172 passedvp 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
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XS
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.tsupdateAsyncRunchecks 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:
bugfixSuggested reviewers:
stienswout,maria-rcks,macroscopeapp
Merge Risk:
Minimal · up to8f3cd-
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:
4-
Check name Status Explanation Title check 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 co… Linked Issues check [ #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 check 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 packa… Description check 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, … 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-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: factory/issue-39871
- File: .coderabbit.config.ts
- Commit: 8f3cdc6
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Team
- Run ID:
0eea1729-447e-4a7c-85c5-8f068ea27a83
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.tspackages/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.
-
-
juliusmarminge merged thisc53ac23
juliusmarminge closed this
Sign in to join this conversation.


Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Other scenarios#
All 64 scenario measurements match
main.All 64 scenario measurements
short turn resumeWebSocket decodedshort turn resumeWebSocket messageslong turn running, cold openHTTP decodedlong turn running, cold openrowslong turn running, history pageHTTP decodedlong turn running, history pagerowslong turn finished, cold openHTTP decodedlong turn finished, cold openrowslong turn finished, socket cold openWebSocket decodedlong turn finished, socket cold openWebSocket messageslong turn finished, socket cold openrowslong turn finished, work pageHTTP decodedlong turn finished, work pagerowsidle thread resumeWebSocket decodedidle thread resumeWebSocket messagesfleet shell snapshotHTTP decodedfleet shell snapshotrowsfleet shell subscribeWebSocket decodedfleet shell subscribeWebSocket messagesfleet shell resume checkHTTP decodedfleet shell resume checkrowsstale shell reloadHTTP decodedstale shell reloadrowsstale shell resumeWebSocket decodedstale shell resumeWebSocket messagesstale todo list cold openHTTP decodedstale todo list cold openrowsstale todo list cold opennodesstale todo list cold opensubagentsstale todo list cold openplansstale todo list cold openproviderTurnsstale todo list cold opencheckpointsshort turn resumeWebSocket decodedshort turn resumeWebSocket messageslong turn running, cold openHTTP decodedlong turn running, cold openrowslong turn running, history pageHTTP decodedlong turn running, history pagerowslong turn finished, cold openHTTP decodedlong turn finished, cold openrowslong turn finished, socket cold openWebSocket decodedlong turn finished, socket cold openWebSocket messageslong turn finished, socket cold openrowslong turn finished, work pageHTTP decodedlong turn finished, work pagerowsidle thread resumeWebSocket decodedidle thread resumeWebSocket messagesfleet shell snapshotHTTP decodedfleet shell snapshotrowsfleet shell subscribeWebSocket decodedfleet shell subscribeWebSocket messagesfleet shell resume checkHTTP decodedfleet shell resume checkrowsstale shell reloadHTTP decodedstale shell reloadrowsstale shell resumeWebSocket decodedstale shell resumeWebSocket messagesstale todo list cold openHTTP decodedstale todo list cold openrowsstale todo list cold opennodesstale todo list cold opensubagentsstale todo list cold openplansstale todo list cold openproviderTurnsstale todo list cold opencheckpointsBaseline:
6f5293f· PR result:8f3cdc6· Source CI: successScenario 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.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.