Skip to content

fix: limit response parsing to values the SDK does not recognize - #653

Merged
razor-x merged 1 commit into
mainfrom
claude/revert-malformed-payload-tolerance
Sep 2, 2026
Merged

fix: limit response parsing to values the SDK does not recognize#653
razor-x merged 1 commit into
mainfrom
claude/revert-malformed-payload-tolerance

Conversation

@razor-x

@razor-x razor-x commented Sep 2, 2026

Copy link
Copy Markdown
Member

Partially reverts #651.

Why

#651 conflated two different things:

  • Unrecognized values — a new event type, action type, error code, or enum value. Reading these must not raise. This is forward compatibility, and it was already on main before feat: Improve API response parsing resilience to unknown fields #651.
  • Malformed payloads — a list sent as a scalar, an object sent as a string, a payload that is not an object at all. These are defects.

#651 added tolerance for the second, which was not the goal and is actively harmful:

  • A null list was already read as empty, so the new guards only caught genuinely broken data and quietly turned it into an empty list or None.
  • Catching exceptions around a known variant meant one bad field silently downgraded a typed event to an untyped DeepAttrDict, with nothing to tell the caller why the type changed.

What this removes

  • seam/parse.py
  • the if not isinstance(d, dict): d = {} guard in every generated from_dict
  • the exception handling around known union variants

What this keeps

The unrecognized-value handling that predates #651 is untouched:

behavior
unknown event_type falls back to DeepAttrDict
unknown error_code / warning_code falls back per item, rest of the resource intact
unknown enum value reads as itself (device.device_type == "future_lock")
unknown action_type / status falls back, status reads as itself

SeamActionAttemptUnknownStatusError also stays. The action attempt contract is strict: waiting promises a succeeded attempt or a raise, and the previous behavior returned an unrecognized status as a success, typed SuccessActionAttempt — telling the caller the action completed when the SDK cannot tell.

Tests

test/total_parsing_test.py is replaced by test/forward_compatibility_test.py, which pins only the rule that survives: the SDK does not explode on values it does not recognize. The tests that asserted malformed-payload tolerance are gone with the behavior.

278 tests, mypy clean, pylint 10.00, black clean.

Note

raw_json() on the webhook event is not in this PR. It follows separately.

🤖 Generated with Claude Code

https://claude.ai/code/session_01M2kJ4nGaM8imZCVMEKjmXA


Generated by Claude Code

#651 conflated two things. Handling values the SDK does not recognize -- new
event types, action types, error codes, enum values -- was already on main
before it, and is what forward compatibility needs. What #651 added on top was
tolerance for payloads that are malformed rather than merely new: a list sent as
a scalar, an object sent as a string, a payload that is not an object.

That is not forward compatibility, it is a defect being swallowed. A null list
was already read as empty, so the new guards only caught genuinely broken data
and turned it into an empty list or None. Worse, catching exceptions around a
known variant meant one bad field silently downgraded a typed event to an
untyped DeepAttrDict, with nothing to tell the caller why the type changed.

Removes seam/parse.py, the isinstance guards in every from_dict, and the
exception handling around known variants. The unrecognized-discriminator
fallback that predates #651 is untouched, so unknown event types still yield a
DeepAttrDict, unknown error codes still fall back per item, and unknown enum
values still read as themselves.

SeamActionAttemptUnknownStatusError stays. The action attempt contract is
strict: waiting promises a succeeded attempt or a raise, and returning an
unrecognized status as a success reports something the SDK cannot vouch for.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M2kJ4nGaM8imZCVMEKjmXA
@razor-x
razor-x requested a review from a team as a code owner September 2, 2026 05:48
@razor-x razor-x changed the title feat: limit response parsing to values the SDK does not recognize fix: limit response parsing to values the SDK does not recognize Sep 2, 2026
@razor-x
razor-x merged commit cca5903 into main Sep 2, 2026
23 checks passed
@razor-x
razor-x deleted the claude/revert-malformed-payload-tolerance branch September 2, 2026 06:01
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.

2 participants