Skip to content

Harden Claude stream exit handling#1504

Merged
juliusmarminge merged 6 commits intomainfrom
t3code/claude-stream-crash
Mar 28, 2026
Merged

Harden Claude stream exit handling#1504
juliusmarminge merged 6 commits intomainfrom
t3code/claude-stream-crash

Conversation

@juliusmarminge
Copy link
Copy Markdown
Member

@juliusmarminge juliusmarminge commented Mar 28, 2026

Summary

  • Guard provider runtime ingestion against malformed runtime.error and turn.completed payloads so Claude exits do not crash orchestration.
  • Simplify bootstrap stream handling for inherited file descriptors and tighten desktop shutdown behavior during update install and window teardown.
  • Remove archived-thread/orchestration paths and related UI/state code that is no longer used.
  • Refresh tests around provider runtime ingestion, bootstrap reading, shell environment sync, and desktop/server startup behavior.

Testing

  • Not run in this session.
  • Existing test coverage was updated for runtime ingestion, bootstrap fd handling, and shell environment sync.
  • Project-level checks still need to pass: bun fmt, bun lint, and bun typecheck.

Note

Medium Risk
Changes Claude session stream lifecycle/cleanup behavior by running handleStreamExit inside the stream fiber and suppressing exit handling when the session is intentionally stopped, which could affect turn completion and session shutdown sequencing.

Overview
Hardens Claude stream shutdown handling in ClaudeAdapter by moving handleStreamExit execution into the stream fiber’s completion path (via Effect.exit(...).flatMap(...)) instead of observer-forking a separate fiber.

It now skips exit handling when context.stopped and tightens context.streamFiber reference clearing to reduce races between observer teardown and cleanup.

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

Note

Harden stream exit handling in ClaudeAdapter by running cleanup inside the stream fiber

  • handleStreamExit now runs inside the stream fiber on completion rather than being invoked via a separate observer-forked fiber, avoiding a race between the observer and fiber teardown.
  • Exit handling is skipped entirely when context.stopped is true, preventing redundant cleanup on intentional stops.
  • The context.streamFiber reference is cleared by the observer unconditionally, and also cleared within the fiber itself when the stream exits normally.
  • streamFiber is now typed explicitly as Fiber.Fiber<void, never> and assigned before being stored on context.
  • Behavioral Change: previously handleStreamExit could be called even after the stream was stopped; it is now suppressed in that case.

Macroscope summarized 4aa898e.

- Prevent stream exit handling from racing with stopped sessions
- Clear the active stream fiber only for the current stream
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 28, 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: feb0a933-cccb-4d4a-ad97-6d4c8169fb24

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
  • Commit unit tests in branch t3code/claude-stream-crash

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added size:S 10-29 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. labels Mar 28, 2026
@juliusmarminge juliusmarminge merged commit 33773ff into main Mar 28, 2026
11 checks passed
@juliusmarminge juliusmarminge deleted the t3code/claude-stream-crash branch March 28, 2026 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant