Skip to content

Raise on error results in the Claude Agent SDK samples - #411

Open
byhashdong wants to merge 1 commit into
temporalio:mainfrom
byhashdong:fix/claude-samples-error-results
Open

byhashdong wants to merge 1 commit into
temporalio:mainfrom
byhashdong:fix/claude-samples-error-results

Conversation

@byhashdong

Copy link
Copy Markdown

The Claude samples take ResultMessage.result as the answer without looking at is_error. Claude Code still ends a failed turn with a ResultMessage, so with a bad API key HooksWorkflow completes with "Invalid API key · Fix external API key" as its result, and structured_output fails with "returned no structured output", which doesn't say why. I hit this with a truncated key.

This checks is_error in each sample and raises an ApplicationError with the reason. In tools, plugin_with_custom_transport and agent_chat it also replaces returning the errors text (e.g. after max turns) as if it were the answer. In agent_chat the update fails and reply_id keeps pointing at the last good reply.

For the test, offline.py can now return an API error. It also sets CLAUDE_CODE_MAX_RETRIES=0, otherwise Claude Code retries the 401 with backoff for a long time. api_error_test.py runs each sample against a rejected key; before the change 9 of the 10 cases finished successfully.

The samples returned ResultMessage.result without checking is_error, so a
turn that failed (for example on a bad API key) completed the Workflow with
the error text as its result.
@byhashdong
byhashdong requested review from a team as code owners November 12, 2026 07:17
@CLAassistant

CLAassistant commented Nov 12, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@brianstrauch brianstrauch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you!

@brianstrauch
brianstrauch enabled auto-merge (squash) November 12, 2026 18:33
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.

3 participants