feat(npm): serve the virtual tarball route (S31 plan: 17/19)

Split into six stacked MRs

This MR is now part 6 of 6. Its diff holds only the slot wiring, the run recipe, and the docs that the wiring makes false. Parts 1 to 5 hold the rest of the original diff:

Part MR Contents
1 !3150 (merged) npm_files.created_at to the hosted tarball winner
2 !3147 (merged) Resolver re-entry on a virtual drain failure
3 !3148 (merged) VirtualTarballHandler, not wired
4 !3149 (merged) Copy-fault accounting, kill log, cold HEAD drain failure
5 !3151 (merged) Usage events
6 This MR Slot wiring, run recipe, docs

Each part targets the branch of the part before it. Merge the parts in order. The six parts together are byte-identical to the diff this MR had before the split (same git patch-id --stable, 5ef60443538a), rebased onto main at a6836dead. The sections below describe the whole change, and the coverage table stays the reference for all six parts.

What this MR delivers

Before this MR, the tarball route of an npm virtual repository answered the interim 501 for GET and HEAD. The cause: npmVirtualDownloadSlot in cmd/artifact-registry/wire_npm_virtual.go returned no DispatchOption, and no virtual tarball handler existed.

This MR adds npm.VirtualTarballHandler and wires it through npm.WithVirtualDownloadHandler over the resolution facade of the npm virtual composition. For each GET and HEAD, the handler does these steps:

  1. It validates the target before any resolution. An unsafe element in the file name returns 400, an unparseable file name returns 404 file_not_found, and an invalid package name returns 422. These rejections run no rule evaluation and no resolution.
  2. It parses the version from the file name, so that a version rule matches against it.
  3. It resolves over the upstream list of the virtual repository and streams the bytes of the priority winner, with no re-point.
  4. For a hosted winner, it sends npm_files.created_at as Last-Modified. A cold stream from a remote winner carries no ETag and no Last-Modified. The next read serves the cached blob and carries its digest.
  5. Cache-Control follows the virtual repository, whatever position wins.
  6. Every no-winner verdict (nothing holds the tarball, no upstreams, every upstream denied) returns 404 file_not_found. This is the same code as the standalone remote tarball route.

The handler arms the write deadline two times:

Arm When Value At the defaults
First On entry, before the file name is parsed resolve_timeout + request_total_timeout + single_flight_wait_timeout + 5s 7m05s
Second When the resolution returns request_total_timeout + single_flight_wait_timeout + 5s 5m35s

The second arm has no floor at server.timeouts.write, the same as the remote tarball read. docs/dev/configuration-reference.md documents both arms.

The run recipe (.claude/skills/run-artifact-registry/) now expects 404 from the smoke check of the virtual tarball route, not the interim 501.

A delivered tarball GET emits the usage events artifact_pulled and virtual_cache_miss (ruling E17). A delivered GET is a clean copy or an issued 307. The events name the virtual repository, not the winner. virtual_cache_miss comes first, and only when the winner's own bytes answer: a hosted winner, or a cold stream from a remote winner. artifact_pulled carries delivery_mode (proxy or redirect) and cache_hit, which is true only for a stored copy of a remote winner.

A HEAD and a matching 304 emit virtual_cache_miss alone, with no artifact_pulled, when the serve needs the winner's own bytes (ruling E22). That is a hosted winner, or a cold fetch from a remote winner that the HEAD drains to commit the cache fill. A HEAD or a 304 on the stored copy of a remote winner emits no event. artifact_pulled never fires for a HEAD or a 304 (ruling E17). A GET keeps the delivered gate: a GET whose copy ends short after its 200 headers emits neither event. A refusal, a vanished blob, a storage fault, and a HEAD whose cold fetch is cut off emit no event. The virtual_cache_miss row of docs/dev/usage-data.md states this npm rule.

The route records no download (ruling E21). A delivered read does not bump last_downloaded_at on the supplying position, and does not book repositories.downloads_count on a hosted winner. S31 states no rule for this. #1520 (closed) owns the recording, after the S31 spec author amends S31 (see Spec gaps below).

If the stored blob of the winner is gone, the answer follows the kind of the winner (ruling E18). A hosted winner answers 404 file_not_found. A remote winner answers 503 upstream_unavailable with the Retry-After of the health interval, because the upstream can still hold the bytes. Both answers write a Warn line. A blob integrity fault and other storage faults still answer 500.

A cold HEAD of a remote winner drains the upstream body, so that the cache fill commits. If the drain fails, the handler sends the failure to the drain-failure path of the S13 resolution layer (virtual.Resolver.ResolveDrainFailure). The answer follows whose failure it is:

  • The upstream cuts off the body, and the winner position holds a cached copy: the handler serves that copy with its digest ETag. A matching If-None-Match answers 304. The cut drain commits nothing.
  • The upstream cuts off the body, and the winner position holds no cached copy: 503 upstream_unavailable with the Retry-After of the health interval.
  • A follower drain ends in a canceled leader, an abandoned fill, or a single-flight timeout: 503 upstream_unavailable with Retry-After: 1.
  • The local cache fill fails (a staging write, the commit, or the digest check): 500.
  • The client left: 499, with no response body.

Decisions made during this work

The coverage table below cites rulings E1, E2 and E3. The review of this branch added rulings E17, E18, E19, E21 and E22.

  • E1, the Last-Modified source. The hosted tarball read projects npm_files.created_at, NpmVirtualHostedHit.CreatedAt carries it, and the winner exposes it. The time arrives with the resolution, and no second query runs.
  • E2, the interim 501 tests. The test commit replaces the three tarball assertions that expected the interim 501 with the served expectation. These are TestBuildNpmVirtualSlots_SetsNoOptionYet (now TestBuildNpmVirtualSlots_SetsTheTarballOption), the tarball row of TestBuildNpmDispatcher_WiredCompositionAnswers501OnEveryVirtualRoute, and the tarball subtest of TestMountSlugAnchoredFormats_NpmVirtualRoutesAnswer501 (now TestMountSlugAnchoredFormats_NpmVirtualRoutes).
  • E3, the not-found code. The tarball route answers 404 file_not_found for a read with no winner, as the spec's Error Cases row states. Spec Resolution #6 (closed) still names package_not_found, and this MR does not change the spec.
  • E17, the usage events. A virtual npm tarball pull emits artifact_pulled and virtual_cache_miss. TestVirtualTarballHandler_DeliveredGET_EmitsTheVirtualPullEvents and TestVirtualTarballHandler_UndeliveredRead_EmitsNoUsageEvent cover it.
  • E18, a vanished blob. A hosted winner whose stored blob is gone answers 404 file_not_found, and a remote winner answers 503 upstream_unavailable. TestVirtualTarballHandler_VanishedBlob_AnswersByWinnerKind covers GET and HEAD for each winner kind. The spec has no row for this case (see Spec gaps below).
  • E19, HEAD under redirect delivery. A HEAD of a stored winner keeps its 200 when the matching GET answers 307. This differs from spec Validation and reads #1 (V-1), and this MR does not change the spec (see Spec gaps below).
  • E21, download recording. This MR adds no download recording to the route. #1520 (closed) owns it (see Spec gaps below).
  • E22, the miss on HEAD and 304. A HEAD or a matching 304 whose serve needs the winner's own bytes emits virtual_cache_miss alone. This changes the effect of the E17 rule "no event for HEAD or 304" for the miss only, and artifact_pulled keeps that rule. TestVirtualTarballHandler_HeadOr304OnTheWinnersOwnBytes_BooksTheMissAlone and TestVirtualTarballHandler_UndeliveredRead_EmitsNoUsageEvent cover it.

Paths outside the issue's file list

  • internal/datastore/npm_virtual_hosted_lookup.go and its two test files, internal/format/npm/virtual_assembly.go, and internal/format/npm/virtual_hosted_upstream.go carry CreatedAt to the winner (E1).
  • cmd/artifact-registry/wire_npm_virtual_test.go and wire_npm_virtual_integration_test.go replace the interim 501 assertions (E2).
  • internal/format/npm/virtual_tarball_usagedata.go emits the usage events, and docs/dev/usage-data.md gets the npm rule in its virtual_cache_miss row (E17, E22).
  • internal/format/npm/virtual_operations.go and its two test files give a failed cold HEAD drain to virtual.Resolver.ResolveDrainFailure, and internal/format/npm/virtual_operations.md records this entry point.
  • These edits correct text that this change made false:
    • docs/dev/storage.md: the virtual tarball route is the caller of the upload-session shed arm.
    • docs/dev/configuration-reference.md: the reason in the negative_cache_ttl row, the npm virtual tarball read in the server.timeouts.write row, and the npm virtual tarball read in the resolve_timeout row.
    • internal/format/npm/virtual_operations.md and internal/format/npm/virtual_read_errors.md: the tarball handler is now a caller.
    • internal/format/npm/remote_tarball.go: comments only, which named two callers where there are now three.
    • internal/format/npm/kill_log.md and the comments in internal/format/npm/remote_tarball_kill_log.go: the virtual tarball route is a fourth holder of the kill log.
    • The NpmVirtualHostedHit.BlobSHA256 comment and the npmVirtualWiring.ServerWriteTimeout comment.
    • docs/testing/e2e/npm.md: the reason in the scope paragraph for virtual repositories.

Acceptance numbering

The issue body cites Conditional requests #5, #6 (closed) and #7 (closed). The spec and plan Step 17 number the same criteria #6 (closed), #7 (closed) and #8 (closed), because a later amendment inserted a criterion above them. The plan records this renumbering. The tests and the coverage table use the spec's current numbers.

Version length cap

The issue note of 2026-08-26 on this issue asks for the version length cap at the boundary that accepts the file name. On main, npmremote.Target.Validate caps the file name at 255 runes (b4d24aea). The version is part of the file name, so this bound also caps the version. This handler calls npmremote.NewTarballTarget before any read. This MR adds no other cap.

Spec coverage

Source of the rows: the spec, docs/specs/S31-npm-virtual.md, one row per Acceptance Criterion, Error Case and Security Consideration, plus the card's test items and issue note F4.

Spec: docs/specs/S31-npm-virtual.md

Acceptance criteria

# Criterion Tests
R-1 Metadata routes merge, the tarball route does not Tarball half: TestVirtualTarballHandler_ServesTheWinnersBytes/with_two_remotes_holding_the_tarball_the_first_position_serves_it_alone. The one-fixture packument half needs the Step 15 route, which is not on this branch.
R-2 Hosted-and-remote mix TestVirtualTarballHandler_ServesTheWinnersBytes/a_remote_miss_ahead_of_a_hosted_holder_is_served_by_the_hosted_position
R-3 Priority winner on the tarball TestVirtualTarballHandler_ServesTheWinnersBytes/a_remote_ahead_of_a_hosted_holder_is_fetched_as_the_priority_winner
R-4 A definite failure never reaches the network (packument) Not this step: Step 15 (packument route).
R-5 Just-published package on its hosted upstream, tarball slice TestVirtualTarballHandler_ServesTheWinnersBytes/a_just-published_hosted_tarball_wins_over_a_remote_holding_the_same_name_with_no_upstream_request. Metadata slices: Steps 15 and 16.
R-6 Nothing holds the package TestVirtualTarballHandler_AnswersTheNoWinnerVerdicts/nothing_holds_the_tarball (file_not_found, ruling E3). Metadata routes: Steps 15 and 16.
R-7 No upstreams configured TestVirtualTarballHandler_AnswersTheNoWinnerVerdicts/no_upstreams_configured (file_not_found, ruling E3)
R-8 All eligible remotes unhealthy TestVirtualTarballHandler_AnswersTheNoWinnerVerdicts/every_eligible_position_is_an_unhealthy_remote
R-9 Hosted miss alongside an unhealthy remote is a 404 TestVirtualTarballHandler_AnswersTheNoWinnerVerdicts/a_hosted_miss_alongside_an_unhealthy_remote_establishes_an_absence
R-10 Shed hosted rebuild vetoes the read Metadata routes only; the spec states it is not asserted on the tarball route.
R-11 Outage is not an absence TestVirtualTarballHandler_AnswersTheNoWinnerVerdicts/an_outage_with_no_cached_copy_is_unavailable,_not_absent
R-12 Cache fallback serves a non-winning position TestVirtualTarballHandler_ServesTheWinnersBytes/an_outage_falls_back_to_the_highest-priority_position_holding_a_cached_copy. The served_from_fallback outcome record is Step 18.
R-13 Winner Fetch failure does not fall through TestVirtualTarballHandler_AnswersTheNoWinnerVerdicts/the_winner's_refused_fetch_maps_its_status_and_does_not_fall_through
R-14 Upstream of an unexpected kind fails closed TestVirtualTarballHandler_AnswersTheNoWinnerVerdicts/an_upstream_of_an_unexpected_kind_fails_closed. Error log and audit reason: resolver suite.
R-15 Soft-deleted upstream skipped Not this step: the upstream-list read (datastore).
R-16 Per-read query count independent of upstream count Not this step: packument read, Steps 11 and 15.
R-17 Health status costs no statement Not this step: assembly, Step 11.
R-18 Tag-less hosted package is a Hit Not this step: dist-tags, Steps 5 and 16.
R-19 Hosted package with no live version misses both metadata reads Not this step: metadata routes.
PM-1 Union of versions Metadata merge: Steps 13, 15. The per-version tarball fetch is the single-winner path R-3 covers.
PM-2 Position-major ordering Not this step: metadata merge.
PM-3 Lowest position wins a version key, whole Not this step: metadata merge.
PM-4 dist-tags union, lowest position wins a tag Not this step: metadata merge.
PM-5 No latest is synthesized Not this step: metadata merge.
PM-6 The two dist-tags surfaces agree Not this step: Step 16.
PM-7 time union, modified maximum, created minimum Not this step: metadata merge.
PM-8 _id and _rev Not this step: metadata merge.
PM-9 Every entry is re-pointed Not this step: metadata merge.
PM-10 Integrity is relayed per contributing position Not this step: metadata merge.
PM-11 Divergence is counted Not this step: metadata merge.
PM-12 Best-effort under outage Not this step: metadata merge.
PM-13 An unhealthy remote contributes from cache only Not this step: metadata merge.
PM-14 A vetoed hosted Hit fails the merge Not this step: metadata merge.
PM-15 A denied position contributes nothing Not this step: metadata merge.
PM-16 A remote contributor's freshness governs its input Not this step: metadata merge.
PM-17 All-absent is a 404 Not this step: metadata merge.
PM-18 All-failed is a 503 Not this step: metadata merge.
PM-19 A data error vetoes the merge 404 Not this step: metadata merge.
PM-20 A malformed input cannot fail the read Not this step: metadata merge.
PM-21 The variant is not mixed Not this step: Step 15.
PM-22 No Content-Length on a merged response Not this step: metadata merge.
PM-23 Determinism Not this step: metadata merge.
PM-24 Merge fan-out is bounded Not this step: metadata merge.
PM-25 A slow position is omitted Not this step: metadata merge.
PM-26 A position's 404 is negatively cached Not this step: metadata merge.
PM-27 A negatively cached position hides a publish for the window Not this step: metadata merge.
PM-28 HEAD matches its GET (metadata) Not this step: Steps 15 and 16.
PM-29 Round trip through a lower-priority position Not this step: e2e, Step 19.
RP-1 Remote contributor entries re-point Not this step: packument route.
RP-2 Redirect delivery does not bypass the re-point Not this step: metadata routes.
RP-3 No Content-Length on a re-pointed response Not this step: metadata routes.
RP-4 Hosted contributor entries re-point Not this step: packument route.
RP-5 A contributor's cache is untouched Not this step: metadata routes.
RP-6 Scoped package encoding survives the re-point Not this step: packument route.
RP-7 Integrity fields survive the re-point Not this step: packument route.
RP-8 Abbreviated variant Not this step: Step 15.
RP-9 dist-tags carries no rewriting Not this step: Step 16.
RP-10 Round trip through a remote tarball winner Not this step: e2e, Step 19.
RP-11 A winner change between the two reads is visible TestVirtualTarballHandler_ServesAWinnerChangeBetweenReads. Its first read is a tarball read, because the packument route is not on this branch; the second read serves hosted_b's bytes and validators.
C-1 ETag is derived from the merge inputs Not this step: metadata routes.
C-2 The validator tracks the inputs Not this step: metadata routes.
C-3 A 304 costs no blob read Not this step: metadata routes.
C-4 A cold contributor still yields a validator Not this step: metadata routes.
C-5 ETag from a hosted contributor's rebuilt row Not this step: metadata routes.
C-6 A streamed tarball carries no ETag TestVirtualTarballHandler_ColdStreamCarriesNoETagAndTheNextReadDoes, TestVirtualTarballHandler_ServesTheWinnersBytes/a_remote_winner's_cold_fetch_streams_the_upstream_body_with_no_ETag_and_no_Last-Modified
C-7 If-Modified-Since follows the winner's kind; If-None-Match decides TestVirtualTarballHandler_ConditionalRequestsFollowTheWinnersKind, TestVirtualTarballHandler_ColdHEADDrainCutHonoursIfNoneMatchOnTheCachedCopy (cold HEAD cache fallback), TestVirtualTarballHandler_ServesTheWinnersBytes (Last-Modified on hosted winners only), TestNpmVirtualHostedTarballLookupStmt_ProjectsCreatedAt, TestNpmVirtualHostedTarballLookup_CarriesTheFilesCreatedAt
C-8 Visibility comes from the virtual repository TestVirtualTarballHandler_CacheControlFollowsTheVirtualRepository
AD-1 Denial re-routes to the next upstream TestVirtualTarballHandler_ServesTheWinnersBytes/a_denial_re-routes_the_read_to_the_next_eligible_position_and_is_audited
AD-2 All upstreams denied TestVirtualTarballHandler_AnswersTheNoWinnerVerdicts/every_upstream_denied_answers_the_absence_and_is_audited (file_not_found, ruling E3)
AD-3 Version rule does not govern a packument Not this step: metadata routes.
AD-4 Version rule governs a tarball TestVirtualTarballHandler_ServesTheWinnersBytes/a_version_rule_matching_the_version_parsed_from_the_file_name_keeps_the_position_eligible, .../a_version_rule_not_matching_the_parsed_version_excludes_the_position
AD-5 Package-name rule admits a match Not this step: matcher, Step 7 and S13.
AD-6 Scope rule admits a match Not this step: matcher, Step 7 and S13.
AD-7 Scope rule on an unscoped package Not this step: matcher, Step 7 and S13.
AD-8 Corrupt rule fails closed on a tarball request TestVirtualTarballHandler_AnswersTheNoWinnerVerdicts/a_corrupt_rule_on_every_upstream_is_a_data_error,_never_an_absence. Error log and audit reason: resolver suite.
AD-9 Corrupt rule fails closed on a packument request Not this step: metadata routes.
AD-10 A corrupted deny rule does not stop denying Tarball half: TestVirtualTarballHandler_AnswersTheNoWinnerVerdicts/a_corrupted_deny_rule_matching_the_package_is_a_data_error,_never_an_admission
AD-11 Every upstream ineligible for a data error TestVirtualTarballHandler_AnswersTheNoWinnerVerdicts/a_corrupt_rule_on_every_upstream_is_a_data_error,_never_an_absence
AD-12 A data error alongside a policy denial is still a 500 TestVirtualTarballHandler_AnswersTheNoWinnerVerdicts/a_denial_alongside_a_corrupt_rule_is_a_500,_not_the_all-denied_404
W-1 Publish rejected Not this step: write unavailability (virtual_unsupported.go).
W-2 Dist-tag set rejected Not this step: write unavailability.
W-3 Dist-tag delete rejected Not this step: write unavailability.
W-4 Single-version unpublish rejected Not this step: write unavailability.
W-5 Whole-package unpublish rejected Not this step: write unavailability.
W-6 Tarball delete rejected Not this step: write unavailability.
W-7 No resolution runs on a write verb Not this step: write unavailability.
W-8 Authorization precedes the kind dispatch Not this step: dispatcher and authorization.
V-1 HEAD matches GET, tarball third TestVirtualTarballHandler_HEADMatchesGET (hosted and cached-remote winners), TestVirtualTarballHandler_RejectsTheTargetBeforeResolution (HEAD status on every rejection)
V-2 Unsafe element in the file name returns 400 before resolution TestVirtualTarballHandler_RejectsTheTargetBeforeResolution
V-3 Unparseable file name returns 404 with no rule evaluation and no resolution TestVirtualTarballHandler_RejectsTheTargetBeforeResolution, TestBuildNpmDispatcher_WiredCompositionServesTheVirtualTarballRoute
V-4 Invalid package name returns 422 before resolution TestVirtualTarballHandler_RejectsTheTargetBeforeResolution (tarball route; Steps 15 and 16 own the metadata routes)
V-5 The legacy tag route is not served Not this step: dispatcher.
CC-1 One upstream fetch across concurrent virtual reads Not this step: Step 15.
CC-2 Coalescing across virtual repositories and positions Not this step: Step 15.
S-1 Reorder in one transaction Not this step: schema, Steps 1 to 3.
S-2 Duplicate upstream rejected Not this step: schema.
S-3 Deleting a listed upstream is refused Not this step: schema.
S-4 Deleting the virtual repository removes its list Not this step: schema.
S-5 Range and length constraints hold Not this step: schema.
S-6 Namespace isolation Not this step: schema.

Card tests and issue notes

# Item Tests
T-1 Tarball larger than the metadata body cap streams TestVirtualTarballHandler_StreamsATarballLargerThanTheMetadataCap (BodyKindBlob, no MaxBodyBytes override)
T-2 The slot is wired and the route is no longer 501 TestBuildNpmVirtualSlots_SetsTheTarballOption, TestBuildNpmDispatcher_WiredCompositionServesTheVirtualTarballRoute, TestMountSlugAnchoredFormats_NpmVirtualRoutes/tarball
T-3 Boot-time refusal of an unusable dependency TestNewVirtualTarballHandler_PanicsOnAnUnusableDependency
T-4 Wiring faults and the repository row read TestVirtualTarballHandler_AnswersAWiringFaultWithA500, TestVirtualTarballHandler_MapsTheRepositoryRowRead, TestVirtualResolution_DrainFailureReportsAnUnbuiltFacade
F4-1 A warm serve read past the budget delivers a whole body TestVirtualTarballHandler_WarmServeOutlivesTheResolveBudget
F4-2 Budget expiry answers 503 with Retry-After: 1 TestVirtualTarballHandler_MapsScriptedResolutionFailures/budget_expiry

Error cases

# Condition Tests
E-1 Write verb on a virtual repository: 405 Not this step: write unavailability.
E-2 No winner, an absence established: 404 file_not_found (tarball) TestVirtualTarballHandler_AnswersTheNoWinnerVerdicts/nothing_holds_the_tarball, .../a_hosted_miss_alongside_an_unhealthy_remote_establishes_an_absence, TestMountSlugAnchoredFormats_NpmVirtualRoutes/tarball
E-3 Merge produced no document: 404 package_not_found Not this step: metadata routes.
E-4 Merge read with some positions omitted: 200 Not this step: metadata routes.
E-5 Merge read, data-error veto: 503 Not this step: metadata routes.
E-6 No upstreams: 404 TestVirtualTarballHandler_AnswersTheNoWinnerVerdicts/no_upstreams_configured
E-7 Every upstream denied: 404 TestVirtualTarballHandler_AnswersTheNoWinnerVerdicts/every_upstream_denied_answers_the_absence_and_is_audited
E-8 Every eligible position unhealthy: 503 with Retry-After TestVirtualTarballHandler_AnswersTheNoWinnerVerdicts/every_eligible_position_is_an_unhealthy_remote
E-9 No absence, no cached copy: 503 with Retry-After TestVirtualTarballHandler_AnswersTheNoWinnerVerdicts/an_outage_with_no_cached_copy_is_unavailable,_not_absent
E-10 No absence, a cached copy: 200 from the highest-priority holder TestVirtualTarballHandler_ServesTheWinnersBytes/an_outage_falls_back_to_the_highest-priority_position_holding_a_cached_copy, TestVirtualTarballHandler_ColdHEADDrainCutServesTheWinnersCachedCopy (cold HEAD whose drain the upstream cuts)
E-11 Winner Fetch fails after a successful Probe: the winner's status TestVirtualTarballHandler_AnswersTheNoWinnerVerdicts/the_winner's_refused_fetch_maps_its_status_and_does_not_fall_through. The relayed Retry-After rule: virtual_read_errors_test.go.
E-12 Upload-session admission cap refuses the winner's fill: 503 TestVirtualTarballHandler_RelaysAnUploadSessionShed
E-13 Hosted metadata serve refused by its rebuild: 503 Not this step: metadata routes; no tarball arm.
E-14 Hosted Hit read fails otherwise: 500 Not this step: metadata routes.
E-15 Abandonment: no response Not asserted on this route: the ResolverCancelled arm is virtual_read_errors_test.go's.
E-16 Budget expiry: 503 with Retry-After: 1 TestVirtualTarballHandler_MapsScriptedResolutionFailures/budget_expiry
E-17 Infrastructure, cache read or write failed: 500 TestVirtualTarballHandler_MapsScriptedResolutionFailures/cache_fill_infrastructure, .../an_unnamed_failure, TestVirtualTarballHandler_ColdHEADDrainResolvedToNoCopyAnswers500
E-18 Infrastructure, no upstream eligible for a data error: 500 TestVirtualTarballHandler_MapsScriptedResolutionFailures/every_upstream_ineligible, TestVirtualTarballHandler_AnswersTheNoWinnerVerdicts/an_upstream_of_an_unexpected_kind_fails_closed, .../a_corrupt_rule_on_every_upstream_is_a_data_error,_never_an_absence
E-19 Infrastructure, a coalesced follower outwaited its leader: 503 with Retry-After: 1 TestVirtualTarballHandler_MapsScriptedResolutionFailures/single-flight_timeout, .../leader_canceled, .../fill_abandoned, TestVirtualTarballHandler_ColdHEADDrainFailureAnswersByWhoseFailureItIs/a_follower's_drain_ends_when_its_leader's_client_disconnects, .../a_follower's_drain_ends_when_its_leader_abandons_the_fill (cold HEAD drain)
E-20 Infrastructure, header injection: 500 TestVirtualTarballHandler_MapsScriptedResolutionFailures/header_injection
E-21 Legacy tag route: 404 Not this step: dispatcher.
E-22 Unsafe file-name element: 400 file_name_invalid TestVirtualTarballHandler_RejectsTheTargetBeforeResolution
E-23 Unparseable tarball file name: 404 file_not_found TestVirtualTarballHandler_RejectsTheTargetBeforeResolution
E-24 Package name fails the npm regex: 422 TestVirtualTarballHandler_RejectsTheTargetBeforeResolution

Security considerations

# Concern Tests
SC-1 No credentials of its own S13 and S15 own the remote legs. Not tested in this MR.
SC-2 Authorization is on the addressed repository Middleware and dispatcher. Not tested in this MR.
SC-3 A composition can widen access; Cache-Control follows the virtual repository TestVirtualTarballHandler_CacheControlFollowsTheVirtualRepository
SC-4 The recursion guard is defended twice TestVirtualTarballHandler_AnswersTheNoWinnerVerdicts/an_upstream_of_an_unexpected_kind_fails_closed (the resolution half)
SC-5 The re-point keeps pulls inside the registry Metadata routes. The tarball route has no re-point.
SC-6 Denied upstreams are indistinguishable in the response TestVirtualTarballHandler_AnswersTheNoWinnerVerdicts: the all-denied and nothing-holds rows assert the same 404 file_not_found
SC-7 No new outbound surface S13 and S15 own it. Every refusal asserts no upstream host in the body (requireVTRefused).
SC-8 Streaming bounds are each position's TestVirtualTarballHandler_StreamsATarballLargerThanTheMetadataCap
SC-9 The merge asks every upstream on every metadata read Not this step: metadata merge.
SC-10 Integrity divergence is reported, not resolved Not this step: metadata merge.

E2E scenario catalog

This MR adds and changes no e2e scenario. docs/testing/e2e/npm.md lists virtual npm repositories as out of scope and owned by S31. Plan Step 19 (#900 (closed)) owns that catalog for the whole plan. It removes that scope line and adds the ## Virtual repositories section.

The one edit in docs/testing/e2e/npm.md corrects the reason in the scope paragraph for virtual repositories, which the tarball route made false. The edit adds no row, no section and no scope entry. Virtual repositories stay out of scope: the packument and dist-tags routes answer 501, so a package manager, which reads the packument first, cannot install through a virtual repository. For the same reason, rulings E17 and E18 add no scenario.

User documentation

This MR changes no file in docs/user/. docs/user/repositories/_index.md states that virtual repositories are in development, and that statement stays true. An npm client cannot install through a virtual repository yet, because the packument route answers 501.

Verification

Check Result
driver.sh smoke against the running service 97 passed, 0 failed
Direct requests against the running service Traversal in the file name: 400. Unparseable file name: 404 with no upstream request. Denied package: 404 file_not_found. HEAD of the same URL: the same status and headers as GET, with no body.
Positive hosted-winner serve against the running service Not run. The sandbox could not seed a hosted npm file. The unit tests in the coverage table cover the Last-Modified, conditional-request and winner-change cases.
npm conformance, CI job conformance:npm:s3-garage The job passed in merged-results pipeline 2910937642 for head 524acb2a7. The job runs scripts/conformance/npm-e2e.sh, the same script as mise run conformance:npm. The harness seeds only a hosted repository, so it does not reach the virtual tarball route.

Size

At head 524acb2a7c20d7ef3a112e0a95e20c3628c1eac1, the diff against the merge base changes 27 files and 4,263 lines (+4,131, −132), from git diff --numstat b777170a1b4ddd78d6ee161160e21113bb5954cf...524acb2a7c20d7ef3a112e0a95e20c3628c1eac1:

File group Files Added Removed
Handler and usage events, internal/format/npm/virtual_tarball.go, virtual_tarball_usagedata.go 2 885 0
Handler tests, internal/format/npm/virtual_tarball_test.go, virtual_tarball_faults_test.go, virtual_tarball_usagedata_test.go 3 2,962 0
CreatedAt carriage, the drain-failure entry point, and comments, other internal/format/npm/*.go 5 49 54
Resolution facade tests, internal/format/npm/virtual_operations_test.go, virtual_operations_internal_test.go 2 42 0
Datastore, internal/datastore/npm_virtual_hosted_lookup.go 1 10 5
Datastore tests 2 68 0
Wiring, cmd/artifact-registry/wire_npm_virtual.go 1 21 8
Wiring tests 2 43 13
Documentation (docs/, internal/format/npm/*.md) 7 29 40
Run recipe, .claude/skills/run-artifact-registry/ 2 22 12

A split does not make this MR easier to review. The handler test suite is 70% of the changed lines. It is the conditional-request and verdict matrix across two winner kinds that the acceptance criteria require, plus the fault and usage-event cases. The plan's seam check for Step 17 found no seam to extract: the tarball serve path is one response with one validator branch. To move the handler away from its tests is to land code with no tests. The CreatedAt carriage (about 140 changed lines with its tests) has no consumer other than this handler.

Merge order

  • !3109 (merged) (sylviashen, open, S31 Step 15, the packument route) rewrites the same text as this MR:

    • the paragraph in internal/format/npm/virtual_read_errors.md
    • the resolve_timeout sentence in internal/format/npm/virtual_operations.md
    • the negative_cache_ttl sentence in docs/dev/configuration-reference.md
    • the count of "npm read paths" in the server.timeouts.write row of docs/dev/configuration-reference.md
    • the npmVirtualWiring.ServerWriteTimeout comment in cmd/artifact-registry/wire_npm_virtual.go

    Each MR writes this text for a tree that does not have the other MR, so the text is not correct after both merge. The MR that merges second reconciles this text so that it names both the packument route and the tarball route.

    git merge-tree of this branch and !3109 (merged) also reports content conflicts in these paths:

    • .claude/skills/run-artifact-registry/SKILL.md
    • .claude/skills/run-artifact-registry/driver.sh
    • cmd/artifact-registry/wire_npm_virtual_integration_test.go
    • cmd/artifact-registry/wire_npm_virtual_test.go
  • !3104 (merged) (sylviashen, docs only) adds to Step 17 the tarball half of the spec criterion for a hosted miss next to an unhealthy remote: 404 file_not_found and no request to the unhealthy remote. This MR already asserts that behavior. Either merge order works, because !3104 (merged) changes no code. Until !3104 (merged) merges, spec Resolution #9 names package_not_found, and this MR's assertion follows the Error Cases row. !3104 (merged) does not change Resolution #6 (closed).

  • The dependency on #895 (closed) (S31 Step 14, the composition root) is met: its MRs !3074 (merged), !3075 (merged) and !3076 (merged) are merged.

Database Review Evidence

Queries

Note

Plans are from EXPLAIN (ANALYZE, BUFFERS) against an ephemeral PostgreSQL 17 container (matching GL_PG_CURR_VERSION from .gitlab-ci-other-versions.yml), with synthesized seed data rolled back per query and the container torn down at the end of the run. Numbers reflect moderate cardinality and do not capture production-scale effects. See Database review evidence for seed sizing, methodology, and the anomalies the skill flags. Expand each row's details for the seed shape, rendered SQL, bound args, and raw plan.

Method Plan node Index Rows (plan / actual) Cost Time Buffers (hit / read) Partitions
datastore.NpmVirtualHostedTarballLookup Unique npm_packages_p34_namespace_id_npm_repository_id_name_idx, npm_versions_p34_namespace_id_npm_package_id_id_idx, npm_files_p34_namespace_id_npm_version_id_idx 1 / 3 46.71 0.254ms 482 / 0 1/64, 1/64, 1/64

Query notes:

  • datastore.NpmVirtualHostedTarballLookup: plan vs actual rows diverge 50x on the npm_versions leg (1 estimated, 50 actual per loop). The planner uses the average version count per package, and the seed gives the target package 50 versions. ANALYZE ran.
  • datastore.NpmVirtualHostedTarballLookup: the npm_files probe uses (namespace_id, npm_version_id) and filters file_name, so it probes once per live version (150 probes for 3 hits). The work grows with the live version count of the package, multiplied by the position count.
  • datastore.NpmVirtualHostedTarballLookup: the plan starts at npm_packages. The merged Step 5 MR !1975 (merged) rejected this join order: driven from npm_packages, the read walks every live version of the package and probes npm_files once for each. ADR-004 permits 25,000 versions per package.
  • datastore.NpmVirtualHostedTarballLookup: no test pins the join order since commit 23f228ed9 ("test(datastore): delete the query-plan assertions"), which removed TestNpmVirtualHostedTarballLookup_DrivesFromNpmFiles. The database review evidence is the only record of this plan.
  • datastore.NpmVirtualHostedTarballLookup: this MR adds npm_files.created_at to the select list. It makes no query change and no index change. The plan shape, the indexes, and the estimates are the same at the merge-base 1ea37fc3.
  • The join order is tracked in the follow-up issue #1518.
datastore.NpmVirtualHostedTarballLookup

Summary: The plan returns the right rows: index scans on all three tables prune to 1 of 64 partitions each, and an Incremental Sort feeds DISTINCT ON. The plan starts at npm_packages, the order that !1975 (merged) rejected. The versions-leg estimate is 50x low, and the files probe filters file_name once per version (see Query notes).

Seed shape: namespaces=1, repositories=10, npm_repositories=10, blob_storage_blobs=1, blob_storage_attachments=1, npm_packages=5000, npm_versions=5490, npm_files=5490

Rendered SQL:

SELECT DISTINCT ON (npm_packages.npm_repository_id) npm_packages.npm_repository_id AS "npm_packages.npm_repository_id",
     npm_files.blob_sha256 AS "npm_files.blob_sha256",
     npm_files.created_at AS "npm_files.created_at"
FROM public.npm_packages
     INNER JOIN public.npm_versions ON ((npm_versions.namespace_id = npm_packages.namespace_id) AND (npm_versions.npm_package_id = npm_packages.id))
     INNER JOIN public.npm_files ON ((npm_files.namespace_id = npm_versions.namespace_id) AND (npm_files.npm_version_id = npm_versions.id))
WHERE ((((((((npm_packages.namespace_id = $1::uuid) AND (npm_packages.npm_repository_id IN ($2::uuid, $3::uuid, $4::uuid))) AND (npm_packages.name = $5::text)) AND (npm_packages.soft_deleted_at IS NULL)) AND (npm_versions.namespace_id = $6::uuid)) AND (npm_versions.soft_deleted_at IS NULL)) AND (npm_files.namespace_id = $7::uuid)) AND (npm_files.file_name = $8::text)) AND (npm_files.soft_deleted_at IS NULL)
ORDER BY npm_packages.npm_repository_id ASC, npm_files.created_at DESC, npm_files.id DESC;

Bound args: [030333d2-2ab0-7cbf-9f9e-d828640fe8e9, 45c747e1-f808-73f0-9347-f02f8d9f1861, f120888d-5280-779f-a06c-8206853a076b, 4a31e261-21c4-759c-bcca-2a08deec867f, review-prep-pkg-0250, 030333d2-2ab0-7cbf-9f9e-d828640fe8e9, 030333d2-2ab0-7cbf-9f9e-d828640fe8e9, review-prep-pkg-0250-1.0.25.tgz]

Plan (EXPLAIN (ANALYZE, BUFFERS) output):

 Unique  (cost=23.74..46.71 rows=1 width=73) (actual time=0.252..0.254 rows=3 loops=1)
   Buffers: shared hit=482
   ->  Incremental Sort  (cost=23.74..46.71 rows=2 width=73) (actual time=0.252..0.253 rows=3 loops=1)
         Sort Key: npm_packages.npm_repository_id, npm_files.created_at DESC, npm_files.id DESC
         Presorted Key: npm_packages.npm_repository_id
         Full-sort Groups: 1  Sort Method: quicksort  Average Memory: 25kB  Peak Memory: 25kB
         Buffers: shared hit=482
         ->  Nested Loop  (cost=0.85..46.62 rows=1 width=73) (actual time=0.094..0.240 rows=3 loops=1)
               Buffers: shared hit=482
               ->  Nested Loop  (cost=0.56..45.35 rows=3 width=48) (actual time=0.036..0.069 rows=150 loops=1)
                     Buffers: shared hit=32
                     ->  Index Scan using npm_packages_p34_namespace_id_npm_repository_id_name_idx on npm_packages_p34 npm_packages  (cost=0.28..20.41 rows=3 width=48) (actual time=0.022..0.027 rows=3 loops=1)
                           Index Cond: ((namespace_id = '030333d2-2ab0-7cbf-9f9e-d828640fe8e9'::uuid) AND (npm_repository_id = ANY ('{45c747e1-f808-73f0-9347-f02f8d9f1861,f120888d-5280-779f-a06c-8206853a076b,4a31e261-21c4-759c-bcca-2a08deec867f}'::uuid[])) AND (name = 'review-prep-pkg-0250'::text))
                           Buffers: shared hit=7
                     ->  Index Scan using npm_versions_p34_namespace_id_npm_package_id_id_idx on npm_versions_p34 npm_versions  (cost=0.28..8.30 rows=1 width=48) (actual time=0.006..0.011 rows=50 loops=3)
                           Index Cond: ((namespace_id = '030333d2-2ab0-7cbf-9f9e-d828640fe8e9'::uuid) AND (npm_package_id = npm_packages.id))
                           Filter: (soft_deleted_at IS NULL)
                           Buffers: shared hit=25
               ->  Index Scan using npm_files_p34_namespace_id_npm_version_id_idx on npm_files_p34 npm_files  (cost=0.28..0.41 rows=1 width=89) (actual time=0.001..0.001 rows=0 loops=150)
                     Index Cond: ((namespace_id = '030333d2-2ab0-7cbf-9f9e-d828640fe8e9'::uuid) AND (npm_version_id = npm_versions.id))
                     Filter: ((soft_deleted_at IS NULL) AND (file_name = 'review-prep-pkg-0250-1.0.25.tgz'::text))
                     Rows Removed by Filter: 1
                     Buffers: shared hit=450
 Planning:
   Buffers: shared hit=105
 Planning Time: 0.860 ms
 Execution Time: 0.294 ms

Timings: planning 0.860ms, execution 0.294ms, total 1.154ms.

Spec gaps

  • A vanished blob (ruling E18). The S31 Error Cases table has no row for a tarball winner whose stored blob is gone. For a hosted winner, this MR answers 404 file_not_found, the same answer as the S11 tarball route for the same row state. For a remote winner, this MR answers 503 upstream_unavailable with the Retry-After of the health interval. This is the same answer as the Maven virtual route, because the upstream can still hold the bytes. This MR does not change the spec.
  • HEAD under redirect delivery (ruling E19). S31 Validation and reads #1 states that a HEAD returns the same status and headers as the matching GET. Under redirect delivery, the tarball GET of a stored winner answers 307, and its HEAD answers 200 from the stored metadata. S10, S14, S16 and S32 specify this 200 for their routes. This MR keeps the 200, so on this route #1 holds only for proxy delivery. This MR does not change the spec.
  • Download recording (ruling E21). S31 does not state whether the virtual tarball route records a download. S30 and S32 record a download on the position that supplied the bytes. This MR records none: a delivered read does not bump last_downloaded_at on the hosted or remote winner, and does not book repositories.downloads_count on a hosted winner. As a result, a package that clients pull only through a virtual repository looks unused in that data. The S31 spec author amends S31 with the recording rule. #1520 (closed) owns the recording. The recording must land before any npm cache retention sweep reads npm remote last_downloaded_at, because a remote row that clients read only through a virtual repository keeps a stale or NULL value. No purger on main reads last_downloaded_at today.

Related to #898 (closed)

This MR does not give evidence for two items of #898 (closed):

  • The packument half of Packument re-point #11 (closed). This half needs the Step 15 packument route, which is open as !3109 (merged).
  • The diff of this test suite against the Step 15 test suite. Step 15 is not merged.

This is a bot message 🤖 — /smurfit

Edited by Pawel Rozlach

Merge request reports

Loading
Loading