Skip to content

fix(package-manifest): write package.json atomically via a temp file - #12642

Merged
zkochan merged 2 commits into
pnpm:mainfrom
YESHYUNGSEOK:fix/pacquet-atomic-manifest-write
Jun 25, 2026
Merged

zkochan merged 2 commits into
pnpm:mainfrom
YESHYUNGSEOK:fix/pacquet-atomic-manifest-write

Conversation

@YESHYUNGSEOK

@YESHYUNGSEOK YESHYUNGSEOK commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

PackageManifest::save rewrote package.json in place with fs::File::create (which truncates)
followed by write_all. If the process is killed (OOM, CI timeout, Ctrl-C) or the disk fills
between 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-script goes 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.json behind. This matches
the write-file-atomic guarantee the TypeScript pnpm CLI relies on for manifest writes, and the
same temp-file-then-rename pattern already used by this repo's workspace-manifest-writer,
lockfile, and fs crates.

tempfile was already a dev-dependency and a workspace dependency; it is promoted to a normal
dependency of pacquet-package-manifest.

Squash Commit Body

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.

Checklist

  • Added or updated tests — save_leaves_the_original_intact_when_the_write_cannot_complete
    (Unix) asserts a failed write leaves the original package.json byte-for-byte intact.
  • Updated the documentation if needed — n/a.

(No changeset: pacquet-* crates are publish = false. No pnpm-side port: this aligns pacquet
with the existing pnpm write-file-atomic behavior.)


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

Summary by CodeRabbit

  • Bug Fixes

    • Improved saving of package metadata to be crash-safe, avoiding partially written or truncated package.json.
    • Ensures the existing package.json remains unchanged if the save can’t complete.
    • Preserves existing package.json file permissions after a successful save.
  • Tests

    • Added Unix-gated tests to verify failed saves don’t corrupt on-disk contents and that file permissions are retained.

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]>
@YESHYUNGSEOK
YESHYUNGSEOK requested a review from zkochan as a code owner June 25, 2026 02:28
@coderabbitai

coderabbitai Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 322892a0-de5e-4b21-b08b-22da8b901b9e

📥 Commits

Reviewing files that changed from the base of the PR and between b0bb7fd and 7b88603.

📒 Files selected for processing (2)
  • pacquet/crates/package-manifest/src/lib.rs
  • pacquet/crates/package-manifest/src/tests.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • pacquet/crates/package-manifest/src/lib.rs

📝 Walkthrough

Walkthrough

The package-manifest crate now saves package.json through a sibling temporary file and atomic persist. Unix tests check failed saves leave the existing file unchanged and successful saves preserve file permissions.

Changes

Atomic package manifest writes

Layer / File(s) Summary
Atomic write helper
pacquet/crates/package-manifest/Cargo.toml, pacquet/crates/package-manifest/src/lib.rs
Adds tempfile, imports NamedTempFile, introduces an atomic write helper, and routes manifest saving through it.
Save behavior tests
pacquet/crates/package-manifest/src/tests.rs
Adds Unix tests for a failed save that leaves the original file intact and a successful save that preserves the existing mode.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

product: pacquet

Suggested reviewers

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

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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

Copy link
Copy Markdown

PR Summary by Qodo

Write package.json atomically using temp file + rename
🐞 Bug fix 🧪 Tests ⚙️ Configuration changes 🕐 20-40 Minutes

Grey Divider

Description

• Prevent data loss by switching manifest writes to temp-file + fsync + rename.
• Add a Unix regression test ensuring failed writes never truncate package.json.
• Promote tempfile to a runtime dependency for atomic manifest persistence.
Diagram

graph TD
  A["CLI ops (add/remove/update)"] --> B["PackageManifest::save"] --> C["write_atomic()"] --> D[("sibling temp file")] --> E["fsync temp"] --> F["rename over target"] --> G[("package.json")]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Centralize atomic-write helper in a shared crate
  • ➕ Avoids duplicating subtle file-safety logic across crates
  • ➕ Enables consistent durability policy (e.g., optional directory fsync)
  • ➖ Requires API design and refactor across current call sites
  • ➖ May be overkill if only a few writers need it
2. Also fsync the parent directory after rename
  • ➕ Stronger durability guarantee on crash/power loss (directory entry persisted)
  • ➖ Extra syscall cost; platform/filesystem semantics vary
  • ➖ May be beyond the intended guarantee (avoid truncation on failed write)

Recommendation: The temp-file-then-rename approach is the right fix to prevent truncation/data loss and matches patterns already used in the repo. Consider a follow-up to either (a) share an atomic-write utility across crates or (b) optionally fsync the parent directory if the project wants stronger durability guarantees than “never leave a truncated file behind”.

Files changed (3) +44 / -2

Bug fix (1) +18 / -2
lib.rsAtomically persist package.json via temp file + fsync + rename +18/-2

Atomically persist package.json via temp file + fsync + rename

• Introduces 'write_atomic()' using 'NamedTempFile::new_in', 'sync_all()', and 'persist()' to avoid in-place truncation. Updates 'save_and_get_written_value()' to use the atomic writer instead of 'File::create' + 'write_all'.

pacquet/crates/package-manifest/src/lib.rs

Tests (1) +25 / -0
tests.rsAdd regression test ensuring failed save does not truncate package.json +25/-0

Add regression test ensuring failed save does not truncate package.json

• Adds a Unix-only test that makes the directory read-only to force the atomic-write path to fail early, then asserts the original 'package.json' remains byte-for-byte unchanged.

pacquet/crates/package-manifest/src/tests.rs

Other (1) +1 / -0
Cargo.tomlPromote 'tempfile' to a normal dependency +1/-0

Promote 'tempfile' to a normal dependency

• Moves 'tempfile' from dev-only usage to a runtime dependency so production code can create sibling temp files for atomic manifest writes.

pacquet/crates/package-manifest/Cargo.toml

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

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

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Remediation recommended

1. Chmod not covered by fsync 🐞 Bug ☼ Reliability
Description
PackageManifest::write_atomic calls sync_all() before copying the destination file’s permissions
onto the temp file, so the fsync does not include the later chmod. On host crash/power loss
boundaries this can make the permission-preservation behavior non-durable (the new file may come
back with the temp file’s default mode instead of the intended preserved mode).
Code

pacquet/crates/package-manifest/src/lib.rs[R109-117]

+        let mut tmp = NamedTempFile::new_in(dir)?;
+        tmp.write_all(contents.as_bytes())?;
+        tmp.as_file().sync_all()?;
+        // A NamedTempFile is created 0o600; preserve the original file's mode
+        // when overwriting an existing package.json (write-file-atomic does the
+        // same) so the rename doesn't silently tighten its permissions.
+        if let Ok(metadata) = fs::metadata(path) {
+            tmp.as_file().set_permissions(metadata.permissions())?;
+        }
Evidence
In write_atomic, sync_all() is called before set_permissions(), so the chmod occurs after the
only explicit durability barrier. The repo’s other atomic-write helper explicitly discusses
permissions/atomicity and when fsync is (or isn’t) done, reinforcing that ordering matters for
what’s actually made durable.

pacquet/crates/package-manifest/src/lib.rs[100-119]
pacquet/crates/patching/src/apply.rs[309-327]

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

## Issue description
`PackageManifest::write_atomic` calls `sync_all()` before `set_permissions()`, so the fsync does not cover the permission change. This makes the “preserve existing mode” behavior potentially non-durable across host crash/power loss boundaries.
### Issue Context
The function is intentionally doing: write temp → fsync → rename-over-destination, and now also copies the destination’s mode to the temp file. With the current call order, content is synced but the chmod is not.
### Fix Focus Areas
- pacquet/crates/package-manifest/src/lib.rs[100-120]
### Suggested fix
Reorder operations so the permission change is included in the sync:
- write temp
- (if destination exists) apply `set_permissions(...)` to the temp file
- `sync_all()`
- `persist()`
(Alternative: keep the existing order but add a second `sync_all()` after `set_permissions()` and before `persist()`, though reordering avoids an extra fsync.)

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


2. Symlink-following permission copy 🐞 Bug ⛨ Security
Description
PackageManifest::write_atomic uses fs::metadata(path) to copy permissions, which follows
symlinks; if package.json is a symlink, the newly-written *regular file* can inherit the symlink
target’s mode rather than the existing directory entry’s intent. This can unexpectedly
loosen/tighten package.json permissions (e.g., becoming world-writable) despite the atomic-write
approach otherwise being designed to overwrite symlinks without following them.
Code

pacquet/crates/package-manifest/src/lib.rs[R112-117]

+        // A NamedTempFile is created 0o600; preserve the original file's mode
+        // when overwriting an existing package.json (write-file-atomic does the
+        // same) so the rename doesn't silently tighten its permissions.
+        if let Ok(metadata) = fs::metadata(path) {
+            tmp.as_file().set_permissions(metadata.permissions())?;
+        }
Evidence
The new code path explicitly uses fs::metadata (symlink-following) to derive permissions, while
other atomic-write implementations in-repo rely on rename to overwrite symlinks without following
them; this makes permission derivation inconsistent specifically when the destination is a symlink.

pacquet/crates/package-manifest/src/lib.rs[100-119]
pacquet/crates/workspace-manifest-writer/src/lib.rs[229-245]
pacquet/crates/workspace-state/src/lib.rs[173-182]
pacquet/crates/patching/src/apply.rs[309-327]

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

## Issue description
`write_atomic` preserves permissions by calling `fs::metadata(path)`, which follows symlinks. If `package.json` is a symlink, this copies the *target’s* permissions onto the replacement file, which is inconsistent with the intended “rename overwrites symlink” safety property and can yield surprising/unsafe modes.
### Issue Context
Other atomic-write code in this repo explicitly documents not following symlinks via rename-overwrite semantics.
### Fix Focus Areas
- pacquet/crates/package-manifest/src/lib.rs[104-119]
### Suggested change
- Use `fs::symlink_metadata(path)` (not `metadata`) and only copy permissions when the existing path is a regular file (e.g., `meta.file_type().is_file()`), skipping permission copying when it is a symlink.
- Keep the current behavior for normal (non-symlink) `package.json` so existing modes are preserved.

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


3. Hardcoded chmod restore mode 🐞 Bug ☼ Reliability
Description
The new Unix-only test restores the temp directory permissions to a hard-coded 0o755 instead of
restoring the original mode, which can make the test environment-dependent and interfere with
TempDir cleanup assumptions. Capture and restore the directory’s original permissions (and
optionally assert the directory is actually non-writable after chmod) to avoid flakiness.
Code

pacquet/crates/package-manifest/src/tests.rs[R34-37]

+    std::fs::set_permissions(dir.path(), std::fs::Permissions::from_mode(0o555)).unwrap();
+    let result = manifest.save();
+    // Restore permissions before the assertions so tempdir cleanup succeeds.
+    std::fs::set_permissions(dir.path(), std::fs::Permissions::from_mode(0o755)).unwrap();
Evidence
The new test hardcodes restoring the tempdir mode to 0o755, while other permission-based tests in
the repo capture and restore the original mode to keep the test and TempDir cleanup stable across
environments.

pacquet/crates/package-manifest/src/tests.rs[18-41]
pacquet/crates/resolving-npm-resolver/src/fetch_full_metadata_cached/tests.rs[307-330]
pacquet/crates/patching/src/apply/tests.rs[545-554]

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

## Issue description
The new test `save_leaves_the_original_intact_when_the_write_cannot_complete` changes the temp directory permissions to `0o555` and then restores them to a hard-coded `0o755`. This is brittle because the original tempdir mode is not guaranteed to be `0o755` (commonly it’s `0o700`), and hardcoding can make cleanup or future test expectations environment-dependent.
## Issue Context
Other tests in this repo that temporarily chmod a TempDir capture the original `mode()` and restore it afterward.
## Fix Focus Areas
- pacquet/crates/package-manifest/src/tests.rs[18-41]
## Suggested fix
- Before setting `0o555`, capture the original permissions mode (e.g. `let mode = dir.path().metadata()?.permissions().mode();`).
- Restore using that captured `mode` rather than `0o755`.
- (Optional but recommended) After chmod to `0o555`, assert the directory is not writable for the current process by attempting to create a probe file and asserting `PermissionDenied`; this makes failures deterministic if the chmod doesn’t take effect in the current environment.

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


View more (2)
4. Manifest perms not preserved ✓ Resolved 🐞 Bug ⛨ Security
Description
PackageManifest::write_atomic swaps in a freshly-created temp file without copying the existing
package.json permissions/metadata, so a save can unexpectedly change the file’s mode/ACLs and can
bypass a read-only target file (rename depends on directory permissions, not opening the target for
write). This can break environments that rely on package.json being group-readable or intentionally
immutable.
Code

pacquet/crates/package-manifest/src/lib.rs[R104-113]

+    fn write_atomic(path: &Path, contents: &str) -> io::Result<()> {
+        let dir = path
+            .parent()
+            .filter(|parent| !parent.as_os_str().is_empty())
+            .unwrap_or_else(|| Path::new("."));
+        let mut tmp = NamedTempFile::new_in(dir)?;
+        tmp.write_all(contents.as_bytes())?;
+        tmp.as_file().sync_all()?;
+        tmp.persist(path).map_err(|err| err.error)?;
+        Ok(())
Evidence
The new atomic write path writes and persists a new file over the target without inspecting or
reapplying the target file’s permissions/metadata. Other repo atomic writers document and implement
permission application before rename to keep the final file mode correct atomically, indicating this
is an established concern in this codebase.

pacquet/crates/package-manifest/src/lib.rs[100-113]
pacquet/crates/patching/src/apply.rs[309-327]

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

## Issue description
`PackageManifest::write_atomic` stages content in a new temp file and renames it over `package.json`, but never reads/apply the original file’s permissions (and potentially other metadata). This can change the resulting on-disk mode (and can also defeat a “read-only file” policy where the directory remains writable).
### Issue Context
The repo already has atomic-write code paths that explicitly apply permissions before rename to ensure the final file has the intended mode atomically.
### Fix Focus Areas
- pacquet/crates/package-manifest/src/lib.rs[100-114]
### Suggested fix
1. If `path` exists, read its metadata (`fs::metadata(path)` or `symlink_metadata` depending on desired semantics) and capture `Permissions`.
2. After writing the temp file (and before `persist`), apply the captured permissions to the temp file (e.g., `fs::set_permissions(tmp.path(), perms)`), so the final renamed file preserves the prior mode.
3. (Optional, but addresses the ‘read-only target’ behavioral change) If the existing `package.json` is not writable by the current user, consider returning `PermissionDenied` early to match the expectation that a read-only manifest cannot be modified.

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


5. No Windows rename retry 🐞 Bug ☼ Reliability
Description
write_atomic relies on a single persist/rename attempt; on Windows, renames can fail transiently
(e.g., antivirus/indexers briefly holding the destination), and this path will surface that failure
immediately. The repo already hardens this exact case with a rename retry helper elsewhere, but
PackageManifest::write_atomic does not use it, so package.json saves may be less robust on affected
Windows environments.
Code

pacquet/crates/package-manifest/src/lib.rs[R109-113]

+        let mut tmp = NamedTempFile::new_in(dir)?;
+        tmp.write_all(contents.as_bytes())?;
+        tmp.as_file().sync_all()?;
+        tmp.persist(path).map_err(|err| err.error)?;
+        Ok(())
Evidence
The repo explicitly implements and documents retry logic for Windows transient rename failures in
pacquet_fs::ensure_file, while the new PackageManifest::write_atomic does not include any
analogous retry around its rename/persist step.

pacquet/crates/package-manifest/src/lib.rs[104-113]
pacquet/crates/fs/src/ensure_file.rs[452-470]

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

## Issue description
`PackageManifest::write_atomic` uses `NamedTempFile::persist` (rename-overwrite) without retry/backoff. The repo already has a Windows-specific retry strategy for transient rename failures (Defender/indexers causing `PermissionDenied`/`ResourceBusy`). Not reusing that logic can make Windows manifest writes less reliable in the field.
### Issue Context
`pacquet_fs::ensure_file` contains `rename_with_retry` and documents why it exists for Windows.
### Fix Focus Areas
- pacquet/crates/package-manifest/src/lib.rs[100-114]
- pacquet/crates/fs/src/ensure_file.rs[452-490]
### Suggested fix
Refactor `PackageManifest::write_atomic` to avoid `NamedTempFile::persist` and instead:
1. Create a sibling temp path (unique name), write contents, `sync_all`, and close the handle.
2. Perform the final rename using the same retry/backoff logic as `pacquet_fs::ensure_file::rename_with_retry` (or extract a shared helper usable by both crates).
3. Keep best-effort temp cleanup on rename failure to avoid leaving stray temp files.

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


Grey Divider

Qodo Logo

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

Copy link
Copy Markdown

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

@codecov-commenter

codecov-commenter commented Jun 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 88.58%. Comparing base (8fec992) to head (7b88603).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pacquet/crates/package-manifest/src/lib.rs 93.33% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: 7b88603e4ed0

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

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.388 ± 0.158 4.229 4.723 1.57 ± 0.08
pacquet@main 4.327 ± 0.085 4.230 4.550 1.54 ± 0.06
pnpr@HEAD 2.802 ± 0.096 2.723 3.042 1.00
pnpr@main 2.955 ± 0.154 2.806 3.192 1.05 ± 0.07
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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 619.8 ± 9.0 609.7 638.5 1.00
pacquet@main 629.4 ± 11.0 614.8 652.6 1.02 ± 0.02
pnpr@HEAD 683.5 ± 32.2 655.4 763.2 1.10 ± 0.05
pnpr@main 691.4 ± 39.3 661.0 796.6 1.12 ± 0.07
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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.672 ± 0.040 4.591 4.710 1.50 ± 0.04
pacquet@main 4.647 ± 0.031 4.590 4.679 1.49 ± 0.03
pnpr@HEAD 3.119 ± 0.070 3.021 3.224 1.00
pnpr@main 3.155 ± 0.148 3.023 3.478 1.01 ± 0.05
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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.344 ± 0.019 1.325 1.390 1.00
pacquet@main 1.350 ± 0.044 1.298 1.425 1.00 ± 0.04
pnpr@HEAD 1.420 ± 0.025 1.370 1.463 1.06 ± 0.02
pnpr@main 1.399 ± 0.012 1.378 1.414 1.04 ± 0.02
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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.961 ± 0.040 2.899 3.035 2.12 ± 0.04
pacquet@main 2.957 ± 0.052 2.895 3.072 2.12 ± 0.05
pnpr@HEAD 1.394 ± 0.017 1.370 1.421 1.00
pnpr@main 1.402 ± 0.041 1.371 1.507 1.01 ± 0.03
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
      ]
    }
  ]
}

@github-actions

github-actions Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchpr/12642
Testbedpacquet
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
milliseconds (ms)
(Result Δ%)
Upper Boundary
milliseconds (ms)
(Limit %)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
🚷 view threshold
4,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%)
🐰 View full continuous benchmarking report in Bencher

@github-actions

github-actions Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchpr/12642
Testbedpnpr

⚠️ WARNING: No Threshold found!

Without a Threshold, no Alerts will ever be generated.

Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the --ci-only-thresholds flag.

Click to view all benchmark results
BenchmarkLatencymilliseconds (ms)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
3,118.74 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
1,394.28 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
1,420.43 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
2,802.09 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
683.45 ms
🐰 View full continuous benchmarking report in Bencher

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]>
@YESHYUNGSEOK

Copy link
Copy Markdown
Contributor Author

Thanks @qodo — dispositions:

  • Manifest perms not preserved ✅ Fixed in 7b88603 — write_atomic now copies the existing package.json mode onto the temp file before persist (NamedTempFile defaults to 0o600), with a Unix test save_preserves_the_existing_package_json_permissions.
  • No Windows rename retry: acknowledged — tempfile::persist doesn't retry on a transient Windows EBUSY (AV/indexer holding the handle) the way write-file-atomic does. A small bounded retry loop is a reasonable follow-up; it's a low-frequency edge and I'd rather land the atomicity + perms fix first.

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

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

Copy link
Copy Markdown

Thanks @qodo — dispositions:

  • Manifest perms not preserved ✅ Fixed in 7b88603 — write_atomic now copies the existing package.json mode onto the temp file before persist (NamedTempFile defaults to 0o600), with a Unix test save_preserves_the_existing_package_json_permissions.
  • No Windows rename retry: acknowledged — tempfile::persist doesn't retry on a transient Windows EBUSY (AV/indexer holding the handle) the way write-file-atomic does. A small bounded retry loop is a reasonable follow-up; it's a low-frequency edge and I'd rather land the atomicity + perms fix first.

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

Got it — thanks for the update.

  • write_atomic now preserves the existing package.json mode and the Unix test covers it.
  • The Windows EBUSY retry gap is acknowledged and can be tracked as a follow-up.

If you want, I can also help draft a small bounded retry implementation for that next step.

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

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 7b88603

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

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 7b88603

@zkochan
zkochan merged commit dd8ea85 into pnpm:main Jun 25, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: pacquet reviewed: coderabbit CodeRabbit submitted an approving review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants