You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(grok): a wait_all over several tasks no longer leaves finished subagents running - #38257
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 output in xaiAcpExtension.test.ts. The rows are a completed subagent (with <subagent_meta> noise), a failed call-<uuid>-<n> shell, and a still-running shell. On main every row comes back running; 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 background spawn_subagent, get_command_or_subagent_output over both ids, _x.ai/task_completed, subagent_finished, the MultiResult update, then end_turn. After turn.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.
…bagents running
Grok answers a get_command_or_subagent_output that waits on more than one
task with TaskOutput.MultiResult. The extractor ignored it and marked every
requested id running, so a subagent waited on alongside another task stayed
in the running background set until the server restarted, and the context
handoff guard refused every later send.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Macroscope'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.
The extractor handles MultiResult and multiResult results, 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.
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 #21060 is 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
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
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) with xaiAcpExtension.ts reverted to origin/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_DONE in the background, spawn one background subagent, then call get_command_or_subagent_output once with both ids. After the turn ends, switch the thread to Replay (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 then TaskOutput.MultiResult (wait_all, "2/2 tasks completed", both rows completed with exit code 0). Grok's last background_tasks report 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.ts provider-switch guard).
Fix: the same sequence, then the switch goes through. The context handoff completes (4.7 Fast → Showcase) and the turn runs.
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
size:M30-99 changed lines (additions + deletions).takeover:in-progressA takeover lead is working on this PRvouch:unvouchedAuthor is not yet trusted in the VOUCHED list.
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
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_outputwith both ids. Grok sent_x.ai/task_completedfor the shell andsubagent_finishedfor the subagent, then answered the wait withTaskOutput.MultiResult(mode: "wait_all", both rowscompleted). Later, when the thread grew too long for its Grok session, every send failed withContextHandoffBackgroundWorkErrorfromProviderTurnStartService, until the server restarted.Change
extractXAiBackgroundTaskCompletiondid not readMultiResult. It fell back to the request'stask_idsand gave all of them one status, which is"running"because there is noResult. The ACP adapter then put each id back inrunningBackgroundTaskIds. The shell recovers through itstask_completedtombstone. The subagent ended throughsubagent_finished, which does not touch that set, so its id stayed running andhasPendingBackgroundWorkstayedtruefor the life of the session.The extractor now returns one completion per
MultiResult.resultsrow. Each row gets its own status and output, through the samestatusFromGetOutputTool/resultFromGetOutputToolrules a singleResultuses. Requests withoutMultiResultbehave 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
runningfor both tasks on main. This PR is a focused version of thewait_allparsing part of the closed #21094. It leaves out that PR's continuation andwill_wakechanges.Verification
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.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: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.Model and harness: Claude Opus 5.5 in Claude Code.
🤖 Generated with Claude Code