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 This PR adds significant new logic for handling Grok/xAI prompt completion as a fallback when the standard RPC hangs, including race conditions between RPC and notification-based completion. The changes affect core session lifecycle and turn settlement behavior, warranting human review despite good test coverage. You can customize Macroscope's approvability policy. Learn more. |
59e347f to
7ac3370
Compare
1b2c893 to
3c38b27
Compare
2037ac6 to
3859afb
Compare
b6f559c to
17d881a
Compare
17d881a to
ba54adf
Compare
ba54adf to
a2aaf61
Compare
a2aaf61 to
2a9ced0
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high 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 2a9ced0. Configure here.
Address Bugbot review: prefer streaming turn for late notification chunks
2a9ced0 to
1ce246d
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_x.ai/session/prompt_completenotification, resolving whichever arrives first.GrokAdaptergains astreamingTurnIdfield so late session-update chunks can still be attributed to a turn afteractiveTurnIdis cleared, and a newsettlePromptInFlighthelper centralizes session-state transitions and failedturn.completedemission.runningat turn start and back toreadywhen the last in-flight prompt settles, rather than only on RPC completion.Macroscope summarized 1ce246d.
Note
Medium Risk
Changes core Grok turn completion and session state in the provider stack; behavior is narrower and well-tested but affects when
turn.completedfires and UI readiness.Overview
Fixes Grok composer sessions that stay stuck on Stop when Grok finishes on the wire but the standard
session/promptRPC never returns.ACP runtime registers a per-session fallback before each prompt and races the normal
session/promptcall against_x.ai/session/prompt_complete, synthesizing a normalPromptResponsewhen the xAI notification wins. Already-completedpromptIds are ignored so stale completions cannot unblock a later prompt.Grok adapter keeps sessions
runningonly while prompts are in flight, usesstreamingTurnIdso trailingsession/updatechunks still attach after the turn settles, andsettlePromptInFlightrestoresready, clearsactiveTurnId, and emitsturn.completed(including failed turns when the prompt RPC errors).Mock agent modes and tests cover hang-after-complete, stale notifications, session lifecycle, and Grok extension notifications batched before the standard prompt response.
Reviewed by Cursor Bugbot for commit 2a9ced0. Bugbot is set up for automated code reviews on this repo. Configure here.