Skip to content

fix(vendor): forward the gRPC-web trailer frame to tonic - #28

Open
danielgorgonha wants to merge 5 commits into
red-dev-inc:feat/nu7-portable-keysfrom
deegalabs:fix/grpc-web-trailers
Open

danielgorgonha wants to merge 5 commits into
red-dev-inc:feat/nu7-portable-keysfrom
deegalabs:fix/grpc-web-trailers

Conversation

@danielgorgonha

@danielgorgonha danielgorgonha commented Nov 15, 2026 •

Copy link
Copy Markdown

Changes

  • A gRPC status sent in the body trailer frame now reaches the caller. The vendored tonic-web-wasm-client 0.8.0 parsed the trailer frame and then dropped it, so tonic never saw the trailers, and tonic 0.14.3 (the locked version) treats HTTP 200 with no trailers as success. A stream that failed part-way looked complete, a unary call that returned a message followed by an error status looked successful, and an error sent with no message before it became an empty successful stream.
  • Example from a public endpoint: zcash-mainnet.chainsafe.dev answers GetBlock for a height past the tip with HTTP 200, no grpc-status header, and a body that is a single trailer frame with grpc-status: 11. Today a unary call on that body fails with Internal: Missing response message. instead of the server's status, and the same body read as a server stream is an empty success. With this change both get OutOfRange: GetBlock: block 999999999 is newer than the latest block. The body, captured on 2026-11-15, is a test fixture here.
  • The body counts as finished only once the trailer frame has been read in full. A trailer frame split across chunks is now read, and a response cut inside it is MalformedResponse instead of a clean end. Unchanged: trailers-only responses (status in the HTTP headers, empty body), and a body that ends with no trailer frame (still MalformedResponse).
  • Where it comes from: the forwarding is the src/response_body.rs change of Check and forward any trailers on stream end. devashishdxt/tonic-web-wasm-client#90 (upstream 0f232d33, released in 0.9.1). The split-trailer case is upstream issue "missing grpc-status trailer" error when the end of the response arrives in two pieces devashishdxt/tonic-web-wasm-client#97, and the open upstream PR fix: read the whole trailers frame when it is split across chunks devashishdxt/tonic-web-wasm-client#112 makes the same change to the end-of-body check (only Done counts as finished); it is not merged. This workspace cannot take 0.9.x: every 0.9.x release depends on wasm-streams 0.5 or later, which requires wasm-bindgen >= 0.2.108, against the =0.2.100 pin kept for the MetaMask Snap.
  • VENDORED.md describes both local fixes. trailers.patch applies on top of trailers-only.patch and reproduces src/ from crates.io 0.8.0, apart from the test files (the patch carries only their two cfg(test) hooks).
  • New CI job vendored-tonic-web-wasm-client: the crate is excluded from the workspace, so --all never built its tests.
  • Why now: tonic 0.14.6 and later report HTTP 200 with no trailers as an error. With tonic 0.14.6 in a scratch lock, the captured successful unary body fails with Unknown: protocol error: missing grpc-status trailer, ... before this change and succeeds after it. So without this fix, a cargo update of tonic breaks every call that has a body.

Behaviour that changes for apps: an error that a server sends in the body trailer now fails the call, where before it was silently dropped. In a normal sync we saw no difference: a read-only sync of the last 200 blocks, with a new account, completed to the tip both before and after this change, against https://zjs.zec.rocks/testnet (testnet), https://zcash-mainnet.chainsafe.dev (mainnet) and https://zjs.zec.rocks/mainnet (the web wallet's mainnet proxy), in headless Chromium with the threaded build.

Other behaviour changes: a trailer block that does not parse now fails with HeaderParsingError whether it arrives in one chunk or split (before, the split case ended silently). Body trailers now reach tonic, and tonic 0.14.3 panics on an invalid grpc-status-details-bin (Status::from_header_map decodes it with expect): a server could already trigger that through the HTTP headers, and now it can also do so through the body trailer.

Known and not changed: grpc-status: 0 in the headers together with an error in a body trailer still reports success; repeated trailer keys keep only the last value (upstream #103); bytes after the trailer frame are ignored; base64 (grpc-web-text) mode is not used here; like a data frame, a trailer frame is buffered until its announced length has arrived.

The problem was found, reproduced and first fixed by @Crackdevs in their browser OHTTP proof, built on this branch (https://github.com/Crackdevs/zcash-browser-ohttp-proof): their wallet.patch already makes the decoder pass the trailers to tonic and require a complete trailer frame. That repository has no licence file, so none of their code is used here; this patch was written separately, from the upstream change named above. If they open their own pull request, we will close this one in its favour. The analysis and the patch were prepared with an AI assistant and reviewed by us.

Tests

cargo test --locked -p tonic-web-wasm-client

15 tests (14 new). The first commit adds the tests, a cfg(test) constructor that feeds the body from in-memory chunks, and moves the body of ResponseBody::new into a private from_body_stream (no change in behaviour). On that commit, 8 fail (trailers never yielded, split trailers, end inside the trailer frame, tonic streaming and unary calls, the captured body). With the fix, all 15 pass. The guards (trailers-only empty body, trailers-only with a truncated body, data with no trailer, cut inside a data frame, captured successful body, nothing after the trailers) pass on both commits.

Issues

🤖 Generated with Claude Code

danielgorgonha and others added 3 commits November 15, 2026 07:50
…wasm-client

The response body can now be fed from in-memory chunks, so the tests run
natively, without a browser: `ResponseBody::new` delegates to a private
`from_body_stream` (no change in behaviour), and a `cfg(test)`
`BodyStream::from_chunks` builds the stream. Eight of the tests fail on this
commit: the trailer frame is parsed but never handed to tonic, so a status
sent in the body trailer is lost.

Co-Authored-By: Claude <noreply@anthropic.com>
tonic-web-wasm-client 0.8.0 parsed the trailer frame, stored it in a field
nothing read, and ended the body as soon as it saw the trailer flag. tonic
never got the trailers, and with HTTP 200 and no trailers it reports success,
so a status sent in the body trailer (an error after some messages, or after
a unary message) was lost.

The body now yields the parsed trailers as a trailers frame, once, after the
last data frame. It only counts as finished once the trailer frame has been
read in full, so a trailer split across chunks is read and a stream that ends
inside the trailer frame is MalformedResponse instead of a clean end.

The first part is the response_body.rs change of upstream 0f232d33
(devashishdxt/tonic-web-wasm-client#90, released in 0.9.1).

Co-Authored-By: Claude <noreply@anthropic.com>
…ob for the vendored tests

trailers.patch applies on top of trailers-only.patch and reproduces src/ from
crates.io 0.8.0, apart from the test files: it carries their two cfg(test)
hooks but not src/response_body/. The vendored crate is excluded from the
workspace, so a separate job runs its tests against the workspace lock.

Co-Authored-By: Claude <noreply@anthropic.com>
Their browser OHTTP proof had already fixed it in its own patch, not only
found it.

Co-Authored-By: Claude <noreply@anthropic.com>
They found the lost trailer status, reproduced it and fixed it first in their
browser OHTTP proof (https://github.com/Crackdevs/zcash-browser-ohttp-proof).

Co-authored-by: Crackdevs <info@crackdevs.org>
Co-Authored-By: Claude <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant