-
Notifications
You must be signed in to change notification settings - Fork 705
Description
Problem
When the CLI process fails during initialize() (e.g., resuming a non-existent session), the SDK correctly parses the JSON error result from stdout and sends it to the message stream. However, it then raises a ProcessError with a hardcoded stderr="Check stderr output for details", which overwrites the real error.
The caller receives a useless ProcessError instead of the actual CLI error (e.g., "No conversation found with session ID ab2c985b").
Root Cause
In query.py:_read_messages:
- Line 210-214: A
resultmessage withsubtype=error_during_executionarrives from the transport, gets sent to the message stream - Line 578-583 (
subprocess_cli.py): The transport sees non-zero exit code and raisesProcessErrorwith hardcodedstderr="Check stderr output for details" - Line 220-226 (
query.py): TheProcessErroris caught and propagated to pending control requests — replacing the real error that's sitting unread in the message stream
During initialize(), the caller is waiting on _send_control_request which listens for control responses, not the message stream. So the real error is buffered but never reaches the caller.
Expected Behavior
The actual CLI error text from the error_during_execution result should be included in the exception that reaches the caller.
Possible Fix
In _read_messages, when a result with subtype=error_during_execution is received, store the error text. Then in the except block (line 220-226), use the stored error text instead of (or in addition to) the ProcessError message when signaling pending control requests.
SDK Version
claude-agent-sdk 0.1.47