Repository navigation
Description
Found by the defect-hotspots skill (pnpm/pnpm#17021) on 2026-10-17 over 90 days of main (086165da7a). The root cause comes from reading the commits and code; it was not reproduced. The design steps are proposals for a maintainer to settle.
Loop: Registry metadata cache (about 10 fixes, one partly reversed)
Property. Whether to serve memory, serve the mirror, revalidate, or fetch depends only on the mirror's recorded headers, the network mode, the document kind, and the release-age need. On an unchanged registry, the second install downloads no body.
Members. pnpm/pnpm#14931 → pnpm/pnpm#15145 → pnpm/pnpm#16507 (the second fix caused a 200 loop the third fixed). pnpm/pnpm#15722, partly reversed by pnpm/pnpm#16533 after it caused 2x memory and 3x time. Also pnpm/pnpm#15879, pnpm/pnpm#15700, pnpm/pnpm#15860 → pnpm/pnpm#16496 (a perf regression), pnpm/pnpm#16647, pnpm/pnpm#16668.
Flaw.
- No explicit state machine. The decision is spread across
pick_package,cached_pick,handle_cache_hit,mirror_fast_paths(four shortcuts),offline_disk_pick, anddisk_fallback. - Request shape is decided again in
metadata_request.uncacheableis read in five places. - Three writers of
MetaHeadersper stack, with no rule for which validator describes which document kind. - v12 has two request pipelines, so fix(resolving-npm-resolver): exclude permit queueing from the slow-request warning pnpm#16647 had to fix both.
Design change.
- Pure
decide(...) -> ServeMemory | ServeMirror | Revalidate | Fetch | FailOfflineandon_response(...) -> MirrorWrite.MirrorWritebecomes the only header writer. - The release-age upgrade becomes a document kind, not a separate fetch.
- v11 gets the same two functions over a shared case table.
Tests.
- Table-driven unit tests of
decideandon_responseover mirror state × status × Cache-Control × ETag × network mode × document kind × release age. - A three-install sequence against a mock registry that keys ETags per representation. Assert the exact request log, with only 304s on installs 2 and 3.
- A v11/v12 request-log differential.
The shared test harnesses that cover this loop and the others are tracked in #141.
Written by an agent (Claude Code, claude-opus-5-5).
Activity
zkochan commentedon Oct 17, 2026
pnpm/pnpm#17024 is open (draft) as a first, partial step, in v12 only. It adds a pure
metadata_cache_policymodule:DocumentKind(Abbreviated/Full/FullInAbbreviatedMirror) gives the request shape. A mirror's validators are sent only for the kind that recorded them.MirrorWrite::on_responsereads a 2xx once and is the only writer of a fetched document's mirror headers. The release-age upgrade is now aFullInAbbreviatedMirrorrequest.mirror_may_answeris the singleuncacheablegate for picks.There is no behavior change, and table-driven unit tests cover each function.
Still open on this task:
decide()over the pick layers.Written by an agent (Claude Code, claude-opus-5-5).
refactor(resolving-npm-resolver): move metadata cache decisions into …
refactor(resolving-npm-resolver): share the metadata response decode …
refactor(resolving-npm-resolver): decide the pick's mirror shortcuts …
fix(resolving-npm-resolver): remember the release-age upgrade of a lo…
zkochan commentedon Oct 17, 2026
Progress, all v12 and all merged:
metadata_cache_policydecides the request shape (DocumentKind,revalidation) and the mirror header writes (MirrorWrite, the only writer for fetched documents). It also adds the singleuncacheablegate (mirror_may_answer).decode_metadata_response) shared by the cached and plain fetchers. A fix to it no longer has to land twice, as fix(resolving-npm-resolver): exclude permit queueing from the slow-request warning pnpm#16647 did.pick_package::routedecides the mirror shortcuts (MirrorShortcuts,RouteInputs::written_after), the disk-first read (DiskFirst), and the fallback after a failed fetch, all from inputs alone. Table-driven tests cover each decision.PickState::upgrade_for_release_agepersists and marks the release-age upgrade. The lowest-version mirror path never marked, so it re-fetched the full document on every pick, a bug shipped since 12.8.0.Still open:
handle_cache_hit's verified/unverified guard).Written by an agent (Claude Code, claude-opus-5-5).
perf(resolving-npm-resolver): fetch the release-age upgrade through t…
perf(npm-resolver): revalidate the full document a release-age upgrad…
refactor(resolving-npm-resolver): decide the in-memory cache hit's ch…
zkochan commentedon Oct 17, 2026
More progress, all merged:
CachedFetchnames the document kind apart from the mirror slot. With a registry that omits some publish times, the upgrade now revalidates the full document it holds and gets a 304. Before, it downloaded the whole body again.route::CacheHitCheck::decidedecides the in-memory cache hit:Serve,StableRangePick, orRevalidate. It reuses the route's stable-range test, sounverified_pick_is_safeis gone. Table-driven tests cover it.The v12 decisions are now pure functions with table tests. Each one answers a single question:
metadata_cache_policy: which document to request and with which validators, and which headers to write after the response.route: which mirror reads to try before fetching, whether to read the disk first, whether a failed fetch may fall back, and whether to reuse an in-memory hit.Still open:
Written by an agent (Claude Code, claude-opus-5-5).
test(cli): assert the registry request log of three installs (#17061)
zkochan commentedon Oct 17, 2026
pnpm/pnpm#17061 (merged) adds the three-install request-log harness for v12.
TestRegistry::start_recording_with_own_storagerecords each request the fixture registry answers.cli/tests/suite/metadata_request_log.rsasserts each install's exact log. Only install 1 downloads a body. Installs 2 and 3 revalidate with the ETag of the same representation, or send no request when the release-age shortcut or--prefer-offlineanswers.Still open:
pnpm, so it needs a TypeScript-side harness over the same fixture registry.Written by an agent (Claude Code, claude-opus-5-5).
test: share the three-install request-log cases between pnpm v11 and …
zkochan commentedon Oct 17, 2026
pnpm/pnpm#17063 (merged) adds the v11/v12 request-log differential.
pnpr/.fixtures/request-logs/metadata-three-installs.jsonis the shared case table. The v12 CLI suite and a new v11 e2e test (pnpm11/pnpm/test/install/metadataRequestLog.ts) both assert it.It found and fixed two v12 bugs:
If-Modified-Sincefor a baremodifieddate, which v11 sends.modifiedbefore 1970 crashed the revalidation. This has shipped since v12.0.0.Still open: the v11 counterpart of the decision functions. v11 has no known defect left in this area, so this is cleanup only. The shared table now guards both stacks against drift, so I suggest closing this task unless that refactor is wanted.
Written by an agent (Claude Code, claude-opus-5-5).
refactor(npm-resolver): decide the pick's mirror shortcuts and cache …
refactor(npm-resolver): move metadata request shapes and mirror heade…
zkochan commentedon Oct 17, 2026
The v11 counterpart is merged:
route.tsdecides the mirror shortcuts and the in-memory cache hit, as v12'spick_package::routedoes.metadataCachePolicy.tsholds the document kind, the requests both v11 pipelines send, the release-age upgrade's request, the only writer of a fetched document's header line, and the uncacheable gate. As a side effect, the upgrade of a mirror that holds the full document reuses its revalidation's 304. The two requests used to differ only in property order, which gave them different memo keys.time, that downloaded the document again after every 304, and the full mirror lost itsetag.Every item in this task has now landed. Two follow-ups are left:
minimumReleaseAgeexclusions, the stable-range shortcuts after a missed prefer-offline read, the unvalidated-mirror shortcut on private routes, and the fallback after a failed fetch. The last one matters most. On a private route v12 fails closed on401/403/private404, while v11 falls back to the mirror.Written by an agent (Claude Code, claude-opus-5-5).
zkochan commentedon Oct 17, 2026
Done. Every item of this task has landed in both stacks. The last pieces were pnpm/pnpm#17064, pnpm/pnpm#17066, and pnpm/pnpm#17068.
Correction to my previous comment. Two of the four v11/v12 differences I listed are not CLI differences: the private-route unvalidated-mirror shortcut and the fail-closed fallback. v12's private metadata scope comes only from pnpr's route hook, so the pnpm CLI behaves as v11 does there. No follow-up is needed for them.
Follow-ups:
minimumReleaseAgeexclusions, and after a missed prefer-offline read. v11 is maintenance-only, so I left them alone.Written by an agent (Claude Code, claude-opus-5-5).
zkochan commentedon Oct 17, 2026
Follow-ups landed:
minimumReleaseAgeExcludekeeps the shortcuts, and offline and prefer-offline picks skip them.v11 and v12 now make the same metadata cache decisions.
Written by an agent (Claude Code, claude-opus-5-5).