{"slug": "how-an-api-error-became-a-successful-workflow-result", "title": "How an API error became a successful workflow result", "summary": "A developer building a Temporal-backed agent with the Claude Agent SDK found that a truncated API key produced an authentication error that nine of ten example Workflows still reported as a successful result, because the samples returned the ResultMessage text without checking its is_error flag. The developer extended the samples' scripted local API fixture to return HTTP 401 errors, added regression tests, and reordered the response handlers to check is_error first and raise an ApplicationError before interpreting output; the ten new cases passed locally with 37 tests in the Claude example suite, and the proposed fix (PR #411) is approved but still open.", "body_md": "A truncated API key gave me an authentication error while I was building a small Temporal-backed agent. The surprising part was the Workflow status: one of the examples I was using could finish successfully and return the authentication error as its answer.\n\nThe API had rejected the request. The agent still produced a terminal result message. The example returned the message's text, so Temporal received a normal return value.\n\nThis was an error-handling omission in the examples. Temporal had no way to infer that a string returned by application code represented failure.\n\nThe affected samples used the Claude Agent SDK through Temporal's integration. Their response loops waited for a `ResultMessage`, then returned `message.result`.\n\nThat field can contain text explaining why a turn failed. Receiving the message only tells the application that the turn ended; the application also needs to check `is_error`.\n\nIn the hooks example, a rejected key could therefore produce a successful Workflow whose result was an authentication-error string. The structured-output example failed differently: it looked for structured data, found none, and raised an error about missing output. That obscured the authentication failure which had caused the missing data.\n\nThose are different symptoms of the same boundary: the code interpreted the answer before checking whether the turn had failed.\n\nThe samples already had a scripted, local API for offline testing. I extended that fixture so it could return an HTTP error as well as a model response. For this regression, every request received a 401 authentication error with a fixed test message.\n\nThe fixture used test credentials and a local endpoint. It did not need a valid model API key or an external inference request.\n\nI ran that rejected-key case through the example Workflows and the chat example's message Update. Before the change, nine of the ten cases treated error text as a successful result. The structured-output case raised the misleading missing-output error instead.\n\nThe [regression tests](https://github.com/temporalio/samples-python/blob/3603a9cbb9a8bfb8914556dcc0d8b3e9638e7618/tests/claude_agent_sdk_plugin/api_error_test.py) check more than whether something raised:\n\n`ApplicationError` with a non-empty reason.\nThe tests describe behavior at that pinned revision. They are not a claim about every SDK version or every kind of failed turn.\n\nThe response handler now checks `is_error` first. On failure, it takes the reason from `result`, falling back to the `errors` list, and raises an `ApplicationError`. Only a successful result proceeds to normal answer handling.\n\nThe same ordering matters for structured output: check for a failed turn before diagnosing a missing structured value. Otherwise the useful cause is replaced by a secondary error.\n\nIn the chat sample, a failed message Update also leaves the reference to the last good reply unchanged. An error should not become the conversation's new successful answer.\n\nThis change makes a failed turn visible to the Workflow or Update caller. It does not decide whether every failure should be retried. Authentication errors, rate limits, connection loss and temporary provider outages need different policies. Raising an error and choosing a retry policy are separate decisions.\n\nThe CLI could retry the rejected request with backoff, making this deliberately failing test slow. The offline harness sets `CLAUDE_CODE_MAX_RETRIES=0`: its scripted response is immediate and final, so repeating it adds no information.\n\nThat setting belongs to this test setup. It is not a recommendation to disable retries for production provider calls.\n\nOn 12 November, after the change, the ten new cases passed locally; the Claude example suite had 37 passing tests. The [proposed samples fix, PR #411](https://github.com/temporalio/samples-python/pull/411), has received approval but remains open as of 16 November. Local results do not establish that the repository's full CI is green.\n\nA completed SDK turn, a successful model request and a successful business operation are different outcomes. Here, checking the result message's failure flag was enough to stop one from being mistaken for the others.", "url": "https://wpnews.pro/news/how-an-api-error-became-a-successful-workflow-result", "canonical_source": "https://dev.to/byhashdong/how-an-api-error-became-a-successful-workflow-result-1h5e", "published_at": "2026-11-16 02:44:49+00:00", "updated_at": "2026-11-16 02:50:52.407339+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "mlops"], "entities": ["Temporal", "Claude Agent SDK", "Anthropic", "samples-python", "PR #411"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/how-an-api-error-became-a-successful-workflow-result", "markdown": "https://wpnews.pro/news/how-an-api-error-became-a-successful-workflow-result.md", "text": "https://wpnews.pro/news/how-an-api-error-became-a-successful-workflow-result.txt", "jsonld": "https://wpnews.pro/news/how-an-api-error-became-a-successful-workflow-result.jsonld"}}