#3836·headroom

CCR continuation on the Anthropic path treats a non-2xx reply as the model's answer

Author: chopratejasCreated Sep 28, 2026Updated Sep 28, 2026

Found while addressing review feedback on #3816, which fixed the same defect on the OpenAI direct chat path.

handlers/anthropic.py:4369, inside the CCR continuation closure:

python
cont_response = await self.http_client.post(...)
result: dict[str, Any] = cont_response.json()
return result

The status is never checked. httpx does not raise on a non-2xx by default, so an upstream 401, 429 or 500 on the continuation is parsed and returned as the model's answer. CCRResponseHandler.handle_response then treats it as the resolved response, and the outer path serializes it under the original call's 200.

Consequence: a client receives HTTP 200 whose body is an Anthropic error object with no content block — a shape no client expects, and one that hides an auth or quota failure rather than surfacing it.

The surrounding try/except does not help: nothing raises. The except only catches a genuine transport error or a JSON decode failure.

Fix shape

#3816 (commit 605035a9) has the pattern. Two parts, both needed:

  1. Check the status before .json() and raise, which routes into handle_response's existing continuation-failure path (response_handler.py:535-544) so the response it already had is forwarded. That matches how transport errors and timeouts on the same call already behave.
  2. Do not leave the parsed dict as the final response on that path — nothing was resolved, so the upstream bytes should be forwarded verbatim rather than re-serialized. Detect by object identity, which also covers max-rounds exhaustion.

Accounting falls out of the same change: a non-2xx body has no usage, and settling against the original leaves the delta at zero.

Note on scope

The Anthropic path differs from the OpenAI one in two ways that affect the fix:

  • It posts through self.http_client directly rather than _retry_request, so there is no retry/backoff for the continuation and every non-2xx arrives on the first attempt.
  • It has the _salvageable_upstream mechanism (#3088) and preserve_opaque_response_fields, so the "forward what we had" path needs to be reconciled with those rather than bolted alongside them.

Worth a regression test parametrized over 401 / 429 / 500, as in tests/test_direct_chat_ccr_resolution.py — the existing tests on this path produce 200s only, which is why this has gone unnoticed.

Generated with Claude Code

Source: headroomlabs-ai/headroom