Repository navigation
fix(cache): serve whole-file NAR with its true compression under CDC - #1346
Conversation
|
This change is part of the following stack:
Change managed by git-spice. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
✅ Files skipped from review due to trivial changes (3)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughFixes a bug where getNarFromStore could relabel a served whole-file NAR’s compression from a CDC-first DB row during lazy-chunking. The change queries the nar_file matching the served representation, stops mutating narURL.Compression from mismatched rows, updates LRU touch behavior, and adds a regression test for xz-vs-none coexistence. ChangesCDC Whole-File NAR Compression Correctness
Sequence DiagramsequenceDiagram
participant Client
participant GetNar
participant WholeFileStore
participant CDC_Database
Client->>GetNar: Request NAR (narURL)
GetNar->>WholeFileStore: Open bytes for requested representation (compression=xz/none)
GetNar->>CDC_Database: (may) query nar_file rows
Note over GetNar: BEFORE: used CDC-first row compression to relabel response\nAFTER: use compression of opened bytes
GetNar->>Client: Respond with compression matching opened bytes + streamed bytes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
Code Review
This pull request fixes a bug where serving a pre-existing whole-file xz NAR during the lazy-chunking transition window mislabels the response compression as 'none' due to a CDC-first database lookup. The fix ensures that the whole-file serve path in getNarFromStore queries the database for the exact representation being served and removes the incorrect compression overwrite. A comprehensive regression test has been added to verify this behavior. The review feedback suggests a minor optimization in the new test file to handle compressed xz bytes as []byte instead of string to avoid unnecessary allocations and conversions.
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.
getNarFromStore streams the raw bytes of the whole file it opened (e.g. xz), but then overwrote narURL.Compression with the compression of the record returned by getNarFileFromDB, which is CDC-first and returns the coexisting chunked compression=none row during the lazy-chunking transition window. The response then advertised Compression:none while the body was raw xz, with Content-Length set to the xz size (< NarSize), so nix failed with 'NAR is incomplete' / 'input compression not recognized'. This deterministically broke the enable-CDC-on-an-existing- whole-file-cache upgrade path. Query the nar_file row for the representation actually being served (hash + served compression + query) instead of the CDC-first lookup, and stop overwriting narURL.Compression. The served compression now matches the streamed bytes; the last_accessed_at touch targets the served row. This is the NAR-serve counterpart to the narinfo-side normalization in maybeCDCNormalizeNarInfoURL (#1332). Caught by the new CDC lifecycle e2e (dev-scripts/test-cdc-lifecycle-e2e.py). Includes a pkg/cache regression test and the OpenSpec change artifacts. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…nar-serve Add the 'GetNar MUST advertise the compression of the bytes it serves' requirement to openspec/specs/cdc-chunking and archive the completed change. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Address PR #1346 review (gemini-code-assist): handle the compressed xz bytes as []byte rather than string and read them via bytes.NewReader, following Go conventions for binary data. Drops the now-unused strings import. Threads: PRRT_kwDONV6tZs6HofRB, PRRT_kwDONV6tZs6HofRC Co-Authored-By: Claude Opus 4.8 <[email protected]>
03c55ce to
7c713f8
Compare
…on (#1348) ## Summary Adds end-to-end test infrastructure for the full CDC lifecycle (successor to `test-migration-e2e.py`): - **Local driver** `dev-scripts/test-cdc-lifecycle-e2e.py` + `task test:cdc-lifecycle` (auto-wrapper brings up the fixed-port `nix run .#deps` stack). Drives non-CDC -> CDC (eager+lazy) -> drain -> non-CDC by restarting ncps, asserting DB + serving invariants per phase plus cross-cutting checks (upload presence; fsck no-data-loss). - **k8s-tests permutation** `ha-s3-postgres-cdc-lifecycle` (`nix/k8s-tests`) gated on a `cdc-lifecycle` marker, with a `_test_cdc_lifecycle` phase script (ConfigMap CDC flip + rollout restart; in-pod `migrate-chunks-to-nar`). This driver **caught the CDC serving bug** fixed below it in the stack (#1346); after that fix the full lifecycle passes end-to-end. Depends on the image fix (#stacked) for in-cluster pod start. ## Test plan - [x] Local lifecycle e2e PASSES end-to-end (Phases 0-4 + cross-cutting), deterministic - [x] `task fmt`/`lint`/`test` green; k8s permutation generates/lists/installs - [ ] Full in-cluster k8s lifecycle run (now unblocked by the image fix) — in progress - [ ] OpenSpec change `cdc-lifecycle-e2e-tests` archived before merge (6.2/6.3 + in-cluster run pending) --------- Co-authored-by: Claude Opus 4.8 <[email protected]>
## Summary The `[Unreleased]` section was populated in #1309 but skewed toward the recent CDC-drain, in-flight-staging, and Ent-migration work, omitting several user-facing features and fixes that also landed since v0.9.4. This backfills the missing notable changes, each cross-referenced by PR. **Added** - `ncps fsck` command + Helm fsck CronJob (#975, #996, #998, #999, #1000, #1004, #1006, #1176) - Closure pinning HTTP endpoints `POST`/`DELETE /pin/{hash}.narinfo`, `GET /pins` (#1108) - pprof server via `--pprof-addr` (#1063) - CDC lazy chunking as a feature + `--cache-cdc-lazy-cleanup-schedule` + recovery cron (#1082, #1083, #1089, #1096) - Helm: auto `GOMEMLIMIT` (#1061), configurable temp volume / `volumeClaimTemplate` (#1074, #1077), SQLite `Recreate` strategy (#1012) - Startup storage reporting + deprecated-narinfo warning (#959, #961) - `docker-dev` image (#1097) **Fixed** - `store/tmp` no longer wiped on startup (#1313) - `nix-hash` NAR verification (#1101) - Prometheus counters primed at startup (#1337, #1343) - 404 on un-reassemblable chunked NARs (#1319), purged narinfo no longer 500 (#1318), fail-fast tmp validation (#1086) - Further CDC/cache reliability fixes (#1317, #1346, #1341, #1342, #1331, #1347) **Changed** - CDC config now persisted in the DB config table (#971) Dependency bumps, CI/test-only changes, and the internal Ent-conversion PRs are intentionally excluded; the existing Ent-migration entry already covers that work. ## Test plan - [x] `nix fmt` reports no changes (docs-only edit) - [x] CHANGELOG section structure intact (Added/Fixed/Changed/Removed/Migration/CI)
Summary
getNarFromStorestreams the raw bytes of the whole file it opened (e.g.xz), but then overwrotenarURL.Compressionwith the compression of the record returned bygetNarFileFromDB, which is CDC-first and returns the coexisting chunkedcompression=nonerow during the lazy-chunking transition window. The response then advertisedCompression: nonewhile the body was raw xz, withContent-Lengthset to the xz size (<NarSize), sonixfailed with:error: NAR for '…' fetched from … is incompleteerror: input compression not recognizedThis deterministically broke the enable-CDC-on-an-existing-whole-file-cache upgrade path. It is the NAR-serve counterpart to the narinfo-side normalization already done in
maybeCDCNormalizeNarInfoURL(#1332).Fix
Query the
nar_filerow for the representation actually being served (hash + served compression + query) instead of the CDC-first lookup, and stop overwritingnarURL.Compression. The served compression now matches the streamed bytes; thelast_accessed_attouch targets the served row.Adds a
pkg/cacheregression test (TestCDCWholeFileServeReportsServedCompression) and the OpenSpec changefix-cdc-incomplete-nar-serve(adds acdc-chunkingrequirement: GetNar must advertise the compression of the bytes it serves).Test plan
none, short length) and passes aftertask fmt,task lint, fulltask testgreen