Repository navigation
fix(lockfile): compute tarball integrity upon download - #12491
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughImplements missing tarball integrity computation and fail-closed handling for registry packages that omit checksums in metadata. When a registry provides no integrity, pnpm downloads the tarball to compute it, persists it in the lockfile, and refetches from store if needed. Frozen installs fail if integrity remains unavailable; non-frozen installs repair the lockfile. Consolidates integrity-requirement and resolution-classification logic into reusable helpers in resolver-base. ChangesMissing Tarball Integrity Recovery
Sequence DiagramsequenceDiagram
participant Client as pnpm install
participant Requester as packageRequester
participant Fetcher as Fetcher
participant Registry as Registry
participant Store as Content Store
Client->>Requester: requestPackage(resolution)
Requester->>Fetcher: resolutionNeedsFetch(resolution)?
alt integrity required
Requester->>Registry: download tarball
Requester->>Fetcher: completeResolution with computed integrity
Requester->>Requester: mustComputeIntegrity = true
end
Requester->>Store: doFetchToStore(mustComputeIntegrity)
alt cached && mustComputeIntegrity
Store->>Registry: refetch tarball
Store->>Store: recompute integrity
else cached && !mustComputeIntegrity
Store->>Store: return cached entry
end
alt integrity still missing
Requester->>Client: throw MISSING_TARBALL_INTEGRITY
else integrity present
Requester->>Client: return resolution with integrity
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Assessment against linked issues
Possibly related PRs
Suggested reviewers
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoFix missing tarball integrity by hashing downloaded tarballs and repairing lockfile Description
Diagram
High-Level Assessment
Files changed (11)
|
There was a problem hiding this comment.
Pull request overview
This PR fixes installs against registries that can’t provide dist.integrity by computing the tarball integrity during fetch and persisting it back into the lockfile (TypeScript implementation only, with pacquet follow-up noted in the PR description).
Changes:
- Introduces
resolutionNeedsIntegrity()in@pnpm/lockfile.utilsto centralize the “tarball integrity is required” decision. - Allows the deps resolution path (non-frozen installs) to carry integrity-less resolutions so the fetch pipeline can download the tarball, compute integrity, and write it back.
- Adds tests covering integrity computation (including the “already in store but missing integrity in resolver output” case) and verifies frozen installs still fail closed.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-lock.yaml | Adds @pnpm/lockfile.utils workspace dependency linkage. |
| lockfile/utils/src/toLockfileResolution.ts | Adds resolutionNeedsIntegrity() helper to consolidate integrity requirement logic. |
| lockfile/utils/src/pkgSnapshotToResolution.ts | Adds allowMissingIntegrity option to permit repair flows to proceed without throwing. |
| lockfile/utils/src/index.ts | Exports the new helper (and isGitHostedTarballUrl) from @pnpm/lockfile.utils. |
| installing/package-requester/tsconfig.json | Adds TS project reference to lockfile/utils. |
| installing/package-requester/test/index.ts | Adds coverage for computing integrity when the package is already in the store but resolver omits integrity. |
| installing/package-requester/src/packageRequester.ts | Forces fetch + writes computed integrity back into the tarball resolution; adds integrity-missing enforcement and refetch behavior changes. |
| installing/package-requester/package.json | Adds dependency on @pnpm/lockfile.utils. |
| installing/deps-resolver/src/resolveDependencies.ts | Reads lockfile resolutions with allowMissingIntegrity: true for repair flows. |
| installing/deps-installer/test/brokenLockfileIntegrity.ts | Adds an end-to-end test for repairing missing integrity on non-frozen installs and failing on frozen installs. |
| installing/deps-installer/src/install/index.ts | Forces full resolution on non-frozen installs when the wanted lockfile contains missing tarball integrity. |
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Code Review by Qodo
Context used 1. Git tarball overmatch
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
installing/package-requester/src/packageRequester.ts (1)
313-326: ⚡ Quick winNarrow the eager fetch to only resolutions that actually need integrity repair
Line 315 currently waits on
fetchResult.fetching()for any tarball without integrity, but the hard requirement is only forresolutionNeedsIntegrity(resolution). This broad await can unnecessarily serialize part of the install hot path.Suggested patch
- // A tarball resolution missing its integrity gets the integrity the worker computed - // from the tarball bytes. - if (!resolution.type && !(resolution as TarballResolution).integrity) { - const fetchedResult = await fetchResult.fetching() - if (fetchedResult.integrity) { - (resolution as TarballResolution).integrity = fetchedResult.integrity - } - } - if (resolutionNeedsIntegrity(resolution)) { + const needsIntegrity = resolutionNeedsIntegrity(resolution) + if (needsIntegrity) { + const fetchedResult = await fetchResult.fetching() + if (fetchedResult.integrity) { + (resolution as TarballResolution).integrity = fetchedResult.integrity + } + } + if (needsIntegrity && !(resolution as TarballResolution).integrity) { throw new PnpmError('MISSING_TARBALL_INTEGRITY', `Cannot compute the integrity of package "${id}": its registry metadata had no integrity and the tarball could not be downloaded to compute one.`, { hint: 'Ensure the tarball is reachable from the registry, then re-run installation.' } ) }As per coding guidelines, performance regressions in pnpm install paths are a prioritized review target.
🤖 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 `@installing/package-requester/src/packageRequester.ts` around lines 313 - 326, The current code eagerly fetches the tarball result for any resolution missing integrity, but the actual requirement is only for resolutions that satisfy resolutionNeedsIntegrity(resolution). Move the await fetchResult.fetching() call and its integrity assignment into the second if block (the one checking resolutionNeedsIntegrity) so that the fetch only happens when it's truly needed. This prevents unnecessary serialization in the install hot path by avoiding the fetch when the resolution ultimately won't require integrity anyway.Source: Coding guidelines
🤖 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 `@installing/deps-installer/src/install/index.ts`:
- Around line 1153-1157: The lockfileHasMissingTarballIntegrity function
incorrectly flags legacy file: snapshots as missing integrity, causing
unnecessary re-resolution work. In the some() callback within
lockfileHasMissingTarballIntegrity, add a check to skip resolutions that are
file: type (those without a tarball) before calling resolutionNeedsIntegrity,
ensuring only actual tarball-based resolutions are evaluated for integrity
requirements.
---
Nitpick comments:
In `@installing/package-requester/src/packageRequester.ts`:
- Around line 313-326: The current code eagerly fetches the tarball result for
any resolution missing integrity, but the actual requirement is only for
resolutions that satisfy resolutionNeedsIntegrity(resolution). Move the await
fetchResult.fetching() call and its integrity assignment into the second if
block (the one checking resolutionNeedsIntegrity) so that the fetch only happens
when it's truly needed. This prevents unnecessary serialization in the install
hot path by avoiding the fetch when the resolution ultimately won't require
integrity anyway.
🪄 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: c0c3ec27-9189-478d-9a5b-67f3af642ed2
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml,!pnpm-lock.yaml
📒 Files selected for processing (10)
installing/deps-installer/src/install/index.tsinstalling/deps-installer/test/brokenLockfileIntegrity.tsinstalling/deps-resolver/src/resolveDependencies.tsinstalling/package-requester/package.jsoninstalling/package-requester/src/packageRequester.tsinstalling/package-requester/test/index.tsinstalling/package-requester/tsconfig.jsonlockfile/utils/src/index.tslockfile/utils/src/pkgSnapshotToResolution.tslockfile/utils/src/toLockfileResolution.ts
|
Code review by qodo was updated up to the latest commit 00ec993 |
|
Code review by qodo was updated up to the latest commit a3df4ea |
Integrated-Benchmark Report (Linux)Each scenario reports direct installs and pnpr installs. Bencher consumes pacquet@HEAD and pnpr@HEAD. Scenario: Isolated linker: fresh restore, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 3.9626944922600003,
"stddev": 0.18429995346333922,
"median": 3.91723690266,
"user": 3.74945514,
"system": 3.3532322999999997,
"min": 3.71235945416,
"max": 4.24527719716,
"times": [
4.24527719716,
4.04693827816,
3.86633828616,
3.71762578716,
3.71235945416,
3.91770958016,
3.90520111916,
3.91676422516,
4.080059701160001,
4.21867129416
]
},
{
"command": "pacquet@main",
"mean": 3.76084096286,
"stddev": 0.0922393021337193,
"median": 3.7398955031599996,
"user": 3.73901204,
"system": 3.3424704999999997,
"min": 3.6796193971599997,
"max": 3.96598395816,
"times": [
3.77631282716,
3.7506722091599998,
3.68888992316,
3.6796193971599997,
3.72911879716,
3.75922122316,
3.96598395816,
3.8710419741599997,
3.70434617616,
3.6832031431599996
]
},
{
"command": "pnpr@HEAD",
"mean": 2.07012380136,
"stddev": 0.08969273632965694,
"median": 2.05581507366,
"user": 2.80000304,
"system": 2.9453935999999996,
"min": 1.9676236851600002,
"max": 2.23312219816,
"times": [
1.97474747516,
2.23312219816,
1.9676236851600002,
2.0382307591599997,
2.18903884516,
1.98602798316,
2.0301592231599996,
2.10008837116,
2.10880008516,
2.07339938816
]
},
{
"command": "pnpr@main",
"mean": 2.1852376464599996,
"stddev": 0.16594537200751014,
"median": 2.1040764186599996,
"user": 2.7776288399999998,
"system": 2.9414873999999993,
"min": 1.98795521416,
"max": 2.4405319681599997,
"times": [
2.03274981616,
2.3636090621599997,
1.98795521416,
2.08247272716,
2.1185226981599996,
2.37603671716,
2.06195704516,
2.2989110771599996,
2.0896301391599996,
2.4405319681599997
]
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.6687839211,
"stddev": 0.041553818445710024,
"median": 0.6515618527,
"user": 0.41929602,
"system": 1.36109424,
"min": 0.6381231547,
"max": 0.7665101077,
"times": [
0.6552863977000001,
0.6575573637000001,
0.7088469437,
0.7665101077,
0.6894117677,
0.6387964767000001,
0.6478373077,
0.6398976247,
0.6381231547,
0.6455720667
]
},
{
"command": "pacquet@main",
"mean": 0.6661382732999999,
"stddev": 0.04474713053561802,
"median": 0.6544941847,
"user": 0.39289572,
"system": 1.33483344,
"min": 0.6393881877,
"max": 0.7900658987,
"times": [
0.6704312467,
0.6505616887,
0.6592114227,
0.6627811707,
0.6584266807,
0.6393881877,
0.6480056337,
0.6409083277000001,
0.6416024757000001,
0.7900658987
]
},
{
"command": "pnpr@HEAD",
"mean": 0.716527801,
"stddev": 0.03382829695923304,
"median": 0.7081268172,
"user": 0.41698062,
"system": 1.3640522399999997,
"min": 0.6837653257,
"max": 0.7925401237,
"times": [
0.7524935957000001,
0.7107050717000001,
0.7090109157000001,
0.6837653257,
0.6883221477,
0.7072427187,
0.6938546847,
0.6956186297,
0.7317247967,
0.7925401237
]
},
{
"command": "pnpr@main",
"mean": 0.7231251554,
"stddev": 0.032952571787889025,
"median": 0.7144706412,
"user": 0.41679291999999996,
"system": 1.3668686399999996,
"min": 0.6854905407,
"max": 0.7999635077,
"times": [
0.7478984927000001,
0.7078171467000001,
0.7177360977,
0.7161525727,
0.7008797977000001,
0.6998380487,
0.7999635077,
0.7426866397,
0.7127887097000001,
0.6854905407
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.331943087800001,
"stddev": 0.04748451213579612,
"median": 4.3136153648,
"user": 3.9390767,
"system": 3.35630146,
"min": 4.2574814413,
"max": 4.4205694123,
"times": [
4.4205694123,
4.3094072113,
4.3113847953,
4.3158459343,
4.3609302113,
4.3852230793,
4.3517540663,
4.3017893643,
4.2574814413,
4.3050453623000005
]
},
{
"command": "pacquet@main",
"mean": 4.3723599256,
"stddev": 0.03260418293400025,
"median": 4.3608513608,
"user": 3.9241397,
"system": 3.3609482599999994,
"min": 4.3169534753,
"max": 4.4150481553,
"times": [
4.405215392300001,
4.3613932513,
4.3507619923,
4.3543489263,
4.3169534753,
4.3517804923000005,
4.3959256763,
4.4150481553,
4.3603094703,
4.4118624243
]
},
{
"command": "pnpr@HEAD",
"mean": 2.1998197577,
"stddev": 0.11798734601028082,
"median": 2.2153715858,
"user": 2.6027175,
"system": 2.8494864599999996,
"min": 2.0592898203,
"max": 2.3991180603,
"times": [
2.2907741483,
2.3189537613000004,
2.2352421403,
2.2397110713000004,
2.0684952813,
2.1229641273,
2.3991180603,
2.1955010313,
2.0681481353,
2.0592898203
]
},
{
"command": "pnpr@main",
"mean": 2.1987570816,
"stddev": 0.1363506140115176,
"median": 2.1267941103,
"user": 2.5821096,
"system": 2.8657875600000002,
"min": 2.0306084593000002,
"max": 2.3958948403,
"times": [
2.3710340603000004,
2.1272036053,
2.0865670433,
2.0917803093000003,
2.3423933063,
2.1203260693000003,
2.1263846153,
2.2953785073,
2.0306084593000002,
2.3958948403
]
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.42853418456,
"stddev": 0.015237290741956002,
"median": 1.42965932676,
"user": 1.40730732,
"system": 1.7579154,
"min": 1.40297379226,
"max": 1.45532002126,
"times": [
1.4230317752600001,
1.41926368226,
1.40297379226,
1.41238090726,
1.42966547026,
1.4384417312600002,
1.44390280426,
1.4296531832600001,
1.45532002126,
1.4307084782600001
]
},
{
"command": "pacquet@main",
"mean": 1.45398048136,
"stddev": 0.04919246660923868,
"median": 1.4401119072600002,
"user": 1.41315932,
"system": 1.7618164999999997,
"min": 1.4269810392600002,
"max": 1.59173240426,
"times": [
1.59173240426,
1.45227264126,
1.4427428822600001,
1.43321728826,
1.4374809322600002,
1.43305962826,
1.44546055526,
1.4272932952600001,
1.44956414726,
1.4269810392600002
]
},
{
"command": "pnpr@HEAD",
"mean": 0.6816471826600001,
"stddev": 0.008078683261437732,
"median": 0.68002261076,
"user": 0.35431061999999997,
"system": 1.2964683,
"min": 0.6732226242600001,
"max": 0.69424689526,
"times": [
0.6903178942600001,
0.6732985572600001,
0.69424689526,
0.6911510322600001,
0.6847934332600001,
0.6732485482600001,
0.68182491726,
0.6782203042600001,
0.6732226242600001,
0.6761476202600001
]
},
{
"command": "pnpr@main",
"mean": 0.75433961626,
"stddev": 0.012900509355370203,
"median": 0.7506628092600001,
"user": 0.36606651999999995,
"system": 1.3624728999999998,
"min": 0.7423502112600001,
"max": 0.78568396626,
"times": [
0.7658672092600001,
0.7438031412600001,
0.7504374342600001,
0.74581519626,
0.75515089826,
0.7542780002600001,
0.7491219212600001,
0.7423502112600001,
0.78568396626,
0.75088818426
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 3.13767341152,
"stddev": 0.02800342513637192,
"median": 3.13595534082,
"user": 1.8481134999999997,
"system": 2.0449363,
"min": 3.10484863032,
"max": 3.20601455632,
"times": [
3.14337785032,
3.14073580532,
3.1321358673199997,
3.1507125653199997,
3.13977481432,
3.10484863032,
3.12614096532,
3.20601455632,
3.1124461333199998,
3.12054692732
]
},
{
"command": "pacquet@main",
"mean": 3.18955351402,
"stddev": 0.05863558310652617,
"median": 3.17283531332,
"user": 1.8483101999999998,
"system": 2.0818791000000005,
"min": 3.13232083132,
"max": 3.30965694532,
"times": [
3.1381081093199996,
3.13232083132,
3.1790978433199997,
3.15723014232,
3.16475565432,
3.16758060532,
3.2801725073199997,
3.30965694532,
3.1885224803199996,
3.1780900213199996
]
},
{
"command": "pnpr@HEAD",
"mean": 0.6860203313200001,
"stddev": 0.01227951074794985,
"median": 0.68638334882,
"user": 0.357857,
"system": 1.3257487,
"min": 0.66741326032,
"max": 0.70787228932,
"times": [
0.68430886132,
0.66973041532,
0.66741326032,
0.70787228932,
0.6837471233200001,
0.68845783632,
0.6926286233200001,
0.6777080533200001,
0.69211896932,
0.6962178813200001
]
},
{
"command": "pnpr@main",
"mean": 0.71755889882,
"stddev": 0.06850436486311745,
"median": 0.69827635882,
"user": 0.3580264,
"system": 1.3214644,
"min": 0.6769574633200001,
"max": 0.90737342032,
"times": [
0.6769574633200001,
0.70975372232,
0.7006301113200001,
0.6809815233200001,
0.7265368323200001,
0.67938463932,
0.7084881403200001,
0.69592260632,
0.68956052932,
0.90737342032
]
}
]
} |
|
| Branch | pr/12491 |
| Testbed | pacquet |
Click to view all benchmark results
| Benchmark | Latency | Benchmark Result milliseconds (ms) (Result Δ%) | Upper Boundary milliseconds (ms) (Limit %) |
|---|---|---|---|
| isolated-linker.fresh-install.cold-cache.cold-store | 📈 view plot 🚷 view threshold | 4,331.94 ms(+2.72%)Baseline: 4,217.25 ms | 5,060.70 ms (85.60%) |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot 🚷 view threshold | 3,137.67 ms(+4.36%)Baseline: 3,006.54 ms | 3,607.85 ms (86.97%) |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot 🚷 view threshold | 1,428.53 ms(+7.66%)Baseline: 1,326.93 ms | 1,592.32 ms (89.71%) |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot 🚷 view threshold | 3,962.69 ms(-0.03%)Baseline: 3,963.76 ms | 4,756.52 ms (83.31%) |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot 🚷 view threshold | 668.78 ms(+7.40%)Baseline: 622.68 ms | 747.22 ms (89.50%) |
|
| Branch | pr/12491 |
| Testbed | pnpr |
⚠️ WARNING: No Threshold found!Without a Threshold, no Alerts will ever be generated.
Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the--ci-only-thresholdsflag.
Click to view all benchmark results
| Benchmark | Latency | milliseconds (ms) |
|---|---|---|
| isolated-linker.fresh-install.cold-cache.cold-store | 📈 view plot | 2,199.82 ms |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot | 686.02 ms |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot | 681.65 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot | 2,070.12 ms |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot | 716.53 ms |
zkochan
left a comment
There was a problem hiding this comment.
any changes should be in pacquet too
|
@zkochan does the approach look good? If yes, I can do the same for Rust as well. |
…leading refetch warning Address review feedback on the missing-tarball-integrity recovery path: - Reword the MISSING_TARBALL_INTEGRITY error so it no longer assumes the cause was an unreachable registry tarball; it now states that no integrity was provided by the resolution nor computed during fetch, and hints at custom fetchers. - Only emit the "Refetching ... to store" warning once a store read confirms the package was actually present. Initializing the flag from resolutionNeedsIntegrity made the warning fire on genuine first-time downloads from registries that omit integrity.
Summary
Fixes #12145.
Since v11.4 pnpm requires every registry tarball to carry an
integrityin the lockfile and fails withERR_PNPM_MISSING_TARBALL_INTEGRITYwhen it is missing, so it can verify the bytes it downloads. That assumes the registry's packument lists an integrity for each version. Some registries generate tarballs on-demand and cannot provide one, so the firstpnpm installwrites integrity-less lockfile entries and the next install (afternode_moduleswas removed) fails — pnpm can't install from its own generated lockfile.This PR makes pnpm compute the missing integrity from the downloaded tarball and write it into the lockfile, so the entry is verifiable on later installs:
resolutionNeedsFetchcontract; the remote-tarball fetcher reportstruewhen a resolution has no integrity. The package requester then downloads the tarball, computes its sha512, and writes it back into the resolution — even under--lockfile-only/skipFetch/ not-installable-here, because the lockfile entry must carry a platform-independent integrity. The fill is non-blocking (deferred onto thefetchingpromise); the deps-resolver awaits just those entries before building the lockfile snapshot and the virtual-store paths hashed from it.createNpmResolutionVerifier): a registry/http(s)tarball entry whoseintegrityis missing, empty, or non-string is rejected withMISSING_TARBALL_INTEGRITY. It fails closed — no silent re-fetch — and the check runs before the URL-keyed and semver short-circuits, so a tampered non-semver/URL-keyed entry can't dodge it.file:and git-hosted tarballs are anchored another way and stay exempt.Ported to the Rust
pacquet/port in the same PR (thePrefetchingResolvercomputes integrity for integrity-less tarball resolutions during resolution, with a per-URL singleflight cache).Related follow-up (not in this PR): #12562 — packages whose integrity is computed during fetch are indexed under a pre-fetch fallback store key, so the immediately-following install re-downloads once before re-keying the store.
Squash Commit Body
Checklist
pacquet/port.pnpm changeset).changeset carries the user-facing release note).
Summary by CodeRabbit
--lockfile-onlyandskipFetch.