Skip to content

fix: preserve session on CLI timeout for auto-resume#24

Merged
PleasePrompto merged 1 commit intoPleasePrompto:mainfrom
n-haminger:fix/timeout-session-preservation
Mar 4, 2026
Merged

fix: preserve session on CLI timeout for auto-resume#24
PleasePrompto merged 1 commit intoPleasePrompto:mainfrom
n-haminger:fix/timeout-session-preservation

Conversation

@n-haminger
Copy link
Copy Markdown
Contributor

@n-haminger n-haminger commented Mar 2, 2026

Summary

  • When the CLI times out mid-execution, the session ID was previously lost (especially for new sessions where the ResultEvent never arrives), causing the next message to start a fresh session without context
  • Captures session_id from SystemInitEvent during streaming so it survives a timeout kill
  • Adds a dedicated _handle_timeout() flow that persists the session for auto-resume
  • Shows a clear user-facing message explaining the timeout and that the session is preserved

Changes

  • executor.py: __TIMEOUT__ marker in ResultEvent.result for reliable timeout detection
  • service.py: Capture SystemInitEvent.session_id in _StreamCallbacks, detect timeout marker, set timed_out on CLIResponse, carry forward init_session_id in fallback path
  • flows.py: _handle_timeout() preserves session + timed_out checks in normal() and normal_streaming()
  • response_format.py: timeout_error_text() with session-preserved messaging

Context

This is complementary to the TimeoutController in v0.11.0 which handles timeout prevention (warnings, activity-based extensions). This PR handles timeout recovery — what happens when the timeout actually fires despite the controller's best efforts.

🤖 Generated with Claude Code

Previously, when the CLI timed out mid-execution, the session ID was
lost (especially for new sessions where the ResultEvent never arrived),
the user received a generic error message, and the next message started
a fresh session without context.

Changes:
- Capture session_id from SystemInitEvent during streaming so it
  survives a timeout kill before the final ResultEvent
- Add __TIMEOUT__ marker in executor ResultEvent for reliable detection
- Detect timeout in CLIService and set timed_out flag on CLIResponse
- Add dedicated _handle_timeout() flow that persists the session for
  auto-resume on the next user message
- Add timeout_error_text() with clear user-facing message explaining
  what happened and that the session is preserved

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

2 participants