fix(provider,claude): handle prompt stream interrupt on session stop#1365
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the 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. Comment |
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]>
485073a to
ee20a29
Compare
|
@macroscope-app review this |
|
Review started! Results will be posted as check runs on this PR. |
…ingdotgg#1365) Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
…ingdotgg#1365) Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
…ingdotgg#1365) Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
What Changed
Stream.catchCauseclause to the prompt stream pipeline inClaudeAdapter.tsthat converts interrupt-only causes into a clean end-of-stream signal before Stream.toAsyncIterable`.stopSessioncleanly 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
Note
Medium Risk
Changes prompt-stream shutdown semantics during
stopSessionby swallowing interrupt-only failures; risk is mainly around subtle stream/lifecycle behavior potentially masking real errors or affecting prompt delivery.Overview
Fixes
ClaudeAdaptersession 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 verifiesstopSessiondoes 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
ClaudeAdapteron session stopWhen a session is stopped, the Claude prompt stream was propagating the interrupt as an error to the SDK prompt consumer. A
Stream.catchCausestage 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 thatstopSessionno longer throws into the prompt consumer.Macroscope summarized ee20a29.