Repository navigation
feat(cache): prefer staging over progressive chunks - #1355
Conversation
|
This change is part of the following stack:
Change managed by git-spice. |
|
Warning Review limit reached
More reviews will be available in 6 minutes and 38 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe PR adds early-exit logic to ChangesIn-flight staging precedence during chunking window
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
Code Review
This pull request modifies the NAR retrieval logic to prefer serving from in-flight staging over progressive chunk streaming during the chunking window (when totalChunks == 0), and adds corresponding unit tests. A critical review comment highlights that TransparentZstd is not cleared when serving from staging, which could lead to protocol or decoding errors at the client, and suggests explicitly setting it to false before returning.
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.
|
Documentation Updates 1 document(s) were updated by changes in this PR: NAR File Download and StreamingView Changes@@ -104,6 +104,8 @@
**Part availability detection**: On each 200ms poll tick, the waiter checks `stagingServeReady` to determine if parts are available. Once `parts_available > 0`, the function returns a staging directive (`downloadState.stagingServe`) instead of continuing to wait for the whole download.
**Streaming from staging parts**: When `GetNar` receives a staging directive, it calls `serveNarFromStaging` to stream the NAR from staging part-objects rather than storage. The implementation creates a `stagingPartReader` that tails part-objects in order, polling `staging_state.parts_available` every 200ms and blocking until each part is durably available.
+
+**Precedence during the chunking window**: When `total_chunks == 0` (actively chunking state), `getNarFromChunks` first checks for in-flight staging parts if staging is enabled. If staging parts are available, it serves the complete NAR from them instead of entering the progressive chunk streaming path (`streamProgressiveChunks`). This precedence improves reliability: staged whole-NAR parts are a complete, ordered representation, so serving from them avoids the fragile progressive reassembly that can truncate. This precedence is strictly scoped to the chunking window—when `total_chunks > 0` (steady-state chunk serving), the new branch is not reached and behavior is unchanged. When serving from staging in this path, the `TransparentZstd` flag is cleared because `serveNarFromStaging` sets the compression based on what's actually in staging. If no staging parts are available, the system falls back to the progressive-chunk path as before.
**Transcoding support**: The reader transcodes if needed—for example, decompressing staged bytes when the client requests uncompressed data—at parity with the same-pod streaming path. The returned `narURL.Compression` advertises the compression actually served.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
1c37969 to
cdfc03f
Compare
Address review feedback on PR #1355 (thread PRRT_kwDONV6tZs6Hr3B-): when the chunking-window path prefers in-flight staging, clear narURL.TransparentZstd before serveNarFromStaging. serveNarFromStaging sets narURL.Compression to the bytes it actually serves (decompressing staged compression on the fly when the client wants none), so leaving TransparentZstd=true would mislead the HTTP layer into expecting a zstd stream and corrupt the response. Co-Authored-By: Claude Opus 4.8 <[email protected]>
4428ac9 to
e313438
Compare
cdfc03f to
891de62
Compare
Address review feedback on PR #1355 (thread PRRT_kwDONV6tZs6Hr3B-): when the chunking-window path prefers in-flight staging, clear narURL.TransparentZstd before serveNarFromStaging. serveNarFromStaging sets narURL.Compression to the bytes it actually serves (decompressing staged compression on the fly when the client wants none), so leaving TransparentZstd=true would mislead the HTTP layer into expecting a zstd stream and corrupt the response. Co-Authored-By: Claude Opus 4.8 <[email protected]>
e313438 to
f51b255
Compare
891de62 to
e9b0c73
Compare
Address review feedback on PR #1355 (thread PRRT_kwDONV6tZs6Hr3B-): when the chunking-window path prefers in-flight staging, clear narURL.TransparentZstd before serveNarFromStaging. serveNarFromStaging sets narURL.Compression to the bytes it actually serves (decompressing staged compression on the fly when the client wants none), so leaving TransparentZstd=true would mislead the HTTP layer into expecting a zstd stream and corrupt the response. Co-Authored-By: Claude Opus 4.8 <[email protected]>
f51b255 to
2761b54
Compare
e9b0c73 to
1926202
Compare
Address review feedback on PR #1355 (thread PRRT_kwDONV6tZs6Hr3B-): when the chunking-window path prefers in-flight staging, clear narURL.TransparentZstd before serveNarFromStaging. serveNarFromStaging sets narURL.Compression to the bytes it actually serves (decompressing staged compression on the fly when the client wants none), so leaving TransparentZstd=true would mislead the HTTP layer into expecting a zstd stream and corrupt the response. Co-Authored-By: Claude Opus 4.8 <[email protected]>
2761b54 to
b09e53e
Compare
1926202 to
bf7af11
Compare
Address review feedback on PR #1355 (thread PRRT_kwDONV6tZs6Hr3B-): when the chunking-window path prefers in-flight staging, clear narURL.TransparentZstd before serveNarFromStaging. serveNarFromStaging sets narURL.Compression to the bytes it actually serves (decompressing staged compression on the fly when the client wants none), so leaving TransparentZstd=true would mislead the HTTP layer into expecting a zstd stream and corrupt the response. Co-Authored-By: Claude Opus 4.8 <[email protected]>
b09e53e to
1d3c1d2
Compare
Read-path precedence for in-flight staging during the eager-CDC chunking window (#1289, group 7). getNarFromChunks now, when total_chunks == 0 and staging is enabled, checks for available staging parts and serves the complete whole-NAR representation from them instead of entering streamProgressiveChunks. The staged parts are an ordered, complete copy, so this avoids the fragile progressive reassembly that can truncate. The precedence is strictly scoped to the chunking window: total_chunks > 0 never reaches the branch, so steady-state chunk serving is unchanged, and when no staging parts are present the progressive path remains the fallback. The shared putStagingParts test helper now takes the NarStore interface so the precedence tests can stage via c.narStore.
Address review feedback on PR #1355 (thread PRRT_kwDONV6tZs6Hr3B-): when the chunking-window path prefers in-flight staging, clear narURL.TransparentZstd before serveNarFromStaging. serveNarFromStaging sets narURL.Compression to the bytes it actually serves (decompressing staged compression on the fly when the client wants none), so leaving TransparentZstd=true would mislead the HTTP layer into expecting a zstd stream and corrupt the response. Co-Authored-By: Claude Opus 4.8 <[email protected]>
1d3c1d2 to
1fb88f8
Compare
…#1386) ## Summary The `staging-contention` e2e's chunking window surfaced a real ncps gap: in-flight NAR staging — documented (#1355/#1374/#1375/#1379, CHANGELOG) as serving cross-pod reads during the eager-CDC chunking window and *"superseding the fragile progressive-chunk reassembly"* — **never actually engaged** for the **uncompressed `.nar`** request, which (since predictive-`none`, #1380) is the *only* request clients make in that window. The cross-pod reader served progressive chunks with zero contention and zero staging. #1379 itself flagged this as unit-verified but with "no green end-to-end run yet." This PR closes the gap (ncps fix), then makes the e2e assert the now-correct behavior. ### Root cause — two read-path sites - **`GetNar` routing (`cache.go:~1320`):** the fall-through to download coordination (the only path that records a staging request) was gated `Compression != none`, so the uncompressed read short-circuited to progressive chunk serving and never contended. - **`pollForDownloadOrTakeOver` state (D) (`cache.go:~6815`):** even once coordinating, an actively-chunking NAR with no staging parts *yet* immediately returned "served-by-peer → progressive," pre-empting staging on an early tick. ### Fix (both gated on `InflightStagingEnabled()`) - Route uncompressed actively-chunking cross-pod reads through coordination (new `shouldCoordinateInflight` predicate) so they record a staging request and serve from staging. - State (D) now waits, bounded (`maxStagingWaitTicks`), for staging parts so the staging serve wins, before falling back to progressive chunks (safety net for a stalled producer). - Unchanged for: staging disabled, lazy CDC, single-replica/same-pod, finished NARs. ### Harness + docs - `staging-contention` chunking window now asserts **staging activation** (with a bounded clean-restart retry — addresses the earlier CodeRabbit review), reverting the interim progressive-chunk assertion. - Corrected the CHANGELOG (the prior entry described intended-but-unverified behavior) and synced the `inflight-nar-staging` + `unified-e2e-harness` specs. ## Verification - [x] `go test -race ./pkg/cache/` green; full `task test` green — no regression - [x] New `pkg/cache` internal tests (red→green) for both sites + the staging-disabled / stalled-producer guards - [x] `task test:e2e ... staging-contention`: **both** windows activate in-flight staging, twice (determinism). Chunking-window race **143s → 4.5s** as staging replaces progressive reassembly. - [x] `task fmt` / `task lint` clean; `openspec validate --all` 41/0 > Note: the first commit on this branch was the interim harness-only change; this PR's net diff is the ncps fix + the staging-activation assertion. --------- Co-authored-by: Claude Opus 4.8 <[email protected]>
Read-path precedence for in-flight staging during the eager-CDC chunking
window (#1289, group 7). getNarFromChunks now, when total_chunks == 0 and
staging is enabled, checks for available staging parts and serves the
complete whole-NAR representation from them instead of entering
streamProgressiveChunks. The staged parts are an ordered, complete copy, so
this avoids the fragile progressive reassembly that can truncate.
The precedence is strictly scoped to the chunking window: total_chunks > 0
never reaches the branch, so steady-state chunk serving is unchanged, and
when no staging parts are present the progressive path remains the fallback.
The shared putStagingParts test helper now takes the NarStore interface so the
precedence tests can stage via c.narStore.