Repository navigation
fix(cache): proxy snix-castore opaque nar URLs - #1427
Conversation
Upstreams such as cache.snix.dev serve narinfos whose URL field is a content-addressed reference (nar/snix-castore/<blob>?narsize=N, Compression: none, no .nar extension). ncps's ParseUpstreamURL required a .nar token, so these were rejected with ErrInvalidURL and the .narinfo request returned HTTP 500 "invalid nar URL" — intermittently, because upstream selection races and a retry landing on a conventional cache (cache.nixos.org) succeeded. Per the Nix HTTP binary-cache protocol the narinfo URL is an opaque path relative to the cache root, so generalize the existing opaque-URL handling (cachix UUID NARs) to tolerate .nar-less URLs: recover a genuine cache-relative path as Compression: none keyed off NarHash, preserving the full path and query for the upstream GET (snix returns 400 without ?narsize=N). Split the download URL (opaque, with query) from ncps's own hash-named storage/serve key so the upstream query never leaks into the nar_file key. Persist the opaque path + query via OpaqueUpstreamRef/WithOpaqueUpstreamRef so evicted NARs re-fetch correctly. The strict ParseURL is unchanged; ncps still emits only hash-named URLs to clients.
|
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 (2)
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds ChangesOpaque upstream URL support
Estimated code review effort: 3 (Moderate) | ~30 minutes Possibly related PRs
Suggested labels: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces support for proxying upstream narinfo URLs that lack a ".nar" extension (such as snix-castore opaque URLs), ensuring that their full path and query string are preserved for upstream GET requests while local storage keys off the NarHash. The reviewer highlighted a platform-dependency issue in pkg/nar/url.go where filepath.Base is used on a URL path, which would fail on Windows, and suggested using strings.LastIndex instead.
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.
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
pkg/nar/url_test.go (1)
254-276: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winAdd a round-trip case for encoded/order-sensitive opaque queries.
The current round-trip only covers
?narsize=N; add one case with escaped characters or multiple ordered params so the persistence contract catches query re-encoding regressions.🤖 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/nar/url_test.go` around lines 254 - 276, The existing round-trip test in nar.ParseUpstreamURL/WithOpaqueUpstreamRef only covers a simple narsize query, so add another case that uses an opaque upstream ref with escaped characters or multiple ordered query parameters. Keep the same round-trip assertions on OpaqueUpstreamRef, ParseURL, and JoinURL, but verify the exact original query string is preserved without re-encoding or reordering.
🤖 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 4343-4346: The URL normalization in the narinfo handling code is
stripping query parameters too broadly for CompressionTypeNone/eager-CDC cases.
Update the logic around the nar.URL construction in the affected branches so
queries are removed only when the upstream URL is opaque, and preserved for
non-opaque hash-named NAR URLs. Make the same adjustment in both matching paths
in the narinfo serialization flow so the advertised URL stays consistent with
the stored/downloadable key.
In `@pkg/nar/url.go`:
- Around line 183-188: The opaque upstream ref parsing currently discards the
original raw query string by only returning parsed url.Values from the URL
helper, which breaks verbatim reconstruction in OpaqueUpstreamRef and
round-tripping in WithOpaqueUpstreamRef. Update the URL parsing/persistence flow
to carry the raw query alongside the decoded values, and make OpaqueUpstreamRef
use that preserved raw form when rebuilding the ref. Ensure
WithOpaqueUpstreamRef stores and reuses the raw query for refetch/persistence,
and add a regression test covering escaped characters and reordered parameters.
---
Nitpick comments:
In `@pkg/nar/url_test.go`:
- Around line 254-276: The existing round-trip test in
nar.ParseUpstreamURL/WithOpaqueUpstreamRef only covers a simple narsize query,
so add another case that uses an opaque upstream ref with escaped characters or
multiple ordered query parameters. Keep the same round-trip assertions on
OpaqueUpstreamRef, ParseURL, and JoinURL, but verify the exact original query
string is preserved without re-encoding or reordering.
🪄 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: 9dfeb77b-0866-4345-9d36-27841d4bac4e
📒 Files selected for processing (12)
CHANGELOG.mddocs/docs/Developer Guide/Architecture/Request Flow.mdopenspec/changes/archive/2026-06-30-support-snix-castore-opaque-urls/.openspec.yamlopenspec/changes/archive/2026-06-30-support-snix-castore-opaque-urls/design.mdopenspec/changes/archive/2026-06-30-support-snix-castore-opaque-urls/proposal.mdopenspec/changes/archive/2026-06-30-support-snix-castore-opaque-urls/specs/upstream-fetch-resilience/spec.mdopenspec/changes/archive/2026-06-30-support-snix-castore-opaque-urls/tasks.mdopenspec/specs/upstream-fetch-resilience/spec.mdpkg/cache/cache.gopkg/cache/cache_test.gopkg/nar/url.gopkg/nar/url_test.go
- url.go: extract the opaque filename with strings.LastIndex instead of filepath.Base, which is platform-dependent (treats "\\" as a separator on Windows); pathPart is guaranteed to contain "/". (PR #1427, gemini thread PRRT_kwDONV6tZs6NeOGy) - cache.go: strip the upstream query from ncps's own hash-named serve URL only for OPAQUE upstream URLs; preserve queries on conventional hash-named none/eager-CDC URLs as before, so the advertised URL does not diverge from the stored key. (PR #1427, coderabbit thread PRRT_kwDONV6tZs6NeRMp) - url_test.go: use https example URLs in the new tests to avoid DevSkim no-TLS findings (code-scanning 381-384).
|
Re: preserving the raw opaque query string (thread on
So opaque re-fetch is no less faithful than the shipped behavior for every other URL, and correct for the real upstream. If an order-/encoding-sensitive multi-param opaque upstream ever appears, carrying a raw query through the |
Summary
Fixes intermittent
HTTP 500 "invalid nar URL"when serving<hash>.narinfofor store paths available on
cache.snix.dev.Root cause (confirmed against production logs): snix serves narinfos whose
URL:field is a snix-castore reference —nar/snix-castore/<blob>?narsize=N,Compression: none, no.narextension. ncps'snar.ParseUpstreamURLrequired a
.nartoken, so it rejected these withErrInvalidURLand thenarinfo request 500'd. It was intermittent because upstream selection races all
healthy upstreams (first responder wins); a retry that landed on
cache.nixos.org served a conventional URL and succeeded.
Fix: follow the Nix HTTP binary-cache protocol, where the narinfo
URL:isan opaque path relative to the cache root. This generalizes the existing opaque
(cachix UUID) handling to
.nar-less URLs:ParseUpstreamURLrecovers a genuine cache-relative.nar-less path asCompression: none, keyed off the narinfoNarHash, preserving the full pathand query for the upstream GET (snix returns
400without?narsize=N).ncps's own hash-named storage/serve key, so the upstream query never leaks
into the
nar_filekey (which otherwise 404'd the NAR on a later read).OpaqueUpstreamRef/WithOpaqueUpstreamRefpersist and restore theopaque path + query so an evicted NAR re-fetches correctly.
ParseURLis unchanged — ncps still emits only hash-named URLs toclients. Conventional and cachix-style URLs are unaffected.
No config, schema, or migration changes.
Test plan
task fmt(0 changed),task lint(0 issues),task test(all green)pkg/nar: parser unit tests (snix parse, query round-trip, strictParseURLstill rejects, invalid-fallback rejected)pkg/cache:TestGetNarInfoSnixCastoreOpaqueURL— full pull → store →serve → evict → re-fetch; asserts
?narsizereaches the upstream GET andnever leaks into ncps's storage key; existing cachix opaque test still
passes