Skip to content

fix: fail-fast boot validation for storage tmp directory - #1086

Merged
kalbasit merged 1 commit into
mainfrom
fix-fail-fast-boot-validation
Mar 13, 2026
Merged

kalbasit merged 1 commit into
mainfrom
fix-fail-fast-boot-validation

Conversation

@kalbasit

Copy link
Copy Markdown
Owner

This adds a writability check for the store/tmp directory in setupDirs()
to ensure the server fails fast at boot time if the tmp directory is not
writable. Previously, the server would fail silently when downloading
NARs or during background migration to chunks, causing database records
to exist without corresponding files in storage. The new validation
creates a temp file in the tmp directory and cleans it up immediately.

@kalbasit

kalbasit commented Mar 13, 2026 •

Copy link
Copy Markdown
Owner Author

This change is part of the following stack:

Change managed by git-spice.

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Mar 13, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the system's robustness by introducing an early validation step during the boot process. It specifically checks the writability of the temporary storage directory, ensuring that critical file system permissions are correctly configured from the start. This proactive measure prevents silent failures and potential data corruption that could arise from an unwritable temporary directory, thereby improving overall system reliability and data consistency.

Highlights

  • Fail-fast validation: Implemented a writability check for the store/tmp directory during boot to ensure the server fails immediately if the temporary directory is not writable.
  • Prevented silent failures: Addressed a class of issues where the server would previously fail silently during operations like NAR downloads or background migrations, leading to database records without corresponding files.
  • Data integrity: Improved data integrity by preventing inconsistencies caused by storage failures that were not detected early enough.
Changelog
  • pkg/storage/local/local.go
    • Added a writability check for the temporary storage directory in setupDirs().
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@dosubot dosubot Bot added bug Something isn't working go Pull requests that update go code labels Mar 13, 2026
@dosubot

dosubot Bot commented Mar 13, 2026 •

Copy link
Copy Markdown

Documentation Updates

2 document(s) were updated by changes in this PR:

Cache and Storage Configuration Flags
View Changes
@@ -88,6 +88,8 @@
 cache:
   temp-path: "/var/lib/ncps/temp"
 ```
+
+**Boot-Time Validation:** The server validates that the temporary directory is writable during startup by creating and removing a test file. If the directory is not writable, the server will fail to start immediately with an error. This fail-fast behavior ensures that configuration issues are caught at boot time rather than during runtime operations such as NAR downloads or background chunk migrations.
 
 **Note:** On some systems, the default `/tmp` directory may have limited space or be stored in memory (e.g., tmpfs on NixOS). In these cases, setting a custom temporary directory with sufficient disk space is recommended.
 
NAR File Download and Streaming
View Changes
@@ -178,7 +178,7 @@
 
 When CDC is enabled and decompression is performed, the cleanup goroutine removes the uncompressed temporary file (`assetPath`) after all readers finish. The `compressedAssetPath` field is kept in the `downloadState` struct for backward compatibility but remains empty in the CDC pipeline since PR #1071 replaced the compressed temp file with an `io.Pipe`. This ensures that no temporary files persist after the NAR is stored.
 
-On startup, ncps cleans up any leftover temporary files from previous runs by removing the temp directory and recreating it [source](https://github.com/kalbasit/ncps/blob/b7653d4303670bb88fd34b8bf82ed3aade09885d/pkg/storage/local/local.go#L305-L459).
+On startup, ncps cleans up any leftover temporary files from previous runs by removing the temp directory and recreating it. The server also validates that the temporary directory is writable during startup by creating and removing a test file. If the temporary directory is not writable, the server will fail to start immediately with an error, preventing silent failures that could occur later during NAR download operations. This boot-time validation ensures configuration issues are detected early, before the server begins accepting requests [source](https://github.com/kalbasit/ncps/blob/b7653d4303670bb88fd34b8bf82ed3aade09885d/pkg/storage/local/local.go#L305-L459).
 
 ### Configuration of Temporary Download Paths
 The temporary directory for downloads is configurable via the `--cache-temp-path` flag or the `CACHE_TEMP_PATH` environment variable. By default, ncps uses the OS temporary directory. For local storage backends, a `tmp` subdirectory under the store path is used [source](https://github.com/kalbasit/ncps/blob/b7653d4303670bb88fd34b8bf82ed3aade09885d/cmd/serve.go#L176-L529).

How did I do? Any feedback?  Join Discord

@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 a useful writability check for the temporary directory during startup, which helps the server fail fast with a clear error message. The suggestion to make the cleanup logic more robust by handling potential errors, especially from Close(), is valid and aligns with the goal of failing fast on any issue, as such errors are not considered benign in this context. This comment is kept as it does not contradict any existing rules.

Comment thread pkg/storage/local/local.go Resolved
@codecov

codecov Bot commented Mar 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 5.04%. Comparing base (6095c7e) to head (eb9c55a).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #1086   +/-   ##
=====================================
  Coverage   5.04%   5.04%           
=====================================
  Files          6       6           
  Lines        436     436           
=====================================
  Hits          22      22           
  Misses       410     410           
  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
kalbasit force-pushed the fix-fail-fast-boot-validation branch from 3202c7a to cfdfc24 Compare March 13, 2026 06:03
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Mar 13, 2026
@kalbasit kalbasit added the backport release-0.9 Backport PR automatically label Mar 13, 2026
@kalbasit

Copy link
Copy Markdown
Owner Author

/gemini review

@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 introduces a valuable fail-fast validation by checking if the temporary directory is writable at boot time. This is a good improvement to prevent silent failures later on. The implementation is correct, and tests have been added to cover the new logic.

My main feedback is regarding code duplication. The writability check logic has been added in two different places (pkg/cache/cache.go and pkg/storage/local/local.go). I've left a comment suggesting to extract this into a shared helper function to improve maintainability.

Comment thread pkg/cache/cache.go Resolved
This adds a writability check for the store/tmp directory in setupDirs()
to ensure the server fails fast at boot time if the tmp directory is not
writable. Previously, the server would fail silently when downloading
NARs or during background migration to chunks, causing database records
to exist without corresponding files in storage. The new validation
creates a temp file in the tmp directory and cleans it up immediately.
@kalbasit
kalbasit force-pushed the fix-fail-fast-boot-validation branch from cfdfc24 to eb9c55a Compare March 13, 2026 06:10
@kalbasit
kalbasit enabled auto-merge (squash) March 13, 2026 06:13
@kalbasit
kalbasit merged commit 06337a9 into main Mar 13, 2026
14 checks passed
@kalbasit
kalbasit deleted the fix-fail-fast-boot-validation branch March 13, 2026 06:22
kalbasit added a commit that referenced this pull request Mar 13, 2026
This adds a writability check for the store/tmp directory in setupDirs()
to ensure the server fails fast at boot time if the tmp directory is not
writable. Previously, the server would fail silently when downloading
NARs or during background migration to chunks, causing database records
to exist without corresponding files in storage. The new validation
creates a temp file in the tmp directory and cleans it up immediately.

(cherry picked from commit 06337a9)
@kalbasit

Copy link
Copy Markdown
Owner Author

Successfully created backport PR for release-0.9:

kalbasit added a commit that referenced this pull request Mar 13, 2026
] (#1087)

Bot-based backport to `release-0.9`, triggered by a label in #1086.

This adds a writability check for the store/tmp directory in setupDirs()
to ensure the server fails fast at boot time if the tmp directory is not
writable. Previously, the server would fail silently when downloading
NARs or during background migration to chunks, causing database records
to exist without corresponding files in storage. The new validation
creates a temp file in the tmp directory and cleans it up immediately.
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

backport release-0.9 Backport PR automatically bug Something isn't working go Pull requests that update go code size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant