Skip to content

feat: tolerate unknown enum values in API responses - #144

Open
matiasedgeandnode wants to merge 1 commit into
mainfrom
ma/tolerant-wire-schemas
Open

feat: tolerate unknown enum values in API responses#144
matiasedgeandnode wants to merge 1 commit into
mainfrom
ma/tolerant-wire-schemas

Conversation

@matiasedgeandnode

Copy link
Copy Markdown
Collaborator

Why

A recent API change nearly added "topup" to the activity feed's type
field — which would have crashed getActivity() for every deployed SDK,
because the SDK's mirrored wire schemas declare closed enums
(Schema.Literals(["earn", "spend"])) and one unknown value fails the
whole response decode. We can't force-upgrade agents in the field, so the
SDK must follow the tolerant-reader rule (protobuf-style open enums): new
fields are already ignored safely; new enum values must flow through
instead of throwing.

What

  • OpenEnum helper: decodes any string (or number), typed as
    "earn" | "spend" | (string & {}) so autocomplete/narrowing survive and
    consumers keep a default branch.
  • Applied to all response-side enums: activity type/status, payment
    status/scheme, deployment status, marketplace source, endpoint
    methods and x402_protocol_version.
  • ApprovalStatus gains a catch-all union member so a new status can't
    crash setup-polling loops.
  • Deliberately unchanged: request-side enums (query filters, approval
    mode, payment events) and protocol discriminants (x402-v1/v2) —
    there, failing fast is correct.
  • Python: SDK models were already tolerant; the 402 decode-failure
    passthrough now warns instead of debug-logging, since it silently skips
    payment.

Deployed agents can't be force-upgraded, so a value added on the
server side (e.g. a new activity type in the shared feed) would make
every existing SDK throw away the whole response. Response-side enums
now decode unknown values through (OpenEnum); request-side enums stay
closed so caller typos still fail fast. The Python transport's 402
decode-failure passthrough now logs a warning instead of debug, since
it silently skips payment.
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.

1 participant