feat: tolerate unknown enum values in API responses - #144
Open
matiasedgeandnode wants to merge 1 commit into
Open
feat: tolerate unknown enum values in API responses#144matiasedgeandnode wants to merge 1 commit into
matiasedgeandnode wants to merge 1 commit into
Conversation
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.
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.
Why
A recent API change nearly added
"topup"to the activity feed'stypefield — 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 thewhole 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
OpenEnumhelper: decodes any string (or number), typed as"earn" | "spend" | (string & {})so autocomplete/narrowing survive andconsumers keep a default branch.
type/status, paymentstatus/scheme, deploymentstatus, marketplacesource, endpointmethodsandx402_protocol_version.ApprovalStatusgains a catch-all union member so a new status can'tcrash setup-polling loops.
mode, payment events) and protocol discriminants (x402-v1/v2) —there, failing fast is correct.
passthrough now warns instead of debug-logging, since it silently skips
payment.