fix: suppress ProcessError when result already received#790
Open
ya-luotao wants to merge 1 commit intoanthropics:mainfrom
Open
fix: suppress ProcessError when result already received#790ya-luotao wants to merge 1 commit intoanthropics:mainfrom
ya-luotao wants to merge 1 commit intoanthropics:mainfrom
Conversation
The CLI can exit with non-zero code after delivering a valid result (e.g., StructuredOutput tool_use triggers exit code 1 because the CLI called a tool but received no tool_result response). When _first_result_event is already set, the ProcessError is expected and should not be propagated to the consumer. Previously this caused query() callers to see a ProcessError even though the full result message was already yielded successfully.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
query()uses StructuredOutput (or any tool_use stop reason), the CLI exits with code 1 because it called a tool but received no tool_result responseProcessErrorafter the process exits, even though a validResultMessagewas already streamed to the consumerQuery._read_messagescatches this and enqueues it as an error, causingreceive_messagesto raise — so the caller sees aProcessErrordespite having received the full resultFix
In
Query._read_messages, add a specificexcept ProcessErrorhandler that checks_first_result_event.is_set(). If a result was already delivered, the non-zero exit code is expected and the error is suppressed with a warning log.Test plan
query()withoutput_schema(StructuredOutput) no longer raisesProcessErrorquery()without a result still raisesProcessErroron non-zero exit🤖 Generated with Claude Code