[Bug]: Unsupported attachment (e.g. HEIC) permanently wedges the turn in "working" with a dead stop button #4200
Closeddmstoykov(GitHub profile, opens in a new tab)wants to merge 8 commits into
main fromrefs/pull/4200/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/CursorAdapter.ts line 966Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -943,20 +942 @@943- if (steeringTurnId === undefined) {944- ctx.lastPlanFingerprint = undefined;945- }946- ctx.session = {947- ...ctx.session,948- activeTurnId: turnId,949- updatedAt: yield* nowIso,950- };951-952- if (steeringTurnId === undefined) {953- yield* offerRuntimeEvent({954- type: "turn.started",955- ...(yield* makeEventStamp()),956- provider: PROVIDER,957- threadId: input.threadId,958- turnId,959- payload: { model: resolvedModel },960- });961- }962-942+ // Validate/build the prompt content BEFORE any turn-state
- apps/server/src/provider/Layers/CursorAdapter.ts line 940OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -919,3 +919,10 @@919919 // resolving from here on does not settle the turn; the matching920920 // decrement is the `ensuring` below.921921 ctx.promptsInFlight += 1;922+ // Reserve the turn id in the same synchronous step as the counter923+ // that gates steering. A concurrent sendTurn arriving while this one924+ // awaits session configuration or attachment I/O must observe this925+ // turn id and steer into it; otherwise it mints a second turn id and926+ // emits a second turn.started, leaving one of the two turns unsettled927+ // (only the last prompt to resolve emits turn.completed).928+ ctx.activeTurnId = turnId;
- apps/server/src/provider/Layers/CursorAdapter.ts line 991OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1004,3 +988,4 @@1004988 });1005989 }1006990991+ ctx.activeTurnId = turnId;
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/Layers/CursorAdapter.ts line 1141Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1056,0 +1096,21 @@1096+ // turn instead of steering into a dead one.1097+ ctx.activeTurnId = undefined;1098+ return;1099+ }1100+ if (!ctx.activeTurnSettled) {1101+ // This prompt failed after another prompt of the merged turn1102+ // resolved while both were still counted, so neither settled1103+ // it on the way out. Settle here with the last known result —1104+ // an announced turn that never completes wedges the UI.1105+ ctx.activeTurnSettled = true;1106+ yield* offerRuntimeEvent({1107+ type: "turn.completed",1108+ ...(yield* makeEventStamp()),1109+ provider: PROVIDER,1110+ threadId: input.threadId,1111+ turnId,1112+ payload: {1113+ state: ctx.activeTurnLastStopReason === "cancelled" ? "cancelled" : "completed",1114+ stopReason: ctx.activeTurnLastStopReason ?? null,1115+ },1116+ });
- apps/server/src/provider/Layers/CursorAdapter.ts line 1105OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1053,4 +1087,19 @@10531087 Effect.ensuring(1054- Effect.sync(() => {1088+ Effect.gen(function* () {10551089 ctx.promptsInFlight = Math.max(0, ctx.promptsInFlight - 1);1056- }),1090+ if (ctx.promptsInFlight > 0 || ctx.activeTurnId !== turnId) {1091+ return;1092+ }1093+ if (!ctx.activeTurnStarted) {1094+ // The reservation never announced a turn (every prompt failed1095+ // preparation); drop it so the next sendTurn opens a fresh1096+ // turn instead of steering into a dead one.1097+ ctx.activeTurnId = undefined;1098+ return;1099+ }1100+ // Settle only when some prompt of the merged turn actually1101+ // resolved (a stop reason was recorded). If every prompt failed,1102+ // emitting turn.completed here would report the failed turn as1103+ // successful and race the caller's turn-start failure recovery,1104+ // masking the real error.1105+ if (!ctx.activeTurnSettled && ctx.activeTurnLastStopReason !== undefined) {
- apps/server/src/provider/Layers/CursorAdapter.ts line 1108OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1055,2 +1089,20 @@1089+ Effect.gen(function* () {10551090 ctx.promptsInFlight = Math.max(0, ctx.promptsInFlight - 1);1056- }),1091+ if (ctx.promptsInFlight > 0 || ctx.activeTurnId !== turnId) {1092+ return;1093+ }1094+ if (!ctx.activeTurnStarted) {1095+ // The reservation never announced a turn (every prompt failed1096+ // preparation); drop it so the next sendTurn opens a fresh1097+ // turn instead of steering into a dead one.1098+ ctx.activeTurnId = undefined;1099+ return;1100+ }1101+ if (ctx.activeTurnSettled) {1102+ return;1103+ }1104+ // An interrupted drain (session teardown) is not a turn1105+ // outcome; leave settling to the session lifecycle events.1106+ if (Exit.isFailure(exit) && Cause.hasInterruptsOnly(exit.cause)) {1107+ return;1108+ }
- @@ -1056,0 +1124,21 @@1124+ ctx.activeTurnSettled = true;1125+ const failureMessage = Exit.isFailure(exit) ? Cause.squash(exit.cause) : undefined;1126+ const errorMessage =1127+ failureMessage instanceof Error && failureMessage.message.trim().length > 01128+ ? failureMessage.message.trim()1129+ : "Cursor turn failed before any prompt resolved.";1130+ yield* offerRuntimeEvent({1131+ type: "turn.completed",1132+ ...(yield* makeEventStamp()),1133+ provider: PROVIDER,1134+ threadId: input.threadId,1135+ turnId,1136+ payload: {1137+ state: "failed",1138+ stopReason: null,1139+ errorMessage,1140+ },1141+ });1142+ return;1143+ }1144+ ctx.activeTurnSettled = true;
juliusmarminge 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
Run ID:
5c613fe2-dc84-49a2-b6be-da0b133359d3You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.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.
❤️ Share