Skip to content

fix(provider,claude): handle prompt stream interrupt on session stop#1365

Merged
juliusmarminge merged 1 commit intopingdotgg:mainfrom
keyzou:fix/prompt-stream-interrupt
Mar 24, 2026
Merged

fix(provider,claude): handle prompt stream interrupt on session stop#1365
juliusmarminge merged 1 commit intopingdotgg:mainfrom
keyzou:fix/prompt-stream-interrupt

Conversation

@keyzou
Copy link
Copy Markdown
Contributor

@keyzou keyzou commented Mar 24, 2026

What Changed

  • Added a Stream.catchCause clause to the prompt stream pipeline in ClaudeAdapter.ts that converts interrupt-only causes into a clean end-of-stream signal before Stream.toAsyncIterable`.
  • Added a regression test that verifies stopSession cleanly ends the prompt async iterable instead of throwing into the SDK's consumer.

Why

When the message queue is shut down (deleting a thread with an active session, or shutting down the server with an active session), the cancellation is passed to the SDK loop and since it's a thrown "error", the loop raises it, causing a crash.

Mitigation is to properly handle the cancellation event before passing it to the SDK, so that we stay in Effect's boundary and properly end the stream.

Fixes #1273

UI Changes

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 prompt-stream shutdown semantics during stopSession by swallowing interrupt-only failures; risk is mainly around subtle stream/lifecycle behavior potentially masking real errors or affecting prompt delivery.

Overview
Fixes ClaudeAdapter session shutdown so stopping a session cleanly ends the SDK prompt async-iterator instead of throwing an interrupt error into the SDK consumer.

Adds a regression test that simulates real SDK for await (... of prompt) consumption and verifies stopSession does not surface an exception, while still rethrowing non-interrupt prompt stream failures.

Written by Cursor Bugbot for commit ee20a29. This will update automatically on new commits. Configure here.

Note

Fix prompt stream interrupt handling in ClaudeAdapter on session stop

When a session is stopped, the Claude prompt stream was propagating the interrupt as an error to the SDK prompt consumer. A Stream.catchCause stage is added in ClaudeAdapter.ts that swallows interrupt-only causes and returns an empty stream, while re-raising non-interrupt failures. A new test in ClaudeAdapter.test.ts verifies that stopSession no longer throws into the prompt consumer.

Macroscope summarized ee20a29.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 24, 2026

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: eecd5276-4a36-4de7-af68-30846cbd928c

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 and usage tips.

@github-actions github-actions bot added size:XS 0-9 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Mar 24, 2026
Queue.shutdown on the prompt queue produces an interrupt cause that
Stream.toAsyncIterable throws as "All fibers interrupted without error"
into the Claude SDK's `for await` loop. Catch interrupt-only causes
and convert them to a clean end-of-stream before toAsyncIterable.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@keyzou keyzou force-pushed the fix/prompt-stream-interrupt branch from 485073a to ee20a29 Compare March 24, 2026 15:44
@juliusmarminge
Copy link
Copy Markdown
Member

@macroscope-app review this

@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp bot commented Mar 24, 2026

Review started! Results will be posted as check runs on this PR.

@juliusmarminge juliusmarminge merged commit 0a503d0 into pingdotgg:main Mar 24, 2026
12 checks passed
kkorenn pushed a commit to kkorenn/k1code that referenced this pull request Mar 25, 2026
emrezeytin pushed a commit to emrezeytin/t3code that referenced this pull request Mar 25, 2026
apexsloth pushed a commit to apexslothforks/t3code that referenced this pull request Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash when deleting Claude threads: "All fibers interrupted without error"

2 participants