Skip to content

fix(pnpr): cap distinct interned configs to bound resolver memory - #12674

Merged
zkochan merged 4 commits into
pnpm:mainfrom
YESHYUNGSEOK:fix/pnpr-resolver-config-cache-bound
Jun 26, 2026
Merged

zkochan merged 4 commits into
pnpm:mainfrom
YESHYUNGSEOK:fix/pnpr-resolver-config-cache-bound

Conversation

@YESHYUNGSEOK

@YESHYUNGSEOK YESHYUNGSEOK commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The pnpr resolver interns one &'static Config per distinct client
configuration — keyed by the canonical JSON of the caller-supplied
registry, namedRegistries, overrides, and verification policy — and
this cache was unbounded. Each config is leaked (config.leak())
because pacquet's install path requires a &'static Config.

An authenticated caller of POST /-/pnpr/v0/resolve (or
/-/pnpr/v0/verify-lockfile) can therefore exhaust the server's memory by
sending a fresh registry/policy combination on every request: each
distinct key leaks another Config that can never be reclaimed. The
field's "typically one distinct config" rationale only holds for honest
clients.

This caps the cache at MAX_INTERNED_CONFIGS (1024, matching the
existing MAX_RESOLUTION_CACHE_ENTRIES). Past the cap, both endpoints
return 503 instead of interning more. The interning logic is extracted
into a free intern_config function so the bound is unit-testable
without standing up a whole Resolver.

Why a hard cap and not LRU eviction: a leaked config can't be freed, and
removing its key from the map would just let the same key be re-leaked on
the next request — so refusing to leak past a fixed cap is the only real
bound. Reclaiming memory instead would mean threading Arc<Config>
through pacquet's install path in place of &'static Config, which is out
of scope here. The cap is far above the handful of distinct setups a real
fleet produces, and it resets on restart, so legitimate callers never hit
it.

Squash Commit Body

The resolve and verify-lockfile endpoints intern one `&'static Config`
per distinct client configuration, keyed by the canonical JSON of the
caller-supplied registry, namedRegistries, overrides, and verification
policy. Each config is leaked because pacquet's install path requires a
`&'static Config`, and the cache was unbounded.

An authenticated caller could exhaust the server's memory by sending a
request with a fresh registry/policy combination every time: each
distinct key leaks another config that can never be reclaimed.

Cap the cache at MAX_INTERNED_CONFIGS (1024, matching
MAX_RESOLUTION_CACHE_ENTRIES); past the cap, both endpoints return 503
instead of interning more. Eviction is not an option — a leaked config
can't be freed, and removing its key would just let it be re-leaked, so
a hard cap is the only real bound. Reclaiming memory instead would
require threading Arc<Config> through pacquet's install path in place of
`&'static Config`, which is out of scope.

Checklist

  • Added or updated tests.
  • Updated the documentation if needed (doc comments on the cap and the
    configs field).

Written by an agent (Claude Code, claude-opus-4-8).

Summary by CodeRabbit

  • Bug Fixes
    • Resolver endpoints now return a clear HTTP 503 with a JSON error (“too many configs”) when configuration interning limits are reached.
    • Once the limit is hit, the service continues using previously cached configurations instead of failing.
    • Added stricter protection to refuse requests that would exceed the configured canonical key size limit.
  • Tests
    • Added unit tests covering distinct-config capping, byte-limit rejection, and override deduplication regardless of JSON key order.

The resolve and verify-lockfile endpoints intern one `&'static Config`
per distinct client configuration, keyed by the canonical JSON of the
caller-supplied `registry`, `namedRegistries`, `overrides`, and
verification policy. Each config is leaked because pacquet's install
path requires a `&'static Config`, and the cache was unbounded.

An authenticated caller could therefore exhaust the server's memory by
sending a request with a fresh registry/policy combination every time:
each distinct key leaks another config that can never be reclaimed. The
field's "typically one" rationale only holds for honest clients.

Cap the cache at MAX_INTERNED_CONFIGS (1024, matching
MAX_RESOLUTION_CACHE_ENTRIES); past the cap, both endpoints return 503
instead of interning more. Eviction is not an option here — a leaked
config can't be freed, and removing its key would just let the same key
be re-leaked, so refusing to leak past a hard cap is the only real
bound. Reclaiming memory instead would require threading `Arc<Config>`
through pacquet's install path in place of `&'static Config`, which is
out of scope for this fix. The cap is far above the handful of distinct
setups a real fleet produces, and it resets on restart, so legitimate
callers never hit it.

Co-authored-by: Claude <[email protected]>
@YESHYUNGSEOK
YESHYUNGSEOK requested a review from zkochan as a code owner June 26, 2026 01:40
@coderabbitai

coderabbitai Bot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 8e8a1ed0-a7ee-41b9-b7bb-f49d914ed8c7

📥 Commits

Reviewing files that changed from the base of the PR and between a08d929 and 55dd395.

📒 Files selected for processing (1)
  • pnpr/crates/pnpr/src/resolver/tests.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • pnpr/crates/pnpr/src/resolver/tests.rs

📝 Walkthrough

Walkthrough

The resolver now bounds config interning, preserves existing cached configs, and returns HTTP 503 when config creation is unavailable. Unit tests cover the cap, byte limit, and override canonicalization.

Changes

Resolver config interning cap

Layer / File(s) Summary
Config interning and limits
pnpr/crates/pnpr/src/resolver.rs, pnpr/crates/pnpr/src/resolver/tests.rs
Resolver::config_for now returns Option<&'static PacquetConfig> through intern_config(...), which reuses existing configs, stops creating new ones at MAX_INTERNED_CONFIGS, bounds canonical key size with MAX_CONFIG_KEY_BYTES, and canonicalizes override ordering. The resolver docs and unit tests cover the capped cache, byte limit, and override deduplication.
503 on config exhaustion
pnpr/crates/pnpr/src/resolver.rs
handle_resolve and handle_verify_lockfile now return HTTP 503 with TOO_MANY_CONFIGS_MESSAGE when config_for(...) returns None.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

product: pnpr

Suggested reviewers

  • zkochan
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Cap pnpr interned resolver configs to prevent unbounded leaked memory
🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes

Grey Divider

Description

• Cap distinct leaked pacquet Configs to bound resolver memory growth under adversarial inputs
• Return 503 when the server has already interned too many unique registry/policy configs
• Extract config interning into a unit-testable function and add coverage for cap behavior
Diagram

graph TD
  C{{"Client"}} --> E[/"Resolve / Verify"/] --> R["Resolver"] --> I["intern_config()"] --> D{"Config cap hit?"}
  D -- "no" --> M[("Config cache")] --> L["Leaked &'static Config"]
  D -- "yes" --> S["503 Service Unavailable"]

  subgraph Legend
    direction LR
    _ext{{"External"}} ~~~ _api[/"API"/] ~~~ _svc["Service"] ~~~ _db[("Cache")] ~~~ _dec{"Decision"}
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Refactor pacquet to accept Arc (no leak)
  • ➕ Eliminates the need for leaking configs entirely
  • ➕ Allows safe eviction/LRU and true memory reclamation
  • ➖ Large cross-crate API change; likely touches install/resolver call chain
  • ➖ Higher regression risk; out of scope for a targeted security fix
2. Rate-limit or quota unique config keys per caller
  • ➕ Reduces abuse impact without global cap
  • ➕ More tenant-isolated behavior for multi-tenant deployments
  • ➖ Doesn’t provide a hard global bound unless combined with a cap
  • ➖ Requires identity/tenant plumbing and policy decisions
3. LRU eviction of the key map only
  • ➕ Keeps the map size bounded and avoids 503s in some cases
  • ➖ Does not bound leaked memory (evicted keys can be re-leaked on next request)
  • ➖ Can worsen leak under adversarial key rotation

Recommendation: Keep the hard-cap approach in this PR: it is the only change that actually bounds leaked memory given the &'static Config requirement. If memory reclamation becomes necessary, pursue the Arc pacquet refactor as a follow-up project.

Files changed (2) +141 / -52

Bug fix (1) +100 / -52
resolver.rsCap interned leaked PacquetConfig entries and return 503 past the limit +100/-52

Cap interned leaked PacquetConfig entries and return 503 past the limit

• Adds MAX_INTERNED_CONFIGS and centralizes config interning/leaking into intern_config() with a hard cap. Updates both resolve and verify-lockfile handlers to return 503 when the cap is exceeded, preventing unbounded memory growth from distinct registry/policy combinations.

pnpr/crates/pnpr/src/resolver.rs

Tests (1) +41 / -0
tests.rsAdd unit test for intern_config cap behavior +41/-0

Add unit test for intern_config cap behavior

• Introduces a test that interns distinct configs up to a small max, verifies new distinct configs are refused past the cap, and confirms already-interned configs remain accessible.

pnpr/crates/pnpr/src/resolver/tests.rs

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 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/resolver/tests.rs`:
- Around line 235-241: The test in tests::intern_config currently only checks
that the over-cap insert returns None, which does not prove nothing was cached.
Update this regression test around intern_config and configs to also assert the
cache size remains exactly max after the rejected
registry_request("https://c.test/") attempt, so the observable behavior is that
no additional interning happens beyond the limit.
🪄 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: 6ededd78-62b9-4088-8412-c08e7ecda10f

📥 Commits

Reviewing files that changed from the base of the PR and between f38e696 and c633408.

📒 Files selected for processing (2)
  • pnpr/crates/pnpr/src/resolver.rs
  • pnpr/crates/pnpr/src/resolver/tests.rs

Comment thread pnpr/crates/pnpr/src/resolver/tests.rs Resolved
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Jun 26, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (9) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Non-canonical config key ✓ Resolved 🐞 Bug ⛨ Security
Description
intern_config claims to intern by canonical JSON, but with serde_json built using
preserve_order and overrides deserialized into an insertion-ordered IndexMap, the same
overrides map with different JSON key order produces different cache keys and interns multiple
leaked configs. This defeats deduplication and makes it much easier for an authenticated caller to
burn through MAX_INTERNED_CONFIGS, degrading availability for any new (previously unseen)
configurations until restart.
Code

pnpr/crates/pnpr/src/resolver.rs[R214-228]

+    let overrides: Option<IndexMap<String, String>> =
+        request.overrides.as_ref().and_then(|value| serde_json::from_value(value.clone()).ok());
+
+    let key = serde_json::json!({
+        "registry": registry,
+        "namedRegistries": request.named_registries,
+        "overrides": overrides,
+        "minimumReleaseAge": request.minimum_release_age,
+        "minimumReleaseAgeExclude": request.minimum_release_age_exclude,
+        "minimumReleaseAgeIgnoreMissingTime": request.minimum_release_age_ignore_missing_time,
+        "trustPolicy": request.trust_policy,
+        "trustPolicyExclude": request.trust_policy_exclude,
+        "trustPolicyIgnoreAfter": request.trust_policy_ignore_after,
+    })
+    .to_string();
Evidence
The workspace enables serde_json preserve_order, ResolveRequest.overrides is raw JSON, and
intern_config converts it into an insertion-ordered IndexMap and serializes it into the cache
key; therefore JSON key-order permutations create distinct keys and distinct leaked configs.

Cargo.toml[143-145]
pnpr/crates/pnpr/src/resolver/protocol.rs[60-66]
pnpr/crates/pnpr/src/resolver.rs[203-228]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`intern_config` is intended to key configs by *canonical* JSON, but because the repo enables `serde_json`'s `preserve_order` feature and `overrides` is converted into an order-preserving `IndexMap`, the stringified key depends on the caller’s JSON object key order. This allows semantically identical configs to be interned multiple times, accelerating exhaustion of `MAX_INTERNED_CONFIGS`.
### Issue Context
- `ResolveRequest.overrides` is accepted as raw JSON (`serde_json::Value`).
- Workspace enables `serde_json` `preserve_order`, so object order is retained.
- `intern_config` converts overrides to `IndexMap` and serializes it into the cache key.
### Fix Focus Areas
- Ensure overrides are canonicalized (stable key ordering) before computing `key` and before storing into the leaked `PacquetConfig`.
- Example approaches:
- Deserialize overrides into `BTreeMap<String, String>` (sorted keys) for keying, then convert to `IndexMap` if pacquet requires it.
- Or, after building the `IndexMap`, call a key-sorting routine (e.g., `sort_keys()`) before serializing/interning.
- pnpr/crates/pnpr/src/resolver.rs[203-247]
- pnpr/crates/pnpr/src/resolver/protocol.rs[60-66]
- Cargo.toml[143-145]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Cap ignores config byte size ✓ Resolved 🐞 Bug ⛨ Security
Description
The cap bounds only the count of leaked configs, but each interned PacquetConfig clones
attacker-controlled named_registries and overrides and is then leaked, so a caller can still
force a large retained memory footprint by submitting very large configuration fields up to the cap.
With the router-wide 100MiB body limit, worst-case retained memory can still reach on the order of
1024 × (size of registry config fields) (tens of GiB) before refusal.
Code

pnpr/crates/pnpr/src/resolver.rs[R220-243]

+    let mut config = PacquetConfig::new();
+    config.store_dir = store_dir.clone();
+    config.cache_dir = cache_dir.to_path_buf();
+    config.registry = registry;
+    config.named_registries = request.named_registries.clone();
+    config.overrides = overrides;
+    config.modules_dir = PathBuf::from("node_modules");
+    config.lockfile = true;
+    config.verify_store_integrity = true;
+    // The client's verification policy drives both the input-lockfile
+    // verifier and the resolver's pick-time `minimumReleaseAge` /
+    // `trustPolicy` checks, so newly-resolved entries are held to the
+    // same policy as the reused ones.
+    config.minimum_release_age = request.minimum_release_age;
+    config.minimum_release_age_exclude.clone_from(&request.minimum_release_age_exclude);
+    if let Some(ignore_missing_time) = request.minimum_release_age_ignore_missing_time {
+        config.minimum_release_age_ignore_missing_time = ignore_missing_time;
+    }
+    config.trust_policy = request.trust_policy;
+    config.trust_policy_exclude.clone_from(&request.trust_policy_exclude);
+    config.trust_policy_ignore_after = request.trust_policy_ignore_after;
+    let config: &'static PacquetConfig = config.leak();
+    configs.insert(key, config);
+    Some(config)
Evidence
intern_config clones request.named_registries and parsed overrides into PacquetConfig and
then leaks it. The router sets a 100MiB request body limit, which permits very large
namedRegistries/overrides payloads; those can become retained memory up to the entry cap. The
underlying PacquetConfig type indeed stores these fields as owned maps.

pnpr/crates/pnpr/src/resolver.rs[186-244]
pnpr/crates/pnpr/src/server.rs[60-71]
pnpr/crates/pnpr/src/server.rs[327-334]
pacquet/crates/config/src/lib.rs[694-718]
pacquet/crates/config/src/lib.rs[1283-1294]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`MAX_INTERNED_CONFIGS` limits only the number of leaked entries, not the per-entry size. Because `named_registries` and `overrides` come from the request body and are cloned into the leaked `PacquetConfig`, an attacker can inflate each interned entry and still drive very large retained memory.
## Issue Context
The router applies a 100MiB body limit broadly, and `intern_config` stores request-supplied maps into leaked memory.
## Fix Focus Areas
- pnpr/crates/pnpr/src/resolver.rs[186-244]
- pnpr/crates/pnpr/src/server.rs[60-71]
- pnpr/crates/pnpr/src/server.rs[327-334]
## Suggested fix
- Add explicit validation before interning:
- maximum number of entries in `named_registries`
- maximum total bytes across registry URLs
- maximum serialized byte size (or entry count) for `overrides`
- reject oversize inputs with 400/413 (and do not intern)
- Consider storing a fixed-size key (e.g., SHA-256 of canonical JSON) instead of the full canonical JSON string to avoid retaining and hashing potentially huge strings.
- Re-evaluate whether `MAX_INTERNED_CONFIGS = 1024` is appropriate given worst-case per-entry size.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

3. Exclude list order burns cap 🐞 Bug ⛨ Security
Description
intern_config keys minimumReleaseAgeExclude/trustPolicyExclude directly from the request, so
reordering, duplicating, or toggling None vs Some([]) produces distinct leaked configs even
though pacquet treats these cases equivalently. An authenticated caller can exploit this to consume
MAX_INTERNED_CONFIGS faster and force 503s for any previously unseen configuration until restart.
Code

pnpr/crates/pnpr/src/resolver.rs[R224-234]

+    let key = serde_json::json!({
+        "registry": registry,
+        "namedRegistries": request.named_registries,
+        "overrides": overrides_key,
+        "minimumReleaseAge": request.minimum_release_age,
+        "minimumReleaseAgeExclude": request.minimum_release_age_exclude,
+        "minimumReleaseAgeIgnoreMissingTime": request.minimum_release_age_ignore_missing_time,
+        "trustPolicy": request.trust_policy,
+        "trustPolicyExclude": request.trust_policy_exclude,
+        "trustPolicyIgnoreAfter": request.trust_policy_ignore_after,
+    })
Evidence
The intern key currently incorporates the exclude vectors directly, making their order/emptiness
part of the cache identity. Downstream, pacquet sorts/uniques these patterns and treats empty lists
as None, so different list order (or None vs []) is semantically equivalent but will still
burn separate intern slots in pnpr.

pnpr/crates/pnpr/src/resolver.rs[203-234]
pacquet/crates/package-manager/src/build_resolution_verifiers.rs[84-146]
pacquet/crates/resolving-npm-resolver/src/create_npm_resolution_verifier.rs[224-235]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`intern_config` claims to key configs by canonical JSON, but the key still includes attacker-controlled exclude vectors (`minimumReleaseAgeExclude`, `trustPolicyExclude`) verbatim. Pacquet normalizes these patterns (sorting/uniquing) and treats empty lists as equivalent to `None`, so the current key allows semantically identical policies to intern multiple leaked configs.
### Issue Context
This undermines the new hard cap by allowing cheap permutation-based slot consumption and earlier cap exhaustion (availability degradation).
### Fix Focus Areas
- pnpr/crates/pnpr/src/resolver.rs[203-235]
- pnpr/crates/pnpr/src/resolver.rs[261-268]
### Suggested fix
- Before building `key`, normalize both exclude fields into a canonical representation:
- Convert `None` and `Some(vec![])` to the same value (e.g., `None`).
- Sort and deduplicate the pattern list (matching pacquet’s `sorted_unique` behavior).
- Use the normalized values both in the JSON key and (optionally) when setting `config.minimum_release_age_exclude` / `config.trust_policy_exclude` to keep the leaked config aligned with the canonical key.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


4. Invalid configs leak slots 🐞 Bug ⛨ Security
Description
pnpr interns and leaks a PacquetConfig before pacquet validates namedRegistries URLs and policy
exclude patterns, so malformed-but-distinct requests can permanently consume intern slots even
though they later fail. This makes cap exhaustion cheaper and reduces availability for legitimate
new configurations.
Code

pnpr/crates/pnpr/src/resolver.rs[R248-271]

+    let mut config = PacquetConfig::new();
+    config.store_dir = store_dir.clone();
+    config.cache_dir = cache_dir.to_path_buf();
+    config.registry = registry;
+    config.named_registries = request.named_registries.clone();
+    config.overrides = overrides;
+    config.modules_dir = PathBuf::from("node_modules");
+    config.lockfile = true;
+    config.verify_store_integrity = true;
+    // The client's verification policy drives both the input-lockfile
+    // verifier and the resolver's pick-time `minimumReleaseAge` /
+    // `trustPolicy` checks, so newly-resolved entries are held to the
+    // same policy as the reused ones.
+    config.minimum_release_age = request.minimum_release_age;
+    config.minimum_release_age_exclude.clone_from(&request.minimum_release_age_exclude);
+    if let Some(ignore_missing_time) = request.minimum_release_age_ignore_missing_time {
+        config.minimum_release_age_ignore_missing_time = ignore_missing_time;
+    }
+    config.trust_policy = request.trust_policy;
+    config.trust_policy_exclude.clone_from(&request.trust_policy_exclude);
+    config.trust_policy_ignore_after = request.trust_policy_ignore_after;
+    let config: &'static PacquetConfig = config.leak();
+    configs.insert(key, config);
+    Some(config)
Evidence
The config is leaked during interning, and handle_resolve obtains that leaked config before
entering the resolve/verify flow. Pacquet performs named-registry URL validation and pattern
validation later during install/verifier construction, meaning requests that fail those validations
can still permanently consume intern capacity.

pnpr/crates/pnpr/src/resolver.rs[203-271]
pnpr/crates/pnpr/src/resolver.rs[288-297]
pacquet/crates/package-manager/src/install_with_fresh_lockfile.rs[530-541]
pacquet/crates/package-manager/src/build_resolution_verifiers.rs[84-146]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`intern_config` leaks (`config.leak()`) a new `PacquetConfig` entry as soon as it sees a new key under the cap. However, key parts of that config (notably `named_registries` URLs and exclude-pattern validity) are validated later inside pacquet’s install path. Requests that will ultimately error can still permanently consume one of the limited intern slots.
### Issue Context
This is an availability/security concern: an authenticated caller can send many distinct invalid configs (cheap to produce, likely to fail fast) and still fill the global intern map, causing 503s for any new unseen configuration until restart.
### Fix Focus Areas
- pnpr/crates/pnpr/src/resolver.rs[203-271]
- pnpr/crates/pnpr/src/resolver.rs[288-305]
### Suggested fix
- Add a pre-validation step before calling `config.leak()` (or before `config_for()` is invoked) that rejects invalid inputs with a 4xx, without consuming an intern slot.
- Validate `namedRegistries` URLs similarly to pacquet’s `merge_named_registries` rules (http/https only, parseable URLs).
- Validate `minimumReleaseAgeExclude` / `trustPolicyExclude` pattern syntax using the same policy-building code path pacquet uses.
- Only after successful validation should you insert/leak the config into the intern map.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


5. NamedRegistries not canonicalized 🐞 Bug ⛨ Security
Description
intern_config keys (and stores) namedRegistries using the raw request URLs, but pacquet
normalizes named-registry URL prefixes to include a trailing slash for matching. Equivalent
configurations like https://npm.pkg.github.com vs https://npm.pkg.github.com/ can therefore
intern multiple leaked configs and hit MAX_INTERNED_CONFIGS sooner, causing avoidable 503s for new
configurations.
Code

pnpr/crates/pnpr/src/resolver.rs[R224-253]

+    let key = serde_json::json!({
+        "registry": registry,
+        "namedRegistries": request.named_registries,
+        "overrides": overrides_key,
+        "minimumReleaseAge": request.minimum_release_age,
+        "minimumReleaseAgeExclude": request.minimum_release_age_exclude,
+        "minimumReleaseAgeIgnoreMissingTime": request.minimum_release_age_ignore_missing_time,
+        "trustPolicy": request.trust_policy,
+        "trustPolicyExclude": request.trust_policy_exclude,
+        "trustPolicyIgnoreAfter": request.trust_policy_ignore_after,
+    })
+    .to_string();
+    if key.len() > max_key_bytes {
+        return None;
}
+
+    let mut configs = configs.lock().expect("config cache poisoned");
+    if let Some(config) = configs.get(&key) {
+        return Some(config);
+    }
+    if configs.len() >= max_interned {
+        return None;
+    }
+
+    let mut config = PacquetConfig::new();
+    config.store_dir = store_dir.clone();
+    config.cache_dir = cache_dir.to_path_buf();
+    config.registry = registry;
+    config.named_registries = request.named_registries.clone();
+    config.overrides = overrides;
Evidence
The interning key includes namedRegistries exactly as provided by the client, so different textual
URL forms produce distinct leaked configs. Pacquet’s resolver/verifier normalizes named-registry URL
prefixes to include a trailing slash, meaning those different textual forms can be semantically
equivalent downstream and should not consume additional interned-config slots.

pnpr/crates/pnpr/src/resolver.rs[211-253]
pacquet/crates/resolving-npm-resolver/src/named_registry.rs[82-115]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`intern_config` uses `request.named_registries` verbatim in both the cache key and the leaked `PacquetConfig`. Pacquet later normalizes named-registry URL prefixes by ensuring the path ends with `/`, so semantically equivalent named registry URLs can produce different intern keys and unnecessarily consume the fixed `MAX_INTERNED_CONFIGS` budget.
## Issue Context
This PR introduces a hard cap to prevent unbounded memory growth from leaking `&'static PacquetConfig`. To keep the cap effective, the interning key should match the canonical form used by downstream resolution/verification.
## Fix Focus Areas
- pnpr/crates/pnpr/src/resolver.rs[211-253]
### Suggested approach
- Canonicalize `request.named_registries` into a normalized map before:
- embedding it into the JSON key, and
- assigning it to `config.named_registries`.
- At minimum, apply the same trailing-slash normalization used in pacquet’s named-registry prefix builder (parse URL, ensure path ends with `/`, rebuild as origin + path).
- Add a unit test asserting that two requests differing only by trailing slash in a named registry URL dedup to a single interned config.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View more (4)
6. Oversize key returns 503 🐞 Bug ⛨ Security
Description
handle_resolve and handle_verify_lockfile return a 503 “too many distinct registry configurations”
whenever config_for() returns None, but intern_config() also returns None when the request’s
canonical config key exceeds MAX_CONFIG_KEY_BYTES. Oversized attacker-controlled
registry/namedRegistries/overrides inputs therefore produce a misleading 503 (server-side capacity
error) instead of a client error response, obscuring diagnosis and potentially encouraging retries.
Code

pnpr/crates/pnpr/src/resolver.rs[R288-290]

+    let Some(config) = runtime.config_for(&request) else {
+        return json_error(StatusCode::SERVICE_UNAVAILABLE, TOO_MANY_CONFIGS_MESSAGE);
+    };
Evidence
intern_config returns None both when the computed JSON key exceeds the byte cap and when the
interned-config count cap is reached, but both resolver endpoints translate any None from config_for
into the same 503 with TOO_MANY_CONFIGS_MESSAGE.

pnpr/crates/pnpr/src/resolver.rs[203-239]
pnpr/crates/pnpr/src/resolver.rs[281-290]
pnpr/crates/pnpr/src/resolver.rs[397-413]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`intern_config` returns `None` for multiple distinct reasons (cap reached vs key too large), but callers map all `None` results to the same `503` with `TOO_MANY_CONFIGS_MESSAGE`. This misclassifies oversized client input as a transient server overload/capacity condition.
## Issue Context
- `intern_config` rejects both (a) exceeding `max_key_bytes` and (b) exceeding `max_interned`.
- Both resolver endpoints currently treat these as the same failure.
## Fix Focus Areas
- pnpr/crates/pnpr/src/resolver.rs[203-239]
- pnpr/crates/pnpr/src/resolver.rs[281-290]
- pnpr/crates/pnpr/src/resolver.rs[397-413]
## Recommended fix
1. Change `intern_config` (and `Resolver::config_for`) to return a `Result<&'static PacquetConfig, InternConfigError>` (or similar enum) with at least:
- `TooManyConfigs`
- `KeyTooLarge`
2. Map errors at call sites:
- `TooManyConfigs` -> `503 Service Unavailable` (existing behavior)
- `KeyTooLarge` -> a client error status (e.g. `413 Payload Too Large` or `400 Bad Request`) with a distinct message like "registry configuration too large".
3. Update/extend unit tests to assert the correct HTTP status/message for the oversize-key case (currently only the pure `intern_config` behavior is tested).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


7. Oversize key serialized first 🐞 Bug ➹ Performance
Description
The MAX_CONFIG_KEY_BYTES limit is checked only after building key via
serde_json::json!(...).to_string(), so oversized attacker-controlled config fields still force
full JSON serialization and a potentially large String allocation before rejection. Because
resolve/verify bodies can be up to 100MiB, an authenticated caller can induce significant extra
CPU/memory churn per request even when the config will be refused.
Code

pnpr/crates/pnpr/src/resolver.rs[R217-231]

+    let key = serde_json::json!({
+        "registry": registry,
+        "namedRegistries": request.named_registries,
+        "overrides": overrides,
+        "minimumReleaseAge": request.minimum_release_age,
+        "minimumReleaseAgeExclude": request.minimum_release_age_exclude,
+        "minimumReleaseAgeIgnoreMissingTime": request.minimum_release_age_ignore_missing_time,
+        "trustPolicy": request.trust_policy,
+        "trustPolicyExclude": request.trust_policy_exclude,
+        "trustPolicyIgnoreAfter": request.trust_policy_ignore_after,
+    })
+    .to_string();
+    if key.len() > max_key_bytes {
+        return None;
+    }
Evidence
The router allows request bodies up to 100MiB, and intern_config always serializes the full key to
a String before checking max_key_bytes, so oversized configs still incur the full
serialization/allocation cost before being refused.

pnpr/crates/pnpr/src/resolver.rs[203-231]
pnpr/crates/pnpr/src/server.rs[65-70]
pnpr/crates/pnpr/src/server.rs[327-333]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`intern_config` enforces `max_key_bytes` after materializing the entire JSON key string. This means the byte cap does not prevent the cost of serializing/allocating an oversized key; it only prevents insertion.
### Issue Context
The server router applies a 100MiB body limit. An attacker can submit very large `namedRegistries`/`overrides` payloads and repeatedly force full key serialization only to be rejected afterward.
### Fix Focus Areas
- Enforce the key byte cap *while serializing*, so the code can abort early without allocating the full string.
- For example, serialize into a custom writer that errors once it exceeds `max_key_bytes`.
- Alternatively, pre-check sizes of attacker-controlled fields (registry string length, overrides/named registries serialized length) before calling `.to_string()`.
- pnpr/crates/pnpr/src/resolver.rs[203-231]
- pnpr/crates/pnpr/src/server.rs[65-70]
- pnpr/crates/pnpr/src/server.rs[327-333]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


8. Misleading cap-hit error text 🐞 Bug ◔ Observability
Description
When MAX_INTERNED_CONFIGS is reached, the server returns a 503 with message "too many distinct
registry configurations", but the intern key also includes verification-policy fields
(minimumReleaseAge/trustPolicy/etc). This can mislead debugging because varying policy alone (with
the same registry) can trigger the cap and produce that error.
Code

pnpr/crates/pnpr/src/resolver.rs[R174-210]

+/// Returned (as a `503`) when [`MAX_INTERNED_CONFIGS`] is reached. The
+/// limit resets on restart and a real client reuses one configuration, so
+/// a legitimate caller never sees it.
+const TOO_MANY_CONFIGS_MESSAGE: &str = "too many distinct registry configurations";
+
+/// Build + leak a `&'static Config` for a request's registry
+/// configuration, interned by its canonical JSON so repeat requests reuse
+/// it. Returns `None` once `max_interned` distinct configurations have
+/// been interned: a leaked config can never be reclaimed, so refusing to
+/// leak more is the only real bound on the per-request leak — eviction
+/// would just let the same key be re-leaked. The cap is generous enough
+/// that legitimate clients (which reuse one configuration) never hit it.
+fn intern_config(
+    configs: &Mutex<HashMap<String, &'static PacquetConfig>>,
+    store_dir: &StoreDir,
+    cache_dir: &Path,
+    request: &ResolveRequest,
+    max_interned: usize,
+) -> Option<&'static PacquetConfig> {
+    let registry =
+        request.registry.clone().unwrap_or_else(|| "https://registry.npmjs.org/".to_string());
+    let registry = if registry.ends_with('/') { registry } else { format!("{registry}/") };
+    let overrides: Option<IndexMap<String, String>> =
+        request.overrides.as_ref().and_then(|value| serde_json::from_value(value.clone()).ok());
+
+    let key = serde_json::json!({
+        "registry": registry,
+        "namedRegistries": request.named_registries,
+        "overrides": overrides,
+        "minimumReleaseAge": request.minimum_release_age,
+        "minimumReleaseAgeExclude": request.minimum_release_age_exclude,
+        "minimumReleaseAgeIgnoreMissingTime": request.minimum_release_age_ignore_missing_time,
+        "trustPolicy": request.trust_policy,
+        "trustPolicyExclude": request.trust_policy_exclude,
+        "trustPolicyIgnoreAfter": request.trust_policy_ignore_after,
+    })
+    .to_string();
Evidence
The 503 body is sourced from TOO_MANY_CONFIGS_MESSAGE, but the capped key includes
minimumReleaseAge/trustPolicy fields in addition to registry/namedRegistries/overrides; therefore
the error text is narrower than the actual limiter scope.

pnpr/crates/pnpr/src/resolver.rs[174-210]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The 503 error message returned when the interned-config cap is reached says "too many distinct registry configurations", but the cap key includes policy fields as well as registry fields. This mismatch can mislead operators and users when diagnosing why requests are being rejected.
### Issue Context
The cap is enforced on a key derived from registry + namedRegistries + overrides + multiple verification policy fields, so the error string should reflect "client configurations" or "registry/policy configurations" rather than only registry.
### Fix Focus Areas
- pnpr/crates/pnpr/src/resolver.rs[174-210]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


9. Global config cap DoS 🐞 Bug ⛨ Security
Description
MAX_INTERNED_CONFIGS is enforced globally per server Resolver, so one authenticated caller can
fill the 1024 distinct slots and then force 503s for any other caller whose registry/policy
combination wasn’t already interned until restart. This is a cross-tenant availability risk in
multi-tenant deployments (existing interned configs still work, but onboarding new ones becomes
impossible).
Code

pnpr/crates/pnpr/src/resolver.rs[R216-218]

+    if configs.len() >= max_interned {
+        return None;
}
Evidence
The cap is enforced by returning None once the shared configs map length reaches max_interned,
and both resolver endpoints translate that into a 503. The resolver endpoints require an
authenticated caller, and the Resolver is stored once per server, so one caller can consume the
shared budget for everyone.

pnpr/crates/pnpr/src/resolver.rs[165-244]
pnpr/crates/pnpr/src/resolver.rs[260-269]
pnpr/crates/pnpr/src/resolver.rs[376-392]
pnpr/crates/pnpr/src/server.rs[251-299]
pnpr/crates/pnpr/src/server.rs[1309-1321]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The interned-config cap is global to the process. Any authenticated caller can exhaust the global budget and prevent other callers from using previously unseen registry/policy configurations (persistent 503 until restart).
## Issue Context
The resolver endpoints are authenticated, but the interned config cache is shared across all callers.
## Fix Focus Areas
- pnpr/crates/pnpr/src/resolver.rs[154-244]
- pnpr/crates/pnpr/src/resolver.rs[260-269]
- pnpr/crates/pnpr/src/server.rs[251-299]
- pnpr/crates/pnpr/src/server.rs[1309-1321]
## Suggested fix
- Thread the caller identity (e.g., username or token ID already known to middleware) into `config_for` / `intern_config` and key the cache as `(caller_id, config_key)`.
- Enforce a **per-caller** cap (small) plus an optional **global** cap to prevent unbounded growth across many callers.
- Return a clearer quota error (consider 429) while preserving the existing 503 behavior if that’s a contract requirement.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

10. Hardcoded /tmp paths in test 🐞 Bug ⚙ Maintainability
Description
The new intern_config unit test uses fixed absolute /tmp paths for StoreDir and cache_dir instead of
using tempfile-managed paths. This reduces test portability/hygiene and is easy to avoid given the
crate already depends on tempfile.
Code

pnpr/crates/pnpr/src/resolver/tests.rs[R216-218]

+    let store_dir = StoreDir::new(PathBuf::from("/tmp/pnpr-intern-test-store"));
+    let cache_dir = PathBuf::from("/tmp/pnpr-intern-test-cache");
+    let max = 2;
Evidence
The added test constructs StoreDir/cache_dir using hardcoded /tmp paths, despite the project having
tempfile available, so the test can be made more robust with per-test temp directories.

pnpr/crates/pnpr/src/resolver/tests.rs[216-218]
pnpr/crates/pnpr/Cargo.toml[66-81]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The unit test uses hardcoded absolute paths under /tmp, which is unnecessary and less portable than allocating a per-test temporary directory.
### Issue Context
The pnpr crate already has a dependency on `tempfile`, so the test can use `tempfile::tempdir()` (or `TempDir`) and derive `store_dir` / `cache_dir` from it.
### Fix Focus Areas
- pnpr/crates/pnpr/src/resolver/tests.rs[216-218]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


11. No cap-hit structured log 🐞 Bug ◔ Observability
Description
When the config cap is reached, requests fail with a 503 response but there is no dedicated
structured log/metric emitted at the refusal site, making it harder to distinguish “cap reached”
from other 503 causes via logs alone. This reduces operator visibility during an active
abuse/misconfiguration event.
Code

pnpr/crates/pnpr/src/resolver.rs[R267-269]

+    let Some(config) = runtime.config_for(&request) else {
+        return json_error(StatusCode::SERVICE_UNAVAILABLE, TOO_MANY_CONFIGS_MESSAGE);
+    };
Evidence
The refusal path is implemented as an early return of json_error(503, ...) and json_error only
builds a response; it emits no tracing event. The server access logs record status/latency but do
not include the JSON body, so the specific reason is not visible without deeper inspection.

pnpr/crates/pnpr/src/resolver.rs[260-269]
pnpr/crates/pnpr/src/resolver.rs[902-909]
pnpr/crates/pnpr/src/server.rs[362-380]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new refusal path returns 503 but does not emit a structured event/counter that operators can alert on.
## Issue Context
Request logging records status/latency but not response bodies; the refusal reason is currently only in the JSON body.
## Fix Focus Areas
- pnpr/crates/pnpr/src/resolver.rs[260-269]
- pnpr/crates/pnpr/src/resolver.rs[186-218]
## Suggested fix
- Add `tracing::warn!` (rate-limited) when `configs.len() >= max_interned`, including fields like `interned_configs`, `max_interned`, and a safely-sanitized registry host (avoid logging auth headers or secrets).
- Add a metrics counter (e.g., `pnpr_intern_config_refused_total`) to support alerting.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit c633408

@codecov-commenter

codecov-commenter commented Jun 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.01493% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.03%. Comparing base (6312916) to head (55dd395).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
pnpr/crates/pnpr/src/resolver.rs 97.01% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12674      +/-   ##
==========================================
- Coverage   87.48%   87.03%   -0.46%     
==========================================
  Files         370      375       +5     
  Lines       55767    57881    +2114     
==========================================
+ Hits        48789    50374    +1585     
- Misses       6978     7507     +529     

☔ View full report in Codecov by Harness.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: 55dd3955269b

Each scenario reports direct installs and pnpr installs. Bencher consumes pacquet@HEAD and pnpr@HEAD.

Scenario: Isolated linker: fresh restore, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.839 ± 0.128 4.659 5.100 1.63 ± 0.06
pacquet@main 4.852 ± 0.111 4.700 5.061 1.63 ± 0.05
pnpr@HEAD 2.990 ± 0.164 2.821 3.265 1.01 ± 0.06
pnpr@main 2.975 ± 0.072 2.869 3.092 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.839235714199999,
      "stddev": 0.12779093163861416,
      "median": 4.819434100900001,
      "user": 4.10266666,
      "system": 3.449539159999999,
      "min": 4.6588721494,
      "max": 5.1002692254,
      "times": [
        4.8183992744,
        5.0006146914,
        4.7425105294,
        5.1002692254,
        4.7945996774,
        4.8361615414,
        4.8669556954,
        4.8204689274,
        4.7535054304,
        4.6588721494
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.8517240629,
      "stddev": 0.110817412165757,
      "median": 4.8220279394,
      "user": 4.081259859999999,
      "system": 3.455724859999999,
      "min": 4.6997824374,
      "max": 5.0605636014,
      "times": [
        5.0605636014,
        4.7998644134,
        4.8619463064,
        5.0084634444,
        4.8930720324,
        4.7566934764,
        4.6997824374,
        4.8376289484,
        4.8064269304,
        4.7927990384
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 2.9899708112,
      "stddev": 0.16388538167347738,
      "median": 2.9626949303999996,
      "user": 2.7920416599999998,
      "system": 2.955517659999999,
      "min": 2.8212739684,
      "max": 3.2650366604,
      "times": [
        2.9126043243999997,
        2.8212739684,
        3.2650366604,
        3.0127855364,
        2.8821980534,
        2.8254335484,
        3.0404084863999996,
        3.2373448754,
        3.0646368734,
        2.8379857854
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 2.9748584372999995,
      "stddev": 0.07248176483572895,
      "median": 2.9724902934,
      "user": 2.83531566,
      "system": 2.9602276599999993,
      "min": 2.8686812624,
      "max": 3.0924082484,
      "times": [
        3.0924082484,
        2.9783688074,
        2.8760539923999997,
        2.9222441094,
        2.9640259654,
        2.9973833004,
        3.0343749663999997,
        3.0484319413999996,
        2.8686812624,
        2.9666117794
      ]
    }
  ]
}

Scenario: Isolated linker: fresh restore, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 640.9 ± 11.2 626.3 654.1 1.00
pacquet@main 659.8 ± 25.4 640.1 728.3 1.03 ± 0.04
pnpr@HEAD 700.8 ± 15.0 681.8 732.0 1.09 ± 0.03
pnpr@main 710.4 ± 24.8 684.1 762.7 1.11 ± 0.04
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.6408853062800002,
      "stddev": 0.011159450946264672,
      "median": 0.6389189951800001,
      "user": 0.38331824000000003,
      "system": 1.32461924,
      "min": 0.6263112661800001,
      "max": 0.65412259518,
      "times": [
        0.6312113871800001,
        0.6331970041800001,
        0.65412259518,
        0.6523415321800001,
        0.6322560131800001,
        0.6263112661800001,
        0.6511182341800001,
        0.6446409861800001,
        0.6305537011800001,
        0.6531003431800001
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.6597524961800001,
      "stddev": 0.02536665189157406,
      "median": 0.6538014226800001,
      "user": 0.38079493999999997,
      "system": 1.33312914,
      "min": 0.6400946501800001,
      "max": 0.7282636651800001,
      "times": [
        0.6647950361800001,
        0.6421818261800001,
        0.6544977741800001,
        0.6531818971800001,
        0.6635332591800001,
        0.6400946501800001,
        0.7282636651800001,
        0.64830683318,
        0.64824907218,
        0.6544209481800001
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.7007699564800001,
      "stddev": 0.014983128788863797,
      "median": 0.69720323118,
      "user": 0.39006864,
      "system": 1.37546714,
      "min": 0.6818070771800001,
      "max": 0.7319752481800001,
      "times": [
        0.7151952931800001,
        0.68908262218,
        0.6912115261800001,
        0.7039946111800001,
        0.6900275011800001,
        0.6818070771800001,
        0.7099992231800001,
        0.6944997671800001,
        0.7319752481800001,
        0.6999066951800001
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.71042218908,
      "stddev": 0.024778266855226203,
      "median": 0.7093485136800001,
      "user": 0.4069711399999999,
      "system": 1.3533307399999999,
      "min": 0.6840753801800001,
      "max": 0.76271667218,
      "times": [
        0.6840753801800001,
        0.7245227441800001,
        0.6992813091800001,
        0.6867506451800001,
        0.6956746021800001,
        0.7209538991800001,
        0.76271667218,
        0.7248330031800001,
        0.6859979171800001,
        0.71941571818
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.836 ± 0.049 4.776 4.944 1.50 ± 0.05
pacquet@main 4.843 ± 0.064 4.750 4.942 1.50 ± 0.05
pnpr@HEAD 3.297 ± 0.158 3.080 3.597 1.02 ± 0.06
pnpr@main 3.234 ± 0.097 3.091 3.425 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.835787938039999,
      "stddev": 0.04883978443168009,
      "median": 4.82718788634,
      "user": 3.9518643199999994,
      "system": 3.3827250199999996,
      "min": 4.77581217234,
      "max": 4.94414730234,
      "times": [
        4.80931922934,
        4.84570142734,
        4.82714290834,
        4.82657791834,
        4.87463239534,
        4.94414730234,
        4.82723286434,
        4.77753892134,
        4.84977424134,
        4.77581217234
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.84301251724,
      "stddev": 0.06367353260059201,
      "median": 4.83972467084,
      "user": 3.9472220200000003,
      "system": 3.37494322,
      "min": 4.75024920934,
      "max": 4.94231123734,
      "times": [
        4.84891498234,
        4.79083809334,
        4.79545155634,
        4.79086397134,
        4.83053435934,
        4.75024920934,
        4.905622560339999,
        4.85434660634,
        4.92099259634,
        4.94231123734
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.29724497694,
      "stddev": 0.15836716896829206,
      "median": 3.28387122884,
      "user": 2.9340741200000005,
      "system": 3.14588922,
      "min": 3.0799753543399997,
      "max": 3.59699341434,
      "times": [
        3.21550927734,
        3.41833262234,
        3.46139497434,
        3.1836974743399997,
        3.59699341434,
        3.1335894243399998,
        3.28713160734,
        3.31521477034,
        3.0799753543399997,
        3.28061085034
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 3.2335115471399996,
      "stddev": 0.09706733491550583,
      "median": 3.21861953634,
      "user": 2.89881562,
      "system": 3.15637962,
      "min": 3.0906185533399997,
      "max": 3.42457396334,
      "times": [
        3.2013837073399998,
        3.23585536534,
        3.3244988743399997,
        3.42457396334,
        3.2791265673399996,
        3.18980856934,
        3.27219192434,
        3.1283019733399997,
        3.0906185533399997,
        3.1887559733399997
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, hot cache + hot store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.395 ± 0.017 1.373 1.435 1.00
pacquet@main 1.419 ± 0.027 1.388 1.489 1.02 ± 0.02
pnpr@HEAD 1.464 ± 0.028 1.422 1.502 1.05 ± 0.02
pnpr@main 1.484 ± 0.021 1.458 1.531 1.06 ± 0.02
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.3948259978000002,
      "stddev": 0.01688959338105943,
      "median": 1.3944935266000003,
      "user": 1.36520518,
      "system": 1.6982741000000001,
      "min": 1.3726574971,
      "max": 1.4346257791,
      "times": [
        1.3942354841000002,
        1.3976723101000001,
        1.4010450471,
        1.3788169641,
        1.3726574971,
        1.3852415411,
        1.4015524301000002,
        1.4346257791,
        1.3947515691,
        1.3876613561000002
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 1.4189992404000003,
      "stddev": 0.027284488594587913,
      "median": 1.4153744041,
      "user": 1.36389248,
      "system": 1.7398401999999997,
      "min": 1.3877113991,
      "max": 1.4893061501000002,
      "times": [
        1.4180027851,
        1.3974585341,
        1.4893061501000002,
        1.3877113991,
        1.4063625911000002,
        1.4132944101,
        1.4237277031000002,
        1.4174543981,
        1.4114396481000002,
        1.4252347851
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.4640731049000002,
      "stddev": 0.028485955975090047,
      "median": 1.4558254916000002,
      "user": 0.5769922799999999,
      "system": 1.574755,
      "min": 1.4221162011000001,
      "max": 1.5017112361,
      "times": [
        1.4984260451000002,
        1.4936216091,
        1.5017112361,
        1.4353676681000003,
        1.4558326311,
        1.4855718491,
        1.4442835081,
        1.4221162011000001,
        1.4479819491,
        1.4558183521
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.4838686166000001,
      "stddev": 0.02146091028950815,
      "median": 1.4770668671,
      "user": 0.5881972799999999,
      "system": 1.5981276999999996,
      "min": 1.4584151761000002,
      "max": 1.5314117941,
      "times": [
        1.5314117941,
        1.4683991191,
        1.4715023711000002,
        1.5068945991,
        1.4750599071000001,
        1.4911302111000002,
        1.4790738271000001,
        1.4712811331000002,
        1.4584151761000002,
        1.4855180281000002
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + hot store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 3.137 ± 0.075 3.062 3.272 2.09 ± 0.06
pacquet@main 3.112 ± 0.028 3.081 3.157 2.07 ± 0.03
pnpr@HEAD 1.502 ± 0.017 1.474 1.529 1.00
pnpr@main 1.506 ± 0.024 1.453 1.535 1.00 ± 0.02
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 3.13687027418,
      "stddev": 0.07505496148483844,
      "median": 3.11716794288,
      "user": 1.8429788999999999,
      "system": 1.9899844999999998,
      "min": 3.06170437088,
      "max": 3.27247949088,
      "times": [
        3.15012980788,
        3.06170437088,
        3.11726903688,
        3.0915424148799997,
        3.06280947688,
        3.09005456688,
        3.11706684888,
        3.26314046788,
        3.1425062598799998,
        3.27247949088
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 3.1118503221799996,
      "stddev": 0.02849557812869541,
      "median": 3.10807461288,
      "user": 1.843198,
      "system": 1.9942737000000001,
      "min": 3.0806677158799998,
      "max": 3.15711915588,
      "times": [
        3.09850476488,
        3.15711915588,
        3.0806677158799998,
        3.11991056788,
        3.11764446088,
        3.09825844488,
        3.0820327338799998,
        3.08160637288,
        3.12960565688,
        3.15315334788
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.50237996638,
      "stddev": 0.016824720620197745,
      "median": 1.4972760453799998,
      "user": 0.6031317,
      "system": 1.6113203999999997,
      "min": 1.47449087688,
      "max": 1.5286607348799999,
      "times": [
        1.5185655598799999,
        1.49640721488,
        1.5286607348799999,
        1.4975545928799998,
        1.5257577488799998,
        1.49895475488,
        1.4969974978799998,
        1.47449087688,
        1.49435821588,
        1.49205246688
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.50572480658,
      "stddev": 0.024230926515987943,
      "median": 1.51383726588,
      "user": 0.5944629,
      "system": 1.6014764,
      "min": 1.4533776758799999,
      "max": 1.53521752288,
      "times": [
        1.49993799788,
        1.51850428588,
        1.49413307588,
        1.5124187118799999,
        1.5296602988799999,
        1.5160107168799999,
        1.53521752288,
        1.51525581988,
        1.48273195988,
        1.4533776758799999
      ]
    }
  ]
}

@github-actions

github-actions Bot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchpr/12674
Testbedpacquet
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
milliseconds (ms)
(Result Δ%)
Upper Boundary
milliseconds (ms)
(Limit %)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
🚷 view threshold
4,835.79 ms
(+1.65%)Baseline: 4,757.14 ms
5,708.57 ms
(84.71%)
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
🚷 view threshold
3,136.87 ms
(+3.12%)Baseline: 3,041.97 ms
3,650.36 ms
(85.93%)
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
🚷 view threshold
1,394.83 ms
(+2.83%)Baseline: 1,356.45 ms
1,627.74 ms
(85.69%)
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
🚷 view threshold
4,839.24 ms
(+1.20%)Baseline: 4,782.09 ms
5,738.51 ms
(84.33%)
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
640.89 ms
(-2.37%)Baseline: 656.45 ms
787.74 ms
(81.36%)
🐰 View full continuous benchmarking report in Bencher

@github-actions

github-actions Bot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchpr/12674
Testbedpnpr

⚠️ 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-thresholds flag.

Click to view all benchmark results
BenchmarkLatencymilliseconds (ms)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
3,297.24 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
1,502.38 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
1,464.07 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
2,989.97 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
700.77 ms
🐰 View full continuous benchmarking report in Bencher

Addresses the review on this PR:

- Cap each interned config's canonical-key size (MAX_CONFIG_KEY_BYTES,
  128 KiB), not just the count. The resolve/verify body inherits the
  publish-sized DefaultBodyLimit, so a caller could pad a distinct
  config's overrides/namedRegistries map and amplify the per-config leak
  even under the count cap; refuse to intern an oversized key.
- Assert the cache size stays exactly at the cap after an over-cap
  request is refused, proving the refusal interns nothing.
- Rewrite the cap-test assertions as single-line calls via a closure,
  fixing the `perfectionist::macro-trailing-comma` dylint error that
  failed Rust CI.

Co-authored-by: Claude <[email protected]>

@coderabbitai coderabbitai 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.

♻️ Duplicate comments (1)
pnpr/crates/pnpr/src/resolver/tests.rs (1)

260-265: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Assert the oversized config was not interned.

is_none() alone does not prove the oversized request left the cache unchanged. A buggy path could still insert/leak the config and return None, and this test would pass.

Suggested assertion
     // A configuration whose canonical key exceeds the byte cap is refused, so a
     // caller can't amplify the per-config leak with a giant overrides/registry.
     let oversized = format!("https://{}.test/", "x".repeat(2048));
     assert!(intern(&oversized).is_none());
+    assert_eq!(configs.lock().expect("config cache poisoned").len(), 1);

As per path instructions, REVIEW_GUIDE.md says regression tests should avoid vacuous assertions and specifically cover that refused requests do not increase cache.

🤖 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/resolver/tests.rs` around lines 260 - 265, The
oversized-config test for intern is currently vacuous because is_none() does not
prove the refused request left the cache unchanged. Update the test around
intern("https://a.test/") and the oversized request to also assert that the
rejected oversized key was not added to the intern cache, preferably by checking
the cache size or count before and after the oversized call using the relevant
intern/cache accessors in resolver/tests.rs. Keep the existing is_none() check,
but add a concrete assertion that no new entry was interned for the oversized
config.

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.

Duplicate comments:
In `@pnpr/crates/pnpr/src/resolver/tests.rs`:
- Around line 260-265: The oversized-config test for intern is currently vacuous
because is_none() does not prove the refused request left the cache unchanged.
Update the test around intern("https://a.test/") and the oversized request to
also assert that the rejected oversized key was not added to the intern cache,
preferably by checking the cache size or count before and after the oversized
call using the relevant intern/cache accessors in resolver/tests.rs. Keep the
existing is_none() check, but add a concrete assertion that no new entry was
interned for the oversized config.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: be5abf29-01a1-4afd-9b50-d826639b62cb

📥 Commits

Reviewing files that changed from the base of the PR and between c633408 and f5fe50c.

📒 Files selected for processing (2)
  • pnpr/crates/pnpr/src/resolver.rs
  • pnpr/crates/pnpr/src/resolver/tests.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • pnpr/crates/pnpr/src/resolver.rs

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Jun 26, 2026
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit f5fe50c

1 similar comment
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit f5fe50c

Addresses a follow-up review on this PR: the cache key is documented as
canonical JSON, but `overrides` was deserialized into an insertion-ordered
`IndexMap` and serde_json runs with `preserve_order`, so the same overrides
sent with a different key order produced distinct keys — interning duplicate
leaked configs, defeating dedup and burning through MAX_INTERNED_CONFIGS
faster. Build the key's `overrides` from a sorted `BTreeMap` so reordered
duplicates collapse to one config. The stored config keeps the request's
`IndexMap` (order doesn't affect resolution).

Co-authored-by: Claude <[email protected]>

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 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/resolver/tests.rs`:
- Around line 284-286: The test in intern should verify actual config reuse, not
just cache size. Capture the results of both intern(...) calls in this test and
assert they point to the same PacquetConfig instance using pointer/reference
equality, in addition to the existing cache len check. This will ensure the
dedup behavior in intern and the config cache behind configs.lock() is truly
reusing the interned config rather than silently creating a second one.
🪄 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: e1cc7eb2-1277-429a-80bf-d11134fae7bf

📥 Commits

Reviewing files that changed from the base of the PR and between f5fe50c and a08d929.

📒 Files selected for processing (2)
  • pnpr/crates/pnpr/src/resolver.rs
  • pnpr/crates/pnpr/src/resolver/tests.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • pnpr/crates/pnpr/src/resolver.rs

Comment thread pnpr/crates/pnpr/src/resolver/tests.rs Resolved
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit a08d929

Follow-up review on this PR: `len() == 1` only proves the key deduped — a
buggy impl could leak a second config and still leave the map at one
entry. Capture both returned refs and assert `std::ptr::eq` so the test
proves the second call reuses the same leaked `&'static Config`.

Co-authored-by: Claude <[email protected]>
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit a08d929

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 55dd395

1 similar comment
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 55dd395

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: pnpr reviewed: coderabbit CodeRabbit submitted an approving review state: automerge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants