Repository navigation
feat(pnpr): multiple-uplink fallback ordering per package - #12648
Conversation
Let a `proxy:` rule name an ordered list of uplinks (`proxy: npmjs private`, or the YAML sequence form) and walk it as a fallback chain, matching verdaccio's serial first-success semantics: try uplinks in declared order, stop at the first that answers, and fall through to the next on a 404 or transport/circuit failure. A later private uplink can host a package the primary 404s; a transient error on one uplink never surfaces as an authoritative 404 the client would cache as "gone". - config: `PackageAccess.proxy` becomes an ordered `AccessSpec` list; `Config::resolve_uplinks` returns the chain (skipping unknown names); `resolve_uplink` stays as a primary-only convenience. - packument: walk the chain, sending each uplink only its own cached validators (an ETag is origin-specific, so replaying one uplink's against another could spuriously 304). Validators are now stored in a per-uplink map keyed by uplink name; an older single-object sidecar degrades to one unconditional refetch. - tarball: try each uplink in order; integrity binds the streamed bytes, so the serving uplink decides whether they are mirrored (`caches()`) while the cache read is gated on whether any uplink caches. - the cache freshness window (`maxage`) comes from the primary uplink. Out of scope (left to a later change): verdaccio's full cross-uplink metadata merge and per-version origin tracking. pnpr stays first-success fallback with one cache entry per package. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughOrdered uplink lists now drive package proxy resolution, cache validators are stored per uplink, and tarball/packument serving falls back across multiple upstreams with per-uplink revalidation. Tests cover config parsing, storage behavior, and two-uplink server flows. ChangesMulti-uplink proxy and cache fallback
Sequence Diagram(s)sequenceDiagram
participant Client
participant server
participant Storage
participant Upstream
Client->>server: request tarball or packument
server->>Storage: load cache entry / validators
loop ordered upstreams
server->>Upstream: fetch or conditional GET
Upstream-->>server: bytes, 304, 404, or error
end
server->>Storage: store refreshed body or per-uplink validators
server-->>Client: response or stale fallback
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Suggested reviewers
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main pnpm/pnpm#12648 +/- ##
==========================================
+ Coverage 88.58% 88.61% +0.03%
==========================================
Files 339 339
Lines 49171 49277 +106
==========================================
+ Hits 43557 43667 +110
+ Misses 5614 5610 -4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
PR Summary by Qodopnpr: Support ordered multi-uplink fallback per package (Verdaccio-style) Description
Diagram
High-Level Assessment
Files changed (8)
|
There was a problem hiding this comment.
Pull request overview
Adds Verdaccio-like ordered multi-uplink fallback support to pnpr on a per-package basis, allowing proxy: rules to specify an uplink chain and having the server try each uplink in order until one succeeds.
Changes:
- Extend config parsing so
proxy:can be a whitespace-separated string or YAML sequence, producing an ordered uplink chain viaConfig::resolve_uplinks. - Update packument and tarball proxying to walk the uplink chain with first-success semantics, including better handling of 404 vs transport/circuit failures.
- Store packument conditional-GET validators per uplink (ETag/Last-Modified are origin-specific) and update cache read/write paths + tests accordingly.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pnpr/crates/pnpr/tests/server.rs | Adds integration tests for packument/tarball fallback behavior and stale-cache serving when uplinks fail. |
| pnpr/crates/pnpr/src/upstream.rs | Introduces ValidatorsByUplink and exposes Upstream::name() for per-uplink cache keying. |
| pnpr/crates/pnpr/src/storage/tests.rs | Updates cache tests to write/read validators keyed by uplink name. |
| pnpr/crates/pnpr/src/storage.rs | Changes packument cache metadata to store validators per uplink and merges validator maps on write. |
| pnpr/crates/pnpr/src/server.rs | Implements uplink-chain resolution and fallback fetching for packuments and tarballs. |
| pnpr/crates/pnpr/src/lib.rs | Re-exports AccessSpec to support new config surface. |
| pnpr/crates/pnpr/src/config/tests.rs | Adds unit tests for proxy: parsing and resolve_uplinks ordering/unknown-name skipping. |
| pnpr/crates/pnpr/src/config.rs | Changes PackageAccess.proxy to AccessSpec and adds ordered-token extraction + resolve_uplinks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // The TTL is a per-package cache property decided before any uplink is | ||
| // contacted, so it comes from the primary (first) uplink in the chain | ||
| // that sets a `maxage` (verdaccio's knob); otherwise the global | ||
| // `packument_ttl` (the `--packument-ttl-secs` flag) applies. | ||
| let ttl = upstreams | ||
| .iter() | ||
| .find_map(|upstream| upstream.maxage()) | ||
| .unwrap_or(state.inner.config.packument_ttl); |
There was a problem hiding this comment.
Fixed — TTL now uses upstreams.first().and_then(maxage) instead of scanning the chain, so only the primary uplink's maxage can set the cache freshness window (else the global packument_ttl). A secondary's maxage no longer affects it.
Written by an agent (Claude Code, claude-opus-4-8).
Code Review by Qodo
1. Tarball cache bypasses hard-4xx
|
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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 `@pnpr/crates/pnpr/src/server.rs`:
- Around line 2413-2418: In the fallback loops around fetch_tarball_response in
server.rs, stop treating every Err as retryable: only continue to the next
upstream for transport/circuit failures or retryable upstream responses like
5xx, and return immediately for hard upstream status errors such as 401/403.
Update both multi-uplink paths at the locations using match on FetchOutcome and
Err so the first non-retryable upstream failure is surfaced instead of being
masked by a later uplink.
- Around line 2478-2485: The packument TTL selection is currently scanning every
uplink for maxage, but it should only use the primary uplink’s setting and
otherwise fall back to the global packument_ttl. Update the ttl computation in
server::... where upstreams.iter().find_map(...) is used so it checks only the
first uplink in the chain for maxage, preserving the stated primary-only
contract.
In `@pnpr/crates/pnpr/src/storage.rs`:
- Around line 390-410: Reset the validator map when `write_cached_packument`
replaces the cached body: it currently merges other uplinks’ validators via
`read_validators` and `map.set`, which can let a later `304` reuse a validator
for a body fetched from a different origin. Update `write_cached_packument` in
`storage.rs` so the written metadata is scoped to the current `uplink` only, or
introduce origin/body tracking before any merge, and ensure
`write_packument_with_meta` receives validators that cannot be reused across
uplinks.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: a67ee6cf-cbf4-4935-b705-7ddabb4cbb37
📒 Files selected for processing (8)
pnpr/crates/pnpr/src/config.rspnpr/crates/pnpr/src/config/tests.rspnpr/crates/pnpr/src/lib.rspnpr/crates/pnpr/src/server.rspnpr/crates/pnpr/src/storage.rspnpr/crates/pnpr/src/storage/tests.rspnpr/crates/pnpr/src/upstream.rspnpr/crates/pnpr/tests/server.rs
|
Code review by qodo was updated up to the latest commit f4fab7e |
Integrated-Benchmark Report (Linux)Commit: Each scenario reports direct installs and pnpr installs. Bencher consumes pacquet@HEAD and pnpr@HEAD. Scenario: Isolated linker: fresh restore, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.499867044759999,
"stddev": 0.16579779168845812,
"median": 4.4540078873599995,
"user": 3.7122152199999996,
"system": 3.4026363799999992,
"min": 4.33388329986,
"max": 4.83060820886,
"times": [
4.69378259486,
4.37925488686,
4.34960436586,
4.4672570048599995,
4.83060820886,
4.63139788886,
4.48959037986,
4.38253304786,
4.4407587698599995,
4.33388329986
]
},
{
"command": "pacquet@main",
"mean": 4.46812143286,
"stddev": 0.1402282235385667,
"median": 4.43457487036,
"user": 3.706179519999999,
"system": 3.41214228,
"min": 4.33877160086,
"max": 4.72532723386,
"times": [
4.72061209886,
4.33877160086,
4.45604579686,
4.40731702686,
4.33896465186,
4.38633865986,
4.43868751886,
4.4325923528599995,
4.43655738786,
4.72532723386
]
},
{
"command": "pnpr@HEAD",
"mean": 2.92938108336,
"stddev": 0.10013427116932833,
"median": 2.88519841736,
"user": 2.7465938199999993,
"system": 3.02839188,
"min": 2.8089532458599997,
"max": 3.10730344186,
"times": [
2.89860557486,
2.87179125986,
2.8089532458599997,
2.87022204886,
3.0419798768599997,
2.85890969886,
2.86313837886,
3.04879045186,
2.92411685586,
3.10730344186
]
},
{
"command": "pnpr@main",
"mean": 2.9867185108600003,
"stddev": 0.10782771481265706,
"median": 2.9405766783600003,
"user": 2.7727089199999995,
"system": 3.0259817799999995,
"min": 2.87215083686,
"max": 3.15813786186,
"times": [
2.87215083686,
3.03850009686,
2.88497750786,
2.89203847386,
3.15813786186,
3.05803988486,
2.92975507886,
3.15243201086,
2.93411708486,
2.94703627186
]
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.62579345892,
"stddev": 0.014397984375567168,
"median": 0.6228721923200001,
"user": 0.3808414399999999,
"system": 1.3103337400000001,
"min": 0.6084281448200001,
"max": 0.6573933738200001,
"times": [
0.6264001838200001,
0.6411583058200001,
0.6226994698200001,
0.6230449148200001,
0.6573933738200001,
0.6084281448200001,
0.6128215838200001,
0.6300614238200001,
0.6167519208200001,
0.6191752678200001
]
},
{
"command": "pacquet@main",
"mean": 0.6343883438200001,
"stddev": 0.02021054127258777,
"median": 0.6266422548200001,
"user": 0.3816077399999999,
"system": 1.3060134399999999,
"min": 0.6159684898200001,
"max": 0.67652919982,
"times": [
0.6572100368200001,
0.6306557408200001,
0.6178068298200001,
0.6226287688200001,
0.6369372878200001,
0.6173666788200001,
0.67652919982,
0.6469763188200001,
0.6218040868200001,
0.6159684898200001
]
},
{
"command": "pnpr@HEAD",
"mean": 0.7375541911200001,
"stddev": 0.14190251785144448,
"median": 0.6939292513200002,
"user": 0.39731094,
"system": 1.3634197399999999,
"min": 0.6749983768200001,
"max": 1.13955979482,
"times": [
0.6819912578200001,
0.7107769758200001,
0.6862864798200001,
0.7101701528200001,
0.7069601938200001,
0.6749983768200001,
0.6775393938200001,
0.7015720228200001,
0.6856872628200001,
1.13955979482
]
},
{
"command": "pnpr@main",
"mean": 0.6915320816200001,
"stddev": 0.01763119450632881,
"median": 0.6918548788200001,
"user": 0.3969512399999999,
"system": 1.3406992399999997,
"min": 0.6640705558200001,
"max": 0.7185837718200001,
"times": [
0.7185837718200001,
0.7038005528200001,
0.6919334898200001,
0.66825203182,
0.6917762678200001,
0.6818453938200001,
0.6870309668200001,
0.6640705558200001,
0.6941797228200001,
0.7138480628200001
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.81209763886,
"stddev": 0.052314583129154484,
"median": 4.810997754460001,
"user": 3.8963776599999997,
"system": 3.40978946,
"min": 4.71047667746,
"max": 4.89602898646,
"times": [
4.84547147046,
4.80558271046,
4.75219242846,
4.71047667746,
4.89602898646,
4.8537425804600005,
4.80413777546,
4.81641279846,
4.80089023646,
4.83604072446
]
},
{
"command": "pacquet@main",
"mean": 4.81703761086,
"stddev": 0.08918653915376426,
"median": 4.78561472546,
"user": 3.8883732600000003,
"system": 3.4088609599999997,
"min": 4.70842047946,
"max": 4.93705871946,
"times": [
4.90583397246,
4.88662612546,
4.92875922446,
4.93705871946,
4.71187645046,
4.77741726246,
4.77805944546,
4.70842047946,
4.74315442346,
4.79317000546
]
},
{
"command": "pnpr@HEAD",
"mean": 3.1785742174599996,
"stddev": 0.06325788512519571,
"median": 3.16737066396,
"user": 2.8439195600000002,
"system": 3.1446324599999995,
"min": 3.09047139646,
"max": 3.26492230546,
"times": [
3.17255908546,
3.10096863946,
3.26124465446,
3.15489145646,
3.16218224246,
3.09047139646,
3.26492230546,
3.14834072946,
3.25687576346,
3.17328590146
]
},
{
"command": "pnpr@main",
"mean": 3.2185505299599995,
"stddev": 0.10976606617907568,
"median": 3.18448461996,
"user": 2.8534494600000007,
"system": 3.1806130599999998,
"min": 3.10838916246,
"max": 3.44788884246,
"times": [
3.16718117646,
3.10838916246,
3.20178806346,
3.2576748324600002,
3.16592293446,
3.36018608746,
3.13820804646,
3.44788884246,
3.21956042246,
3.11870573146
]
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.34142102082,
"stddev": 0.012050802146344962,
"median": 1.33925476992,
"user": 1.31898496,
"system": 1.6924059599999999,
"min": 1.32213567242,
"max": 1.3606094124199999,
"times": [
1.3288413454199999,
1.32213567242,
1.33646959642,
1.3606094124199999,
1.35211656842,
1.3384915144199998,
1.33482408842,
1.3556493244199999,
1.34505466042,
1.34001802542
]
},
{
"command": "pacquet@main",
"mean": 1.34380567942,
"stddev": 0.0676670553791599,
"median": 1.32162696842,
"user": 1.3110213600000002,
"system": 1.67856466,
"min": 1.30769111642,
"max": 1.53368108442,
"times": [
1.31959210242,
1.3210772574199998,
1.53368108442,
1.30769111642,
1.32182157742,
1.31038505942,
1.32450169542,
1.34963337442,
1.3282411674199999,
1.32143235942
]
},
{
"command": "pnpr@HEAD",
"mean": 1.42771925972,
"stddev": 0.06993965329705215,
"median": 1.4031871654199999,
"user": 0.5820005599999998,
"system": 1.5577170599999999,
"min": 1.38340695542,
"max": 1.61977062042,
"times": [
1.4467512194199998,
1.38340695542,
1.4004010814199999,
1.61977062042,
1.40124131342,
1.42674149342,
1.4083612454199999,
1.39640639442,
1.4051330174199999,
1.3889792564199999
]
},
{
"command": "pnpr@main",
"mean": 1.42034398662,
"stddev": 0.045758774403746816,
"median": 1.41122622392,
"user": 0.5885012599999999,
"system": 1.5548361599999998,
"min": 1.37862386842,
"max": 1.54056246042,
"times": [
1.4311660074199999,
1.54056246042,
1.42605907742,
1.3972709054199999,
1.42502026042,
1.39501074242,
1.37862386842,
1.3872740964199999,
1.4064268434199998,
1.41602560442
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 3.04633424792,
"stddev": 0.04383646707561471,
"median": 3.03980649402,
"user": 1.7890325,
"system": 1.9721621599999999,
"min": 2.98580191352,
"max": 3.12345519552,
"times": [
3.07017922952,
3.03184764552,
2.98580191352,
2.99724506652,
3.0080837585199998,
3.03245525052,
3.12345519552,
3.04715773752,
3.08934864152,
3.07776804052
]
},
{
"command": "pacquet@main",
"mean": 3.04234828682,
"stddev": 0.06230797419240921,
"median": 3.0322249990200003,
"user": 1.80625,
"system": 1.9612971599999998,
"min": 3.00142881952,
"max": 3.21414122252,
"times": [
3.00142881952,
3.03729549652,
3.00291682552,
3.02021395552,
3.0049107515199998,
3.03409962152,
3.03390593052,
3.03054406752,
3.21414122252,
3.04402617752
]
},
{
"command": "pnpr@HEAD",
"mean": 1.4475314426199999,
"stddev": 0.015417562216925442,
"median": 1.44876908952,
"user": 0.5882489,
"system": 1.59948386,
"min": 1.4142423875199999,
"max": 1.47344858052,
"times": [
1.44772958752,
1.4590068115200001,
1.45491679652,
1.44542682552,
1.47344858052,
1.44217720252,
1.44980859152,
1.4518201475199999,
1.43673749552,
1.4142423875199999
]
},
{
"command": "pnpr@main",
"mean": 1.45727442522,
"stddev": 0.018100180879253157,
"median": 1.45568081102,
"user": 0.6068832,
"system": 1.5616286599999998,
"min": 1.43242579252,
"max": 1.4878511535199999,
"times": [
1.47819664252,
1.47494793652,
1.4878511535199999,
1.45650534052,
1.45893058752,
1.45485628152,
1.43931546052,
1.44658973052,
1.43242579252,
1.44312532652
]
}
]
} |
|
| Branch | pr/12648 |
| Testbed | pacquet |
Click to view all benchmark results
| Benchmark | Latency | Benchmark Result milliseconds (ms) (Result Δ%) | Upper Boundary milliseconds (ms) (Limit %) |
|---|---|---|---|
| isolated-linker.fresh-install.cold-cache.cold-store | 📈 view plot 🚷 view threshold | 4,812.10 ms(+0.94%)Baseline: 4,767.28 ms | 5,720.74 ms (84.12%) |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot 🚷 view threshold | 3,046.33 ms(+0.17%)Baseline: 3,041.08 ms | 3,649.30 ms (83.48%) |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot 🚷 view threshold | 1,341.42 ms(-0.56%)Baseline: 1,348.95 ms | 1,618.74 ms (82.87%) |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot 🚷 view threshold | 4,499.87 ms(-3.70%)Baseline: 4,672.86 ms | 5,607.43 ms (80.25%) |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot 🚷 view threshold | 625.79 ms(-0.29%)Baseline: 627.61 ms | 753.14 ms (83.09%) |
|
| Branch | pr/12648 |
| Testbed | pnpr |
⚠️ WARNING: No Threshold found!Without a Threshold, no Alerts will ever be generated.
Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the--ci-only-thresholdsflag.
Click to view all benchmark results
| Benchmark | Latency | milliseconds (ms) |
|---|---|---|
| isolated-linker.fresh-install.cold-cache.cold-store | 📈 view plot | 3,178.57 ms |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot | 1,447.53 ms |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot | 1,427.72 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot | 2,929.38 ms |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot | 737.55 ms |
- Restrict uplink fallthrough to availability failures (RegistryError::allows_uplink_fallthrough): transport errors, an open circuit, and upstream 5xx. Any authoritative 4xx (401/403 auth, 429 throttle, 400/410, ...) now stops the walk immediately so a later uplink can't mask the primary's rejection of a scoped or rate-limited request. - Scope cached packument validators to the body's origin uplink: the validator map is replaced, not merged, on every write. The cache holds one shared body, so a conditional GET only ever reaches that body's origin and a 304 can no longer revalidate another origin's bytes. - Select the packument TTL from the primary uplink's maxage only (.first().and_then), not the first uplink in the chain that sets one, so a secondary's maxage can't govern the shared cache. Adds unit coverage for the fallthrough classifier and a storage test for origin-scoped validators, plus an integration test that a primary 4xx is not masked by a later uplink. Part of pnpm/pnpm#11973. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Code review by qodo was updated up to the latest commit d20c0e7 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pnpr/crates/pnpr/src/error/tests.rs (1)
157-187: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover the transport-error branch too.
allows_uplink_fallthrough()also returnstrueforRegistryError::Upstream { .. }, but this test only pins theUpstreamStatus(5xx)andUpstreamUnavailablepaths. Adding oneUpstreamcase would keep the third allowed branch from regressing silently.As per path instructions, REVIEW_GUIDE.md says "tests—add regression tests proving failover rules".
🤖 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 `@pnpr/crates/pnpr/src/error/tests.rs` around lines 157 - 187, Add a regression case in allows_uplink_fallthrough_only_for_availability_failures to cover the RegistryError::Upstream branch, since the current test only exercises UpstreamStatus and UpstreamUnavailable. Create an Upstream error instance with representative url/uplink/body data and assert that allows_uplink_fallthrough() returns true, keeping the failover rules pinned alongside the existing cases.Source: Path instructions
🤖 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.
Nitpick comments:
In `@pnpr/crates/pnpr/src/error/tests.rs`:
- Around line 157-187: Add a regression case in
allows_uplink_fallthrough_only_for_availability_failures to cover the
RegistryError::Upstream branch, since the current test only exercises
UpstreamStatus and UpstreamUnavailable. Create an Upstream error instance with
representative url/uplink/body data and assert that allows_uplink_fallthrough()
returns true, keeping the failover rules pinned alongside the existing cases.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 64aeee4d-5d06-4b17-9148-65ce82adfc5b
📒 Files selected for processing (7)
pnpr/crates/pnpr/src/error.rspnpr/crates/pnpr/src/error/tests.rspnpr/crates/pnpr/src/server.rspnpr/crates/pnpr/src/storage.rspnpr/crates/pnpr/src/storage/tests.rspnpr/crates/pnpr/src/upstream.rspnpr/crates/pnpr/tests/server.rs
🚧 Files skipped from review as they are similar to previous changes (4)
- pnpr/crates/pnpr/tests/server.rs
- pnpr/crates/pnpr/src/upstream.rs
- pnpr/crates/pnpr/src/storage/tests.rs
- pnpr/crates/pnpr/src/server.rs
|
Code review by qodo was updated up to the latest commit d20c0e7 |
A non-fallthrough upstream error (an authoritative 4xx: 401/403 auth, 429 throttle, 400/410, ...) now returns the error directly rather than routing through the stale-cache fallback. Serving a cached packument body on a hard rejection would mask the upstream's denial and keep handing out content it is now refusing. Stale-cache fallback is retained only for the case where the whole chain fails with availability errors (transport/circuit/5xx). Adds an integration test that a primary 403 surfaces as a gateway error and does not serve the warmed stale body (and never consults the secondary); the existing all-uplinks-fail stale test confirms transient fallback is unchanged. Part of pnpm/pnpm#11973. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
| let upstreams = resolve_upstreams(state, &name); | ||
| // Read the cache if any uplink in the chain mirrors tarballs (or there's | ||
| // no upstream left at all — a leftover mirror). Reading is harmless: the | ||
| // bytes are verified against the version's `dist.integrity` before being | ||
| // served, whichever uplink originally wrote them. | ||
| let should_read_cache = upstreams.is_empty() || upstreams.iter().any(|u| u.caches()); | ||
| if should_read_cache { | ||
| match state.inner.storage.open_cached_tarball(&name, &filename).await { | ||
| Ok(Some((file, len))) => { |
There was a problem hiding this comment.
1. Tarball cache bypasses hard-4xx 🐞 Bug ⛨ Security
serve_tarball() serves a cached tarball before attempting the uplink fallback chain, so an authoritative upstream 4xx (401/403/429/etc.) from the primary uplink is never observed on a cache hit and can be masked. With multi-uplink chains, the new “hard-4xx stops the walk” policy is therefore unenforced for tarballs whenever the cache contains the bytes.
Agent Prompt
### Issue description
`serve_tarball()` returns a cached tarball before contacting any upstream when `should_read_cache` is true. This means the new hard-4xx policy (do not mask authoritative upstream 4xx) is bypassed entirely on cache hits, and a previously cached tarball can be served even if the primary uplink would now reject the request.
### Issue Context
The PR introduces `RegistryError::allows_uplink_fallthrough()` specifically to prevent masking authoritative upstream 4xx responses across the `proxy:` chain. That enforcement currently only happens inside the upstream-walk code (`fetch_tarball_with_fallback()`), but the tarball cache fast-path returns before that logic runs.
### Fix Focus Areas
- pnpr/crates/pnpr/src/server.rs[888-940]
- pnpr/crates/pnpr/src/error.rs[200-220]
- pnpr/crates/pnpr/src/upstream.rs[285-374]
### Implementation direction (one acceptable approach)
- Treat the tarball cache as a fallback, not a pre-check, when an upstream chain exists:
- Attempt the uplink chain first.
- If the chain returns `NotFound`, return 404.
- If the chain returns a hard 4xx (i.e., `!allows_uplink_fallthrough()`), surface it immediately.
- Only fall back to the cached tarball when the chain fails with an *availability* error (transport/open circuit/5xx), similar to packument’s stale fallback.
- If you need to preserve the “cache-first” performance for the common case, add origin metadata for cached tarballs (uplink name) and only use cache-first when the cached origin is the primary uplink; otherwise consult the primary uplink first to enforce hard-4xx.
- Add an integration test covering: cached tarball exists, primary uplink returns 403, response must be 502/403-equivalent rather than 200 from cache.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
There was a problem hiding this comment.
This is intended behavior, not a bypass — the hard-4xx policy is enforced for tarballs, at the layer that gates them. serve_tarball runs before the cache read: (1) authorize(..., Action::Access) gates the client via pnpr's own access: policy — the upstream's 4xx is about pnpr's service-account credentials, not the client's authorization; (2) load_packument_bytes is called first and applies the full hard-4xx-stops-the-walk / no-stale-on-hard-4xx enforcement and gates which version/integrity are valid (a revoked version 404s once the packument refreshes, bounded by packument_ttl). A cache hit then serves immutable, content-addressed bytes already verified against the packument-declared dist.integrity.
Re-fetching a cached tarball on every request to re-check upstream auth would defeat the mirror and contradict immutable-artifact caching (and matches neither verdaccio nor npm). So no behavior change; I've added a comment at the cache-read site documenting why the policy is enforced upstream of this point so it isn't re-raised.
Written by an agent (Claude Code, claude-opus-4-8).
|
Code review by qodo was updated up to the latest commit 8c1ffd6 |
1 similar comment
|
Code review by qodo was updated up to the latest commit 8c1ffd6 |
Let a
proxy:rule name an ordered list of uplinks (proxy: npmjs private, or the YAML sequence form) and walk it as a fallback chain, matching verdaccio's serial first-success semantics: try uplinks in declared order, stop at the first that answers, and fall through to the next on a 404 or an availability failure. A later private uplink can host a package the primary 404s.PackageAccess.proxybecomes an orderedAccessSpeclist;Config::resolve_uplinksreturns the chain (skipping unknown names);resolve_uplinkstays as a primary-only convenience.304can only confirm the bytes actually on disk and can't revalidate another origin's body. The freshness window (maxage) comes from the primary uplink only.caches()) while the cache read is gated on whether any uplink caches.RegistryError::allows_uplink_fallthrough): transport errors, an open circuit, and upstream5xx. Any authoritative4xx(401/403auth,429throttle,400/410, …) stops the walk immediately so a later uplink can't mask the primary's rejection of a scoped or rate-limited request.Out of scope (left to a later change): verdaccio's full cross-uplink metadata merge and per-version origin tracking. pnpr stays first-success fallback with one cache entry per package.
Summary
Implements the Multiple-uplink fallback ordering per package checklist item of the pnpr↔verdaccio backend-parity tracking issue.
Related to pnpm/tasks#19 — this is a tracking issue covering many parity items, so this PR is intentionally linked without a closing keyword and must not auto-close it on merge.
Squash Commit Body
Checklist
resolve_uplinksparsing/ordering; integration fallback cases: primary 5xx/404 fallback, all-404, hard-4xx no-fallthrough, tarball fallback, stale-cache;errorclassifier unit test; storage origin-scoped-validators test).cargo fmt --all --check,cargo clippy --locked --workspace --all-targets -D warnings,cargo nextest run -p pnpr, doc build with-D warnings,typos, andcargo dylint.Written by an agent (Claude Code, claude-opus-4-8).
Summary by CodeRabbit
NotFoundwhen no upstreams match; failover no longer triggers for hard upstream rejections.