Skip to content

Conversation

@grumpygordon
Copy link
Contributor

Summary

When the CLI exits with an error (e.g., invalid session ID passed to --resume), signal all pending control requests immediately instead of waiting for the 60-second timeout.

The fix adds 4 lines to the exception handler in _read_messages:

# Signal all pending control requests so they fail fast instead of timing out
for request_id, event in list(self.pending_control_responses.items()):
    if request_id not in self.pending_control_results:
        self.pending_control_results[request_id] = e
        event.set()

Problem

When the CLI exits with an error, the SDK's message reader catches it but doesn't notify pending control requests. This causes initialize() to wait for the full 60-second timeout even though the error is known within seconds.

Example scenario:

  1. User passes invalid session ID via ClaudeAgentOptions(resume="invalid-id")
  2. CLI prints No conversation found with session ID: xxx and exits with code 1
  3. SDK message reader catches the error after ~3 seconds
  4. But initialize() keeps waiting for 60 seconds before timing out

Solution

The existing code at _send_control_request lines 361-362 already handles exceptions in results:

if isinstance(result, Exception):
    raise result

The fix simply signals all pending control events when an error occurs, allowing them to fail fast with the actual error instead of timing out.

Test Plan

  • Test with invalid session ID - should fail fast (~3s) instead of timing out (60s)
  • Test normal flow still works
  • Test multiple pending requests all get signaled

Fixes #387

When the CLI exits with an error (e.g., invalid session ID), signal all
pending control requests immediately instead of waiting for timeout.

This fixes the issue where initialize() waits 60 seconds before failing
even though the CLI error is known within seconds.

Fixes anthropics#387
Copy link
Collaborator

@ashwin-ant ashwin-ant left a comment

Choose a reason for hiding this comment

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

Thanks!

@ashwin-ant ashwin-ant merged commit 69a310c into anthropics:main Dec 4, 2025
13 checks passed
@jakerachleff
Copy link

hey @ashwin-ant can you guys please release this change soon?

ashwin-ant added a commit that referenced this pull request Dec 5, 2025
Include the three bug fixes that were merged but not documented:
- #388: Faster CLI error propagation
- #385: Pydantic 2.12+ compatibility
- #391: Concurrent subagent write lock

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@ashwin-ant
Copy link
Collaborator

@jakerachleff it's published as 0.1.13

@jakerachleff
Copy link

@jakerachleff it's published as 0.1.13

Thanks!

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.

CLI exit errors not propagated to pending control requests - initialize times out instead of failing fast

3 participants