Skip to content

fix(cache): coordinate a compressed request mid-chunking, not 404 - #1376

Merged
kalbasit merged 2 commits into
mainfrom
fix-cdc-getnar-chunk-route
Jun 9, 2026
Merged

kalbasit merged 2 commits into
mainfrom
fix-cdc-getnar-chunk-route

Conversation

@kalbasit

@kalbasit kalbasit commented Jun 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • GetNar short-circuited to chunk-based serving for an actively-chunking NAR (via isServable), 404-ing a compressed (.nar.xz) request and skipping download coordination entirely so the cross-pod waiter never recorded a staging request.
  • Gate the short-circuit: an actively-chunking NAR (isServable && !hasFinishedNar) with a compressed request now falls through to prePullNar → coordination. Uncompressed progressive serving and finished NARs are unaffected.

Status — IMPORTANT: prerequisite, not a complete fix. Instrumented debugging shows the chunking-window e2e is still red due to a deeper lock-lifecycle design mismatch: the holder releases the download:nar lock after the decompress while CDC chunking continues in the background, so the cross-pod reader acquires the lock instead of contending — bypassing the staging-request path — and hits a third isServable site (the coordinateDownload post-lock check). Naively fixing that site would cause a re-download + double-chunk. Closing #1289 needs a holistic redesign of staging activation under CDC, not another patch; the full root cause is documented for a follow-up.

Test plan

  • task fmt / task lint / task test (race) pass — no regression
  • Multi-process e2e: the loser now reaches coordination (chunking-window still red pending the redesign)

@kalbasit

kalbasit commented Jun 8, 2026 •

Copy link
Copy Markdown
Owner Author

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Jun 8, 2026
@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@kalbasit, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 23 minutes. 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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 95f77648-f4d0-4fef-9389-6ea29a8f8f81

📥 Commits

Reviewing files that changed from the base of the PR and between 52df659 and 3b3e9e5.

📒 Files selected for processing (7)
  • openspec/changes/archive/2026-06-08-fix-cdc-getnar-chunk-route/.openspec.yaml
  • openspec/changes/archive/2026-06-08-fix-cdc-getnar-chunk-route/design.md
  • openspec/changes/archive/2026-06-08-fix-cdc-getnar-chunk-route/proposal.md
  • openspec/changes/archive/2026-06-08-fix-cdc-getnar-chunk-route/specs/inflight-nar-staging/spec.md
  • openspec/changes/archive/2026-06-08-fix-cdc-getnar-chunk-route/tasks.md
  • openspec/specs/inflight-nar-staging/spec.md
  • pkg/cache/cache.go
📝 Walkthrough

Walkthrough

This PR fixes a CDC (Change Data Capture) failure where cross-pod replicas incorrectly short-circuit compressed NAR requests to chunk-based serving during active chunking, resulting in HTTP 404 responses. The fix adds a routing guard in Cache.GetNar to gate the short-circuit on whether the NAR is finished and whether the request is compressed, ensuring compressed requests fall through to coordination and staging instead.

Changes

CDC GetNar Chunking-Window Fix

Layer / File(s) Summary
Problem Definition and Design Decision
openspec/changes/archive/2026-06-08-fix-cdc-getnar-chunk-route/proposal.md, design.md, .openspec.yaml
Proposal describes the CDC chunking-window failure mode where compressed requests incorrectly serve from chunks and receive 404. Design document specifies the gating logic decision: gate the hasNar short-circuit on whether the NAR is finished and whether the request is uncompressed, so compressed cross-pod reads fall through to coordination and can serve from staging with transcoding.
Specification Requirements for Cross-Pod Staging Serving
openspec/changes/archive/2026-06-08-fix-cdc-getnar-chunk-route/specs/inflight-nar-staging/spec.md, openspec/specs/inflight-nar-staging/spec.md
Archive spec and main spec updates define cross-pod NAR serving from in-flight staging across CDC modes. New scenarios explicitly state that during active chunking, compressed requests must not short-circuit to chunks but must instead record an in-flight staging request via coordination; uncompressed requests continue streaming progressively from chunks.
GetNar Routing Guard and Verification
pkg/cache/cache.go, openspec/changes/archive/2026-06-08-fix-cdc-getnar-chunk-route/tasks.md
Code change adds a guard in GetNar to treat compressed requests as non-servable when the NAR is actively chunking but not finished, forcing the call through prePullNar coordination. Task checklist documents the gating logic applied and multi-process acceptance criteria (loser reaches coordination; staging eventually yields complete NAR).

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly Related PRs

  • kalbasit/ncps#1353: Main PR updates Cache.GetNar routing so cross-pod "losers" fall through to prePullNar and record an in-flight staging request for compressed chunk-mismatch cases, which directly depends on #1353's holder-side pullNarIntoStore/stageInflightNar staging producer that activates when that request is recorded.
  • kalbasit/ncps#1354: Both PRs modify pkg/cache/cache.go's Cache.GetNar download/servability routing during cross-pod "active/in-flight" windows—main PR forces compressed requests (while NAR isn't finished) to fall through to coordination, while the retrieved PR extends that coordination to allow staging and serve NAR immediately from in-flight staging parts.
  • kalbasit/ncps#1361: The main PR's Cache.GetNar routing change for compressed cross-pod requests during active chunking is directly exercised/validated by the retrieved PR's new distributed e2e test InflightStagingCrossPodServe, which asserts byte-correct in-flight staging NARs returned by concurrent replicas.

Suggested Labels

bug, go, size:S, merge-stack

Poem

🐰 A chunker was caught in the compress,
Returning a 404 mess,
But now compressed requests,
Take the coordination jest,
And staging brings NAR success! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title directly addresses the main change: preventing a 404 error for compressed requests mid-chunking by forcing coordination instead of short-circuiting.
Description check ✅ Passed The description clearly explains the bug (short-circuit 404 on compressed requests), the fix (gate the short-circuit), and provides important context about deeper design issues and test results.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request addresses an issue where cross-pod readers of an actively-chunking NAR with a compressed request receive an HTTP 404 instead of entering download coordination. To resolve this, a check is added in GetNar to prevent short-circuiting to chunk-based serving when the NAR is not yet finished and the request is compressed, forcing it to fall through to coordination and serve from staging. The review feedback points out a performance optimization in this new check: calling c.hasFinishedNar performs a redundant and potentially expensive storage stat check because hasNarInStore is already computed in the local scope. The reviewer suggests checking !hasNarInStore first and querying c.HasNarInChunks directly to avoid this overhead.

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.

Comment thread pkg/cache/cache.go Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@openspec/changes/archive/2026-06-08-fix-cdc-getnar-chunk-route/design.md`:
- Around line 5-12: The fenced code block containing the Go snippet (lines
referencing hasNar, c.isServable(ctx, narURL), c.HasNarInChunks(ctx, narURL),
serveNarFromStorageViaPipe) lacks a language tag and triggers markdownlint
MD040; fix it by adding the "go" language identifier to the opening fence
(```go) so the block is treated as Go code and linting passes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f11b2b89-2e97-4303-a508-a1ad670b5eaa

📥 Commits

Reviewing files that changed from the base of the PR and between 6903097 and 52df659.

📒 Files selected for processing (7)
  • openspec/changes/archive/2026-06-08-fix-cdc-getnar-chunk-route/.openspec.yaml
  • openspec/changes/archive/2026-06-08-fix-cdc-getnar-chunk-route/design.md
  • openspec/changes/archive/2026-06-08-fix-cdc-getnar-chunk-route/proposal.md
  • openspec/changes/archive/2026-06-08-fix-cdc-getnar-chunk-route/specs/inflight-nar-staging/spec.md
  • openspec/changes/archive/2026-06-08-fix-cdc-getnar-chunk-route/tasks.md
  • openspec/specs/inflight-nar-staging/spec.md
  • pkg/cache/cache.go

@kalbasit
kalbasit force-pushed the fix-cdc-window-nonholder-404 branch from 6903097 to df1060c Compare June 9, 2026 00:10
kalbasit added a commit that referenced this pull request Jun 9, 2026
#1376)

The compressed-request gate called hasFinishedNar, repeating the
HasNarInStore stat and nar_file lookup already done by the servability
check at the top of GetNar. Call narServability once to get both
`servable` (hasNar) and `finished`, and reuse `finished` in the gate.
Also tag the design-doc code fence with a language for markdownlint.

Resolves threads PRRT_kwDONV6tZs6H_Ve-, _XSL.
@kalbasit
kalbasit force-pushed the fix-cdc-getnar-chunk-route branch from 52df659 to 5a879d7 Compare June 9, 2026 00:10
@kalbasit
kalbasit force-pushed the fix-cdc-window-nonholder-404 branch from df1060c to c16367d Compare June 9, 2026 00:16
kalbasit added a commit that referenced this pull request Jun 9, 2026
#1376)

The compressed-request gate called hasFinishedNar, repeating the
HasNarInStore stat and nar_file lookup already done by the servability
check at the top of GetNar. Call narServability once to get both
`servable` (hasNar) and `finished`, and reuse `finished` in the gate.
Also tag the design-doc code fence with a language for markdownlint.

Resolves threads PRRT_kwDONV6tZs6H_Ve-, _XSL.
@kalbasit
kalbasit force-pushed the fix-cdc-getnar-chunk-route branch from 5a879d7 to 5047344 Compare June 9, 2026 00:16
@kalbasit
kalbasit force-pushed the fix-cdc-window-nonholder-404 branch from c16367d to 32f3f06 Compare June 9, 2026 00:26
kalbasit added a commit that referenced this pull request Jun 9, 2026
#1376)

The compressed-request gate called hasFinishedNar, repeating the
HasNarInStore stat and nar_file lookup already done by the servability
check at the top of GetNar. Call narServability once to get both
`servable` (hasNar) and `finished`, and reuse `finished` in the gate.
Also tag the design-doc code fence with a language for markdownlint.

Resolves threads PRRT_kwDONV6tZs6H_Ve-, _XSL.
@kalbasit
kalbasit force-pushed the fix-cdc-getnar-chunk-route branch from 5047344 to c1ae107 Compare June 9, 2026 00:26
Base automatically changed from fix-cdc-window-nonholder-404 to main June 9, 2026 00:35
kalbasit added a commit that referenced this pull request Jun 9, 2026
## Summary

- Under eager CDC, a non-holder replica 404s a compressed NAR request:
the download-coordination poll loop early-returned a "served-by-peer"
state for an *actively-chunking* NAR because `isServable` conflates
"finished" with "actively chunking", routing to chunk serving (which
can't produce a compressed variant from decompressed chunks).
- Split a finished-only predicate `hasFinishedNar` (whole-file-in-store
OR `total_chunks>0`) out of `isServable`, threaded as `hasFinishedAsset`
through `coordinateDownload` + `pollForDownloadOrTakeOver`, and
restructured the per-tick decision into four states
(dead-holder→takeover[D5] / finished→serve / chunking+staging→staging /
chunking+no-staging→progressive).

> **Status:** a correct, regression-free **prerequisite** toward closing
the chunking-window cross-pod 404 (#1289). It does NOT fully close that
404 on its own — see the stack head (#1376) for the remaining root cause
(a CDC lock-lifecycle design mismatch).

## Test plan

- [x] `task fmt` / `task lint` / `task test` (race) pass — no regression
to progressive-chunk/takeover paths
- [x] New `hasFinishedNar` unit test

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
kalbasit and others added 2 commits June 9, 2026 00:35
…nking

Under eager CDC, a non-holder replica 404s a compressed (.nar.xz)
request while the holder chunks: GetNar's isServable check is true for
the holder's cross-pod-visible actively-chunking nar_file row, so it
short-circuits to serveNarFromStorageViaPipe -> serveFromChunks, which
cannot produce a compressed variant from decompressed chunks and returns
"only available as chunks" (404). Log evidence: the loser had zero
download-coordination lines -- it never reached prePullNar, so it never
recorded an in-flight staging request.

Gate the GetNar short-circuit: when the NAR is servable only because it
is actively chunking (isServable && !hasFinishedNar) and the request is
compressed, treat it as not-servable-here so it falls through to
prePullNar -> coordination, where a cross-pod waiter records a staging
request and (once parts exist) serves from in-flight staging, transcoding
to the requested compression. The uncompressed progressive-chunk path and
finished NARs are unaffected. Reuses hasFinishedNar from the prior change.

Verified by the contention e2e: with this gate the loser now REACHES
coordination (2 lock-acquisition lines, vs 0 before) and records a
staging request -- which also activates the prior coordination-loop fix.
Full -race suite green; no regression to uncompressed progressive serving.

This is the second of three layers. The chunking-window e2e is still red
because the CDC holder produces no staging parts despite the now-recorded
request -- a separate downstream producer defect, now investigable and
escalated to its own change.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
#1376)

The compressed-request gate called hasFinishedNar, repeating the
HasNarInStore stat and nar_file lookup already done by the servability
check at the top of GetNar. Call narServability once to get both
`servable` (hasNar) and `finished`, and reuse `finished` in the gate.
Also tag the design-doc code fence with a language for markdownlint.

Resolves threads PRRT_kwDONV6tZs6H_Ve-, _XSL.
@kalbasit
kalbasit force-pushed the fix-cdc-getnar-chunk-route branch from c1ae107 to 3b3e9e5 Compare June 9, 2026 00:35
@kalbasit
kalbasit enabled auto-merge (squash) June 9, 2026 00:36
@kalbasit
kalbasit merged commit 8eeb8d9 into main Jun 9, 2026
37 checks passed
@kalbasit
kalbasit deleted the fix-cdc-getnar-chunk-route branch June 9, 2026 00:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working merge-stack size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant