fix(grok): Complete turns from xAI prompt completion#3156
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Needs human review 1 blocking correctness issue found. This PR introduces a new fallback mechanism for completing Grok turns with complex async state management. Unresolved review comments identify potential race conditions where You can customize Macroscope's approvability policy. Learn more. |
59e347f to
7ac3370
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 59e347f. Configure here.
7ac3370 to
4ffdde1
Compare
4ffdde1 to
1b2c893
Compare

Summary
session/promptstranded.runningonly while prompts are actually in flight, then clearactiveTurnIdon completion.Problem and Fix
This is a narrow bridge fix for the current Grok Composer 2.5 Fast hang while the sturdier ACP/orchestrator work in #2829 continues.
_x.ai/session/prompt_completeand return the session to idle while the standardsession/promptRPC remains stranded. T3 Code waits forsession/promptbefore emittingturn.completed, so the composer can stay stuck on Stop even though the turn is done._x.ai/session/prompt_complete, synthesizing the normal ACPPromptResponseshape when the xAI notification wins.activeTurnIdafter the prompt settled. Consumers reading adapter session state could still see the session as active.runningwhile prompt work is active and restorereadywhile clearingactiveTurnIdwhen the final prompt in the turn settles.AcpSessionRuntimeandGrokAdapterlevels.Defensive Fixes
session/promptresponse.Validation
vp test apps/server/src/provider/Layers/GrokAdapter.test.ts apps/server/src/provider/acp/AcpJsonRpcConnection.test.ts packages/effect-acp/src/client.test.tsvp run typecheckvp checkNote
Fix Grok turn completion by resolving prompts from xAI
_x.ai/session/prompt_completenotificationsAcpSessionRuntimenow races the standardsession/promptRPC against a fallback Deferred resolved by_x.ai/session/prompt_completenotifications, handling the case where Grok emits its own completion signal but never settles the RPC.prompt_completenotifications (for already-completed prompts) are tracked and ignored using a bounded list of completed prompt IDs.GrokAdaptermarks sessions asrunningat prompt start and transitions back toreadyonly when the last in-flight prompt for the active turn settles, including on error or RPC hang.Macroscope summarized 1b2c893.
Note
Medium Risk
Changes Grok turn completion and session lifecycle in the provider stack; behavior is narrow and heavily regression-tested but affects when
turn.completedfires and adapter session snapshots update.Overview
Fixes Grok turns that finish on the wire but never unblock the UI because
session/promptnever returns.AcpSessionRuntimenow races each prompt against Grok’s_x.ai/session/prompt_completenotification, building a normalPromptResponsewhen the xAI signal wins first. Already-finishedpromptIdvalues are remembered so late duplicate completions are ignored.GrokAdaptersets sessions torunningwhile prompts are in flight and returns them toready(clearingactiveTurnIdand emittingturn.completed) only when the last prompt for the active turn settles, including on RPC failure viasettlePromptInFlight.The ACP mock agent gains env-driven modes (prompt-complete-then-hang, stale completion, forced prompt failure), with coverage in
AcpJsonRpcConnection,GrokAdapter, andeffect-acpclient batching tests.Reviewed by Cursor Bugbot for commit 1b2c893. Bugbot is set up for automated code reviews on this repo. Configure here.