[PR #12971] fix: propagate abort signal to prevent TUI freeze during processing #14461

Open
opened 2026-02-16 18:19:15 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/12971

State: open
Merged: No


Fixes #12834

Problem

When a user aborts a request (e.g., via Ctrl+C or the abort button), the abort signal is not fully propagated through the processor's main loop. This causes the TUI to freeze because:

  1. The processing loop continues iterating even after the abort signal fires
  2. Retry logic still engages on errors caused by the abort, creating unnecessary retry/sleep cycles
  3. The error assigned to the message doesn't reflect that it was an intentional abort
  4. The loop can return "continue" instead of "stop" after an abort, causing the session to keep processing

Solution

Propagate the abort signal at multiple critical points in the processor loop:

  • Break on abort at loop entry: Check input.abort.aborted at the top of the while(true) loop so we exit immediately if already aborted
  • Skip retry on abort: Add !input.abort.aborted guard to the retry condition so we don't retry requests that were intentionally cancelled
  • Skip continue on abort: After SessionRetry.sleep, only continue if not aborted
  • Set proper abort error: When aborted, assign MessageV2.AbortedError instead of the underlying network/API error, giving the TUI an accurate signal to stop
  • Return "stop" on abort: After the loop body, check abort status and return "stop" to prevent the session from continuing
  • Fallback return: Add return "stop" after the while loop as a safety net
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/12971 **State:** open **Merged:** No --- Fixes #12834 ## Problem When a user aborts a request (e.g., via Ctrl+C or the abort button), the abort signal is not fully propagated through the processor's main loop. This causes the TUI to freeze because: 1. The processing loop continues iterating even after the abort signal fires 2. Retry logic still engages on errors caused by the abort, creating unnecessary retry/sleep cycles 3. The error assigned to the message doesn't reflect that it was an intentional abort 4. The loop can return "continue" instead of "stop" after an abort, causing the session to keep processing ## Solution Propagate the abort signal at multiple critical points in the processor loop: - **Break on abort at loop entry**: Check `input.abort.aborted` at the top of the `while(true)` loop so we exit immediately if already aborted - **Skip retry on abort**: Add `!input.abort.aborted` guard to the retry condition so we don't retry requests that were intentionally cancelled - **Skip continue on abort**: After `SessionRetry.sleep`, only `continue` if not aborted - **Set proper abort error**: When aborted, assign `MessageV2.AbortedError` instead of the underlying network/API error, giving the TUI an accurate signal to stop - **Return "stop" on abort**: After the loop body, check abort status and return `"stop"` to prevent the session from continuing - **Fallback return**: Add `return "stop"` after the `while` loop as a safety net
yindo added the pull-request label 2026-02-16 18:19:15 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14461