fix(decisioning): project malformed-JSON 2xx responses to AdcpError#836
Draft
bokelley wants to merge 1 commit into
Draft
fix(decisioning): project malformed-JSON 2xx responses to AdcpError#836bokelley wants to merge 1 commit into
bokelley wants to merge 1 commit into
Conversation
When an upstream returns a 2xx status with a non-JSON body (e.g. a CDN or proxy returning an HTML error page), re-raise json.JSONDecodeError as AdcpError(SERVICE_UNAVAILABLE, recovery="transient") so adopters get a typed error consistent with the rest of the error-projection surface. Refs #453 https://claude.ai/code/session_018wq8sxhkG9c2WW4vgpYgS8
This was referenced May 23, 2026
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.
Refs #453
When an upstream returns a successful (2xx) status with a non-JSON body (e.g. a CDN or proxy returning an HTML error page),
UpstreamHttpClient._requestpreviously propagated a rawjson.JSONDecodeErrorfromresponse.json(). Adopters catchAdcpErrorthroughout; an unhandledValueErrorsubclass breaks that contract and is invisible in typed code. This PR wraps the call inexcept ValueErrorand re-raises asAdcpError(SERVICE_UNAVAILABLE, recovery="transient")— the same code used for 5xx responses, since an upstream returning HTML for a JSON endpoint is indistinguishable from a transient infrastructure failure.This is a re-cut of the original branch from #767 (
claude/issue-453-json-decode-error-handling), which was behind main and had maintainer edits disabled. The diff is identical to #767 but rebased cleanly on current main.What changed
src/adcp/decisioning/upstream.py: wrapresponse.json()intry/except ValueError; raiseAdcpError(SERVICE_UNAVAILABLE)withrecovery="transient"andfrom excchain.tests/test_upstream_helpers.py: addtest_200_with_malformed_json_raises_service_unavailable— mocks a 200 with an HTML body and asserts code, recovery, and__cause__.What tested
pytest tests/test_upstream_helpers.py -q— 35 passed, 0 failedmypy src/adcp/decisioning/upstream.py— cleanruff check src/adcp/decisioning/upstream.py tests/test_upstream_helpers.py— cleanPre-PR review
@pytest.mark.asyncio(false positive:asyncio_mode = "auto"in pyproject.toml); one nit on truncatingexcin message (low severity,AdcpErroris internal)SERVICE_UNAVAILABLE / transientis correct for CDN/proxy interception; nit on adding boundedresponse.text[:200]snippet to message; no blockersNits (not fixed):
exctext rather than a body-length hint; useful for debugging, acceptable for an internal error typerecovery="transient"is correct per the spec but can't distinguish "CDN blip" from "permanently misconfigured upstream" — no better enum value existsSession: https://claude.ai/code/session_018wq8sxhkG9c2WW4vgpYgS8
Generated by Claude Code