fix: two-layer gzip decompression for all inbound routes#160
Conversation
|
Warning Review limit reached
More reviews will be available in 24 minutes and 53 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
8227c5c to
4639c6e
Compare
|
PR image build and manifest generation completed successfully! 📦 PR image: 🗂️ CI manifests |
Layer 1 (transport): Change GzipRequestMiddleware.DEFAULT_PATHS from
("/data/upload",) to ("*",) so gzip decompression covers all HTTP
routes including /consumer/kserve/v2. Content-type gating and
decompression bomb protection remain intact.
Layer 2 (application): Add decompress_if_gzip() for the CloudEvent
endpoint (POST /) where Knative Eventing strips the Content-Encoding
header while leaving the body gzip-compressed. Detects gzip by magic
bytes (0x1F 0x8B) and decompresses before JSON parsing, matching the
Java service's CloudEventConsumer.decompressIfGzip() fix.
Extract process_cloud_event() from the HTTP endpoint so the upload
endpoint's internal forwarding path (data_upload.py) can call it
directly without going through HTTP request parsing.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
4639c6e to
9e39299
Compare
Summary
Fixes gzip decompression for KServe inference payloads across all three inbound paths:
/data/upload(FastAPI)/consumer/kserve/v2(FastAPI)POST /) (FastAPI)Mirrors the two-layer fix from Java TrustyAI service: trustyai-explainability/trustyai-explainability#707
Problem
TrustyAI fails to parse gzip-compressed inference payloads from KServe logger sidecar with error:
The gzip magic bytes
0x1F 0x8Bare being parsed as JSON. The initial gzip middleware was scoped only to/data/upload, leaving two paths uncovered:/consumer/kserve/v2— FastAPI endpoint but outside middleware scopePOST /) — Knative Eventing bypasses standard HTTP middlewareDesign Philosophy
HTTP
Content-Encodingis a transport-layer concern, not an application-layer concern. Handling it per-endpoint creates coverage gaps — every new endpoint becomes vulnerable by default until someone remembers to add decompression.The correct approach is layered defense:
Transport layer first: Enable middleware-level decompression to handle all HTTP requests before they reach endpoint handlers
Application layer fallback: When a framework bypasses the transport layer (Knative Eventing strips
Content-Encodingheader but leaves body gzipped), add endpoint-specific decompression as a safety netThis ensures:
Solution
Two-layer fix:
Middleware layer (FastAPI endpoints):
GzipRequestMiddleware.DEFAULT_PATHSfrom("/data/upload",)to("*",)Application layer (CloudEvent endpoints):
decompress_if_gzip()utility insrc/endpoints/consumer/gzip_utils.py0x1F 0x8B)Content-Encodingheader is missingChanges
src/middleware/gzip_middleware.pyDEFAULT_PATHSto("*",)src/endpoints/consumer/gzip_utils.pysrc/endpoints/consumer/consumer_endpoint.pysrc/endpoints/data/data_upload.pytests/middleware/test_gzip_middleware_unit.pytests/endpoints/consumer/test_cloud_event_gzip.pyNet: +245 / -24 lines
Test Plan
uv run pytest tests/middleware/test_gzip_middleware_unit.py -v- All tests passuv run pytest tests/endpoints/consumer/test_cloud_event_gzip.py -v- All tests pass/data/upload,/consumer/kserve/v2,/)Content-EncodingheaderRelated
🤖 Generated with Claude Code