Skip to content

feat: add --verify-content flag to fsck - #1176

Merged
kalbasit merged 3 commits into
mainfrom
feat-add-verify-content-flag-to
May 17, 2026
Merged

kalbasit merged 3 commits into
mainfrom
feat-add-verify-content-flag-to

Conversation

@kalbasit

Copy link
Copy Markdown
Owner

Nix build errors like 'bad archive: input doesn't look like a
Nix archive' can be caused by bit-rot in CDC chunks that are
served without any content verification. The existing fsck only
stat-checks that chunk files exist — it never reads or hashes
their content.

Add an opt-in --verify-content flag that:

  • Reads and decompresses every chunk via GetChunk, hashes the
    output with SHA-256, and compares it against the stored BLAKE3
    key (narFilesWithCorruptChunks).
  • For NARs that pass per-chunk checks, assembles the full stream
    and compares the SHA-256 against the narinfo NarHash field
    (narFilesWithHashMismatch).
  • Repairs both categories with the same cascade as broken CDC
    NARs (nar_file + orphaned narinfo + orphaned chunks).
  • Shows the two new rows in the fsck summary only when
    --verify-content is active.

The flag is opt-in because reading all chunk bytes is O(total
NAR bytes) of I/O and zstd decompression. Combine with
--verified-since to limit scope on large caches.

Helm chart: adds fsck.verifyContent value (default false) and
the corresponding --verify-content arg in the CronJob template.
Docs: new usage section, flags reference row, and repair table
entries.

@kalbasit

kalbasit commented May 17, 2026 •

Copy link
Copy Markdown
Owner Author

This change is part of the following stack:

Change managed by git-spice.

@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. documentation Improvements or additions to documentation enhancement New feature or request go Pull requests that update go code helm labels May 17, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds an opt-in --verify-content flag to ncps fsck, enabling deep integrity checks for CDC-mode caches by verifying individual chunk hashes and the assembled NAR's NarHash. The implementation includes updates to the CLI, database queries, Helm chart, and documentation. Feedback was provided to switch from io.ReadAll to streaming with io.Copy during chunk verification to prevent potential memory issues and adhere to the design specification.

Comment thread pkg/ncps/fsck.go Resolved
@kalbasit
kalbasit force-pushed the feat-add-verify-content-flag-to branch from b2f37a1 to 8fc0b60 Compare May 17, 2026 05:10
@kalbasit
kalbasit enabled auto-merge (squash) May 17, 2026 05:11
@codecov

codecov Bot commented May 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 5.04%. Comparing base (0ac4a95) to head (b80b574).

Additional details and impacted files
@@           Coverage Diff            @@
##            main   #1176      +/-   ##
========================================
- Coverage   6.38%   5.04%   -1.34%     
========================================
  Files          6       6              
  Lines        329     436     +107     
========================================
+ Hits          21      22       +1     
- Misses       304     410     +106     
  Partials       4       4              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

kalbasit added 3 commits May 17, 2026 00:01
Nix build errors like 'bad archive: input doesn't look like a
Nix archive' can be caused by bit-rot in CDC chunks that are
served without any content verification. The existing fsck only
stat-checks that chunk files exist — it never reads or hashes
their content.

Add an opt-in --verify-content flag that:
- Reads and decompresses every chunk via GetChunk, hashes the
  output with SHA-256, and compares it against the stored BLAKE3
  key (narFilesWithCorruptChunks).
- For NARs that pass per-chunk checks, assembles the full stream
  and compares the SHA-256 against the narinfo NarHash field
  (narFilesWithHashMismatch).
- Repairs both categories with the same cascade as broken CDC
  NARs (nar_file + orphaned narinfo + orphaned chunks).
- Shows the two new rows in the fsck summary only when
  --verify-content is active.

The flag is opt-in because reading all chunk bytes is O(total
NAR bytes) of I/O and zstd decompression. Combine with
--verified-since to limit scope on large caches.

Helm chart: adds fsck.verifyContent value (default false) and
the corresponding --verify-content arg in the CronJob template.
Docs: new usage section, flags reference row, and repair table
entries.
Using io.ReadAll to load the full chunk into memory before hashing
with blake3.Sum256 risks OOM on large chunks and contradicts the
design intent of streaming chunk verification.

Replace with blake3.New() + io.Copy so the hasher consumes the
reader incrementally without allocating a per-chunk buffer.
@kalbasit
kalbasit force-pushed the feat-add-verify-content-flag-to branch from 8fc0b60 to b80b574 Compare May 17, 2026 07:02
@github-actions

Copy link
Copy Markdown
Contributor

@kalbasit
kalbasit merged commit 0f57fb1 into main May 17, 2026
15 of 16 checks passed
@kalbasit
kalbasit deleted the feat-add-verify-content-flag-to branch May 17, 2026 07:15
kalbasit added a commit that referenced this pull request Jun 8, 2026
## 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request go Pull requests that update go code helm size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant