fix(grok): interrupt mid-turn sends like Claude/Codex #8286
main fromrefs/pull/8286/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/server/src/provider/Layers/GrokAdapter.ts line 948OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -939,3 +941,8 @@939941 activeTurnId: turnId,940942 updatedAt: yield* nowIso,941943 };944+ if (steeringTurnId !== undefined) {945+ yield* settlePendingApprovalsAsCancelled(ctx.pendingApprovals);946+ yield* settlePendingUserInputsAsCancelled(ctx.pendingUserInputs);947+ yield* Effect.ignore(948+ ctx.acp.cancel.pipe(apps/server/src/provider/Layers/GrokAdapter.ts line 948OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -939,3 +941,8 @@939941 activeTurnId: turnId,940942 updatedAt: yield* nowIso,941943 };944+ if (steeringTurnId !== undefined) {945+ yield* settlePendingApprovalsAsCancelled(ctx.pendingApprovals);946+ yield* settlePendingUserInputsAsCancelled(ctx.pendingUserInputs);947+ yield* Effect.ignore(948+ ctx.acp.cancel.pipe(
- apps/server/src/provider/acp/XAiAcpExtension.ts lines 600 to 606OutdatedResolvedby mavenskylab(GitHub profile, opens in a new tab)@@ -367 +372,21 @@367372373+const settleXAiPromptCompletion = (374+ deferred: Deferred.Deferred<EffectAcpSchema.PromptResponse, EffectAcpErrors.AcpRequestError>,375+ notification: XAiPromptCompleteNotification,376+) => {377+ if (notification.stopReason === "rate_limit") {378+ return Deferred.fail(379+ deferred,380+ new EffectAcpErrors.AcpRequestError({381+ code: xAiRateLimitedErrorCode,382+ errorMessage: "Grok usage limit reached. Try again later.",383+ }),384+ ).pipe(Effect.asVoid);385+ }386+ if (notification.stopReason === "error") {387+ return Deferred.fail(388+ deferred,389+ EffectAcpErrors.AcpRequestError.internalError(390+ xAiAgentResultMessage(notification.agentResult) ?? "Grok prompt failed.",391+ ),392+ ).pipe(Effect.asVoid);apps/server/src/provider/acp/XAiAcpExtension.ts lines 603 to 604OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -365,3 +370,21 @@365370 }),366371 );367372373+const settleXAiPromptCompletion = (374+ deferred: Deferred.Deferred<EffectAcpSchema.PromptResponse, EffectAcpErrors.AcpRequestError>,375+ notification: XAiPromptCompleteNotification,376+) => {377+ if (notification.stopReason === "rate_limit") {378+ return Deferred.fail(379+ deferred,380+ new EffectAcpErrors.AcpRequestError({381+ code: xAiRateLimitedErrorCode,382+ errorMessage: "Grok usage limit reached. Try again later.",383+ }),384+ ).pipe(Effect.asVoid);385+ }386+ if (notification.stopReason === "error") {387+ return Deferred.fail(388+ deferred,389+ EffectAcpErrors.AcpRequestError.internalError(390+ xAiAgentResultMessage(notification.agentResult) ?? "Grok prompt failed.",
- apps/server/src/provider/Layers/GrokAdapter.ts line 954OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -939,3 +941,14 @@939941 activeTurnId: turnId,940942 updatedAt: yield* nowIso,941943 };944+ if (steeringTurnId !== undefined) {945+ yield* settlePendingApprovalsAsCancelled(ctx.pendingApprovals);946+ yield* settlePendingUserInputsAsCancelled(ctx.pendingUserInputs);947+ yield* Effect.ignore(948+ ctx.acp.cancel.pipe(949+ Effect.mapError((error) =>950+ mapAcpToAdapterError(PROVIDER, input.threadId, "session/cancel", error),951+ ),952+ ),953+ );954+ }
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/provider/acp/XAiAcpExtension.ts lines 603 to 605OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -367,0 +377,21 @@377+ if (notification.stopReason === "rate_limit") {378+ return Deferred.fail(379+ deferred,380+ new EffectAcpErrors.AcpRequestError({381+ code: xAiRateLimitedErrorCode,382+ errorMessage: "Grok usage limit reached. Try again later.",383+ }),384+ ).pipe(Effect.asVoid);385+ }386+ if (notification.stopReason === "error") {387+ return Deferred.fail(388+ deferred,389+ EffectAcpErrors.AcpRequestError.internalError(390+ "Grok prompt failed.",391+ notification.agentResult,392+ {393+ method: "session/prompt",394+ ...(notification.promptId !== undefined ? { requestId: notification.promptId } : {}),395+ cause: notification.agentResult,396+ },397+ ),
- apps/server/src/provider/acp/XAiAcpExtension.ts lines 594 to 597OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -359,9 +364,20 @@359364 }360365 return [361- Deferred.succeed(entry.deferred, promptResponseFromXAi(notification)).pipe(Effect.asVoid),366+ settleXAiPromptCompletion(entry.deferred, notification),362367 [...pending.slice(0, index), ...pending.slice(index + 1)],363368 ] as const;364369 }).pipe(Effect.flatten);365370 }),366371 );367372373+const settleXAiPromptCompletion = (374+ deferred: Deferred.Deferred<EffectAcpSchema.PromptResponse, EffectAcpErrors.AcpRequestError>,375+ notification: XAiPromptCompleteNotification,376+) => {377+ if (notification.stopReason === "rate_limit") {378+ return Deferred.fail(379+ deferred,380+ new EffectAcpErrors.AcpRequestError({381+ code: xAiRateLimitedErrorCode,382+ errorMessage: "Grok usage limit reached. Try again later.",383+ }),
mavenskylab(GitHub profile, opens in a new tab) changed the title
- apps/server/src/provider/Layers/GrokAdapter.ts line 1708OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1667,0 +1688,21 @@1688+ }1689+ if (prepared.steeringTurnId !== undefined) {1690+ yield* Effect.ignore(1691+ liveCtx.acp.cancel.pipe(1692+ Effect.mapError((error) =>1693+ mapAcpToAdapterError(PROVIDER, input.threadId, "session/cancel", error),1694+ ),1695+ ),1696+ );1697+ }1698+ if (liveCtx.interruptedTurnIds.has(prepared.turnId)) {1699+ yield* settlePromptInFlight(1700+ input.threadId,1701+ prepared.turnId,1702+ prepared.acpSessionId,1703+ {1704+ completedStopReason: "cancelled",1705+ settleAllPrompts: true,1706+ },1707+ );1708+ return Option.none();
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/server/src/provider/Layers/GrokAdapter.ts line 1492OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1466,12 +1476,17 @@14661476 input.threadId,14671477 Effect.gen(function* () {14681478 const ctx = yield* requireSession(input.threadId);1469- // A sendTurn while a prompt is in flight is a steer: the agent1470- // folds the new prompt into the ongoing work, so the active turn1471- // id is reused instead of opening a new turn.1479+ // A sendTurn while a prompt is in flight is a steer: reuse the1480+ // active turn and cancel the in-flight ACP prompt so Grok takes1481+ // the new instruction immediately, matching Claude/Codex, instead1482+ // of waiting behind serialized session/prompt.14721483 const steeringTurnId = ctx.promptsInFlight > 0 ? ctx.activeTurnId : undefined;14731484 const turnId = steeringTurnId ?? TurnId.make(yield* randomUUIDv4);14741485 // Count this prompt immediately so a superseded in-flight prompt14751486 // resolving from here on does not settle the turn; decremented on14761487 // preparation failure here, and after the prompt below otherwise.14771488 ctx.promptsInFlight += 1;1489+ ctx.promptEpoch += 1;1490+ const promptEpoch = ctx.promptEpoch;1491+ if (steeringTurnId !== undefined) {1492+ ctx.discardBeforeEpoch = promptEpoch;
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
c591ac84-be6f-412c-83d8-16939f31d732You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Comment `@coderabbitai help` to get the list of available commands.