fix(grok): stop Working after 10 minutes of silence #7215
Closedgb1095(GitHub profile, opens in a new tab)wants to merge 1 commit into
main fromrefs/pull/7215/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/provider/Layers/GrokAdapter.ts lines 380 to 386OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -296,0 +366,21 @@366+ });367+368+ const hasActiveTurnWork = (ctx: GrokSessionContext) =>369+ ctx.activeToolCallIds.size > 0 ||370+ ctx.pendingApprovals.size > 0 ||371+ ctx.pendingUserInputs.size > 0;372+373+ const signalSessionTurnLiveness = (threadId: ThreadId, turnId: TurnId | undefined) => {374+ const ctx = sessions.get(threadId);375+ return ctx && turnId !== undefined ? signalTurnLiveness(ctx, turnId) : Effect.void;376+ };377+378+ const resumeSessionTurnLiveness = (threadId: ThreadId, turnId: TurnId | undefined) => {379+ const ctx = sessions.get(threadId);380+ if (381+ !ctx ||382+ turnId === undefined ||383+ ctx.livenessTurnId !== turnId ||384+ ctx.lastTurnActivityAtMillis === undefined385+ ) {386+ return Effect.void;
- apps/server/src/provider/Layers/GrokAdapter.ts line 634Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -432,3 +533,18 @@432533 }433534 });434535536+ const isLiveTurn = (ctx: GrokSessionContext, turnId: TurnId) =>537+ ctx.promptsInFlight > 0 &&538+ ctx.activeTurnId === turnId &&539+ ctx.session.activeTurnId === turnId &&540+ (ctx.session.status === "running" || ctx.session.status === "connecting");541+542+ const settleStalledTurn = (ctx: GrokSessionContext, turnId: TurnId) =>543+ withThreadLock(544+ ctx.threadId,545+ Effect.gen(function* () {546+ const liveCtx = sessions.get(ctx.threadId);547+ if (548+ liveCtx !== ctx ||549+ ctx.stopped ||550+ !isLiveTurn(ctx, turnId) ||apps/server/src/provider/Layers/GrokAdapter.ts line 560OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -434,0 +540,21 @@540+ (ctx.session.status === "running" || ctx.session.status === "connecting");541+542+ const settleStalledTurn = (ctx: GrokSessionContext, turnId: TurnId) =>543+ withThreadLock(544+ ctx.threadId,545+ Effect.gen(function* () {546+ const liveCtx = sessions.get(ctx.threadId);547+ if (548+ liveCtx !== ctx ||549+ ctx.stopped ||550+ !isLiveTurn(ctx, turnId) ||551+ ctx.interruptedTurnIds.has(turnId) ||552+ hasActiveTurnWork(ctx)553+ ) {554+ return;555+ }556+ const lastActivityAtMillis = ctx.lastTurnActivityAtMillis;557+ if (lastActivityAtMillis === undefined) {558+ return;559+ }560+ const nowMillis = yield* Clock.currentTimeMillis;
- apps/server/src/provider/Layers/GrokAdapter.ts lines 360 to 369OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -296,0 +349,21 @@349+ AcpSessionRuntime.AcpSessionRuntimeEvent,350+ { _tag: "ToolCallUpdated" | "ContentDelta" }351+ >,352+ ) =>353+ Effect.gen(function* () {354+ if (ctx.livenessTurnId !== turnId) {355+ return;356+ }357+ if (event._tag === "ContentDelta" && event.text.length === 0) {358+ return;359+ }360+ if (event._tag === "ToolCallUpdated") {361+ if (event.toolCall.status === "completed" || event.toolCall.status === "failed") {362+ ctx.activeToolCallIds.delete(event.toolCall.toolCallId);363+ } else {364+ // A tool update without a terminal status is conservatively treated365+ // as active so a long-running tool cannot be mistaken for a stall.366+ ctx.activeToolCallIds.add(event.toolCall.toolCallId);367+ }368+ }369+ ctx.lastTurnActivityAtNanos = yield* Clock.currentTimeNanos;
- apps/server/src/provider/Layers/GrokAdapter.ts line 1100Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -807,3 +1068,5 @@8071068 ) {8081069 return;8091070 }1071+ if (1072+ event._tag === "AssistantItemStarted" ||
- apps/server/src/provider/Layers/GrokAdapter.ts line 1338Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1032,3 +1308,6 @@10321308 updatedAt: yield* nowIso,10331309 ...(displayModel ? { model: displayModel } : {}),10341310 };1311+ if (steeringTurnId === undefined) {1312+ yield* beginTurnLiveness(ctx, turnId);1313+ }apps/server/src/provider/Layers/GrokAdapter.ts line 699Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -434,0 +657,21 @@657+ function* (ctx: GrokSessionContext) {658+ while (true) {659+ if (ctx.stopped) {660+ return;661+ }662+ const turnId = ctx.livenessTurnId;663+ if (turnId === undefined || !isLiveTurn(ctx, turnId) || hasLivenessPause(ctx)) {664+ yield* Queue.take(ctx.livenessSignals);665+ continue;666+ }667+668+ const lastActivityAtNanos = ctx.lastTurnActivityAtNanos;669+ if (lastActivityAtNanos === undefined) {670+ yield* Queue.take(ctx.livenessSignals);671+ continue;672+ }673+ const nowNanos = yield* Clock.currentTimeNanos;674+ const remainingNanos = livenessTimeoutFor(ctx).nanos - (nowNanos - lastActivityAtNanos);675+ if (remainingNanos <= 0n) {676+ yield* settleStalledTurn(ctx, turnId);677+ continue;
- apps/server/src/provider/Layers/GrokAdapter.ts line 1338Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1032,3 +1313,8 @@10321313 updatedAt: yield* nowIso,10331314 ...(displayModel ? { model: displayModel } : {}),10341315 };1316+ if (steeringTurnId === undefined) {1317+ yield* beginTurnLiveness(ctx, turnId);1318+ } else {1319+ yield* resumeSessionTurnLiveness(input.threadId, turnId);1320+ }apps/server/src/provider/Layers/GrokAdapter.ts line 1107Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -807,3 +1079,11 @@8071079 ) {8081080 return;8091081 }1082+ if (1083+ event._tag === "AssistantItemStarted" ||1084+ event._tag === "AssistantItemCompleted" ||1085+ event._tag === "ToolCallUpdated" ||1086+ event._tag === "ContentDelta"1087+ ) {1088+ yield* recordTurnActivity(ctx, notificationTurnId, event);1089+ }
gb1095(GitHub profile, opens in a new tab) changed the title
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:
0b8fdbae-3b9b-414d-9f51-8addc2aed5baYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
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.
❤️ Share