fix(grok): a wait_all over several tasks no longer leaves finished subagents running #38257
main fromrefs/pull/38257/head·opened View on GitHubProblem#
A Grok thread can refuse every new message with "The target provider still has background work running. Wait for it to finish or stop it before retrying the handoff." Nothing is running in Grok, Stop does nothing because the thread is idle, and only a server restart clears it.
Seen on T3 Code v0.1.9 with Grok CLI 1.0.77. The root agent started a background shell and a background subagent, then called get_command_or_subagent_output with both ids. Grok sent _x.ai/task_completed for the shell and subagent_finished for the subagent, then answered the wait with TaskOutput.MultiResult (mode: "wait_all", both rows completed). Later, when the thread grew too long for its Grok session, every send failed with ContextHandoffBackgroundWorkError from ProviderTurnStartService, until the server restarted.
Change#
extractXAiBackgroundTaskCompletion did not read MultiResult. It fell back to the request's task_ids and gave all of them one status, which is "running" because there is no Result. The ACP adapter then put each id back in runningBackgroundTaskIds. The shell recovers through its task_completed tombstone. The subagent ended through subagent_finished, which does not touch that set, so its id stayed running and hasPendingBackgroundWork stayed true for the life of the session.
The extractor now returns one completion per MultiResult.results row. Each row gets its own status and output, through the same statusFromGetOutputTool / resultFromGetOutputTool rules a single Result uses. Requests without MultiResult behave as before.
Scope#
Fixes the stuck state reported in #21060. That issue was closed as not reproduced because no signed-in Grok CLI was available. Its closing comment notes that the unit-level case already returned running for both tasks on main. This PR is a focused version of the wait_all parsing part of the closed #21094. It leaves out that PR's continuation and will_wake changes.
Verification#
- New case
gives each task of a wait_all MultiResult its own status and outputinxaiAcpExtension.test.ts. The rows are a completed subagent (with<subagent_meta>noise), a failedcall-<uuid>-<n>shell, and a still-running shell. On main every row comes backrunning; with the fix each row keeps its own status and output. - Adapter-level replay, not committed: the frame sequence above, run through
makeGrokAdapterV2+makeAcpReplayRuntime. The frames are a background shell, a backgroundspawn_subagent,get_command_or_subagent_outputover both ids,_x.ai/task_completed,subagent_finished, theMultiResultupdate, thenend_turn. Afterturn.terminal:main: [proof] hasPendingBackgroundWork after turn terminal = true fix: [proof] hasPendingBackgroundWork after turn terminal = false vp test run packages/provider-grok/ apps/server/src/orchestration-v2/Adapters/GrokAdapterV2.test.ts apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts: 244 passed.vp run check:changed: format, lint, knip, typecheck (10 packages) and tests all pass.- Not checked: a live Grok session on this branch. The original incident was on a separate machine running v0.1.9.
Model and harness: Claude Opus 5.5 in Claude Code.
🤖 Generated with Claude Code
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
tanstack-source added labelsbug
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
Approvability#
Verdict: Approved at
681e436Macroscope's review found this PR approvable — Grok multi-task poll responses now update each task's status and output independently, allowing finished tasks to leave running-state tracking. The change reuses existing parsing and lifecycle handling without changing product defaults or issuing task-control commands.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Important
Review skipped#
Review was skipped as selected files did not have any reviewable changes.
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: bfd37b2
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
f986d599-6bed-4ba9-bb41-26ccc10f6657
Commits-
Reviewing files that changed from the base of the PR and between 681e436640b72723f7401857a4925943fc9bfbbb and 96d9945ac1d3c85e1742de271e22d20215974aa3.
You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
- Trigger review
No actionable comments were generated in the recent review.
Walkthrough
-
The Grok completion extractor now parses multi-result task output into per-task completions. Tests cover completed, failed, and running task results.
Changes: Grok multi-result task completion
Layer / File(s) Summary Parse multi-result task completions
packages/provider-grok/src/server/xaiAcpExtension.ts,packages/provider-grok/src/server/xaiAcpExtension.test.tsThe extractor handles MultiResultandmultiResultresults, skips entries without task IDs, and uses existing parsing logic to derive each task’s status and output. The test covers completed output without subagent metadata, an exit code of 2, and retained output for a running task.Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested reviewers:
juliusmarminge,t3dotgg
Merge Risk:
Minimal · previous review681e4-
This change makes a wait_all over several tasks report each task's own status and output, so finished subagents no longer stay marked as running. Existing single-result behavior is unchanged, and the new test covers the mixed-status case. Merge risk is minimal. Behavior against a live Grok session was not checked.
Pre-merge checks:
4-
Check name Status Explanation Title check The title names the main change: a wait_all over several tasks no longer leaves finished subagents running. The raw summary confirms the extractor now returns one completion per MultiResult row, which… Description check The description follows the template sections: Problem, Change, Scope, and Verification. The Problem section gives the symptom, expected behavior, and reproduction context. The Change section explains… Linked Issues check The only linked issue, #21094, is closed. Under the assessment rules it supplies background only, so no active directly linked targets remain and no linked-issue coding requirements apply. Issue#2106…Out of Scope Changes check The changes stay within the PR's stated scope. In packages/provider-grok/src/server/xaiAcpExtension.ts, extractXAiBackgroundTaskCompletion now reads per-row results from TaskOutput MultiResult / multi… Full details: Title check
-
Explanation
The title names the main change: a wait_all over several tasks no longer leaves finished subagents running. The raw summary confirms the extractor now returns one completion per MultiResult row, which matches the title. The title is a conventional commit with a scope and a plain-language description, and it is specific enough for a teammate scanning history. The title is 84 characters, which is slightly long but acceptable.
Full details: Description check
-
Explanation
The description follows the template sections: Problem, Change, Scope, and Verification. The Problem section gives the symptom, expected behavior, and reproduction context. The Change section explains the root cause and the fix. The Scope section links the related issues and explains the exclusions. The Verification section lists the focused test, the adapter-level replay with before and after results, the test command outcomes, and what was not checked. It also names the model and harness, as the template asks. The template's conventional-commit guidance is satisfied by the title. The description is thorough and complete.
Full details: Linked Issues check
-
Explanation
The only linked issue,
#21094, is closed. Under the assessment rules it supplies background only, so no active directly linked targets remain and no linked-issue coding requirements apply. Issue#21060is cited in the PR description and in the linked issue text, but it is not an active linked target in this assessment. The PR does not need to meet#21094's acceptance criteria, including its continuation and will_wake work, which the PR explicitly excludes.
Full details: Out of Scope Changes check
-
Explanation
The changes stay within the PR's stated scope. In packages/provider-grok/src/server/xaiAcpExtension.ts, extractXAiBackgroundTaskCompletion now reads per-row results from TaskOutput MultiResult / multiResult objects and applies the existing single-result status and output parsing to each row. This directly addresses the wait_all mis-parsing described in the PR. The new test in xaiAcpExtension.test.ts covers that same parsing path. Both changes are the focused fix the PR describes. The reported adapter-level replay is uncommitted and does not add repository changes. The summary shows no unrelated files or unrelated behavior changes. Scope conclusion is based on the whole-PR summary; no source hunks were inspected beyond it.
-
Finishing Touches
-
Generate unit tests (beta)
-
- 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: main
- File: .coderabbit.config.ts
- Commit: 4d0e2f5
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
54819ca8-a352-427a-bcdb-7e7dd11ab958
Commits-
Reviewing files that changed from the base of the PR and between 4d0e2f52d25a7cf663068b2d6f12c290d1a4f40f and 681e436640b72723f7401857a4925943fc9bfbbb.
Files selected for processing: 2-
packages/provider-grok/src/server/xaiAcpExtension.test.tspackages/provider-grok/src/server/xaiAcpExtension.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
-
-
juliusmarminge added labelstakeover:in-progress
Live verification with a signed-in Grok CLI (1.0.77,
grok-4.7-build-fast), web client on a local dev server. Base is this PR's head (96d9945ac1) withxaiAcpExtension.tsreverted toorigin/main. Fix is the head as is. Each run used a fresh T3 home and a fresh thread.Steps: one Grok turn asking it to run
sleep 15 && echo SHELL_DONEin the background, spawn one background subagent, then callget_command_or_subagent_outputonce with both ids. After the turn ends, switch the thread toReplay (dev)and send a message. A provider switch runs the same background-work check as the context-handoff path in #21060.On both runs Grok's session log has
BackgroundTaskStarted,task_completed,subagent_finished, and thenTaskOutput.MultiResult(wait_all, "2/2 tasks completed", both rowscompletedwith exit code 0). Grok's lastbackground_tasksreport lists no running task.Base: every send is refused with "The previous provider is still running background agents or commands, and switching would end them. Wait for them to finish, or press Stop, then send the message again." The thread is idle, so no Stop button is shown. Four separate sends over about two minutes were all refused (
Orchestrator.tsprovider-switch guard).
Fix: the same sequence, then the switch goes through. The context handoff completes (4.7 Fast → Showcase) and the turn runs.

This patch parses
wait_allresults from the retired Grok ACP task-output extension. #46363 retired that integration in favor of Grok Build through the Cursor SDK, so this is no longer needed.juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes