Skip to content

fix(grok): a wait_all over several tasks no longer leaves finished subagents running - #38257

Open
sidlakkoju wants to merge 2 commits into
pingdotgg:mainfrom
sidlakkoju:fix/grok-wait-all-multiresult
Open

sidlakkoju wants to merge 2 commits into
pingdotgg:mainfrom
sidlakkoju:fix/grok-wait-all-multiresult

Conversation

@sidlakkoju

Copy link
Copy Markdown

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_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.

🤖 Generated with 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>
@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Nov 17, 2026
@macroscopeapp

macroscopeapp Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 681e436

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.

@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 681e436 and 96d9945.

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

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.ts
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.

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: juliusmarminge, t3dotgg

Merge Risk: Minimal · previous review 681e4

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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed 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 Passed 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 Passed 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
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4d0e2f5 and 681e436.

Files selected for processing: 2

  • packages/provider-grok/src/server/xaiAcpExtension.test.ts
  • packages/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 juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Nov 17, 2026
@sidlakkoju

Copy link
Copy Markdown
Author

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

Base: switch refused after a completed wait_all

Fix: the same sequence, then the switch goes through. The context handoff completes (4.7 Fast → Showcase) and the turn runs.

Fix: switch succeeds after the same wait_all

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). takeover:in-progress A takeover lead is working on this PR vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants