Skip to content

fix(resolver): recover after metadata cache loss - #13014

Merged
zkochan merged 9 commits into
pnpm:mainfrom
YESHYUNGSEOK:fix/npm-resolver-304-cache-race
Jul 17, 2026
Merged

zkochan merged 9 commits into
pnpm:mainfrom
YESHYUNGSEOK:fix/npm-resolver-304-cache-race

Conversation

@YESHYUNGSEOK

@YESHYUNGSEOK YESHYUNGSEOK commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Recover when a registry responds with 304 Not Modified after the corresponding metadata cache entry has disappeared.

Both the TypeScript resolver and pacquet now retry the request once without cache validators, then reuse their existing metadata normalization and persistence paths. The retry remains bounded and does not recursively fall back to stale app metadata.

Regression tests cover the picker path, the cached full-metadata helper, the absence of conditional headers on the retry, and preservation of the bypass state across Rust body and decoding retries.

Squash Commit Body

Treat a 304 response without a matching metadata cache entry as a recoverable cache race. Retry the registry request once without conditional validators and feed the fresh response through the normal cache persistence path.

Implement the same bounded recovery in the TypeScript resolver and pacquet, including Rust retries that occur while reading or decoding the response body. Add regression coverage for both resolver implementations.

Checklist

  • The change is implemented in both the TypeScript CLI and the Rust
    pnpm/ port, or the description notes what still needs porting.
  • Added a changeset (pnpm changeset) if this PR changes any published
    package. Keep it short and written for pnpm users — it becomes a release note.
  • Added or updated tests.

Written by an agent (Codex, GPT-5).


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes
    • Improved recovery when cached package metadata disappears after the registry returns “not modified” (304), preventing resolver failures.
    • Added a controlled fallback that retries metadata once in cache-bypass mode (no conditional validators) when the cached mirror body can’t be loaded.
    • Ensures refreshed metadata is saved back to the mirror with updated headers, covering both full and abbreviated cache formats.
    • Propagates registry/network errors and stops after the single intended fallback when recovery isn’t possible.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Metadata resolvers recover when cached metadata disappears after a 304 Not Modified response by retrying once without validators and with no-cache headers. Rust and TypeScript implementations add this flow, error handling, persistence checks, and coverage for full and abbreviated metadata.

Changes

Metadata cache recovery

Layer / File(s) Summary
Cache-bypass request handling
pnpm/crates/resolving-npm-resolver/src/fetch_full_metadata.rs, pnpm11/resolving/npm-resolver/src/fetch.ts
Request options support bypass mode, omit conditional validators, add Cache-Control: no-cache, and reject a bypassed 304 without cached content.
Cached metadata fallback flow
pnpm/crates/resolving-npm-resolver/src/fetch_full_metadata_cached.rs, pnpm11/resolving/npm-resolver/src/fetchFullMetadataCached.ts, pnpm11/resolving/npm-resolver/src/pickPackage.ts
Cached fetches retry once with bypass enabled when metadata cannot be loaded after 304, while successful responses, repeated 304 responses, and fallback errors follow explicit paths.
Cache-race recovery validation
pnpm/crates/resolving-npm-resolver/src/fetch_full_metadata_cached/tests.rs, pnpm11/resolving/npm-resolver/test/ifModifiedSince.test.ts, pnpm11/resolving/npm-resolver/test/metaCache.test.ts
Tests cover full and abbreviated metadata, persisted headers and manifests, single-fallback termination, body retry behavior, and registry error propagation.
Release metadata
.changeset/recover-metadata-cache-race.md
The changeset records patch updates and documents the cache-bypass retry behavior.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Resolver
  participant Registry
  participant MetadataCache
  Resolver->>Registry: Send conditional metadata request
  Registry-->>Resolver: Return 304 Not Modified
  Resolver->>MetadataCache: Load cached metadata
  MetadataCache-->>Resolver: Cached body unavailable
  Resolver->>Registry: Retry without validators and with no-cache
  Registry-->>Resolver: Return fresh metadata
  Resolver->>MetadataCache: Persist refreshed metadata
Loading

Possibly related PRs

  • pnpm/pnpm#12888: Implements the same 304-without-cache fallback and terminal error behavior.

Suggested labels: product: pacquet, product: pnpm@11

Suggested reviewers: zkochan, ychampion

✨ 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.

@github-actions

github-actions Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: 8cba06fb26cf

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 2.613 ± 0.130 2.434 2.806 1.70 ± 0.20
pacquet@main 2.645 ± 0.150 2.457 2.936 1.72 ± 0.21
pnpr@HEAD 1.572 ± 0.139 1.429 1.805 1.02 ± 0.14
pnpr@main 1.536 ± 0.165 1.400 1.834 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.61338220846,
      "stddev": 0.13019017271918681,
      "median": 2.61135094526,
      "user": 2.0862119999999997,
      "system": 1.6592612599999998,
      "min": 2.43350899476,
      "max": 2.80586398076,
      "times": [
        2.72771969476,
        2.43350899476,
        2.5939533897600002,
        2.72548877776,
        2.48589330676,
        2.60043929176,
        2.80586398076,
        2.7048914597600002,
        2.43380058976,
        2.62226259876
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.6451459245600004,
      "stddev": 0.15038290155293574,
      "median": 2.60361489626,
      "user": 2.3680903,
      "system": 1.86801096,
      "min": 2.45698240976,
      "max": 2.9361423437600003,
      "times": [
        2.83540199776,
        2.45698240976,
        2.69636357076,
        2.54031798476,
        2.50958876776,
        2.9361423437600003,
        2.70556634376,
        2.56386603476,
        2.57569743876,
        2.63153235376
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.5723159460600002,
      "stddev": 0.1389274645590798,
      "median": 1.54931164376,
      "user": 1.6255115,
      "system": 1.5633002599999999,
      "min": 1.42919329076,
      "max": 1.80458037076,
      "times": [
        1.70614078376,
        1.43518712476,
        1.60455511676,
        1.4547777797600001,
        1.73367813576,
        1.42919329076,
        1.4528706577600001,
        1.49406817076,
        1.60810802976,
        1.80458037076
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.5361176745599998,
      "stddev": 0.1645113757134952,
      "median": 1.4689241822599999,
      "user": 1.5493190000000001,
      "system": 1.5079239599999998,
      "min": 1.40022337576,
      "max": 1.8335889067600002,
      "times": [
        1.41168809576,
        1.40022337576,
        1.81739941176,
        1.8335889067600002,
        1.40184656976,
        1.58116100676,
        1.46008905676,
        1.42437216576,
        1.55304884876,
        1.47775930776
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 286.9 ± 13.7 269.7 308.9 1.03 ± 0.08
pacquet@main 277.8 ± 17.1 254.0 304.5 1.00
pnpr@HEAD 320.9 ± 15.0 305.9 355.6 1.16 ± 0.09
pnpr@main 288.9 ± 16.0 263.2 307.9 1.04 ± 0.09
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.28690069266,
      "stddev": 0.013662645674005441,
      "median": 0.28339627225999997,
      "user": 0.23208886,
      "system": 0.56684768,
      "min": 0.26972631376,
      "max": 0.30888988076,
      "times": [
        0.28748822176,
        0.30888988076,
        0.29735766776,
        0.27802509376,
        0.30695677276,
        0.27700820276000004,
        0.27930432276,
        0.28952910276000005,
        0.27472134776,
        0.26972631376
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.27782760346,
      "stddev": 0.017066327713884045,
      "median": 0.28016113726,
      "user": 0.22778826,
      "system": 0.55318168,
      "min": 0.25395235776,
      "max": 0.30449643476000005,
      "times": [
        0.25592967676,
        0.27534132976000003,
        0.28498094476,
        0.28796681676,
        0.27188244176000004,
        0.25395235776,
        0.26123597376,
        0.28738980476000003,
        0.29510025376000004,
        0.30449643476000005
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.32089179075999996,
      "stddev": 0.0149916834053399,
      "median": 0.31428415426,
      "user": 0.25925876,
      "system": 0.60047348,
      "min": 0.30593914976000003,
      "max": 0.35564852676,
      "times": [
        0.31190865576000004,
        0.32637694176000004,
        0.32746509776000005,
        0.30593914976000003,
        0.33222918376000005,
        0.31038578176000003,
        0.31490078076,
        0.31039626176,
        0.31366752776,
        0.35564852676
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.28893681396,
      "stddev": 0.016004279727042783,
      "median": 0.29059867976000003,
      "user": 0.23224155999999999,
      "system": 0.55477938,
      "min": 0.26315069676,
      "max": 0.30794084776,
      "times": [
        0.29899967676,
        0.27585097976,
        0.27889312276,
        0.27194991376,
        0.26315069676,
        0.28585882376000005,
        0.29533853576,
        0.30794084776,
        0.30407342976,
        0.30731211276000003
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.958 ± 0.031 2.915 3.010 1.69 ± 0.13
pacquet@main 3.019 ± 0.078 2.877 3.110 1.73 ± 0.14
pnpr@HEAD 1.747 ± 0.136 1.529 1.886 1.00
pnpr@main 1.798 ± 0.150 1.594 2.026 1.03 ± 0.12
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.9578245891600004,
      "stddev": 0.031125188840513816,
      "median": 2.95273815656,
      "user": 2.6040414800000002,
      "system": 1.9100996999999995,
      "min": 2.91519371956,
      "max": 3.0098599895600002,
      "times": [
        3.0007385385600003,
        2.9603863675600004,
        3.0098599895600002,
        2.94854037656,
        2.94804207056,
        2.91919569956,
        2.94145548556,
        2.97789770756,
        2.91519371956,
        2.9569359365600003
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 3.0187217450599997,
      "stddev": 0.07828441598455942,
      "median": 3.03236299706,
      "user": 2.7858529800000005,
      "system": 1.8885336000000001,
      "min": 2.8771074975600004,
      "max": 3.11039485656,
      "times": [
        3.05288024656,
        2.9695605025600003,
        2.8771074975600004,
        2.99282427656,
        2.92346302356,
        3.08988983056,
        3.0435313655600003,
        3.02119462856,
        3.10637122256,
        3.11039485656
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.74650319256,
      "stddev": 0.13641150881093142,
      "median": 1.7955709795600001,
      "user": 1.7916469799999994,
      "system": 1.7356702,
      "min": 1.52874102056,
      "max": 1.88647648756,
      "times": [
        1.88647648756,
        1.8085282065600001,
        1.5927091665600002,
        1.52874102056,
        1.8625052875600001,
        1.84659942556,
        1.83849909656,
        1.78261375256,
        1.5485755485600001,
        1.76978393356
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.7981267137600003,
      "stddev": 0.14984035988767702,
      "median": 1.76227077306,
      "user": 1.8502471799999998,
      "system": 1.8324076999999996,
      "min": 1.59447498356,
      "max": 2.02588004556,
      "times": [
        1.73064815056,
        2.02588004556,
        1.7319412465600001,
        1.8923686435600002,
        1.67990479356,
        1.6317255855600001,
        1.9866103445600003,
        1.79260029956,
        1.91511304456,
        1.59447498356
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 999.4 ± 132.7 769.1 1182.8 2.68 ± 0.49
pacquet@main 779.8 ± 63.9 683.4 855.6 2.09 ± 0.31
pnpr@HEAD 373.5 ± 46.1 315.5 448.4 1.00
pnpr@main 383.2 ± 35.6 334.2 443.7 1.03 ± 0.16
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.9994037751799999,
      "stddev": 0.13269998254640578,
      "median": 1.00895883068,
      "user": 1.2237065,
      "system": 0.9512110999999999,
      "min": 0.76913541618,
      "max": 1.1827567721799999,
      "times": [
        1.13876903818,
        0.9982607791800001,
        1.0340539491799998,
        1.01690669618,
        1.1827567721799999,
        1.08733959218,
        0.76913541618,
        1.0010109651799999,
        0.79337499018,
        0.97242955318
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.7797538376800001,
      "stddev": 0.0638720157557281,
      "median": 0.7791665671800001,
      "user": 0.9842944000000001,
      "system": 0.9122523000000001,
      "min": 0.68343262518,
      "max": 0.8555922221800001,
      "times": [
        0.8555922221800001,
        0.83153994218,
        0.84189933118,
        0.8450928831800001,
        0.7860290291800001,
        0.7562209641800001,
        0.77230410518,
        0.73758299118,
        0.68784428318,
        0.68343262518
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.37349796207999997,
      "stddev": 0.046109492349114184,
      "median": 0.36288256318,
      "user": 0.2630639,
      "system": 0.5962132,
      "min": 0.31547192118,
      "max": 0.44840037718000003,
      "times": [
        0.37331702518000004,
        0.35244810118000003,
        0.38904286618000006,
        0.33343703218000004,
        0.33941341918,
        0.31547192118,
        0.33558913018000003,
        0.43347271718,
        0.44840037718000003,
        0.41438703118000003
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.38316382958000006,
      "stddev": 0.03556336282932487,
      "median": 0.38378931168,
      "user": 0.25527079999999996,
      "system": 0.6631273999999999,
      "min": 0.33419471618,
      "max": 0.44374690718000004,
      "times": [
        0.44374690718000004,
        0.36083713118000005,
        0.33966463818000003,
        0.33419471618,
        0.37830236818,
        0.39270924018000003,
        0.38927625518000003,
        0.42948087518000005,
        0.39935170518,
        0.36407445918000003
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.109 ± 0.050 2.017 2.195 6.21 ± 0.42
pacquet@main 2.124 ± 0.095 1.939 2.227 6.25 ± 0.49
pnpr@HEAD 0.364 ± 0.019 0.334 0.389 1.07 ± 0.09
pnpr@main 0.340 ± 0.022 0.305 0.370 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.1087113766199996,
      "stddev": 0.049511394143986844,
      "median": 2.10256922662,
      "user": 1.40355896,
      "system": 1.07913278,
      "min": 2.01666590362,
      "max": 2.19467896362,
      "times": [
        2.09712095262,
        2.15238207262,
        2.12621921162,
        2.01666590362,
        2.19467896362,
        2.09696523062,
        2.0576201096199997,
        2.10634999262,
        2.1403228686199998,
        2.09878846062
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.12414133682,
      "stddev": 0.09461136087714224,
      "median": 2.1718699711199996,
      "user": 1.4381370599999999,
      "system": 1.04797988,
      "min": 1.93910382962,
      "max": 2.22713017962,
      "times": [
        2.07358417362,
        2.17487672462,
        2.16886321762,
        2.19450236862,
        2.1776666316199997,
        2.17695712062,
        2.22713017962,
        2.11856470462,
        1.99016441762,
        1.93910382962
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.36403465132,
      "stddev": 0.01916998403848161,
      "median": 0.36826182762000004,
      "user": 0.25006736,
      "system": 0.6502108799999999,
      "min": 0.33439593062000006,
      "max": 0.38891072162000007,
      "times": [
        0.37938349462000004,
        0.34909414562,
        0.33741683062000005,
        0.38712753962000007,
        0.36859184362,
        0.38891072162000007,
        0.36980536262,
        0.35768883262000006,
        0.33439593062000006,
        0.36793181162000005
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.33965282482000003,
      "stddev": 0.021710252066931193,
      "median": 0.33615321162,
      "user": 0.22804626,
      "system": 0.59718708,
      "min": 0.30530975362000007,
      "max": 0.36970603762000004,
      "times": [
        0.35868718162,
        0.36306634562000006,
        0.36970603762000004,
        0.32209516362000007,
        0.32803635262,
        0.32386214862000007,
        0.30530975362000007,
        0.35706627062000007,
        0.34427007062000003,
        0.32442892362000003
      ]
    }
  ]
}

Scenario: Isolated linker: fresh resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 394.2 ± 15.3 374.9 417.3 4.34 ± 0.28
pacquet@main 388.9 ± 12.3 368.2 407.2 4.28 ± 0.26
pnpr@HEAD 90.8 ± 4.6 83.0 105.5 1.00
pnpr@main 95.4 ± 5.7 87.0 112.2 1.05 ± 0.08
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.39420317762,
      "stddev": 0.015346041301524527,
      "median": 0.39086222832000006,
      "user": 0.3687985199999999,
      "system": 0.10933384000000002,
      "min": 0.37492771232000005,
      "max": 0.41728170632000006,
      "times": [
        0.41728170632000006,
        0.40512927632000006,
        0.39188786932,
        0.40784279832000003,
        0.37492771232000005,
        0.38191923132000005,
        0.38983658732000004,
        0.38333453532000006,
        0.37739460332,
        0.41247745632000005
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.38885653832000006,
      "stddev": 0.01225774011771924,
      "median": 0.39113164082000007,
      "user": 0.37352051999999997,
      "system": 0.09675653999999999,
      "min": 0.36824491232000006,
      "max": 0.40723853932000004,
      "times": [
        0.40723853932000004,
        0.39619032332000004,
        0.39550913132000004,
        0.40191496732000004,
        0.36824491232000006,
        0.37523938632000003,
        0.38129057632,
        0.39183743832000006,
        0.39042584332,
        0.38067426532000004
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.09081017488666668,
      "stddev": 0.004606802667069082,
      "median": 0.09004499182,
      "user": 0.019698786666666666,
      "system": 0.014473473333333335,
      "min": 0.08298463432,
      "max": 0.10546711032,
      "times": [
        0.09163768432000001,
        0.08866122632000001,
        0.08962183032000001,
        0.09107437932000001,
        0.08946171132000001,
        0.08920157932,
        0.09071881632,
        0.08859932832,
        0.08298463432,
        0.08703331832000001,
        0.08477589832,
        0.08582313832,
        0.09989070432000001,
        0.10546711032,
        0.10111253932000001,
        0.08834623632000001,
        0.09032737332,
        0.09199673532000001,
        0.09241666232000001,
        0.08593946332,
        0.09446650832,
        0.08894935732,
        0.09169055432,
        0.08976261032,
        0.09108478532,
        0.09254728732,
        0.08952991032,
        0.09080003932000001,
        0.09087931232,
        0.08950451232000001
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.09543093711999999,
      "stddev": 0.005741446318428109,
      "median": 0.09380767332,
      "user": 0.02383812,
      "system": 0.013822539999999998,
      "min": 0.08699764932000001,
      "max": 0.11224135332000001,
      "times": [
        0.09337347832000001,
        0.08823937232000001,
        0.09791069332,
        0.09808565332000001,
        0.09223017332000001,
        0.09347284532000001,
        0.10324704232000001,
        0.10571609632000001,
        0.10010628832000001,
        0.09373163332000001,
        0.09123176532,
        0.09579673032000001,
        0.09642662932000001,
        0.09182160632000001,
        0.08699764932000001,
        0.09388371332,
        0.09986671932,
        0.09906319932,
        0.09442238332000001,
        0.11224135332000001,
        0.10054982532000001,
        0.08924200432000001,
        0.09163005332,
        0.09059277932000001,
        0.10095766232,
        0.08969282632,
        0.08822586632000001,
        0.09980515132000001,
        0.09300972232,
        0.09135719732000001
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.613 ± 0.057 4.542 4.698 1.29 ± 0.04
pacquet@main 4.698 ± 0.164 4.508 4.927 1.31 ± 0.06
pnpr@HEAD 3.576 ± 0.095 3.482 3.781 1.00
pnpr@main 3.673 ± 0.112 3.527 3.811 1.03 ± 0.04
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.61250227038,
      "stddev": 0.05681569630210078,
      "median": 4.59258991838,
      "user": 2.6440478,
      "system": 2.0264215,
      "min": 4.54174345688,
      "max": 4.69772853788,
      "times": [
        4.69772853788,
        4.5556999218800005,
        4.65673444088,
        4.67360927788,
        4.54174345688,
        4.57484879888,
        4.56817269588,
        4.60333885788,
        4.67130573688,
        4.58184097888
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.69780039388,
      "stddev": 0.1639134166348344,
      "median": 4.70101894738,
      "user": 2.5858162,
      "system": 1.9521903000000003,
      "min": 4.5080117918800005,
      "max": 4.92740694888,
      "times": [
        4.75877590488,
        4.6477573558800005,
        4.92740694888,
        4.75428053888,
        4.51339040988,
        4.5080117918800005,
        4.5320823718800005,
        4.84856133488,
        4.91002268288,
        4.57771459888
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.57600110198,
      "stddev": 0.09534097698636838,
      "median": 3.55709753988,
      "user": 1.5571181999999997,
      "system": 1.4356554,
      "min": 3.48224163088,
      "max": 3.78059453988,
      "times": [
        3.48468635588,
        3.48224163088,
        3.65485761088,
        3.51830802088,
        3.5241064048800004,
        3.59008867488,
        3.4940224838800003,
        3.59921377688,
        3.63189152088,
        3.78059453988
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 3.67335192548,
      "stddev": 0.11205944491872386,
      "median": 3.66309532088,
      "user": 1.7956933,
      "system": 1.737307,
      "min": 3.5270573038800004,
      "max": 3.81138612288,
      "times": [
        3.5366058538800003,
        3.80948292288,
        3.65717269888,
        3.56297057688,
        3.5270573038800004,
        3.66901794288,
        3.61759557988,
        3.81138612288,
        3.75321917188,
        3.78901108088
      ]
    }
  ]
}

@github-actions

github-actions Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchpr/13014
Testbedpacquet

🚨 1 Alert

BenchmarkMeasure
Units
ViewBenchmark Result
(Result Δ%)
Upper Boundary
(Limit %)
isolated-linker.fresh-install.hot-cache.hot-storeLatency
milliseconds (ms)
📈 plot
🚷 threshold
🚨 alert (🔔)
999.40 ms
(+33.37%)Baseline: 749.33 ms
899.20 ms
(111.14%)

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
2,957.82 ms
(-0.05%)Baseline: 2,959.34 ms
3,551.21 ms
(83.29%)
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
🚷 view threshold
2,108.71 ms
(-0.87%)Baseline: 2,127.19 ms
2,552.62 ms
(82.61%)
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
🚷 view threshold
🚨 view alert (🔔)
999.40 ms
(+33.37%)Baseline: 749.33 ms
899.20 ms
(111.14%)

isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
🚷 view threshold
394.20 ms
(-12.11%)Baseline: 448.51 ms
538.21 ms
(73.24%)
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
🚷 view threshold
2,613.38 ms
(-3.24%)Baseline: 2,700.91 ms
3,241.09 ms
(80.63%)
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
🚷 view threshold
4,612.50 ms
(-3.86%)Baseline: 4,797.66 ms
5,757.19 ms
(80.12%)
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
286.90 ms
(-3.63%)Baseline: 297.71 ms
357.25 ms
(80.31%)
🐰 View full continuous benchmarking report in Bencher

@github-actions

github-actions Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchpr/13014
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
1,527.20 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
361.15 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
340.74 ms
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
⚠️ NO THRESHOLD
86.38 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,513.80 ms
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
⚠️ NO THRESHOLD
3,638.31 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
275.55 ms
🐰 View full continuous benchmarking report in Bencher

@YESHYUNGSEOK
YESHYUNGSEOK marked this pull request as ready for review July 16, 2026 01:32
@YESHYUNGSEOK
YESHYUNGSEOK requested a review from zkochan as a code owner July 16, 2026 01:32
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@greptile-apps

greptile-apps Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

Safe to merge. The recovery logic is bounded (one bypass retry, no recursion), both implementations follow the same pattern, and the tests cover all four observable outcomes of the new path.

The change is a single, well-contained error-recovery addition to two parallel code paths (TypeScript and Rust). The AtomicBool in Rust correctly propagates bypass state across body-read retries. In TypeScript, fetchMetadataFromFromRegistry correctly rejects a bypass 304 before returning, so the notModified guard in callers is a type-narrowing safety check rather than a reachable production path. The outer try/catch in pickPackage correctly rethrows when the mirror is gone.

No files require special attention.

Reviews (9): Last reviewed commit: "refactor(resolver): rename metaCachedInS..." | Re-trigger Greptile

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Jul 16, 2026
Remove the pacquet `CacheMissingAfter304` variant, orphaned when the cache-loss
recovery replaced its only construction site. It advertised
`ERR_PNPM_CACHE_MISSING_AFTER_304` as reachable while the TypeScript CLI had
dropped its equivalents outright, so the two stacks disagreed on a public error
code. A `pub` enum variant draws no dead-code warning, so nothing flagged it.

Collapse the four hand-copied `META_NOT_MODIFIED_WITHOUT_CACHE` constructions
into `notModifiedWithoutCacheError`, and state at the recovery call sites why a
bypass request can only come back with a body or an error. The guards that
remain are type narrowing over the fetcher's union return, not a claim that a
bypassed 304 is reachable.

Drop the caller-side nulling of `etag`/`modified` in the cached fetcher:
`send_metadata_request` already forces both to `None` before computing
`has_validator`, so the conditional was a third expression of the same fact.

Changeset now names `ERR_PNPM_CACHE_MISSING_AFTER_304`, the error users search
for when they hit this.
@zkochan
zkochan force-pushed the fix/npm-resolver-304-cache-race branch from 65ce0d2 to 0cd9655 Compare July 17, 2026 13:26
@qodo-code-review

qodo-code-review Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (1) 📜 Skill insights (0)

Context used
✅ Compliance rules (platform): 18 rules

Grey Divider


Action required

1. notModifiedWithoutCacheError declared too early ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
notModifiedWithoutCacheError is declared before its first usage in the same file. This violates
the rule requiring TypeScript function declarations to appear only after their first use.
Code

pnpm11/resolving/npm-resolver/src/fetch.ts[R63-68]

+export function notModifiedWithoutCacheError (pkgName: string): PnpmError {
+  return new PnpmError(
+    'META_NOT_MODIFIED_WITHOUT_CACHE',
+    `Registry returned 304 for ${pkgName} without an existing cache to refresh.`
+  )
+}
Evidence
PR Compliance ID 713432 requires top-level/exported TypeScript function declarations to be declared
only after their first usage within the same file. In fetch.ts, notModifiedWithoutCacheError is
declared at lines 63-68, but its first usage occurs later at lines 208-214.

Rule 713432: Declare TypeScript functions only after their first usage
pnpm11/resolving/npm-resolver/src/fetch.ts[63-68]
pnpm11/resolving/npm-resolver/src/fetch.ts[208-214]

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

## Issue description
In `pnpm11/resolving/npm-resolver/src/fetch.ts`, the exported function declaration `notModifiedWithoutCacheError()` appears before any call site in the same file, violating the required declaration ordering.

## Issue Context
The first usage is later in the file where `reject(notModifiedWithoutCacheError(pkgName))` is called.

## Fix Focus Areas
- pnpm11/resolving/npm-resolver/src/fetch.ts[63-68]
- pnpm11/resolving/npm-resolver/src/fetch.ts[208-214]

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



Remediation recommended

2. Uncoded invariant Errors 🐞 Bug ◔ Observability ⭐ New
Description
fetchMetadataCached() throws plain Error in two “unreachable” 304 guard branches, which would bypass
pnpm’s stable PnpmError codes if those invariants are ever violated (e.g., via future
refactors/mocks). This would degrade error classification/observability compared to the existing
META_NOT_MODIFIED_WITHOUT_CACHE contract used elsewhere.
Code

pnpm11/resolving/npm-resolver/src/fetchFullMetadataCached.ts[R77-80]

+  // A 304 only resolves as `notModified` when a validator was sent, which
+  // requires cache headers loaded from a mirror — so a null mirror here is an
+  // unreachable invariant breach.
+  if (pkgMirror == null) throw new Error(`Unexpected 304 for ${pkgName} without a metadata cache`)
Evidence
The focused hunk throws plain Error for unexpected 304 situations, while the resolver already has
a dedicated helper that emits a coded PnpmError for 304-without-cache semantics and uses it in
other flows; keeping error types consistent preserves pnpm’s error-code contract if these defensive
guards are ever triggered.

pnpm11/resolving/npm-resolver/src/fetchFullMetadataCached.ts[77-80]
pnpm11/resolving/npm-resolver/src/fetchFullMetadataCached.ts[94-96]
pnpm11/resolving/npm-resolver/src/fetch.ts[255-266]
pnpm11/resolving/npm-resolver/src/pickPackage.ts[408-415]

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

### Issue description
`fetchMetadataCached()` uses `throw new Error(...)` for two defensive “should be unreachable” 304 cases. If reached, these errors will not carry pnpm’s structured error code (e.g. `ERR_PNPM_META_NOT_MODIFIED_WITHOUT_CACHE`), making failures harder to classify and handle.

### Issue Context
The repo already centralizes this condition in `notModifiedWithoutCacheError(pkgName)` which returns a `PnpmError('META_NOT_MODIFIED_WITHOUT_CACHE', ...)`. Other call sites (e.g. `pickPackage`) throw that helper for the same semantic condition.

### Fix Focus Areas
- pnpm11/resolving/npm-resolver/src/fetchFullMetadataCached.ts[77-80]
- pnpm11/resolving/npm-resolver/src/fetchFullMetadataCached.ts[94-96]

### Suggested change
- Import `notModifiedWithoutCacheError` from `./fetch.js`.
- Replace both `new Error(...)` throws with `throw notModifiedWithoutCacheError(pkgName)` (or, if you want to preserve the “internal invariant breach” wording, throw a `PnpmError` with an internal code used for invariants, but keep it coded/structured).

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


3. Relaxed bypass flag ordering 🐞 Bug ☼ Reliability
Description
fetch_full_metadata_cached persists cache-bypass state across retry_async re-attempts using an
AtomicBool with Ordering::Relaxed. This works in practice, but it relies on subtle cross-thread
visibility semantics (the retry loop awaits and can resume on another worker), so a later attempt
may theoretically observe the old value and re-send validators, re-entering the 304 recovery path
and adding an avoidable extra request.
Code

pnpm/crates/resolving-npm-resolver/src/fetch_full_metadata_cached.rs[R116-124]

+        let request = MetadataRequestOptions {
            pkg_name,
            url: &url,
            accept,
            http_client: opts.http_client,
            auth_headers: opts.auth_headers,
            etag: cache_headers.as_ref().and_then(|headers| headers.etag.as_deref()),
            modified: cache_headers.as_ref().and_then(|headers| headers.modified.as_deref()),
+            bypass_cache: cache_bypass.load(Ordering::Relaxed),
Evidence
The request’s bypass_cache field is driven by cache_bypass.load(Ordering::Relaxed), and the flag
is set via cache_bypass.store(true, Ordering::Relaxed) when the mirror body is missing after a
304. retry_async re-invokes the attempt closure across await points/backoff, so the read is
explicitly intended to observe the prior write across attempts.

pnpm/crates/resolving-npm-resolver/src/fetch_full_metadata_cached.rs[110-136]
pnpm/crates/resolving-npm-resolver/src/fetch_full_metadata_cached.rs[233-265]
pnpm/crates/network/src/retry.rs[195-225]

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

### Issue description
`cache_bypass` is written in `recover_from_not_modified()` and then read when building the next request in the surrounding `retry_async` loop. Using `Ordering::Relaxed` makes the code’s correctness depend on weak memory-model details when the future is resumed on a different thread.

### Issue Context
The bypass is intended to stay enabled for subsequent body/JSON retries to prevent re-validation against a mirror already known to be missing.

### Fix Focus Areas
- pnpm/crates/resolving-npm-resolver/src/fetch_full_metadata_cached.rs[116-126]
- pnpm/crates/resolving-npm-resolver/src/fetch_full_metadata_cached.rs[247-264]

### Suggested fix
Change the atomic operations to a stronger ordering:
- `cache_bypass.load(Ordering::Acquire)` (or `SeqCst`)
- `cache_bypass.store(true, Ordering::Release)` (or `SeqCst`)

`SeqCst` is simplest and the overhead here is negligible compared to network I/O.

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


4. notModifiedWithoutCacheError JSDoc lacks contract 📘 Rule violation ⚙ Maintainability
Description
The new JSDoc explains HTTP 304 semantics but does not document the function contract (when to call
it, expectations for pkgName, and what error code/message it guarantees). This makes the exported
helper harder to use correctly and violates the JSDoc contract requirement.
Code

pnpm11/resolving/npm-resolver/src/fetch.ts[R255-266]

+/**
+ * A 304 answers a validator with "the body you already have is current". Sent
+ * without one — either because nothing was cached or because `cacheBypass`
+ * dropped the validators to recover a lost cache entry — it refers to a body
+ * nobody holds, so there is nothing to serve and nothing left to retry.
+ */
+export function notModifiedWithoutCacheError (pkgName: string): PnpmError {
+  return new PnpmError(
+    'META_NOT_MODIFIED_WITHOUT_CACHE',
+    `Registry returned 304 for ${pkgName} without an existing cache to refresh.`
+  )
+}
Evidence
PR Compliance ID 713430 requires JSDoc to describe function contracts
(preconditions/postconditions/edge cases) rather than general implementation narration. The added
JSDoc describes what a 304 means but does not document the contract of
notModifiedWithoutCacheError (e.g., pkgName expectations and the guaranteed PnpmError
code/message).

Rule 713430: JSDoc must document function contracts, not re-describe implementation
pnpm11/resolving/npm-resolver/src/fetch.ts[255-266]

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 JSDoc for `notModifiedWithoutCacheError` explains the rationale but does not specify the function’s contract (inputs/expectations and guaranteed output), as required.

## Issue Context
This is an exported helper that constructs a specific `PnpmError` (`META_NOT_MODIFIED_WITHOUT_CACHE`). The documentation should help callers understand when it is appropriate to call and what it guarantees (error code/message semantics).

## Fix Focus Areas
- pnpm11/resolving/npm-resolver/src/fetch.ts[255-266]

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


Grey Divider

Previous review results

Review updated until commit 8cba06f

Results up to commit 0cd9655


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


Action required
1. notModifiedWithoutCacheError declared too early ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
notModifiedWithoutCacheError is declared before its first usage in the same file. This violates
the rule requiring TypeScript function declarations to appear only after their first use.
Code

pnpm11/resolving/npm-resolver/src/fetch.ts[R63-68]

+export function notModifiedWithoutCacheError (pkgName: string): PnpmError {
+  return new PnpmError(
+    'META_NOT_MODIFIED_WITHOUT_CACHE',
+    `Registry returned 304 for ${pkgName} without an existing cache to refresh.`
+  )
+}
Evidence
PR Compliance ID 713432 requires top-level/exported TypeScript function declarations to be declared
only after their first usage within the same file. In fetch.ts, notModifiedWithoutCacheError is
declared at lines 63-68, but its first usage occurs later at lines 208-214.

Rule 713432: Declare TypeScript functions only after their first usage
pnpm11/resolving/npm-resolver/src/fetch.ts[63-68]
pnpm11/resolving/npm-resolver/src/fetch.ts[208-214]

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

## Issue description
In `pnpm11/resolving/npm-resolver/src/fetch.ts`, the exported function declaration `notModifiedWithoutCacheError()` appears before any call site in the same file, violating the required declaration ordering.

## Issue Context
The first usage is later in the file where `reject(notModifiedWithoutCacheError(pkgName))` is called.

## Fix Focus Areas
- pnpm11/resolving/npm-resolver/src/fetch.ts[63-68]
- pnpm11/resolving/npm-resolver/src/fetch.ts[208-214]

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


Results up to commit 1b46b8c


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


Remediation recommended
1. notModifiedWithoutCacheError JSDoc lacks contract 📘 Rule violation ⚙ Maintainability
Description
The new JSDoc explains HTTP 304 semantics but does not document the function contract (when to call
it, expectations for pkgName, and what error code/message it guarantees). This makes the exported
helper harder to use correctly and violates the JSDoc contract requirement.
Code

pnpm11/resolving/npm-resolver/src/fetch.ts[R255-266]

+/**
+ * A 304 answers a validator with "the body you already have is current". Sent
+ * without one — either because nothing was cached or because `cacheBypass`
+ * dropped the validators to recover a lost cache entry — it refers to a body
+ * nobody holds, so there is nothing to serve and nothing left to retry.
+ */
+export function notModifiedWithoutCacheError (pkgName: string): PnpmError {
+  return new PnpmError(
+    'META_NOT_MODIFIED_WITHOUT_CACHE',
+    `Registry returned 304 for ${pkgName} without an existing cache to refresh.`
+  )
+}
Evidence
PR Compliance ID 713430 requires JSDoc to describe function contracts
(preconditions/postconditions/edge cases) rather than general implementation narration. The added
JSDoc describes what a 304 means but does not document the contract of
notModifiedWithoutCacheError (e.g., pkgName expectations and the guaranteed PnpmError
code/message).

Rule 713430: JSDoc must document function contracts, not re-describe implementation
pnpm11/resolving/npm-resolver/src/fetch.ts[255-266]

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 JSDoc for `notModifiedWithoutCacheError` explains the rationale but does not specify the function’s contract (inputs/expectations and guaranteed output), as required.

## Issue Context
This is an exported helper that constructs a specific `PnpmError` (`META_NOT_MODIFIED_WITHOUT_CACHE`). The documentation should help callers understand when it is appropriate to call and what it guarantees (error code/message semantics).

## Fix Focus Areas
- pnpm11/resolving/npm-resolver/src/fetch.ts[255-266]

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


Results up to commit e1419b6


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


Remediation recommended
1. Relaxed bypass flag ordering 🐞 Bug ☼ Reliability
Description
fetch_full_metadata_cached persists cache-bypass state across retry_async re-attempts using an
AtomicBool with Ordering::Relaxed. This works in practice, but it relies on subtle cross-thread
visibility semantics (the retry loop awaits and can resume on another worker), so a later attempt
may theoretically observe the old value and re-send validators, re-entering the 304 recovery path
and adding an avoidable extra request.
Code

pnpm/crates/resolving-npm-resolver/src/fetch_full_metadata_cached.rs[R116-124]

+        let request = MetadataRequestOptions {
            pkg_name,
            url: &url,
            accept,
            http_client: opts.http_client,
            auth_headers: opts.auth_headers,
            etag: cache_headers.as_ref().and_then(|headers| headers.etag.as_deref()),
            modified: cache_headers.as_ref().and_then(|headers| headers.modified.as_deref()),
+            bypass_cache: cache_bypass.load(Ordering::Relaxed),
Evidence
The request’s bypass_cache field is driven by cache_bypass.load(Ordering::Relaxed), and the flag
is set via cache_bypass.store(true, Ordering::Relaxed) when the mirror body is missing after a
304. retry_async re-invokes the attempt closure across await points/backoff, so the read is
explicitly intended to observe the prior write across attempts.

pnpm/crates/resolving-npm-resolver/src/fetch_full_metadata_cached.rs[110-136]
pnpm/crates/resolving-npm-resolver/src/fetch_full_metadata_cached.rs[233-265]
pnpm/crates/network/src/retry.rs[195-225]

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

### Issue description
`cache_bypass` is written in `recover_from_not_modified()` and then read when building the next request in the surrounding `retry_async` loop. Using `Ordering::Relaxed` makes the code’s correctness depend on weak memory-model details when the future is resumed on a different thread.

### Issue Context
The bypass is intended to stay enabled for subsequent body/JSON retries to prevent re-validation against a mirror already known to be missing.

### Fix Focus Areas
- pnpm/crates/resolving-npm-resolver/src/fetch_full_metadata_cached.rs[116-126]
- pnpm/crates/resolving-npm-resolver/src/fetch_full_metadata_cached.rs[247-264]

### Suggested fix
Change the atomic operations to a stronger ordering:
- `cache_bypass.load(Ordering::Acquire)` (or `SeqCst`)
- `cache_bypass.store(true, Ordering::Release)` (or `SeqCst`)

`SeqCst` is simplest and the overhead here is negligible compared to network I/O.

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


Qodo Logo

@qodo-code-review

qodo-code-review Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

PR Code Suggestions ✨

Latest suggestions up to 744047a

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

CategorySuggestion                                                                                                                                    Impact
Possible issue
Narrow metadata result unions safely

Use the 'in' operator to narrow the type before accessing the notModified
property.

pnpm11/resolving/npm-resolver/src/fetchFullMetadataCached.ts [87-105]

-if (!conditional.notModified) return persistAndReturn(conditional)
+if (!('notModified' in conditional)) return persistAndReturn(conditional)
 ...
-if (refetched.notModified) throw notModifiedWithoutCacheError(pkgName)
+if ('notModified' in refetched) throw notModifiedWithoutCacheError(pkgName)
 return persistAndReturn(refetched)

[To ensure code accuracy, apply this suggestion manually]

Suggestion importance[1-10]: 8

__

Why: Directly accessing a property that is only present in one constituent of a union without type narrowing causes TypeScript compilation errors.

Medium
✅ Preserve union narrowing after fallback
Suggestion Impact:The fetch flow was refactored to use separate `conditional` and `refetched` constants with early-return guards on `notModified`, allowing TypeScript to narrow each result before passing it to `persistFreshMeta`. This addresses the narrowing issue without using the suggested `'notModified' in fetchResult` check.

code diff:

+      const conditional = await ctx.fetch(spec.name, {
+        authHeaderValue: opts.authHeaderValue,
+        fullMetadata,
+        etag: cacheHeaders?.etag,
+        modified: cacheHeaders?.modified,
+        registry: opts.registry,
+      })
+      // 200 — the registry sent a fresh body; persist and return it. `await`
+      // keeps a persist-path failure inside this try's cached-meta fallback.
+      if (!conditional.notModified) return await persistFreshMeta(conditional)
+
+      // 304 Not Modified — the registry confirmed the mirror is still fresh, so
+      // serve the body it vouched for.
+      metaCachedInStore = metaCachedInStore ?? await limit(async () => loadMeta(pkgMirror))
+      if (metaCachedInStore != null) return await serveValidatedMeta(metaCachedInStore)
+
+      // The mirror vanished between the headers read and this read (concurrent
+      // store cleanup, antivirus, ...), so the 304 now validates nothing. Ask
+      // again as a cold cache would, which the registry can only answer with a
+      // body or an error — never another 304.
+      const refetched = await ctx.fetch(spec.name, {
+        authHeaderValue: opts.authHeaderValue,
+        cacheBypass: true,
+        fullMetadata,
+        registry: opts.registry,
+      })
+      if (refetched.notModified) throw notModifiedWithoutCacheError(spec.name)
+      return await persistFreshMeta(refetched)

Use 'notModified' in fetchResult to safely narrow the union type before
accessing the property.

pnpm11/resolving/npm-resolver/src/pickPackage.ts [444]

-if (fetchResult.notModified) throw notModifiedWithoutCacheError(spec.name)
+if ('notModified' in fetchResult) throw notModifiedWithoutCacheError(spec.name)

[Suggestion processed]

Suggestion importance[1-10]: 8

__

Why: Directly accessing a property that is only present in one constituent of a union without type narrowing causes TypeScript compilation errors.

Medium
  • More

Previous suggestions

Suggestions
CategorySuggestion                                                                                                                                    Impact
Possible issue
Restore safe union discrimination

Use the in operator to safely check for the notModified property on the result
union type.

pnpm11/resolving/npm-resolver/src/fetchFullMetadataCached.ts [74-92]

-  if (result.notModified) {
+  if ('notModified' in result && result.notModified) {
 ...
-    if (result.notModified) throw notModifiedWithoutCacheError(pkgName)
+    if ('notModified' in result && result.notModified) {
+      throw notModifiedWithoutCacheError(pkgName)
+    }
Suggestion importance[1-10]: 9

__

Why: Directly accessing notModified on the union type will cause a TypeScript compilation error since the property doesn't exist on FetchMetadataResult.

High
✅ Safely narrow fallback results
Suggestion Impact:The fallback result was separated into a new `refetched` constant and handled independently before being passed to `persistFreshMeta`, avoiding the previous reassigned union variable. However, the commit did not use the suggested `in` operator and still accesses `refetched.notModified` directly.

code diff:

+      const refetched = await ctx.fetch(spec.name, {
+        authHeaderValue: opts.authHeaderValue,
+        cacheBypass: true,
+        fullMetadata,
+        registry: opts.registry,
+      })
+      if (refetched.notModified) throw notModifiedWithoutCacheError(spec.name)
+      return await persistFreshMeta(refetched)

Use the in operator to safely narrow the union type before accessing
notModified.

pnpm11/resolving/npm-resolver/src/pickPackage.ts [444]

-        if (fetchResult.notModified) throw notModifiedWithoutCacheError(spec.name)
+        if ('notModified' in fetchResult && fetchResult.notModified) {
+          throw notModifiedWithoutCacheError(spec.name)
+        }
Suggestion importance[1-10]: 9

__

Why: Directly accessing notModified on the union type will cause a TypeScript compilation error because the property is missing from FetchMetadataResult.

High

@codecov-commenter

codecov-commenter commented Jul 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.11765% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.49%. Comparing base (e7138af) to head (8cba06f).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
...ing-npm-resolver/src/fetch_full_metadata_cached.rs 92.50% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13014      +/-   ##
==========================================
+ Coverage   85.45%   85.49%   +0.04%     
==========================================
  Files         501      502       +1     
  Lines       80654    80859     +205     
==========================================
+ Hits        68924    69134     +210     
+ Misses      11730    11725       -5     

☔ 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.

… use

The helper sat above the interfaces at the top of fetch.ts while its only
in-file call site is inside fetchMetadataFromFromRegistry. Move it below that
function, next to the other helpers it sits with, so the file keeps reading
top-down from entry point to detail.
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 1b46b8c

@qodo-code-review

qodo-code-review Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

CategorySuggestion                                                                                                                                    Impact
Possible issue
Restore safe union discrimination

Use the in operator to safely check for the notModified property on the result
union type.

pnpm11/resolving/npm-resolver/src/fetchFullMetadataCached.ts [74-92]

-  if (result.notModified) {
+  if ('notModified' in result && result.notModified) {
 ...
-    if (result.notModified) throw notModifiedWithoutCacheError(pkgName)
+    if ('notModified' in result && result.notModified) {
+      throw notModifiedWithoutCacheError(pkgName)
+    }

[To ensure code accuracy, apply this suggestion manually]

Suggestion importance[1-10]: 9

__

Why: Directly accessing notModified on the union type will cause a TypeScript compilation error since the property doesn't exist on FetchMetadataResult.

High
Safely narrow fallback results

Use the in operator to safely narrow the union type before accessing
notModified.

pnpm11/resolving/npm-resolver/src/pickPackage.ts [444]

-        if (fetchResult.notModified) throw notModifiedWithoutCacheError(spec.name)
+        if ('notModified' in fetchResult && fetchResult.notModified) {
+          throw notModifiedWithoutCacheError(spec.name)
+        }
  • Apply / Chat
Suggestion importance[1-10]: 9

__

Why: Directly accessing notModified on the union type will cause a TypeScript compilation error because the property is missing from FetchMetadataResult.

High
  • More

@greptile-apps

greptile-apps Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

…rd clauses

fetchMetadataCached threaded one reassigned `result` through a two-level nested
304 branch, so the persist-and-return at the bottom could hold either the
conditional fetch or the cold retry. Give each fetch its own name, turn the 304
handling into top-down guard clauses, and name the shared persist-a-fresh-body
step once. Behavior is unchanged; the cache-race tests cover every exit.
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 744047a

Convert persistAndReturn, serveValidatedMeta, and persistFreshMeta from const
arrow closures to hoisted function declarations placed after their call sites,
matching the repo convention (functions are declared after they are used) that
already governs the module-level helpers here. They still close over the same
enclosing scope, so behavior is unchanged.
@qodo-code-review

Copy link
Copy Markdown

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

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

Auto-approved notes - no code suggestions found
- 'approve_pr_on_self_review' flag enabled

zkochan added 2 commits July 17, 2026 19:59
The pkgMirror-null and cache-bypass-refetch 304 branches in fetchMetadataCached
are unreachable: fetchMetadataFromFromRegistry only resolves notModified after
sending a validator, and rejects a validator-less 304 itself. Per the repo
convention — PnpmError is for user-reachable errors, while type-guard and
unreachable-branch errors stay plain Error — throw plain Error there. The
user-facing ERR_PNPM_META_NOT_MODIFIED_WITHOUT_CACHE still surfaces from
fetch.ts on the reachable path, and pickPackage keeps the PnpmError because its
injected fetch can reach the branch (a test asserts the code).

Also trim call-site comments that restated a guard or duplicated the helper's
own doc.
@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

Auto-approved notes - no code suggestions found
- 'approve_pr_on_self_review' flag enabled

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 0226ed7

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

Auto-approved notes - no code suggestions found
- 'approve_pr_on_self_review' flag enabled

The on-disk mirror meta reads more clearly as diskMeta, and the shorter name
declutters pickPackage's fast paths. It stays distinct from cachedMeta, the
in-memory metaCache hit, so the disk-vs-memory contrast the old name carried is
preserved.
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 8cba06f

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

Auto-approved notes - no code suggestions found
- 'approve_pr_on_self_review' flag enabled

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants