Skip to content

fix(edge): preserve JSON-RPC batch envelopes - #321

Merged
punkpeye merged 3 commits into
punkpeye:mainfrom
pacocartones:fix/edge-json-rpc-batch-envelope
Aug 12, 2026
Merged

punkpeye merged 3 commits into
punkpeye:mainfrom
pacocartones:fix/edge-json-rpc-batch-envelope

Conversation

@pacocartones

Copy link
Copy Markdown
Contributor

Summary

Preserve the JSON-RPC batch envelope in the Edge transport based on the shape of the original request, rather than the number of response objects that remain after notifications are omitted.

This follows JSON-RPC 2.0 batch semantics:

  • every non-empty batch response is an array, even when the batch contains one request or only one response survives;
  • an empty batch ([]) is invalid and returns one response object (not an array) with HTTP 200, error -32600, and id: null;
  • a batch containing only notifications keeps the existing HTTP 202 response with no body or content type;
  • mixed batches omit notifications, preserve the current sequential response order, and return HTTP 200 with application/json;
  • non-batch requests continue to return a single response object.

Implementation

  • Record whether the parsed request body was an array before normalizing it into messages.
  • Reject an empty array before the notification-only 202 path.
  • Serialize responses according to the original request shape.
  • Add regressions for a one-request batch and an empty batch.

The diff is limited to src/edge/index.ts and src/edge/edge.test.ts; package manifests and the lockfile are unchanged. This branch is based directly on main at v4.14.4 after #320 merged.

Verification

Fresh RED on v4.14.4 with the tests only:

  • one-request batch returned an object instead of an array;
  • [] returned HTTP 202 instead of an Invalid Request object.

GREEN on this head:

  • focused batch regressions: 2/2;
  • complete Edge suite: 17/17;
  • complete test suite: 45 files, 553/553;
  • tsc --noEmit: pass;
  • ESLint: pass;
  • Prettier on both touched files: pass;
  • ESM/CJS/DTS build: pass;
  • JSR publish dry-run: pass;
  • runtime probe for mixed batches, notification-only batches, response order, status codes, content type, and single-request envelope: pass.

@punkpeye
punkpeye merged commit b8f43be into punkpeye:main Aug 12, 2026
1 check passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 4.15.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants