Skip to content

nix: shorten get-missing-paths and push audits - #40

Merged
Uzaaft merged 2 commits into
masterfrom
perf/nix-push-routes
Nov 18, 2026
Merged

Uzaaft merged 2 commits into
masterfrom
perf/nix-push-routes

Conversation

@Uzaaft

@Uzaaft Uzaaft commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Resolve the cache, refresh retention, and read both the published and
the upstream membership of the requested hashes in a single statement.
Previously the handler looked the cache up, then ran the refresh and
membership statement, then asked upstream_paths about the absent
hashes whenever upstreams were configured. Each was its own pool
checkout and round trip to a database about 2 ms away, which is most
of what this endpoint costs.

Authorization used to sit between the lookup and the refresh, and the
refresh is a write. The statement therefore receives the caller's push
scope, computed by authz::authorize for the named cache without an ID
and for each cache ID the token is granted, and neither reads nor
refreshes paths outside it. The handler still authorizes against the
resolved cache afterwards, so an unknown cache, another org's cache,
and a cache without the Nix protocol stay 404 ahead of a scope
failure, which stays 403.

The upstream lookup is gated on a parameter-only condition, so without
configured upstreams it is never started. With them it now probes all
requested hashes rather than only the absent ones; the response is
unchanged because published membership is applied first.
Record a Nix write endpoint's audit row as tracked background work
instead of awaiting the insert before returning the response.
Previously every authorized push request, from get-missing-paths to
the upload and push-job routes, paid one more pool checkout and round
trip to the database after its handler had already decided the
answer.

The insert runs on the state's task tracker, so a graceful shutdown
still waits for it before closing SQL. What changes is durability: a
response used to imply its audit row was written, and a crash between
the response and the insert now loses that row. Rows may also commit
in a different order than their requests completed. A failed insert
is logged and ignored, as before.

The refusal of a token without push permission stays awaited. It is
the one row here that records an attempt to exceed a credential's
permissions, and it is off the hot path.

Tests that read audit_logs after a response now drain background work
first, and the inline batch test selects its endpoint's row rather
than assuming it is the newest.
@Uzaaft
Uzaaft merged commit 626df2c into master Nov 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant