Repository navigation
feat(fsck): repair narinfos advertising a non-producible compression - #1395
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 (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThis PR adds a repair mechanism to fsck that rewrites narinfo rows advertising non-producible compressions (e.g., xz) to the servable ChangesNarinfo Compression Desync Repair
Sequence DiagramsequenceDiagram
participant fsck as fsck --repair
participant repairFsck as repairFsckIssues
participant repairFunc as repairNarInfoCompressionDesync
participant db as Database
participant perRow as repairOneNarInfoCompressionDesync
fsck->>repairFsck: initiate repair
repairFsck->>repairFunc: call repair function
repairFunc->>db: query nar_info with xz compression
db-->>repairFunc: return desynced narinfos
loop for each desynced narinfo
repairFunc->>perRow: reconcile narinfo
perRow->>db: check xz nar_file exists
db-->>perRow: no xz file found / backing NAR presence
perRow->>db: update to Compression: none, normalize URL, clear FileHash/FileSize
db-->>perRow: narinfo rewritten
perRow-->>repairFunc: return repaired=true
end
repairFunc-->>repairFsck: return count of repairs
repairFsck-->>fsck: log repair summary
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 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. ✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces a one-shot fsck repair mechanism to resolve compression desync issues where a narinfo advertises xz compression but the backing physical NAR is stored under a different compression. These desynced entries are rewritten to the servable 'none' form with cleared FileHash and FileSize fields to allow transparent decompression at serve time. The feedback identifies a potential performance bottleneck in the database query within repairNarInfoCompressionDesync and suggests optimizing the query to filter out healthy xz entries directly in the database, avoiding N+1 query issues.
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)
pkg/ncps/fsck.go (1)
564-566:⚠️ Potential issue | 🟠 Major | ⚡ Quick winCompression-desync repair is gated off in normal
--repairflows.At Line [564],
fsckexits early when no pre-collected issues exist, so desync-only datasets never reachrepairFsckIssues. At Line [1623],repairFsckIssuesreturns before the new repair when CDC/chunk-store is unavailable, even though this repair is independent of chunk mode.Suggested fix direction
--- a/pkg/ncps/fsck.go +++ b/pkg/ncps/fsck.go @@ - if results.totalIssues() == 0 { + if results.totalIssues() == 0 && !repair { return nil } @@ - if !results.cdcMode || chunkStore == nil { - return nil - } + // Run narinfo compression desync repair regardless of CDC/chunk-store mode. + repairedCompression, err := repairNarInfoCompressionDesync(ctx, dbClient) + if err != nil { + return fmt.Errorf("repair narinfo compression desync: %w", err) + } + if repairedCompression > 0 { + logger.Info(). + Int("count", repairedCompression). + Msg("repaired narinfos advertising a non-producible compression") + } + + if !results.cdcMode || chunkStore == nil { + return nil + } @@ - repairedCompression, err := repairNarInfoCompressionDesync(ctx, dbClient) - if err != nil { - return fmt.Errorf("repair narinfo compression desync: %w", err) - } - - if repairedCompression > 0 { - logger.Info(). - Int("count", repairedCompression). - Msg("repaired narinfos advertising a non-producible compression") - }Also applies to: 1623-1625, 1718-1730
🤖 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 `@pkg/ncps/fsck.go` around lines 564 - 566, The early return in fsck (the check if results.totalIssues() == 0) prevents compression-desync-only datasets from reaching repairFsckIssues; remove or change this guard so fsck always invokes repairFsckIssues (or invoke repairFsckIssues when either totalIssues()>0 OR a compression-desync condition is present). Inside repairFsckIssues, do not short-circuit the entire function when CDC/chunk-store is unavailable—separate the CDC/chunk-store dependent repairs from the compression-desync repair and ensure the compression-desync repair path still runs even if chunk-store/CDC is disabled, keeping any chunk-mode checks only around the chunk-dependent code.
🧹 Nitpick comments (1)
pkg/ncps/fsck_narinfo_compression_repair_internal_test.go (1)
19-105: ⚡ Quick winAdd command-path coverage for this repair.
This test validates the helper directly, but not
ncps fsck --repairexecution. Add an integration case with only compression-desync rows so regressions in command/repair gating are caught.🤖 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 `@pkg/ncps/fsck_narinfo_compression_repair_internal_test.go` around lines 19 - 105, Add a command-path integration test that exercises "ncps fsck --repair" (instead of directly calling repairNarInfoCompressionDesync) to ensure the CLI repair gating is covered: create a new test (e.g., TestFsckRepairCompressionDesyncCommandPath) that sets up the same desynced/healthy rows as in TestRepairNarInfoCompressionDesync, then invoke the CLI entrypoint or command runner used by the ncps fsck code path (the code that parses args and calls repairNarInfoCompressionDesync) and assert the repaired count and idempotency just like the helper test; reference repairNarInfoCompressionDesync, the existing TestRepairNarInfoCompressionDesync setup for row creation, and the CLI entry function (the fsck command handler / main command runner) to locate where to call the command.
🤖 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 `@pkg/ncps/fsck.go`:
- Around line 564-566: The early return in fsck (the check if
results.totalIssues() == 0) prevents compression-desync-only datasets from
reaching repairFsckIssues; remove or change this guard so fsck always invokes
repairFsckIssues (or invoke repairFsckIssues when either totalIssues()>0 OR a
compression-desync condition is present). Inside repairFsckIssues, do not
short-circuit the entire function when CDC/chunk-store is unavailable—separate
the CDC/chunk-store dependent repairs from the compression-desync repair and
ensure the compression-desync repair path still runs even if chunk-store/CDC is
disabled, keeping any chunk-mode checks only around the chunk-dependent code.
---
Nitpick comments:
In `@pkg/ncps/fsck_narinfo_compression_repair_internal_test.go`:
- Around line 19-105: Add a command-path integration test that exercises "ncps
fsck --repair" (instead of directly calling repairNarInfoCompressionDesync) to
ensure the CLI repair gating is covered: create a new test (e.g.,
TestFsckRepairCompressionDesyncCommandPath) that sets up the same
desynced/healthy rows as in TestRepairNarInfoCompressionDesync, then invoke the
CLI entrypoint or command runner used by the ncps fsck code path (the code that
parses args and calls repairNarInfoCompressionDesync) and assert the repaired
count and idempotency just like the helper test; reference
repairNarInfoCompressionDesync, the existing TestRepairNarInfoCompressionDesync
setup for row creation, and the CLI entry function (the fsck command handler /
main command runner) to locate where to call the command.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: afaa278a-1ffa-4834-99ed-924497000a00
📒 Files selected for processing (8)
openspec/changes/archive/2026-06-10-repair-narinfo-compression-desync/.openspec.yamlopenspec/changes/archive/2026-06-10-repair-narinfo-compression-desync/design.mdopenspec/changes/archive/2026-06-10-repair-narinfo-compression-desync/proposal.mdopenspec/changes/archive/2026-06-10-repair-narinfo-compression-desync/specs/narinfo-compression-repair/spec.mdopenspec/changes/archive/2026-06-10-repair-narinfo-compression-desync/tasks.mdopenspec/specs/narinfo-compression-repair/spec.mdpkg/ncps/fsck.gopkg/ncps/fsck_narinfo_compression_repair_internal_test.go
|
Done — narrowed the query with the suggested predicate (advertised xz, has a linked nar_file, no linked xz nar_file) so only the desynced rows are loaded. Kept the per-row |
Filter the candidate set in SQL to only desynced rows — advertised xz, backed by a nar_file, but not backed by an xz nar_file — so a cache with many healthy xz narinfos loads only the few desynced ones and does no per-row work for healthy entries. The per-row verification is retained as a precise re-check before rewriting. Addresses PR #1395 review thread PRRT_kwDONV6tZs6Ip9J6. Co-Authored-By: Claude Opus 4.8 <[email protected]>
5bc522d to
0b7e679
Compare
Filter the candidate set in SQL to only desynced rows — advertised xz, backed by a nar_file, but not backed by an xz nar_file — so a cache with many healthy xz narinfos loads only the few desynced ones and does no per-row work for healthy entries. The per-row verification is retained as a precise re-check before rewriting. Addresses PR #1395 review thread PRRT_kwDONV6tZs6Ip9J6. Co-Authored-By: Claude Opus 4.8 <[email protected]>
0b7e679 to
8ffb231
Compare
After the serve-side fixes (#1393, serve-zstd-from-chunks) ncps tolerates most narinfo<->nar_file compression drift at serve time by transcoding. The one case it still cannot serve is a narinfo advertising a compression ncps has no compressor for (xz) whose backing NAR is stored under a different compression (none/zstd/chunks) -- ~59 such pairs on the live cache. These pre-existing drifted rows cannot be healed at request time, so they need a one-shot data repair. Add repairNarInfoCompressionDesync, invoked from repairFsckIssues under --repair: find narinfos advertising xz with no matching xz nar_file but a backing non-xz nar_file, and rewrite each to the servable none form (URL nar/<hash>.nar, Compression: none, FileHash/FileSize cleared), reusing the advertised hash so the resolve-by-hash serve path (#1393) decompresses the stored bytes. Healthy narinfos are untouched and the repair is idempotent. Refs #1392 Co-Authored-By: Claude Opus 4.8 <[email protected]>
Filter the candidate set in SQL to only desynced rows — advertised xz, backed by a nar_file, but not backed by an xz nar_file — so a cache with many healthy xz narinfos loads only the few desynced ones and does no per-row work for healthy entries. The per-row verification is retained as a precise re-check before rewriting. Addresses PR #1395 review thread PRRT_kwDONV6tZs6Ip9J6. Co-Authored-By: Claude Opus 4.8 <[email protected]>
8ffb231 to
f4fa370
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)
pkg/ncps/fsck.go (1)
564-566:⚠️ Potential issue | 🟠 Major | ⚡ Quick win
--repaircan exit before running the new narinfo compression repair.Line 564 returns immediately when
results.totalIssues() == 0. Because compression-desync rows are not part offsckResults,repairFsckIssues(and Line 1721) is skipped when this is the only inconsistency, soncps fsck --repairdoes nothing for the PR’s target case.Suggested fix
- if results.totalIssues() == 0 { - return nil - } + if results.totalIssues() == 0 { + // Still run targeted narinfo compression desync repair under --repair. + if repair { + repairedCompression, err := repairNarInfoCompressionDesync(ctx, dbClient) + if err != nil { + return fmt.Errorf("repair narinfo compression desync: %w", err) + } + if repairedCompression > 0 { + logger.Info(). + Int("count", repairedCompression). + Msg("repaired narinfos advertising a non-producible compression") + } + } + return nil + }🤖 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 `@pkg/ncps/fsck.go` around lines 564 - 566, The early return in the function that checks if results.totalIssues() == 0 causes repairFsckIssues (and the new narinfo compression repair logic) to be skipped because compression-desync rows are not counted in fsckResults; update the control flow so that repairFsckIssues (or the compression-desync repair path at/near Line 1721) still runs when compression-desync inconsistencies are present — either by including compression-desync in results.totalIssues() or by changing the if-condition to also check a new flag/function (e.g., hasCompressionDesync or compressionDesyncFound) before returning; ensure the code that calls repairFsckIssues remains reachable when such desyncs exist.
🧹 Nitpick comments (1)
pkg/ncps/fsck_narinfo_compression_repair_internal_test.go (1)
39-104: ⚡ Quick winAdd one query-preservation assertion to lock the URL rewrite contract.
Current coverage uses empty query strings only. Since the repair intentionally preserves
advertised.Query, add a case with a non-empty query and assert it remains after rewriting toCompression:none.Suggested test tweak
- SetURL("nar/" + driftedHash + ".nar.xz"). + SetURL("nar/" + driftedHash + ".nar.xz?download=1"). ... - assert.Equal(t, "nar/"+driftedHash+".nar", *got.URL, "URL must drop the .xz extension") + assert.Equal(t, "nar/"+driftedHash+".nar?download=1", *got.URL, "URL must drop .xz and preserve query")🤖 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 `@pkg/ncps/fsck_narinfo_compression_repair_internal_test.go` around lines 39 - 104, Modify the test to include a non-empty query on the desynced nar_file and assert it is preserved after repair: when creating the desynced nar_file (driftedNF) call SetQuery with a non-empty value (e.g. "v=1") instead of SetQuery(""), run repairNarInfoCompressionDesync(ctx, dbClient), then after fetching got via dbClient.Ent().NarInfo.Get(ctx, driftedNI.ID) assert that *got.URL equals "nar/"+driftedHash+".nar?v=1" (i.e. the .xz extension is dropped but the original query string from the NarFile remains) so the URL rewrite contract is locked; reference driftedNF, driftedNI, SetQuery and repairNarInfoCompressionDesync in the change.
🤖 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/ncps/fsck.go`:
- Around line 1816-1818: The existence check for backing currently only tests
any NarFile linked to the narinfo (hasBacking) which is too broad; update the
query that sets hasBacking (the call starting with
dbClient.Ent().NarFile.Query().Where(entnarfile.HasNarInfoNarFilesWith(entnarinfonarfile.NarinfoIDEQ(ni.ID))))
to require a NarFile row that matches the advertised content address (include
the nar file hash and query used by the narinfo) — e.g., add the
entnarfile.HashEQ(ni.Hash) and the appropriate query field predicate (e.g.,
entnarfile.QueryEQ(ni.Query) or equivalent) to the Where clause so you only
treat backing as present when a NarFile with the same hash+query and narinfo_id
exists before rewriting Compression/URL.
---
Outside diff comments:
In `@pkg/ncps/fsck.go`:
- Around line 564-566: The early return in the function that checks if
results.totalIssues() == 0 causes repairFsckIssues (and the new narinfo
compression repair logic) to be skipped because compression-desync rows are not
counted in fsckResults; update the control flow so that repairFsckIssues (or the
compression-desync repair path at/near Line 1721) still runs when
compression-desync inconsistencies are present — either by including
compression-desync in results.totalIssues() or by changing the if-condition to
also check a new flag/function (e.g., hasCompressionDesync or
compressionDesyncFound) before returning; ensure the code that calls
repairFsckIssues remains reachable when such desyncs exist.
---
Nitpick comments:
In `@pkg/ncps/fsck_narinfo_compression_repair_internal_test.go`:
- Around line 39-104: Modify the test to include a non-empty query on the
desynced nar_file and assert it is preserved after repair: when creating the
desynced nar_file (driftedNF) call SetQuery with a non-empty value (e.g. "v=1")
instead of SetQuery(""), run repairNarInfoCompressionDesync(ctx, dbClient), then
after fetching got via dbClient.Ent().NarInfo.Get(ctx, driftedNI.ID) assert that
*got.URL equals "nar/"+driftedHash+".nar?v=1" (i.e. the .xz extension is dropped
but the original query string from the NarFile remains) so the URL rewrite
contract is locked; reference driftedNF, driftedNI, SetQuery and
repairNarInfoCompressionDesync in the change.
🪄 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: 8a8ea059-7e3b-4f1a-8ee9-e1e5e0465a9c
📒 Files selected for processing (8)
openspec/changes/archive/2026-06-10-repair-narinfo-compression-desync/.openspec.yamlopenspec/changes/archive/2026-06-10-repair-narinfo-compression-desync/design.mdopenspec/changes/archive/2026-06-10-repair-narinfo-compression-desync/proposal.mdopenspec/changes/archive/2026-06-10-repair-narinfo-compression-desync/specs/narinfo-compression-repair/spec.mdopenspec/changes/archive/2026-06-10-repair-narinfo-compression-desync/tasks.mdopenspec/specs/narinfo-compression-repair/spec.mdpkg/ncps/fsck.gopkg/ncps/fsck_narinfo_compression_repair_internal_test.go
✅ Files skipped from review due to trivial changes (4)
- openspec/changes/archive/2026-06-10-repair-narinfo-compression-desync/.openspec.yaml
- openspec/changes/archive/2026-06-10-repair-narinfo-compression-desync/proposal.md
- openspec/specs/narinfo-compression-repair/spec.md
- openspec/changes/archive/2026-06-10-repair-narinfo-compression-desync/tasks.md
🚧 Files skipped from review as they are similar to previous changes (1)
- openspec/changes/archive/2026-06-10-repair-narinfo-compression-desync/specs/narinfo-compression-repair/spec.md
The compression-desync repair's backing guard checked for any nar_file linked to the narinfo, so a stale/mismatched link could pass and rewrite the narinfo to Compression:none for a hash with no servable bytes (a 404). Require the backing nar_file to match the advertised hash+query (the xz row is already excluded earlier, so a match is a non-xz row the serve path can produce none from). Legitimately-backed narinfos are linked by the relink repair earlier in the same fsck pass. Addresses PR #1395 review thread PRRT_kwDONV6tZs6Itsvd. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Good catch — tightened the backing guard to require a nar_file matching the advertised hash+query (still linked to the narinfo), so a stale/mismatched link can no longer cause a rewrite to a non-servable |
Summary
Stacked on #1394. After the serve-side fixes (#1393, #1394) ncps tolerates most narinfo↔nar_file compression drift at serve time by transcoding. The one case it still cannot serve is a narinfo advertising a compression ncps has no compressor for (
xz) whose backing NAR is stored otherwise (none/zstd/chunks) — ~59 such pairs on the live cache. These pre-existing drifted rows cannot be healed at request time, so they need a one-shot data repair.Add
repairNarInfoCompressionDesync, invoked fromrepairFsckIssuesunder--repair: find narinfos advertisingxzwith no matchingxznar_file but a backing non-xz nar_file, and rewrite each to the servablenoneform (URL: nar/<hash>.nar,Compression: none,FileHash/FileSizecleared), reusing the advertised hash so the resolve-by-hash serve path (#1393) decompresses the stored bytes. Healthy narinfos are untouched; the repair is idempotent.Test plan
TestRepairNarInfoCompressionDesync: a desynced xz-advertised/none-stored narinfo is rewritten to none; a healthy xz/xz pair is untouched; a second run is a no-op.task fmt/lintgreen; targeted fsck tests pass.Refs #1392