fix(prover-client): do not send explicit content-length header to proof server#456
Merged
Merged
Conversation
…of server undici >= 8.2.0 rejects malformed content-length request headers (nodejs/undici#5060). When the npm undici package is installed as the process-wide fetch dispatcher — a module-load side effect of importing it transitively, e.g. via testcontainers or @effect/platform-node — the explicit content-length header set by HttpClientRequest.bodyUint8Array gets duplicated with the one Node's bundled fetch computes from the body, and the combined value fails undici's digit-only validation, making every proof-server request fail with 'invalid content-length header'. Build the request body with HttpBody.raw instead, which attaches no content-length header and lets fetch derive it from the body. This also matches the fetch spec, where Content-Length is a forbidden request header.
dijnie
pushed a commit
to htlabs-xyz/midnight-wallet
that referenced
this pull request
Jun 10, 2026
…of server (midnightntwrk#456) [verdaccio: 7111b55]
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.
Problem
Proving fails with
ClientError: Failed to prove transactionwhenever the npmundicipackage (>= 8.2.0) is present in the process — e.g. in any test importingtestcontainersor@effect/platform-node. Both "should prove a valid transaction" tests inhttpProverClient.test.tsfail. This is the same regression that previously forced pinning undici back to 8.1.0 (d9531ec); the combined dependency updates re-introduce it by moving the pin to 8.4.x.Root cause
Two things conspire:
lib/global.jsinstalls its ownAgentas the global dispatcher at module load, including under the legacySymbol.for('undici.globalDispatcher.1')slot that Node 22's bundled fetch (undici 6.24.1) reads. Merely importing testcontainers reroutes everyfetch()in the process through npm undici 8 via aDispatcher1Wrapper.HttpClientRequest.bodyUint8Arrayfrom@effect/platformsets an explicitcontent-lengthheader; Node's bundled fetch also computes one from the body, and the duplicated value arriving at undici 8's validator fails the check withInvalidArgumentError: invalid content-length header.Verified in isolation: the same
fetchPOST with an explicitcontent-lengthheader succeeds beforeimport 'undici'and fails withinvalid content-length headerafter it; without the explicit header it succeeds in both cases.Fix
Build the proof-server request body with
HttpBody.raw(body, { contentType: 'application/octet-stream' })instead ofbodyUint8Array, so no explicitcontent-lengthheader is attached andfetchderives it from the body. This also matches the fetch spec, whereContent-Lengthis a forbidden request header (browsers strip it silently anyway), and decouples the prover client from whichever undici version owns the global dispatcher.This is the only place in the SDK that sends a request body through
FetchHttpClient, so no other call sites are affected.Testing
yarn test --filter=@midnight-ntwrk/wallet-sdk-prover-client --force: 11/11 pass (2 failed before the fix)yarn turbo typecheck lint --filter=@midnight-ntwrk/wallet-sdk-prover-client: clean