Repository navigation
fix(cache): never surface purged narinfo as HTTP 500 - #1318
Conversation
A narinfo present in the database but missing its backing NAR is purged by
getNarInfoFromDatabase, which signals the internal errNarInfoPurged sentinel.
After an upstream re-pull, GetNarInfo re-read that sentinel verbatim and the
narinfo HTTP handler mapped it to a 500 ("the narinfo was purged"). Nix treats
a 500 as a hard error and aborts the build instead of falling back to its next
substituter; fsck reported 3013 such backing-less narinfos, each a permanent
500.
Why: a purge is internal cache maintenance, not a server fault. It must never
reach the client as a 500.
How: in GetNarInfo, the post-pull re-read now maps errNarInfoPurged to
storage.ErrNotFound (HTTP 404 -> Nix upstream fallback). The sentinel is
exported as cache.ErrNarInfoPurged, and the narinfo GET handler's error->status
decision is extracted into narInfoErrorStatus, which maps the sentinel (and
ErrNotFound) to 404 while writing only the generic status text, never the
internal message. Adds deterministic cache and server tests, using an
unexported context-scoped test seam to reproduce the otherwise timing-racy bug.
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 (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThis PR fixes a production issue where the internal narinfo-purge sentinel could leak to clients as HTTP 500. The fix exports the sentinel, maps it to ChangesNarinfo Purge Sentinel Resolution
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 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 prevents internal narinfo purge events from surfacing to clients as HTTP 500 errors. It exports the internal ErrNarInfoPurged sentinel, maps it to storage.ErrNotFound (HTTP 404) in both the cache layer (GetNarInfo) and the server layer's error handler, and ensures that generic status text is returned instead of leaking internal error messages. Additionally, it introduces test-only context hooks to disable NAR prefetching, allowing deterministic testing of these edge cases, and adds comprehensive unit tests. No review comments were provided, so I have no feedback 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.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
openspec/changes/archive/2026-06-03-fix-purged-narinfo-500/design.md (1)
106-109: 💤 Low valueMinor grammar issue in "Open Questions" section.
Line 108: "None blocking" is grammatically incomplete. Consider "None are blocking" or simply "None."
🤖 Prompt for 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. In `@openspec/changes/archive/2026-06-03-fix-purged-narinfo-500/design.md` around lines 106 - 109, In the "Open Questions" section replace the grammatically incomplete phrase "None blocking" with a correct form such as "None are blocking" or simply "None" by editing the text under the Open Questions header (look for the line containing "None blocking" in the document).
🤖 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/specs/narinfo-purge-serving/spec.md`:
- Around line 3-4: Replace the placeholder under the "## Purpose" header with a
complete purpose for the `narinfo-purge-serving` capability: explain that it
defines how the cache serves narinfo requests when the internal purge guard
fires (narinfo exists but backing NAR is missing and no download is in flight),
specify that purge events must not surface as HTTP 500 to clients, and state
that the system should re-fetch upstream and return HTTP 200 (if available) or
HTTP 404 (to trigger Nix substituter fallback); reference the related
capabilities `narinfo-concurrent-fetch` and `nar-cache-miss-recovery` to show
complementarity.
---
Nitpick comments:
In `@openspec/changes/archive/2026-06-03-fix-purged-narinfo-500/design.md`:
- Around line 106-109: In the "Open Questions" section replace the grammatically
incomplete phrase "None blocking" with a correct form such as "None are
blocking" or simply "None" by editing the text under the Open Questions header
(look for the line containing "None blocking" in the document).
🪄 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: 14386aa5-3be2-4efe-9c56-333af0b267bd
📒 Files selected for processing (11)
openspec/changes/archive/2026-06-03-fix-purged-narinfo-500/.openspec.yamlopenspec/changes/archive/2026-06-03-fix-purged-narinfo-500/design.mdopenspec/changes/archive/2026-06-03-fix-purged-narinfo-500/proposal.mdopenspec/changes/archive/2026-06-03-fix-purged-narinfo-500/specs/narinfo-purge-serving/spec.mdopenspec/changes/archive/2026-06-03-fix-purged-narinfo-500/tasks.mdopenspec/specs/narinfo-purge-serving/spec.mdpkg/cache/cache.gopkg/cache/purge_serving_internal_test.gopkg/server/export_test.gopkg/server/purge_serving_test.gopkg/server/server.go
The main spec was created by archiving and left a TBD Purpose placeholder. Replace it with a real Purpose describing the purge-serving contract (never 500; re-fetch and serve 200, else 404 for Nix substituter fallback) and its relation to the narinfo-concurrent-fetch and nar-cache-miss-recovery capabilities. 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
A narinfo present in the database but missing its backing NAR is purged by
getNarInfoFromDatabase, which signals the internalerrNarInfoPurgedsentinel. After an upstream re-pull,GetNarInfore-read that sentinel verbatim and the narinfo HTTP handler mapped it to HTTP 500 (the narinfo was purged). Nix treats a 500 as a hard error and aborts the build instead of falling back to its next substituter —fsckreported 3013 such backing-less narinfos, each a permanent 500.A purge is internal cache maintenance, not a server fault, so it must never reach the client as a 500.
Changes
pkg/cache/cache.go—GetNarInfo's post-pull re-read now mapserrNarInfoPurged→storage.ErrNotFound(HTTP 404 → Nix upstream fallback). The sentinel is exported ascache.ErrNarInfoPurged.pkg/server/server.go— the narinfoGETerror→status decision is extracted intonarInfoErrorStatus, mapping the sentinel (andErrNotFound) to 404 while writing only the generic status text, never the internal message.withNarPrefetchDisabled) to reproduce the otherwise timing-racy bug.Scoped to serving semantics only. Non-goals (deferred): the NAR background-download race under distributed-lock contention (root cause of missing NARs) and reconciliation of the existing orphaned-narinfo backlog.
OpenSpec capability:
narinfo-purge-serving.Test plan
task fmtcleantask lint— 0 issuestask test— all packages pass with-racencps.nasreddine.comreturns 404 (not 500) for an orphaned narinfo hash after deploy🤖 Generated with Claude Code