Skip to content

serve: a request body sent gzip or deflate is read decoded; another content coding is a 415 - #1049

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-usab-gzip-request
Oct 31, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-usab-gzip-request

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

압축된 HTTP 요청 body(gzip, deflate)를 풀어서 읽고, 지원하지 않는 content coding은 415로 답합니다.

What and why

A client that sends Content-Encoding: gzip or deflate today gets a 400 "invalid JSON body", because the server parses the compressed bytes as JSON. This PR decodes such a body in the shared HTTP body stage (http::read_body) before any route reads it, so the generation server and the decision server both accept it.

  • gzip (also x-gzip, including several members) and deflate (a zlib stream) are decoded.
  • The existing 64 MiB body limit holds for the bytes sent and again for the decoded body, and decoding stops one byte past it.
  • Any other coding (br, zstd) or a list of two or more is a 415 with Accept-Encoding: gzip, deflate, answered from the head before 100 Continue.
  • A body that does not decode, or has bytes after its stream, is a 400 that names the coding.
  • A request with no body is read as sent, so a client that attaches the header to every request still works.

docs/serving.md lists the new behavior. flate2 is already linked into bloomery-serve through bloomery-vision, so the PR adds no new crate to the build.

Release notes: Added: the server reads gzip and deflate encoded request bodies and answers any other content coding with a 415.

Code shape

The review reads these first. A box left unticked needs one line of why.

  • No second copy. Logic two models (or two call sites) share has one common owner; I lifted it there instead of
    copying it (AGENTS.md "Common code first", docs/rust-quality.md R14). Where I found an existing copy, I
    named it below.
  • Model code holds only architecture facts. A model's own files carry only what its architecture forces
    (tensor shapes, the attention kind, the quant). A common owner gained no per-model branch, flag or trait method.
  • Dead code is gone. Nothing I made unused is left behind (functions, flags, gate clauses, docs).
  • No silent failure. Undefined input is a named error or panic, never a defined-looking output.
  • Comments state what is true now. No dates, issue numbers or how a bug was found (tools/check-comments.sh).
  • No relaxed gate. No band, tolerance or lint moves, and no existing test is edited.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up.

Duplication found or removed (path:line), or "none": none. Nothing else in crates/ decoded a request body or read Content-Encoding.

What I ran

The new test api::tests::compressed_request_bodies_are_read_decoded covers gzip, a multi-member gzip, chunked gzip, deflate, the limit exactly and one byte past it for both codings, trailing bytes, an undecodable body, br, a coding list, and a bodiless request with a Content-Encoding header.

Before the change (new test on the base server code):

$ cargo test -p bloomery-serve --lib compressed_request_bodies
assertion `left == right` failed: gzip
  left: (400, "{\"error\":{\"code\":400,\"message\":\"invalid JSON body: expected value at line 1 column 1\",\"type\":\"invalid_request_error\"}}")
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 474 filtered out

After the change, the serve library and integration tests:

$ bash tools/gate.sh -p bloomery-serve --lib --test serve -- --include-ignored
test api::tests::compressed_request_bodies_are_read_decoded ... ok
test result: ok. 475 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 111 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

The limit check is guarded from both sides: with decoded.len() > MAX_BODY changed to >=, the test fails on the row that decodes to exactly 64 MiB with gzip: body too large: the gzip body decodes past the limit of 67108864 bytes (64 MiB).

Real binary on a DGX Spark (GB10, driver 595.84, CUDA 13.3), bloomery-serve 0.3.11, model nvidia/Qwen3.8-Flash-Next-FP4-Local at b9ce18a6887e18c089fdea8509a33e63429a3300, started with -m <model folder> --ctx-size 2048. The same chat request is sent plain, gzip and deflate, then three bad requests, then a plain request again:

POST /v1/chat/completions Content-Encoding: None    sent 110 bytes -> 200
POST /v1/chat/completions Content-Encoding: gzip    sent 112 bytes -> 200
POST /v1/chat/completions Content-Encoding: deflate sent 100 bytes -> 200
ANSWERS {"None": [55, ""], "gzip": [55, ""], "deflate": [55, ""]}
POST ... Content-Encoding: br      -> 415 Accept-Encoding: gzip, deflate  "unsupported content-encoding \"br\": the server reads a body in one coding, gzip, deflate or identity"
POST ... Content-Encoding: gzip    (uncompressed JSON) -> 400 "the body does not decode as gzip: invalid gzip header"
POST ... Content-Encoding: deflate (stream plus 2 bytes) -> 400 "2 bytes follow the body's deflate stream"
POST ... plain -> 200
GZIP-REQUEST PASS

ANSWERS lists the prompt token count (55 for all three) and the visible content. The 16 generated ids all fall inside the reasoning span, so the content is empty and the reasoning text is the same in all three answers.

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

…ontent coding is a 415

A body with Content-Encoding gzip (or x-gzip) or deflate is decoded before any route reads it, on the generative and decision servers alike. The 64 MiB body limit holds for the bytes sent and again for the decoded body, and decoding stops one byte past it. A body that does not decode, or carries bytes after its stream, is a 400 invalid_request_error that names the coding. Any other coding, or a list of two or more, is a 415 whose Accept-Encoding header names gzip, deflate; it is answered from the head, before 100 Continue. A request that frames no body reads as sent. The decoder is flate2, which the vision crate's PNG reader already links.
@github-actions github-actions Bot added documentation Improvements or additions to documentation serve The HTTP server: crates/serve labels Oct 31, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: CLEAN: Request decoding is bounded, malformed bodies return named errors, and unsupported codings are rejected before body reads.

Checked

Duplicates: 5 new functions, types and constants checked; no duplicate owner found. Dryer reported no pairs.
Complexity: read_body rose 16→21 through coding validation and decode dispatch; keep_alive rose 24→26 through the additional error-status arm. Both keep HTTP policy in its existing owner.
Silent failure: 4 refusal paths followed. Unsupported coding returns 415; decoding, decoded-size and trailing-byte failures return named 400 errors.
Tests: mutation review, not executed. Dropping decoding at http.rs:278, changing > to >= at line 342, or dropping the trailing-byte check at line 348 breaks the new assertions. Unsupported-coding assertions also reject an early 100 Continue. The PR includes FAIL-first output.
Gates: no existing gate, threshold or pin changed.
Escape catalog: no patterns matched.
Adversarial checks: decoded overflow, malformed/trailing streams, repeated coding headers and pipelined-request framing checked against the guards and assertions. Decoding uses only the framed body and request-local state.

Notes

Tests were not rerun. The reported card run lacks the required nvidia-smi line, both compared commit hashes and just gate-* output.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit 27533de into midagedev:main Oct 31, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation serve The HTTP server: crates/serve

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant