Repository navigation
fix(cache): match unlinked prefixed narinfo URLs hash-aware - #1342
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 (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe PR fixes de-chunking logic to recover unlinked nix-serve-style prefixed narinfo URLs by replacing simple string-prefix matching with hash-aware URL normalization. Three call sites are updated to use new helpers that parse, normalize, and hash-compare narinfo URLs, enabling verification of unlinked narinfos and preventing 404s when serving normalized NARs. ChangesUnlinked narinfo de-chunk recovery via hash-aware URL matching
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 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. ✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces a hash-aware URL matching mechanism to resolve and normalize unlinked narinfos with nix-serve-style prefixed URLs during de-chunking. The changes replace raw prefix matching with a robust helper that parses and normalizes URLs to extract the embedded NAR hash, updating three key sites in pkg/cache/cache.go (MigrateChunksToNar, NormalizeChunkedNarInfoURL, and LinkedNarinfoNarHash). Comprehensive unit tests have been added to verify these scenarios, and the corresponding specifications have been updated. There are no review comments, so I have no feedback to provide.
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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
openspec/specs/chunks-to-nar-migration/spec.md (1)
141-169:⚠️ Potential issue | 🟠 Major | ⚡ Quick winResolve normative conflict: “skip de-chunk” vs “must drive chunked count to zero.”
This section now requires skipping de-chunk when no linked/hash-matched narinfo exists, but the same canonical spec already requires that a full pass must not leave chunked rows and must purge un-verifiable NARs (see Line 191 and Line 201+). Please align these requirements to one behavior to avoid implementation ambiguity.
🤖 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/specs/chunks-to-nar-migration/spec.md` around lines 141 - 169, The spec has a normative conflict between "skip de-chunk when no linked/hash-matched narinfo exists" and the other requirement that a full pass "must not leave chunked rows / purge un-verifiable NARs"; pick one canonical behavior and make the text for MigrateChunksToNar and all scenarios consistent with that choice. Concretely: decide whether MigrateChunksToNar will (A) skip de-chunking if no verification NarHash is found (leaving nar_file.total_chunks > 0) or (B) treat missing verification as grounds to purge/truncate the nar_file (drive total_chunks to 0); then update the narrative, the three scenarios (the two positive de-chunk scenarios and the "no match" scenario), and any overarching requirement paragraphs so that mentions of MigrateChunksToNar, nar_file, narinfo_nar_files, and NarHash all reflect the single chosen policy.
🤖 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.
Outside diff comments:
In `@openspec/specs/chunks-to-nar-migration/spec.md`:
- Around line 141-169: The spec has a normative conflict between "skip de-chunk
when no linked/hash-matched narinfo exists" and the other requirement that a
full pass "must not leave chunked rows / purge un-verifiable NARs"; pick one
canonical behavior and make the text for MigrateChunksToNar and all scenarios
consistent with that choice. Concretely: decide whether MigrateChunksToNar will
(A) skip de-chunking if no verification NarHash is found (leaving
nar_file.total_chunks > 0) or (B) treat missing verification as grounds to
purge/truncate the nar_file (drive total_chunks to 0); then update the
narrative, the three scenarios (the two positive de-chunk scenarios and the "no
match" scenario), and any overarching requirement paragraphs so that mentions of
MigrateChunksToNar, nar_file, narinfo_nar_files, and NarHash all reflect the
single chosen policy.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 385ee8b0-de4d-4db5-9a4d-27b2dde30904
📒 Files selected for processing (8)
openspec/changes/archive/2026-06-06-fix-dechunk-unlinked-narinfo-url-match/.openspec.yamlopenspec/changes/archive/2026-06-06-fix-dechunk-unlinked-narinfo-url-match/design.mdopenspec/changes/archive/2026-06-06-fix-dechunk-unlinked-narinfo-url-match/proposal.mdopenspec/changes/archive/2026-06-06-fix-dechunk-unlinked-narinfo-url-match/specs/chunks-to-nar-migration/spec.mdopenspec/changes/archive/2026-06-06-fix-dechunk-unlinked-narinfo-url-match/tasks.mdopenspec/specs/chunks-to-nar-migration/spec.mdpkg/cache/cache.gopkg/cache/migrate_chunks_to_nar_test.go
The de-chunk path located narinfos referencing a NAR with a raw
URLHasPrefix("nar/"+hash+".") fallback. That only matches canonical
nar/<hash>... URLs, so a nix-serve-style prefixed URL
(nar/<narinfoHash>-<hash>.nar.xz) on an unlinked narinfo (a known race
drops the join row) matched neither the join link nor the prefix. Such
narinfos were left unnormalized after de-chunk (later serve 404s) and
their NarHash could not be resolved (NAR purged / drain stuck).
Match hash-aware instead: narrow candidates in SQL via
URLContains(hash), then confirm in Go with ParseURL+Normalize so the
embedded hash (prefix stripped) equals the target. A shared
normalizedURLHash helper backs all three sites (LinkedNarinfoNarHash,
MigrateChunksToNar, NormalizeChunkedNarInfoURL); the join link stays the
primary match. Surfaced by CodeRabbit review on PR #1331.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
6665c84 to
1e9fd16
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
openspec/specs/chunks-to-nar-migration/spec.md (1)
141-169:⚠️ Potential issue | 🟠 Major | ⚡ Quick winConflicting normative behavior: “skip” here contradicts later “purge, not skipped” requirements.
This section says the system SHALL skip de-chunking when no narinfo is found, but Line 191 and the scenarios at Lines 201-207 require unverifiable chunked NARs to be purged so chunked count reaches zero. Please reconcile these requirements (either skip-or-purge) to avoid contradictory implementation/test behavior.
🤖 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/specs/chunks-to-nar-migration/spec.md` around lines 141 - 169, The spec contains conflicting requirements about unverifiable chunked NARs: update MigrateChunksToNar behavior so it's consistent (choose either skip or purge) and make all scenarios and normative language match that choice; specifically, decide whether a nar_file with total_chunks>0 and no narinfo_nar_files link and no hash-matched narinfo should be (a) skipped (no truncation/deletion) or (b) purged/truncated to total_chunks=0 without verification, then modify the narrative and all occurrences of "SHALL" / scenario outcomes to reflect the chosen policy for resolving NarHash and handling unverifiable chunks (referencing MigrateChunksToNar, nar_file, narinfo_nar_files, NarHash).
🤖 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 `@pkg/cache/cache.go`:
- Around line 8769-8796: narInfoIDsByNormalizedHash currently only verifies
normalizedURLHash(*ni.URL) == narHash which ignores the normalized URL's query
component and allows different-query variants to be returned and later
rewritten; change the function to compute the full normalized URL (including
query) for each candidate using the same normalizer used elsewhere (the code
that produces noneURL.String()/NormalizeChunkedNarInfoURL) and compare both the
normalized hash and the normalized query (or compare the complete normalized URL
string) before appending ni.ID, or alternatively change the function signature
to accept the full target nar URL and match against that exact normalized URL;
update narInfoIDsByNormalizedHash and the call sites (e.g.,
MigrateChunksToNar/NormalizeChunkedNarInfoURL) to use the stricter match so
different-query variants are not mixed.
---
Outside diff comments:
In `@openspec/specs/chunks-to-nar-migration/spec.md`:
- Around line 141-169: The spec contains conflicting requirements about
unverifiable chunked NARs: update MigrateChunksToNar behavior so it's consistent
(choose either skip or purge) and make all scenarios and normative language
match that choice; specifically, decide whether a nar_file with total_chunks>0
and no narinfo_nar_files link and no hash-matched narinfo should be (a) skipped
(no truncation/deletion) or (b) purged/truncated to total_chunks=0 without
verification, then modify the narrative and all occurrences of "SHALL" /
scenario outcomes to reflect the chosen policy for resolving NarHash and
handling unverifiable chunks (referencing MigrateChunksToNar, nar_file,
narinfo_nar_files, NarHash).
🪄 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: 15f402a1-7cd4-41c3-9756-a0d028459b87
📒 Files selected for processing (8)
openspec/changes/archive/2026-06-06-fix-dechunk-unlinked-narinfo-url-match/.openspec.yamlopenspec/changes/archive/2026-06-06-fix-dechunk-unlinked-narinfo-url-match/design.mdopenspec/changes/archive/2026-06-06-fix-dechunk-unlinked-narinfo-url-match/proposal.mdopenspec/changes/archive/2026-06-06-fix-dechunk-unlinked-narinfo-url-match/specs/chunks-to-nar-migration/spec.mdopenspec/changes/archive/2026-06-06-fix-dechunk-unlinked-narinfo-url-match/tasks.mdopenspec/specs/chunks-to-nar-migration/spec.mdpkg/cache/cache.gopkg/cache/migrate_chunks_to_nar_test.go
✅ Files skipped from review due to trivial changes (2)
- openspec/changes/archive/2026-06-06-fix-dechunk-unlinked-narinfo-url-match/.openspec.yaml
- openspec/changes/archive/2026-06-06-fix-dechunk-unlinked-narinfo-url-match/tasks.md
🚧 Files skipped from review as they are similar to previous changes (1)
- pkg/cache/migrate_chunks_to_nar_test.go
Addresses CodeRabbit review on #1342. narInfoIDsByNormalizedHash matched referencing narinfos by NAR hash only, but nar_file rows are keyed by (hash, compression, query). A narinfo whose URL normalized to the same hash with a DIFFERENT query was pulled into the rewrite set, so de-chunk normalization clobbered that distinct variant's URL (losing its query). Match on the normalized hash AND query: normalizedURL now returns the full normalized nar.URL, and the renamed narInfoIDsByNormalizedURL takes the target nar.URL (the de-chunk noneURL) and compares both. The verification-NarHash resolver (LinkedNarinfoNarHash) keeps its hash-only match: the content hash is query-invariant and de-chunk content-verifies. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Addressed CodeRabbit's findings on this PR: ✅ Fixed (inline) — ⏭️ Out of scope (outside-diff) — spec normative conflict at |
Address review on #1344: use the unhyphenated "unverifiable" in the reworded scenario title (matching the rest of the spec and the proposal), and reconcile the cache.go / migrate_chunks_to_nar.go line references so proposal.md, design.md, and tasks.md all cite the same authoritative ranges (cache.go:8398-8408, migrate_chunks_to_nar.go:419-462) — the positions shifted when #1342 merged. Co-Authored-By: Claude Opus 4.8 <[email protected]>
## Summary The `chunks-to-nar-migration` spec read as self-contradictory: one requirement said an unverifiable chunked NAR is **skipped** and not deleted, while another said the de-chunk pass **purges** unverifiable NARs to drive the chunked count to zero. CodeRabbit flagged the ambiguity on #1342. Tracing the code shows **no behavioral conflict** — only two layers the spec failed to distinguish: - The single `MigrateChunksToNar` operation is verified-or-nothing: when it cannot resolve a NarHash it signals `ErrNoNarHashToVerify` and **leaves the NAR chunked**, never deleting it (`pkg/cache/cache.go:8398-8408`). - The batch pass **purges** what the operation declined to de-chunk, driving the chunked count to zero — and leaves the NAR chunked only on context cancellation (`pkg/ncps/migrate_chunks_to_nar.go:419-462`). This reconciles the spec by making the operation-vs-pass layering explicit in both requirements and the affected scenarios. **Spec-only — no code change** (the implementation already matches the documented policy). ## Test plan - [x] `openspec validate chunks-to-nar-migration` passes - [x] No code change; behavior unchanged (verified against `MigrateChunksToNar` and the batch driver) --------- 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
The de-chunk path located narinfos referencing a NAR with a raw
URLHasPrefix("nar/"+hash+".")fallback. That only matches canonicalnar/<hash>...URLs, so a nix-serve-style prefixed URL (nar/<narinfoHash>-<hash>.nar.xz) on an unlinked narinfo (a known race drops thenarinfo_nar_filesjoin row) matched neither the join link nor the prefix. Such narinfos were left unnormalized after de-chunk (a later serve 404s) and their verificationNarHashcould not be resolved (NAR purged / drain stuck).This matches hash-aware instead: narrow candidates in SQL via
URLContains(hash), then confirm in Go withParseURL+Normalizeso the embedded hash (narinfo-hash prefix stripped) equals the target. A sharednormalizedURLHashhelper backs all three sites —LinkedNarinfoNarHash,MigrateChunksToNar,NormalizeChunkedNarInfoURL— and the join link stays the primary match.Surfaced by a CodeRabbit "outside diff range" finding on #1331; scoped out of that PR as pre-existing, now fixed on its own.
Specs: updates two
chunks-to-nar-migrationrequirements (URL-based narinfo lookup is hash-aware, covering unlinked nix-serve-style prefixed URLs).Test plan
task fmt,task lint,task testpassTestMigrateChunksToNar_DeChunksUnlinkedPrefixedNarinfoURL(de-chunk + normalize via hash-aware match)TestNormalizeChunkedNarInfoURL_MatchesUnlinkedPrefixedURL(first direct test of that entry point)