fix(core,hono): decouple 402 generation from facilitator init for serverless cold start#2221
Open
lau90eth wants to merge 1 commit into
Open
fix(core,hono): decouple 402 generation from facilitator init for serverless cold start#2221lau90eth wants to merge 1 commit into
lau90eth wants to merge 1 commit into
Conversation
…d start Fixes x402-foundation#2157 Root cause: buildPaymentRequirements() called getSupportedKind() which threw when supportedResponsesMap was empty (facilitator not yet initialized). This made syncFacilitatorOnStart: false unusable — the middleware would crash on the first 402 response instead of timing out. Fix in @x402/core: - When supportedResponsesMap is empty (not yet initialized), skip getSupportedKind validation and enhancePaymentRequirements - Return baseRequirements directly using local route config data - When initialized, behavior is unchanged - Facilitator validation is still enforced at verify/settle time Fix in @x402/hono: - Change syncFacilitatorOnStart default from true to false - Now safe because core supports lazy 402 generation - Updated retry test to pass syncFacilitatorOnStart: true explicitly Result: cold-start 402 responses work correctly on serverless/edge environments (Cloudflare Workers, AWS Lambda) without blocking or errors. Tests: 442 core + 36 hono all passing
|
@lau90eth is attempting to deploy a commit to the Coinbase Team on Vercel. A member of the Team first needs to authorize it. |
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.
Fixes #2157
Root cause
buildPaymentRequirements()calledgetSupportedKind()which threw whensupportedResponsesMapwas empty (facilitator not yet initialized).This made
syncFacilitatorOnStart: falseunusable — the middleware wouldcrash on the first 402 response instead of returning a valid 402.
Fix
@x402/core (
x402ResourceServer.ts):supportedResponsesMapis empty, skipgetSupportedKindvalidationand
enhancePaymentRequirementsbaseRequirementsdirectly using local route config data@x402/hono (
index.ts):syncFacilitatorOnStartdefault fromtruetofalseResult
Cold-start 402 responses work correctly on serverless/edge environments
(Cloudflare Workers, AWS Lambda) without blocking or errors.
Discovery probes receive a valid 402 immediately on cold isolates.
Tests
should build base requirements without facilitator init (cold start)syncFacilitatorOnStart: trueexplicitly