Skip to content

fix(core,hono): decouple 402 generation from facilitator init for serverless cold start#2221

Open
lau90eth wants to merge 1 commit into
x402-foundation:mainfrom
lau90eth:fix/hono-lazy-init-decoupled
Open

fix(core,hono): decouple 402 generation from facilitator init for serverless cold start#2221
lau90eth wants to merge 1 commit into
x402-foundation:mainfrom
lau90eth:fix/hono-lazy-init-decoupled

Conversation

@lau90eth
Copy link
Copy Markdown

@lau90eth lau90eth commented May 7, 2026

Fixes #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 returning a valid 402.

Fix

@x402/core (x402ResourceServer.ts):

  • When supportedResponsesMap is empty, 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

@x402/hono (index.ts):

  • Change syncFacilitatorOnStart default from true to false
  • Now safe because core supports lazy 402 generation

Result

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

  • Added test: should build base requirements without facilitator init (cold start)
  • Updated hono retry test to pass syncFacilitatorOnStart: true explicitly
  • 442 core tests passing + 36 hono tests passing

…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
@vercel
Copy link
Copy Markdown

vercel Bot commented May 7, 2026

@lau90eth is attempting to deploy a commit to the Coinbase Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sdk Changes to core v2 packages typescript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@x402/hono: paymentMiddleware syncFacilitatorOnStart default makes discovery probes time out on cold serverless/edge isolates

1 participant