Repository navigation
fix(package-manifest): write package.json atomically via a temp file - #12642
Conversation
PackageManifest::save truncated package.json in place with File::create + write_all. A crash, OOM, or ENOSPC between the truncate and the completed write left the file empty or partial, destroying the user's dependency declarations with no recovery path. add/remove/update and set-script all go through this path. Write the serialized manifest to a sibling temp file, fsync it, then rename it over the target, matching the write-file-atomic guarantee the TypeScript pnpm CLI relies on. The crate's sibling workspace-manifest-writer already uses this pattern. Co-authored-by: Claude <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe package-manifest crate now saves ChangesAtomic package manifest writes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
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 QodoWrite package.json atomically using temp file + rename Description
Diagram
High-Level Assessment
Files changed (3)
|
Code Review by Qodo
1. Chmod not covered by fsync
|
|
Code review by qodo was updated up to the latest commit b0bb7fd |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #12642 +/- ##
==========================================
- Coverage 88.59% 88.58% -0.02%
==========================================
Files 338 339 +1
Lines 49065 49184 +119
==========================================
+ Hits 43468 43568 +100
- Misses 5597 5616 +19 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Integrated-Benchmark Report (Linux)Commit: Each scenario reports direct installs and pnpr installs. Bencher consumes pacquet@HEAD and pnpr@HEAD. Scenario: Isolated linker: fresh restore, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.387930450440001,
"stddev": 0.15823551959754456,
"median": 4.34290268314,
"user": 3.66861886,
"system": 3.3482126,
"min": 4.22852280864,
"max": 4.72308908564,
"times": [
4.72308908564,
4.26453677164,
4.37664113364,
4.34445961564,
4.609266477639999,
4.29901343264,
4.22852280864,
4.28370617364,
4.40872325464,
4.3413457506399995
]
},
{
"command": "pacquet@main",
"mean": 4.327248674240001,
"stddev": 0.08460962297566306,
"median": 4.30836901414,
"user": 3.6960840599999996,
"system": 3.3716524000000008,
"min": 4.22968802564,
"max": 4.54996214064,
"times": [
4.54996214064,
4.28922350764,
4.22968802564,
4.33091739564,
4.3181858776399995,
4.29905845364,
4.28909931764,
4.35088452964,
4.29778791964,
4.31767957464
]
},
{
"command": "pnpr@HEAD",
"mean": 2.8020850972400004,
"stddev": 0.09579881942009899,
"median": 2.7757833396400002,
"user": 2.71437406,
"system": 2.9820192000000003,
"min": 2.7232075046400004,
"max": 3.04165299864,
"times": [
2.85370141464,
2.7232075046400004,
2.84164788764,
3.04165299864,
2.78863530364,
2.7978608206400004,
2.7521181176400002,
2.72882984264,
2.7629313756400005,
2.7302657066400005
]
},
{
"command": "pnpr@main",
"mean": 2.9554898033400003,
"stddev": 0.15399311495488308,
"median": 2.88467209714,
"user": 2.7571679600000003,
"system": 3.0005269999999995,
"min": 2.8061263926400004,
"max": 3.19156148264,
"times": [
2.8166686806400003,
2.8061263926400004,
3.12309294364,
3.19156148264,
2.8248442486400003,
2.8457157056400004,
3.15976967964,
2.9236284886400004,
2.84505063964,
3.01843977164
]
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.61977455548,
"stddev": 0.008954301123297263,
"median": 0.6176809269800001,
"user": 0.36074824,
"system": 1.3091989599999998,
"min": 0.6097418229800001,
"max": 0.6385033069800001,
"times": [
0.6385033069800001,
0.62831195098,
0.6185345339800001,
0.6218697109800001,
0.6098786409800001,
0.6127890399800001,
0.6247950669800001,
0.6097418229800001,
0.6164941609800001,
0.6168273199800001
]
},
{
"command": "pacquet@main",
"mean": 0.6293547810800001,
"stddev": 0.010987569488345953,
"median": 0.6265511329800001,
"user": 0.37325174,
"system": 1.29577576,
"min": 0.6148242709800001,
"max": 0.6525609319800001,
"times": [
0.6276613149800001,
0.6254409509800001,
0.6220542799800001,
0.6339159939800001,
0.63899651298,
0.6343659249800001,
0.6245365859800001,
0.6525609319800001,
0.6148242709800001,
0.6191910439800001
]
},
{
"command": "pnpr@HEAD",
"mean": 0.6834539430800001,
"stddev": 0.03220763170365816,
"median": 0.6765641704800001,
"user": 0.38417344,
"system": 1.32888456,
"min": 0.6553558839800001,
"max": 0.7632049839800001,
"times": [
0.6869360979800001,
0.6659231969800001,
0.6588549129800001,
0.6553558839800001,
0.6583991249800001,
0.6898208029800001,
0.6989399529800001,
0.6909122309800001,
0.7632049839800001,
0.6661922429800001
]
},
{
"command": "pnpr@main",
"mean": 0.6914454267800001,
"stddev": 0.039265270667498624,
"median": 0.6863130954800001,
"user": 0.38543243999999993,
"system": 1.33793156,
"min": 0.6609567099800001,
"max": 0.7966162899800001,
"times": [
0.6688808679800001,
0.6870693579800001,
0.66676653898,
0.6969803749800001,
0.69620642198,
0.6609567099800001,
0.6855568329800001,
0.7966162899800001,
0.6658203979800001,
0.6896004749800001
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.6724774491600005,
"stddev": 0.03956333236774609,
"median": 4.68496212106,
"user": 3.8113527399999994,
"system": 3.3462236999999995,
"min": 4.59077087156,
"max": 4.71043469356,
"times": [
4.71043469356,
4.70910080656,
4.61569503156,
4.6863792995599995,
4.66179173056,
4.68354494256,
4.59077087156,
4.69633957956,
4.69143706856,
4.67928046756
]
},
{
"command": "pacquet@main",
"mean": 4.6468551718599995,
"stddev": 0.030853299935692583,
"median": 4.64914286806,
"user": 3.81358294,
"system": 3.3569250000000004,
"min": 4.58990767456,
"max": 4.67899245656,
"times": [
4.65590294056,
4.67899245656,
4.60715270356,
4.58990767456,
4.67862697856,
4.63758513756,
4.63373525856,
4.64238279556,
4.677960544559999,
4.66630522856
]
},
{
"command": "pnpr@HEAD",
"mean": 3.1187446016600004,
"stddev": 0.06996725764638198,
"median": 3.10574089006,
"user": 2.76825234,
"system": 3.1338832999999995,
"min": 3.02091078756,
"max": 3.22428001156,
"times": [
3.10193772356,
3.07941519656,
3.02812628056,
3.02091078756,
3.20294579856,
3.19435038956,
3.09971731356,
3.12621845856,
3.22428001156,
3.10954405656
]
},
{
"command": "pnpr@main",
"mean": 3.1550579224599997,
"stddev": 0.14775949924596504,
"median": 3.09445597006,
"user": 2.8388866399999997,
"system": 3.1477434999999994,
"min": 3.02273214956,
"max": 3.47811664956,
"times": [
3.11632917056,
3.2503447305599997,
3.31379911956,
3.02273214956,
3.0629910745599997,
3.07258276956,
3.47811664956,
3.13939121056,
3.04349077456,
3.05080157556
]
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.3440105803000002,
"stddev": 0.018786850008775693,
"median": 1.3380032353,
"user": 1.2982669799999997,
"system": 1.7055446800000003,
"min": 1.3253399858000001,
"max": 1.3899389618,
"times": [
1.3253399858000001,
1.3372176118,
1.3570339118,
1.3451160148,
1.3502322598,
1.3300406568,
1.3387888588,
1.3313813798,
1.3350161618,
1.3899389618
]
},
{
"command": "pacquet@main",
"mean": 1.349920511,
"stddev": 0.0443911696360186,
"median": 1.3564347863,
"user": 1.2932684799999996,
"system": 1.7009421799999997,
"min": 1.2984996248,
"max": 1.4247873258000001,
"times": [
1.3543362608,
1.3585333118,
1.4247873258000001,
1.3789608298,
1.4008637868,
1.3640442438,
1.3117977488,
1.3000415328000001,
1.2984996248,
1.3073404448000001
]
},
{
"command": "pnpr@HEAD",
"mean": 1.4204269596000003,
"stddev": 0.02514597989565675,
"median": 1.4202352433,
"user": 0.5813712799999999,
"system": 1.55825668,
"min": 1.3703163178,
"max": 1.4625395308,
"times": [
1.4323304668,
1.4270509708,
1.4625395308,
1.4461999118000002,
1.4256535018,
1.4148169848,
1.4101173788,
1.4132580998000002,
1.4019864328000002,
1.3703163178
]
},
{
"command": "pnpr@main",
"mean": 1.3985037346000002,
"stddev": 0.012492898856099454,
"median": 1.4039783728000002,
"user": 0.57055698,
"system": 1.56281568,
"min": 1.3784675198,
"max": 1.4142547718,
"times": [
1.4077207198000001,
1.4064562848000002,
1.4015004608000001,
1.3838073598,
1.4142547718,
1.4077278358,
1.3860290828000001,
1.3911965978,
1.3784675198,
1.4078767128
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.9609654121799998,
"stddev": 0.03966459324196721,
"median": 2.95537129928,
"user": 1.7293486999999998,
"system": 1.9287944399999997,
"min": 2.89942724328,
"max": 3.03544369128,
"times": [
3.01167218828,
2.95550943628,
2.97718230528,
2.9514063782799997,
2.93803263028,
2.89942724328,
2.95523316228,
2.9609960312799997,
3.03544369128,
2.92475105528
]
},
{
"command": "pacquet@main",
"mean": 2.9566316653799993,
"stddev": 0.052337407950181984,
"median": 2.9425781022799997,
"user": 1.72238,
"system": 1.93696284,
"min": 2.89479380728,
"max": 3.07161930228,
"times": [
2.94858474028,
2.94280310228,
2.92517381328,
2.89479380728,
2.92165128628,
2.9565664192799996,
2.94235310228,
3.02444460028,
3.07161930228,
2.9383264802799998
]
},
{
"command": "pnpr@HEAD",
"mean": 1.39428279438,
"stddev": 0.017061632369485793,
"median": 1.3944104347800002,
"user": 0.5564697999999999,
"system": 1.60562614,
"min": 1.37002558228,
"max": 1.4212494262800002,
"times": [
1.4212494262800002,
1.40427998128,
1.3978917932800001,
1.38552600828,
1.39516062428,
1.4164843332800001,
1.38849713328,
1.37002558228,
1.37005281628,
1.3936602452800002
]
},
{
"command": "pnpr@main",
"mean": 1.40169238978,
"stddev": 0.040981738266557224,
"median": 1.38716793528,
"user": 0.5612796999999998,
"system": 1.5522235400000002,
"min": 1.37143084128,
"max": 1.5068201742800003,
"times": [
1.43303582028,
1.39293238328,
1.4031836692800002,
1.5068201742800003,
1.39078658428,
1.38049796828,
1.38354928628,
1.37866652228,
1.37143084128,
1.3760206482800001
]
}
]
} |
|
| Branch | pr/12642 |
| 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,672.48 ms(-1.99%)Baseline: 4,767.28 ms | 5,720.74 ms (81.68%) |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot 🚷 view threshold | 2,960.97 ms(-2.63%)Baseline: 3,041.08 ms | 3,649.30 ms (81.14%) |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot 🚷 view threshold | 1,344.01 ms(-0.37%)Baseline: 1,348.95 ms | 1,618.74 ms (83.03%) |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot 🚷 view threshold | 4,387.93 ms(-6.10%)Baseline: 4,672.86 ms | 5,607.43 ms (78.25%) |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot 🚷 view threshold | 619.77 ms(-1.25%)Baseline: 627.61 ms | 753.14 ms (82.29%) |
|
| Branch | pr/12642 |
| Testbed | pnpr |
⚠️ WARNING: No Threshold found!Without a Threshold, no Alerts will ever be generated.
Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the--ci-only-thresholdsflag.
Click to view all benchmark results
| Benchmark | Latency | milliseconds (ms) |
|---|---|---|
| isolated-linker.fresh-install.cold-cache.cold-store | 📈 view plot | 3,118.74 ms |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot | 1,394.28 ms |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot | 1,420.43 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot | 2,802.09 ms |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot | 683.45 ms |
The atomic temp-file-then-rename created the temp file with NamedTempFile's default 0o600 and renamed it over package.json, silently tightening the file's mode. Copy the existing file's permissions onto the temp file before persisting (as write-file-atomic does) so an existing package.json keeps its mode. Addresses the review. Co-authored-by: Claude <[email protected]>
|
Thanks @qodo — dispositions:
Written by an agent (Claude Code, claude-opus-4-8). |
Got it — thanks for the update.
If you want, I can also help draft a small bounded retry implementation for that next step. |
|
Code review by qodo was updated up to the latest commit 7b88603 |
1 similar comment
|
Code review by qodo was updated up to the latest commit 7b88603 |
Summary
PackageManifest::saverewrotepackage.jsonin place withfs::File::create(which truncates)followed by
write_all. If the process is killed (OOM, CI timeout, Ctrl-C) or the disk fillsbetween the truncate and the completed write, the file is left empty or partial and the user's
dependency declarations are lost with no recovery path. Every
pacquet add,remove,update,and
set-scriptgoes through this path.This writes the serialized manifest to a sibling temp file, fsyncs it, then renames it over the
target, so a crash or write error never leaves a truncated
package.jsonbehind. This matchesthe
write-file-atomicguarantee the TypeScript pnpm CLI relies on for manifest writes, and thesame temp-file-then-rename pattern already used by this repo's
workspace-manifest-writer,lockfile, andfscrates.tempfilewas already a dev-dependency and a workspace dependency; it is promoted to a normaldependency of
pacquet-package-manifest.Squash Commit Body
Checklist
save_leaves_the_original_intact_when_the_write_cannot_complete(Unix) asserts a failed write leaves the original
package.jsonbyte-for-byte intact.(No changeset:
pacquet-*crates arepublish = false. No pnpm-side port: this aligns pacquetwith the existing pnpm
write-file-atomicbehavior.)Written by an agent (Claude Code, claude-opus-4-8).
Summary by CodeRabbit
Bug Fixes
package.json.package.jsonremains unchanged if the save can’t complete.package.jsonfile permissions after a successful save.Tests