fix: Raise a Seam error for a success response that is malformed - #638
Open
razor-x wants to merge 1 commit into
Open
Conversation
This was referenced Aug 27, 2026
razor-x
changed the base branch from
main
to
claude/python-sdk-audit-o2iid9-04-wait-option
August 28, 2026 00:15
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y1RzepycXEYA3LStfjt8cY
razor-x
force-pushed
the
claude/python-sdk-audit-o2iid9-05-invalid-response
branch
from
August 28, 2026 19:30
87cab53 to
38dc6ab
Compare
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.
What
A 2xx response with an unexpected envelope — a proxy rewrite, a maintenance page served with a JSON content type, a renamed response key — escaped the SDK's error hierarchy entirely: generated routes unwrapped
res["device"]inline at ~240 sites, so callers got a bareKeyError,TypeError: string indices must be integers, or a rawjson.decoder.JSONDecodeError(SDK audit finding M3; same fix as JS #1005 and PHP #475).SeamHttpInvalidResponseError(SeamError)withpathandresponse_keyattributes and the same message shape as the JS/PHP SDKs:Seam returned an invalid response for {path}: expected "{key}", {reason}.seam/response.pywithunwrap/unwrap_listhelpers that verify the body is an object, the key is present, and the value has the right shape.seam/modules/action_attempts.pyuse the same helper._handle_responsenow hands an unparseable JSON body on as text instead of leakingJSONDecodeError, so it surfaces as the same invalid-response error (this matches the JS SDK, where axios keeps the string).Depends on #634 (SeamError base) and is stacked on #637; the diff shrinks as those merge.
Testing
New
test/invalid_response_test.py(sync + async, recording server, pinned messages): missing key, JSONnull/string body, HTML page with a JSON content type, plain-text response, non-object value under the key, non-list value under a list key, and a malformed poll response mid-wait.Revert check: with
seam/routes/devices.pyandseam/client.pyreverted, the tests fail with the audit's exact symptoms (KeyError: 'device',TypeError: string indices must be integers, rawJSONDecodeError).Regeneration is drift-free at this head; the generated diff touches exactly the unwrap sites. Full suite: 216 passed; mypy, pylint (10.00), black clean.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Y1RzepycXEYA3LStfjt8cY
Generated by Claude Code