Repository navigation
fix(cache): don't route serve to chunks without a chunk store - #1325
Conversation
The flaky TestCacheBackends/.../RunLRUCleanupInconsistentNarInfoState failed with "chunk store not initialized, cannot serve NAR from chunks". The cause is a TOCTOU on hasInStore in GetNar: it reads HasNarInStore once, then re-evaluates servability via isServable, which performs its own fresh HasNarInStore. When the whole-file NAR lands in the store between those two checks, the first flag is stale (false) while the NAR is in fact present. serveNarFromStorageViaPipe then computed serveFromChunks := !hasInStore = true and routed an uncompressed request to getNarFromChunks, which hard-fails when no chunk store is configured. This is the inverse of #1324 (present-at-check, deleted-before-use); here it is absent-at-check, present-before-use. Gate the chunk route on isChunkStoreAvailable() so an uncompressed request is never routed to chunks when no chunk store exists; the present whole file is served and a genuine absence returns a clean ErrNotFound (cache-miss recovery and the upload-only contract are preserved). When a chunk store IS present the gate reduces to the original !hasInStore, so standard CDC and drain serving are unchanged. Adds a deterministic regression test reproducing the exact error (RED -> GREEN) and syncs the cdc-chunking spec with the new resilience requirement. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
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)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThis PR fixes a TOCTOU race in the NAR cache serving path where stale store-presence observations cause uncompressed requests to misroute to chunk serving. The fix re-gates routing on current chunk-store availability within ChangesStale HasInStore Routing Fix
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
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 addresses a flaky test failure (RunLRUCleanupInconsistentNarInfoState) caused by a time-of-check to time-of-use (TOCTOU) race condition on the hasInStore flag. When a whole-file NAR is initially observed as absent but lands in the store before being served, the stale flag previously routed uncompressed requests to the chunk store, resulting in a 'chunk store not initialized' error when no chunk store was configured. The fix gates the chunk-routing decision on chunk store availability (c.isChunkStoreAvailable()) in serveNarFromStorageViaPipe. Additionally, a new test file cdc_serve_stale_hasinstore_internal_test.go was added to deterministically reproduce and verify the fix, and relevant specifications were updated. There are no review comments to address.
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.
Summary
Fixes the flaky
TestCacheBackends/.../RunLRUCleanupInconsistentNarInfoStatefailure in CI (run 26929993682)
—
chunk store not initialized, cannot serve NAR from chunks.The root cause is a TOCTOU on
hasInStoreinGetNar. It readsHasNarInStoreonce, then re-evaluates servability viaisServable, whichperforms its own fresh
HasNarInStore. When the whole-file NAR lands in thestore between those two checks, the first flag is stale (
false) while the NARis in fact present.
serveNarFromStorageViaPipethen computedserveFromChunks := !hasInStore = trueand routed an uncompressed request togetNarFromChunks, which hard-fails when no chunk store is configured.This is the inverse of #1324 (present-at-check, deleted-before-use); here it is
absent-at-check, present-before-use.
Fix
serveFromChunks := !hasInStore && c.isChunkStoreAvailable().whole-file store: a present whole file is served; a genuine absence returns a
clean
storage.ErrNotFound, preserving cache-miss recovery and theupload-only contract.
!hasInStore, so standard CDC and drain-mode serving are byte-identical(the fix(cache): fall back to chunks when migration races serve #1324 store→chunks fallback is unchanged).
Test plan
(RED → GREEN):
pkg/cache/cdc_serve_stale_hasinstore_internal_test.goRunLRUCleanupInconsistentNarInfoStatepasses 5× under-race#1324migration-race tests still pass (no regression)task fmt,task lint(0 issues),task test, and fulltask test:auto(real Postgres/MySQL/Redis/Garage) pass
Spec
Adds the
cdc-chunkingrequirement "Serving a whole-file NAR MUST be resilientto a stale time-of-check store-presence observation" (4 scenarios), and archives
the OpenSpec change under
openspec/changes/archive/2026-06-03-fix-flaky-pg-test/.