Skip to content

server: carry the scheme's workOptional into the 402 requirements - #7

Merged
kilkelly merged 1 commit into
x402nano:v1.0.0from
pursekeeper:fix/work-optional-reaches-402
Nov 6, 2026
Merged

kilkelly merged 1 commit into
x402nano:v1.0.0from
pursekeeper:fix/work-optional-reaches-402

Conversation

@pursekeeper

Copy link
Copy Markdown

On the v1.0.0 branch, ExactNanoScheme.enhancePaymentRequirements in src/typescript/server/scheme.ts voids supportedKind and copies only the route's own extra, and @x402/core does not merge supportedKind.extra either. So when the Facilitator advertises extra.workOptional: true in its SupportedKind, the flag never reaches the 402 unless the route config repeats it by hand, and the client generates work itself. The spec's Appendix says a Resource Server whose Facilitator advertises workOptional: true MUST set extra.workOptional: true in PaymentRequirements.

This change forwards supportedKind.extra.workOptional into extra when it is true and the route has not set the key (one if in enhancePaymentRequirements, plus the JSDoc line). The new test in src/typescript/test/unit/server.test.ts mocks a Facilitator whose getSupported carries extra: { workOptional: true }, builds the requirements for a route with no extra, and checks the result has extra.workOptional: true; it also checks a Facilitator without the flag leaves extra as {}. The test fails on the branch tip without the source change and passes with it; the unit suite is 61 of 61. Filed at kilkelly's request in #5, item 1.

🤖 Generated with Claude Code

The Facilitator advertises `extra.workOptional: true` in its SupportedKind
when it can generate work, and the spec's Appendix says a Resource Server
whose Facilitator does so MUST set `extra.workOptional: true` in the
PaymentRequirements it serves. `enhancePaymentRequirements` voided
`supportedKind` and copied only the route's own `extra`, and @x402/core
does not merge `supportedKind.extra` either, so the flag never reached the
402 unless the route config repeated it by hand; the client then generated
work itself.

Forward `supportedKind.extra.workOptional` into `extra` when it is `true`
and the route has not set the key. Adds a server unit test that mocks a
Facilitator advertising work generation and checks the built requirement
carries `extra.workOptional: true` for a route with no `extra`.

Filed at kilkelly's request in the x402nano#5 thread (review item 1).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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