Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

What

Allow interrupt (Esc / Ctrl+C) to cancel a message while the UI is still in "Starting..." (i.e., before stream-start).

Why

Previously, interrupts were gated on canInterrupt (active StreamManager stream). If a send was blocked during init/runtime setup, there was no active stream to stop, so the UI could get stuck in "Starting..." with no way to cancel.

How

  • Frontend:
    • Treat pendingStreamStartTime as interruptible for keybind interception.
    • Show cancel hint during the starting barrier.
    • Clear pendingStreamStartTime on stream-abort (abort can arrive before stream-start).
    • Command palette interrupt disables auto-retry (matches keybind behavior).
  • Backend:
    • Register a per-workspace AbortController at the start of AIService.streamMessage().
    • stopStream() aborts pending startup and emits a synthetic stream-abort when cancelled before StreamManager starts.
    • Mock mode now respects the abort signal during startup.

Tests

  • make static-check
  • Added tests/ipc/interruptStream.starting.test.ts (requires TEST_INTEGRATION=1 + ANTHROPIC_API_KEY).

Generated with mux • Model: openai:gpt-5.2 • Thinking: xhigh • Cost: $11.21

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: df524048ba

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@ammar-agent ammar-agent force-pushed the fix/interrupt-stream-startup branch from df52404 to 22cac8f Compare January 9, 2026 19:40
@ammar-agent
Copy link
Collaborator Author

@codex review

Addressed the startup-interrupt race by honoring already-aborted signals before atomic stream creation, plus a unit test that aborts during temp-dir creation to ensure we never emit stream-start / start streaming.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bfe9be15f0

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@ammar-agent
Copy link
Collaborator Author

@codex review

Refactored stream startup abort handling to be race-free by construction:

  • Link abort signals via shared helper (linkAbortSignal)
  • startStream now cleans up runtimeTempDir if abort happens before stream registration
  • Added unit coverage asserting the pre-start temp-dir cleanup path

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0fe42157f1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines 199 to +205
if (!appendResult.success) {
return Err({ type: "unknown", raw: appendResult.error });
}

if (abortSignal?.aborted) {
return Ok(undefined);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Clean up mock history when abort after append

In mock mode, play() now checks abortSignal after appending the assistant placeholder to history and returns early when aborted. If the user cancels during startup (after appendToHistory resolves but before scheduleEvents), the history ends up with an empty assistant message and no stream-abort/cleanup for that message ID, so reloads or retry logic can treat the response as completed even though nothing streamed. Consider moving the abort check before the history append or emitting a stream-abort/removing the assistant entry when this abort path is hit.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant