Skip to content
Source
Sign inSign up
pingdotgg/t3code

[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 intomain fromrefs/pull/4200/headopened View on GitHub

What Changed

sendTurn now validates attachments and builds the user message before mutating any turn state, in both adapters that had the wrong order.

  • ClaudeAdapter.sendTurn: buildUserMessageEffect (which validates attachment mime types) is hoisted above session.status = "running", the activeTurnId assignment, and the turn.started emission.
  • CursorAdapter.sendTurn: same hoist for its attachment-id and empty-prompt validation.
  • A validation failure now leaves the session completely untouched — no status change, no activeTurnId, no turn.started — so ProviderCommandReactor's existing recoverTurnStartFailure path produces a clean ready state with the error surfaced.
  • Codex, OpenCode, and Grok adapters were audited and already validate before emitting (or handle failure synchronously in-fiber), so they are unchanged.
  • Tests: regression tests in both adapter suites asserting that an unsupported attachment yields the request error, emits no turn.started, and leaves the session ready with no activeTurnId — plus that a subsequent valid turn emits exactly one turn.started with the correct turn id. ClaudeAdapter.test.ts 60/60, CursorAdapter.test.ts 19/19.

Why

Pasting an image the provider rejects (e.g. a HEIC screenshot from an iPhone, which passes the composer's image/* check) permanently wedges the thread: it shows "working" forever and the stop button does nothing.

The cause is an ordering race, not the validation itself. Because turn.started is emitted before validation runs, a validation failure leaves an event already in flight. recoverTurnStartFailure correctly resets the session to ready, but ProviderRuntimeIngestion processes that stale turn.started asynchronously; when it lands after the recovery it flips the session back to running with an activeTurnId for a turn that can never finish — the message was never queued, so no turn.completed can ever arrive, and query.interrupt() has nothing to interrupt.

Reordering is the smallest fix that removes the race at its source: if the failure happens before any state is published, there is no stale event to lose the race to, and no new recovery machinery is needed. The alternative — emitting a compensating turn-end event on failure — adds a second event path to keep correct and still leaves a window where the UI shows a phantom running turn.

UI Changes

No UI code changed. The user-visible difference is that a rejected attachment now surfaces its error and returns the thread to ready, instead of leaving it stuck in "working" with an unresponsive stop button.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Note

Medium Risk Changes core provider turn lifecycle, event ordering, and concurrent sendTurn settlement in Cursor—high user impact if wrong, but scope is adapter-layer with extensive new regression tests.

Overview Fixes threads stuck in working when a provider rejects an attachment (e.g. HEIC): validation used to run after turn.started and session turn state were published, so async ingestion could flip the session back to running with no matching turn.completed.

ClaudeAdapter moves buildUserMessageEffect (including mime-type checks) before marking the session running, setting activeTurnId, or emitting turn.started.

CursorAdapter does the same for prompt/attachment validation, and expands turn handling for overlapping sendTurn calls: early turnId reservation while promptsInFlight is tracked, turn.started only after validation (first surviving prompt announces), and an onExit drain that emits a matching turn.completed (including failed) when the last prompt exits without a normal settle—covering steer-during-prep, reserver prep failure, interrupt, and first-prompt ACP failure.

The ACP mock agent gains T3_ACP_SET_CONFIG_OPTION_DELAY_MS and T3_ACP_FAIL_FIRST_PROMPT; adapter tests lock in no phantom turn.started, clean session state after validation errors, and merged-turn boundaries.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit dd18ff4c5d52e3cffba29672b92d40360e2b1e57. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Fix unsupported attachments wedging turns in 'working' state with a dead stop button

  • In ClaudeAdapter.ts, reorders sendTurn to build and validate the user message before emitting turn.started or mutating session state, so unsupported attachments (e.g. HEIC) return an error without leaving a stuck turn.
  • In CursorAdapter.ts, reserves the active turn ID and increments promptsInFlight immediately so concurrent sendTurn calls steer into the same turn, and defers turn.started emission until after validation succeeds.
  • CursorAdapter now tracks activeTurnStarted, activeTurnSettled, and activeTurnLastStopReason on session context to guarantee exactly one turn.started per turn and always settle an announced turn even when the last prompt holder exits without resolving.
  • acp-mock-agent.ts gains T3_ACP_FAIL_FIRST_PROMPT and T3_ACP_SET_CONFIG_OPTION_DELAY_MS env vars to support testing these failure modes.
  • Behavioral Change: failures during message construction no longer emit turn.started, so the UI stop button will not appear and the turn will not appear to be running when attachment validation fails.
Macroscope summarized dd18ff4.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro

      Run ID: 5c613fe2-dc84-49a2-b6be-da0b133359d3

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      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
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs human review

      This bug fix introduces significant turn lifecycle state management changes in CursorAdapter with subtle edge case handling. An unresolved review comment identifies a potential bug where turn completion events may fire after session exit during stopSession, potentially corrupting session state.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit dd18ff4c5d52e3cffba29672b92d40360e2b1e57. Configure [here](https://www.cursor.com/dashboard/bugbot).
      @@ -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 > 0
      1128+ ? 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;

      Interrupt settle resurrects stopped session

      Medium Severity

      The new onExit path settles an announced turn with a recorded sibling result even when the last holder exits via interrupt-only, and it never checks ctx.stopped. During stopSession, scope close can interrupt a still-preparing holder after a sibling already recorded a result, so turn.completed can publish after session.exited. Ingestion then maps that completion to ready, undoing the stopped session.

      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit dd18ff4c5d52e3cffba29672b92d40360e2b1e57. Configure [here](https://www.cursor.com/dashboard/bugbot).
    5. Closing in favor of #2829 (orchestration V2).

      #2829 deletes the V1 orchestration layer this PR builds on — apps/server/src/orchestration/**, provider/Layers/*Adapter.ts and provider/Services/** are removed and replaced by apps/server/src/orchestration-v2/**, with the IPC surface renamed to ORCHESTRATION_V2_WS_METHODS. The files this PR touches either no longer exist or are rewritten, so it can't be rebased — it would need reimplementing against the V2 adapters.

      This is not a judgement on the change itself. Several of these are real gaps we still want fixed; the base just moved out from under them.

      Once #2829 merges, please rebase onto main, port the change to the V2 equivalent, and reopen (or open a fresh PR). Ping me and I'll prioritise the review.

    6. juliusmarminge closed this

Sign in to join this conversation.