fix(provider-acp): keep Grok's wake reply after another task was read in the turn #17793
main fromrefs/pull/17793/head·opened View on GitHubProblem#
When a Grok turn reads one background command and leaves another running, Grok's reply to the second command never shows up. The continuation run opens, but it has no answer in it.
isInTurnHandledAgentChatter in packages/provider-acp/src/server/adapter.ts treats every agent chunk as chatter once any task has been handled in the turn (handledBackgroundTaskIdsInActiveTurn.size > 0). The context.finalized branch of the session-update handler has the same check. Grok tags every frame of its own wake turn with task-completed-<task id>. A wake turn for a task the root turn never read is therefore dropped as chatter for a different task.
I found it while investigating #15888 on Grok 1.0.50. #17144 describes the same drop in its "Left out" section as a separate problem. No PR touches it.
Change#
- The Grok flavor exposes the task a wake turn answers:
providerWakeTaskId, read from thetask-completed-prompt id. - The chatter rule uses that id when a frame has one: the frame is chatter only if that task was handled in the turn.
- Frames that name no task keep the existing rule.
So the #4218 case is unchanged: Grok's acks after a monitor it already reported in the turn are still dropped.
Scope and approval#
I'm submitting this as a very small, focused fix for an obvious bug. The agent's reply to a finished background command disappears, and the cause is a single over-broad condition, used in two places. The fix is one flavor hook and that condition. It adds no new behavior, setting or workflow. Only Grok sets the hook, so other ACP flavors behave as before.
Verification#
- New replay fixture
grok_background_bash_wake_after_handled. It was recorded live from Grok CLI 1.0.50 withapps/server/scripts/record-grok-acp-replay-fixture.ts. Grok starts two background shells, reads the first withget_command_or_subagent_outputand repliesROOT_DONE. The second ends after the prompt settles, and Grok answers it intask-completed-<second task id>.- The live recording ran on unpatched
main. Its own assertion failed:Grok's reply to the second command must land in the continuation run: expected '' to include 'second done'. - Replayed on
main, it fails the same way. With this change it passes.
- The live recording ran on unpatched
- New adapter test in
AcpAdapterV2.test.ts,a provider wake turn is chatter only for the background task it names. It checks both halves of the rule:- wake frames naming the task handled in the turn open no continuation and leave no pending work;
- a wake reply naming an unread task stays as wake evidence.
- On
mainit fails witha wake reply for an unread task must stay as wake evidence: expected false to be true.
- New unit test for
xAiTaskCompletedWakeTaskId: UUID andcall-*task ids, other prompt ids, an empty suffix. - Commands:
vp test run apps/server/src/orchestration-v2/testkit/OrchestratorReplayFixtures.integration.test.ts -t grok: 17 passed, includinggrok_monitor,grok_background_bashandgrok_background_bash_fast_wake.vp test run apps/server/src/orchestration-v2/testkit/OrchestratorReplayFixtures.contract.test.ts: 2 passed.vp test run apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts: 116 passed.vp test run packages/provider-grok/src/server/xaiAcpExtension.test.ts: 58 passed.tsc --noEmitinpackages/provider-acp,packages/provider-grokandapps/server: clean.vp lintandvp fmt --checkon the touched files: no new findings.
Not verified#
- A patched desktop build against a live Grok session. Only the recorder ran live, on unpatched code.
- Grok frames where the wake prompt id and the handled task id use different spellings for the same task. In the recording they match. If they ever differ, this fix keeps the reply, so the worst case is an extra continuation run with an ack, not a lost answer.
- This does not address the held run itself (#15888, #17144).
Written with Claude Opus 5.5 in Claude Code.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
Approvability#
Verdict: Approved at
f23b819Macroscope's review found this PR approvable — This is a narrowly scoped Grok ACP bug fix that restores a lost background-task reply while preserving behavior for other providers and untagged frames. The production logic is small and covered by focused unit, adapter, and replay tests.
Notes:
- Diff unchanged. Approvability was decided on eligibility alone.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
a9740db7-caed-40e4-bcb3-b2434b0c3c69
📥 Commits
-
Reviewing files that changed from the base of the PR and between c77a7b7eebd6ea8a3a63bbcaaa7c1707fe65c86e and f23b8193830cfc4e72ba7052c915959ac034f779.
📒 Files selected for processing (9)
-
apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.tsapps/server/src/orchestration-v2/testkit/fixtures/grok_background_bash_wake_after_handled/grok_transcript.ndjsonapps/server/src/orchestration-v2/testkit/fixtures/grok_background_bash_wake_after_handled/input.tsapps/server/src/orchestration-v2/testkit/fixtures/grok_background_bash_wake_after_handled/output.tsapps/server/src/orchestration-v2/testkit/fixtures/index.tspackages/provider-acp/src/server/adapter.tspackages/provider-grok/src/server/adapter.tspackages/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.
-
📝 Walkthrough
-
Walkthrough#
The ACP adapter now uses provider wake task IDs to filter handled-task chatter. Grok extracts those IDs from task-completion prompt IDs. Tests cover task-specific filtering and a two-command Grok orchestration fixture.
Changes#
Provider wake task IDs
Layer / File(s) Summary Extract and provide Grok wake task IDs
packages/provider-grok/src/server/xaiAcpExtension.ts,packages/provider-grok/src/server/adapter.ts,packages/provider-grok/src/server/xaiAcpExtension.test.tsxAiTaskCompletedWakeTaskIdextracts a non-empty task ID from matching completion prompt IDs. The Grok flavor supplies this function to the ACP adapter. Tests cover matching and non-matching prompt IDs.ACP handled-chatter filtering
Layer / File(s) Summary Match handled chatter to the wake task
packages/provider-acp/src/server/adapter.tsThe adapter adds an optional wake-task ID callback. When a notification has a task ID, the shared predicate checks whether that task was handled in the active turn. Without an ID, it checks whether any task was handled. Filtering and orchestration tests
Layer / File(s) Summary Validate filtering and orchestration
apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts,apps/server/src/orchestration-v2/testkit/fixtures/grok_background_bash_wake_after_handled/*,apps/server/src/orchestration-v2/testkit/fixtures/index.tsThe adapter test checks that chatter for a handled task does not create a continuation or pending work, while chatter for an unread task remains pending. The Grok fixture models two background commands and checks their completed runs and output. Priority: ⬇️ Low
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix
Suggested reviewers:
juliusmarminge,t3dotgg
Merge Risk | ⚪ Minimal · up to
f23b8-
Merge Risk: ⚪ Minimal · up to
f23b8The wake-task filtering change is mergeable after normal checks; no material regression was established.
-
Security Architecture Review
-
Security architecture risk: 🔵 Low · up to
f23b8The change preserves replies for background tasks that were not already handled. No new privilege or cross-session access was identified, but mixed-task timing and recovery behavior are not fully verified.
Retained concerns No architecture-level concerns identified.
-
Security review details
-
Security Blast Radius
- inferred — The directly affected surface is provider-output retention and continuation bookkeeping for the active ACP session. The task suffix influences chatter classification, not a credential, tenant selector or permission decision. Cross-session wake routing remains separately gated.
Trust Boundaries and Controls
- observed — Task identity comes from provider-controlled notification metadata and is compared with handled-task state. That comparison is not authentication. Existing root-session checks, stopped-run quarantine and running-background-work gates remain in the buffering path.
Resilience and Maintainability Implications
- observed — Turn startup resets handled-task state and clears unowned wake residue while preserving an explicitly queued buffered continuation. Hard interruption invokes quarantine; rollback clears wake, continuation and task-tracking state. These unchanged controls limit stale-output inheritance, although they do not resolve every mixed-task timing case.
-
-
-
-
Pre-merge checks |
4-
✅ Passed checks (4 passed)
-
Check name Status Explanation Title check The title clearly and concisely describes the primary fix: preserving Grok's wake reply when another background task was already read. It uses a valid conventional commit format. Description check The description follows the required Problem, Change, Scope and approval, and Verification sections. It explains the bug, implementation, scope, test results, and unverified cases. It also justifies t… Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request.
-
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment `@coderabbitai help` to get the list of available commands.-
coderabbitai[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge added labelsmacroscope-review
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Note
Written by
gpt-6.1-solon behalf of MariaThanks for reproducing the lost Grok wake reply and tracing the task-specific chatter condition. At 629 changed lines across nine files, this unvouched submission exceeds what we can take over; right now we are only taking focused bug fixes from outside contributors within our review capacity, as explained in Read this first. Please preserve the lost-reply reproduction in #15888 and request maintainer agreement on a smaller adapter fix and essential regression coverage for reconsideration.
maria-rcks closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed