Repository navigation
feat(cache): decompress Content-Encoding on the S3 origin (#804) - #806
Conversation
The S3 origin previously rejected any non-identity Content-Encoding, while the HTTP origin transparently decodes gzip/zstd. Reuse the HTTP decode path on S3 so encoded objects decode to canonical bytes before the engine's BLAKE3 verify, with the same strict/auto DecompressMode semantics. - Extract the shared gzip/zstd decoder, encoding classification, and a new resolve_encoding policy helper into origin/decompress.rs; refactor HttpOrigin to use it (behavior unchanged). - Add a configurable `decompress` knob to the S3 origin config, wired through ResolvedS3Config and the runtime build_origin S3 arm, defaulting to Auto. Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request centralizes Content-Encoding handling by introducing a shared decompress module for both HTTP and S3 origin backends. It enables transparent decompression of gzip and zstd compressed bodies from S3 origins, mirroring the existing behavior of the HTTP origin, and exposes a decompress configuration option for S3. Since there are no review comments, I have no additional feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Pull request overview
This PR closes #804 by bringing Content-Encoding decompression parity to the S3 origin backend, matching the HTTP origin’s existing DecompressMode::{Auto, Strict} semantics so that gzip/zstd-encoded objects decode to canonical bytes before the cache engine’s BLAKE3 verification.
Changes:
- Introduces a shared
origin::decompresshelper to centralize encoding classification, strict/auto policy, and the gzip/zstd decode pipeline. - Refactors
HttpOriginto use the shared helper (intended behavior unchanged) and updatesS3Originto transparently decode gzip/zstd inAutomode while preservingStrictrejection behavior. - Wires an optional
decompressknob through config resolution and runtime origin construction; adds integration/unit tests and updates the changelog.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/node/src/runtime/mod.rs | Passes resolved S3 decompress mode into the constructed S3Origin; updates runtime tests for the new resolved field. |
| crates/common/src/config/types.rs | Adds decompress option to S3 origin config with documented semantics aligned to HTTP origin. |
| crates/common/src/config/resolved.rs | Extends ResolvedS3Config with a resolved decompress mode (default Auto). |
| crates/common/src/config/mod.rs | Wires S3 decompress through resolver, adds resolver tests, and updates existing config tests’ struct literals. |
| crates/cache/tests/s3_origin.rs | Adds S3 integration tests covering gzip/zstd decode, strict rejection, unknown encoding rejection, and identity passthrough behavior. |
| crates/cache/src/origin/s3.rs | Implements S3-side decode via shared resolve_encoding + decode_stream; adds decompress field and builder method. |
| crates/cache/src/origin/mod.rs | Exposes the new shared decompress module within the origin subsystem. |
| crates/cache/src/origin/http.rs | Refactors HTTP origin to delegate encoding policy/decoder plumbing to the shared helper. |
| crates/cache/src/origin/decompress.rs | New shared module implementing resolve_encoding and decode_stream plus unit tests for the policy table. |
| CHANGELOG.md | Updates documentation to reflect S3 Content-Encoding handling parity and the new configuration knob. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 87.12% (was 87.06%, ▲ +0.06%) — 27798/31908 lines
History
|
…alsely rejected Both the HTTP and S3 origins advertised the encoded Content-Length as size_hint for compressed bodies. When that encoded length fit under buffered_max_bytes, the engine took the buffer/drain path, whose cap (buffered_max_bytes) is applied to the *decoded* stream — falsely rejecting an in-bounds blob (decoded size between buffered_max_bytes and max_blob_bytes) as BlobTooLarge. Inert for S3 until #804 made it decompress; S3 is the common production origin, so the bug is now live. Hand None for compressed bodies so they always take the streaming path, where count_and_cap_stream checks the decoded running total against the correct max_blob_bytes. The pre-stream advertised > max_bytes short-circuit still fires first. Add S3 failure-path tests at parity with the HTTP suite, exercising the S3-specific ByteStream::into_async_read -> ReaderStream -> decode_stream seam: truncated gzip -> Permanent DecompressionFailed (no retry burned), decompression bomb -> BlobTooLarge via the decoded cap, BLAKE3 verify over decoded bytes, plus a regression test for the size_hint fix. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
alpergundogdu
left a comment
There was a problem hiding this comment.
Review: request changes
The core engineering is sound — the extraction into decompress.rs is a faithful, byte-identical move of the error-classification logic; the S3 decoded stream genuinely streams through the same count_and_cap_stream cap seam (verified: size_hint: None for compressed ⇒ never drained ⇒ engine running-total cap applies); and the bomb/truncation/verify-over-canonical cases are tested specifically on the S3 SDK body adapter. Two things to address before merge.
High — "behavior-unchanged refactor" silently changes (and fixes) the HTTP path, untested
crates/cache/src/origin/http.rs:379-394: on main, HTTP reports size_hint: advertised_len even for compressed bodies; this PR changes it to None. That is a real behavior change to a second backend, not the pure extraction the description claims. It happens to be a correct latent-bug fix — the same #804 bug (encoded length under buffered_max_bytes routes a large decoded body into the drain path, which caps at buffered_max_bytes and falsely raises BlobTooLarge) existed on HTTP too, masked because the existing HTTP test only crosses 2 MiB < 4 MiB. But the fix ships untested on HTTP — the new buffer-threshold regression test was added for S3 only.
- Please (a) call out the HTTP
size_hintchange explicitly in the PR description / CHANGELOG, and (b) add the HTTP twin ofcache_engine_s3_compressed_above_buffer_threshold_succeeds(encoded < 4 MiB, decoded ~8 MiB, < 16 MiB blob cap) topull_through.rsso the HTTP fix is pinned against regression. Optionally split the HTTP fix into its own commit.
Medium — strict-mode rejection lost its operator runbook hint
crates/cache/src/origin/s3.rs:510-515: the old reject message guided operators to "store canonical bytes or front the bucket with an HTTP CDN that strips encoding." The new UnsupportedEncoding context says what failed but not what to do, and fetch_with_strict_mode_rejects_gzip_encoding was loosened to drop the "canonical bytes" wording. Either enrich the strict-rejection context with the actionable hint (store canonical bytes / set decompress = "auto"), or confirm the runbook was updated. Lower urgency since strict is opt-in.
Backward-compat note (not a defect)
Default flips from reject-all-encoding to Auto/decompress. Safe — BLAKE3 verify runs over canonical bytes, so a mis-decode fails closed as HashMismatch — but worth one CHANGELOG sentence framing it as a default change for operators who relied on the old rejection as a guard.
…book hint Address Alper's review on #806: - High: the "behavior-unchanged" refactor also fixed a latent #804 bug on the HTTP origin (compressed size_hint advertised_len -> None). Pin it with the HTTP twin of the S3 buffer-threshold regression test, and call out the HTTP change + S3 default flip in the CHANGELOG. - Medium: restore the operator runbook hint on the S3 strict/unknown-encoding rejection (store canonical bytes, or set decompress = "auto"); re-tighten the strict-mode test to pin the wording. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Summary
Closes #804.
The S3 origin previously rejected any non-
identityContent-Encodingoutright, while the HTTP origin transparently decompresses gzip/zstd. This left a real functional gap between the two first-class origin backends — operators on S3/R2/B2 had to pre-store canonical bytes or front their bucket with an HTTP CDN that strips encoding.This PR reuses the HTTP origin's decode path on the S3 backend so encoded objects decode to canonical bytes before the engine's BLAKE3 verify runs, with the same strict/auto
DecompressModesemantics.Changes
crates/cache/src/origin/decompress.rs(pub(crate)):decode_stream— the gzip/zstd decoder sandwich, generic over the input byte stream so both backends share it.resolve_encoding— collapses identity / known / unknown / strict-rejection into a single decision.classify_encodingandtyped_decoder_error(moved out ofhttp.rs).http.rs— refactored to call the shared helper. One intentional behavior change (see "Behavior change" below): compressed responses now reportsize_hint: Noneinstead of the encodedContent-Length.s3.rs— added adecompress: DecompressModefield (defaultAuto) and awith_decompress_modebuilder; replaced the upfront encoding-reject withresolve_encoding+decode_stream.decompressflows through the wireS3OriginConfig→ResolvedS3Config→resolve_s3_origin(defaults toAuto) → runtimebuild_originS3 arm, mirroring the HTTP origin's knob.Tests
s3_origin.rsintegration tests: gzip decode, zstd decode,Strictrejects a known encoding, unknown encoding (br) → permanent error, identity passthrough.configresolver tests: S3 defaults toAuto, S3strictround-trips.decompress.rsunit tests for theresolve_encodingpolicy table.Behavior change (HTTP origin) — latent #804 bug fixed on a second backend
This is not a pure S3 extraction: the refactor also changes the HTTP origin's
size_hintfor compressed bodies from the encodedContent-LengthtoNone. That fixes a latent instance of the #804 bug that existed on HTTP too — a compressed body whose encoded length fit undercache.buffered_max_bytesbut decoded above it was routed into the buffer/drain path, whose cap (buffered_max_bytes) is applied to the decoded stream, and was falsely rejected asBlobTooLarge. ReportingNoneforces compressed bodies onto the streaming path, capped atmax_blob_bytesbycount_and_cap_stream. Pinned by a new HTTP regression test (http_origin_compressed_above_buffer_threshold_succeeds) — the twin of the S3cache_engine_s3_compressed_above_buffer_threshold_succeeds. Also called out inCHANGELOG.md.Default change (S3): the S3 backend's default flips from reject-all-
Content-Encodingtodecompress = "auto". Safe by construction (BLAKE3 verify over canonical bytes ⇒ a mis-decode fails closed as a hash mismatch), but operators who relied on the old blanket rejection should setdecompress = "strict". Documented inCHANGELOG.md.Notes
max_bytescap remains enforced by the engine'scount_and_cap_stream, so a small compressed payload that decodes to a huge blob still fails fast at the engine seam (decompression-bomb protection preserved).Content-Length > max_bytesshort-circuit on compressed bodies still fires first on both backends (an encoded length over the blob cap already implies a decoded overrun under sane ratios); only thesize_hinthanded to the engine changed.decompress = "auto"for gzip/zstd).Validation
cargo build,cargo clippy --tests,cargo fmt --check, andcargo nextest run -p decdn-cache -p decdn-common -p decdn-nodeall pass (476 + 441 tests).