Skip to content

fix(fs): register the atomic-write temp file before creating it - #15593

Merged
zkochan merged 1 commit into
mainfrom
fix/pending-temp-register-before-create
Sep 24, 2026
Merged

zkochan merged 1 commit into
mainfrom
fix/pending-temp-register-before-create

Conversation

@zkochan

@zkochan zkochan commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-up to #15486, carrying two fixes from its last review round that were ready after it merged.

  • pnpm_fs::write_atomic let NamedTempFile choose the random name while creating the file, so the temp file could only be registered with the interrupt cleanup after it existed. An interrupt in that gap left it behind. It now uses tempfile::Builder::make_in, whose closure receives the chosen name before the file exists. The closure registers the name, then creates the file with create_new and mode 0600, the mode NamedTempFile used. The cross-process test now interrupts as soon as the temp file exists, instead of waiting for content. It cannot pin down the order of registration and create, since the child is polled from another process, so the ordering itself rests on the code in write_tmp_over.
  • The lockfile cleanup test wrote a 256 MiB payload. It now writes 64 MiB and allows ten attempts to catch a save in flight.

This affects only the Rust CLI. The TypeScript writer already registers its exit callback before fs.open(tempPath, 'wx'). There is no changeset, because the cleanup from #15486 has not been released yet.

Squash Commit Body

write_atomic let NamedTempFile pick the random name while creating the
file, so the registration could only follow the create and an interrupt
in between left the temp file behind. tempfile's Builder::make_in hands
the chosen name to a closure, which now registers it and then creates
the file exclusively with mode 0600, as NamedTempFile did. A colliding
name is retried under a new one, whose registration replaces the old.
The cross-process test now interrupts as soon as the temp file exists,
instead of waiting for content.

Also shrink the lockfile cleanup test's payload from 256 MiB to 64 MiB
and allow it ten attempts to catch a save in flight.

Follow-up to pnpm/pnpm#15486.

Checklist

  • New features are implemented only in the Rust pnpm v12 CLI. Bug fixes
    are implemented in every affected version.
  • Added or updated tests.

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

🤖 Generated with Claude Code

write_atomic let NamedTempFile pick the random name while creating the
file, so the registration could only follow the create and an interrupt
in between left the temp file behind. tempfile's Builder::make_in hands
the chosen name to a closure, which now registers it and then creates
the file exclusively with mode 0600, as NamedTempFile did. The
cross-process test now interrupts as soon as the temp file exists,
which covers that earliest window.

Also shrink the lockfile cleanup test's payload to 64 MiB and allow it
ten attempts to catch a save in flight.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 1 minute.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository: pnpm/pnpm/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: cc87412e-721a-47a9-aee4-33b6b130ad56

📥 Commits

Reviewing files that changed from the base of the PR and between 43fe371 and 46d3ba4.

📒 Files selected for processing (3)
  • pnpm/crates/fs/src/write_atomic.rs
  • pnpm/crates/fs/tests/atomic_write_holder.rs
  • pnpm/crates/lockfile/src/save_lockfile/tests.rs

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.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.82%. Comparing base (84f8d69) to head (46d3ba4).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main   #15593    +/-   ##
========================================
  Coverage   91.81%   91.82%            
========================================
  Files        1435     1438     +3     
  Lines      193989   194154   +165     
========================================
+ Hits       178111   178281   +170     
+ Misses      15878    15873     -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.

@github-actions

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                                            main                                   pr
-----                                            ----                                   --
lockfile/parse_pnpm_lock                         1.04     16.6±1.90ms    22.6 MB/sec    1.00     15.9±1.99ms    23.6 MB/sec
packument/parse                                  1.02     45.3±1.84µs  1463.5 MB/sec    1.00     44.5±2.37µs  1490.1 MB/sec
tarball/download_dependency                      1.00      5.7±0.84ms   761.2 KB/sec    1.03      5.9±0.86ms   741.5 KB/sec
tarball_batch/cold_store_many_medium_tarballs    1.07   287.6±21.00ms 55.6 KElem/sec    1.00   269.2±15.11ms 59.4 KElem/sec
workspace_resolution/hoist_heavy                 1.00   305.4±20.02ms        ? ?/sec    1.03   314.5±18.12ms        ? ?/sec
workspace_sort/chained_projects                  1.23     19.4±3.81ms        ? ?/sec    1.00     15.7±2.86ms        ? ?/sec

@github-actions

Copy link
Copy Markdown
Contributor

Same-run regression check

HEAD and main are measured on the same runner. The tolerance is 5% of the main median or 2 ms, whichever is larger. A regression requires both the median slowdown and the gap between the fastest retained HEAD sample and slowest retained main sample to exceed this tolerance, after trimming up to 10% from each tail. Suspected regressions are rerun once with target order reversed and only fail if reproduced. This conservative noise guard is not a statistical confidence interval.

Inconclusive rows do not fail the check. They remain visible for performance review. Bencher retains absolute minimum timings for historical tracking; historical alerts do not gate this PR. Sequential measurements can still be affected by runner drift.

Scenario Engine main median HEAD median Change Tolerance Result
isolated-fresh-restore-cold-cache-cold-store pacquet 2363.72 ms 2602.82 ms 10.1% 118.19 ms Inconclusive (overlapping samples)
isolated-fresh-restore-cold-cache-cold-store pnpr 1545.11 ms 1428.68 ms -7.5% 77.26 ms Within tolerance
isolated-fresh-restore-hot-cache-hot-store pacquet 323.28 ms 316.69 ms -2.0% 16.16 ms Within tolerance
isolated-fresh-restore-hot-cache-hot-store pnpr 296.68 ms 369.31 ms 24.5% 14.83 ms Inconclusive (overlapping samples)
isolated-repeat-install-hot-cache-hot-store pacquet 10.56 ms 9.86 ms -6.7% 2.00 ms Within tolerance
isolated-repeat-install-hot-cache-hot-store pnpr 11.22 ms 10.94 ms -2.5% 2.00 ms Within tolerance
isolated-repeat-install-cold-cache-hot-store pacquet 15.64 ms 14.97 ms -4.3% 2.00 ms Within tolerance
isolated-repeat-install-cold-cache-hot-store pnpr 11.06 ms 17.54 ms 58.6% 2.00 ms Inconclusive (overlapping samples)
isolated-fresh-install-cold-cache-cold-store pacquet 3266.50 ms 3423.98 ms 4.8% 163.33 ms Within tolerance
isolated-fresh-install-cold-cache-cold-store pnpr 1698.83 ms 1959.93 ms 15.4% 84.94 ms Inconclusive (overlapping samples)
isolated-fresh-install-hot-cache-hot-store pacquet 683.35 ms 648.49 ms -5.1% 34.17 ms Within tolerance
isolated-fresh-install-hot-cache-hot-store pnpr 493.95 ms 488.50 ms -1.1% 24.70 ms Within tolerance
isolated-fresh-install-cold-cache-hot-store pacquet 1926.65 ms 1813.50 ms -5.9% 96.33 ms Within tolerance
isolated-fresh-install-cold-cache-hot-store pnpr 368.26 ms 447.53 ms 21.5% 18.41 ms Inconclusive (overlapping samples)
isolated-fresh-resolve-hot-cache-offline pacquet 230.09 ms 238.94 ms 3.8% 11.50 ms Within tolerance
isolated-fresh-resolve-hot-cache-offline pnpr 95.92 ms 97.78 ms 1.9% 4.80 ms Within tolerance
isolated-peer-heavy-resolve-hot-cache-offline pacquet 960.88 ms 1023.16 ms 6.5% 48.04 ms Inconclusive (overlapping samples)
isolated-linked-workspace-resolve-hot-cache-offline pacquet 335.23 ms 276.55 ms -17.5% 16.76 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store-cold-pnpr pacquet 4631.90 ms 4618.93 ms -0.3% 231.59 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store-cold-pnpr pnpr 3802.92 ms 3625.34 ms -4.7% 190.15 ms Within tolerance
gvs-fresh-restore-hot-cache-hot-store pacquet 147.77 ms 130.92 ms -11.4% 7.39 ms Within tolerance
gvs-fresh-restore-hot-cache-hot-store pnpr 143.88 ms 144.39 ms 0.4% 7.19 ms Within tolerance

Integrated-Benchmark Report (Linux)

Commit: 46d3ba40ee47

Regular scenarios report direct and pnpr installs. The peer-heavy resolver scenario compares current Rust, main Rust, and TypeScript pnpm; the linked-workspace scenario compares current Rust against main Rust. Bencher consumes pacquet@HEAD and pnpr@HEAD.

The tables below show mean ± σ. Bencher tracks absolute minimum latency; PR regression checks compare HEAD and main samples from the same runner. Historical timing alerts do not gate PRs.

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.628 ± 0.193 2.391 2.935 1.80 ± 0.20
pacquet@main 2.370 ± 0.036 2.323 2.422 1.62 ± 0.14
pnpr@HEAD 1.461 ± 0.125 1.308 1.692 1.00
pnpr@main 1.551 ± 0.103 1.420 1.697 1.06 ± 0.12
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.6279196479599998,
      "stddev": 0.19281039094711755,
      "median": 2.6028151696600004,
      "user": 2.25027316,
      "system": 2.0832032,
      "min": 2.39149046516,
      "max": 2.93492286816
    },
    {
      "command": "pacquet@main",
      "mean": 2.37047850866,
      "stddev": 0.03556638136489856,
      "median": 2.36371902566,
      "user": 1.63697326,
      "system": 1.5091146,
      "min": 2.3234607881600002,
      "max": 2.4220327361600003
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.4607546330599999,
      "stddev": 0.12500417313619222,
      "median": 1.42868181716,
      "user": 1.50524616,
      "system": 1.4817500999999997,
      "min": 1.30765165816,
      "max": 1.69214662816
    },
    {
      "command": "pnpr@main",
      "mean": 1.5508946681599998,
      "stddev": 0.1029931671396743,
      "median": 1.5451103856600001,
      "user": 1.6422874599999997,
      "system": 1.6319861,
      "min": 1.42037632116,
      "max": 1.69740633816
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 325.3 ± 23.3 300.4 370.3 1.03 ± 0.10
pacquet@main 316.1 ± 22.0 284.9 351.7 1.00
pnpr@HEAD 371.7 ± 25.9 335.5 421.6 1.18 ± 0.12
pnpr@main 323.4 ± 59.9 271.1 465.1 1.02 ± 0.20
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.32528667908000003,
      "stddev": 0.0233345095509245,
      "median": 0.31669183428000003,
      "user": 0.36200953999999996,
      "system": 0.7085004199999999,
      "min": 0.30044550128,
      "max": 0.37031615828000003
    },
    {
      "command": "pacquet@main",
      "mean": 0.31612117677999996,
      "stddev": 0.021981348937095798,
      "median": 0.32328388078000003,
      "user": 0.35292594,
      "system": 0.7019841199999999,
      "min": 0.28487334428,
      "max": 0.35169509728000004
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.37165251628000007,
      "stddev": 0.025923210084172737,
      "median": 0.36931280628,
      "user": 0.38990823999999996,
      "system": 0.75046112,
      "min": 0.33545204928,
      "max": 0.42157192928000004
    },
    {
      "command": "pnpr@main",
      "mean": 0.32341694748,
      "stddev": 0.0598647494194494,
      "median": 0.29667756878,
      "user": 0.35085544,
      "system": 0.68089912,
      "min": 0.27110571328,
      "max": 0.46506084128
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 9.9 ± 1.0 7.0 13.1 1.00
pacquet@main 10.8 ± 1.5 8.3 20.6 1.09 ± 0.19
pnpr@HEAD 11.4 ± 2.5 7.5 23.9 1.15 ± 0.27
pnpr@main 12.0 ± 2.4 9.2 23.7 1.21 ± 0.27
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.009897507742857149,
      "stddev": 0.0009799815734284367,
      "median": 0.009858062099999999,
      "user": 0.005792350634920632,
      "system": 0.004662574444444443,
      "min": 0.0070373461,
      "max": 0.0130905031
    },
    {
      "command": "pacquet@main",
      "mean": 0.010772367074264695,
      "stddev": 0.0015009907502099348,
      "median": 0.010560956600000001,
      "user": 0.006233694044117646,
      "system": 0.005161796249999999,
      "min": 0.0082880131,
      "max": 0.0205551391
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.011424450046666665,
      "stddev": 0.0024559163910430333,
      "median": 0.0109391696,
      "user": 0.006941146666666665,
      "system": 0.005117616133333335,
      "min": 0.0075226711,
      "max": 0.0239180971
    },
    {
      "command": "pnpr@main",
      "mean": 0.01199828980081967,
      "stddev": 0.0024261521259482575,
      "median": 0.0112242321,
      "user": 0.006899692295081964,
      "system": 0.005692963032786888,
      "min": 0.0092431631,
      "max": 0.0236908291
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 15.5 ± 2.7 11.1 21.3 1.33 ± 0.34
pacquet@main 15.5 ± 2.8 9.5 21.0 1.33 ± 0.34
pnpr@HEAD 19.0 ± 6.9 10.0 50.4 1.63 ± 0.67
pnpr@main 11.6 ± 2.2 8.7 18.9 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.015476271458644067,
      "stddev": 0.002735568906436452,
      "median": 0.01497229034,
      "user": 0.007588056949152541,
      "system": 0.008759813220338983,
      "min": 0.011079265840000001,
      "max": 0.02134995384
    },
    {
      "command": "pacquet@main",
      "mean": 0.015496067763611118,
      "stddev": 0.0027896904632305256,
      "median": 0.01563847634,
      "user": 0.007825671944444449,
      "system": 0.008547144444444443,
      "min": 0.00948405884,
      "max": 0.02102665184
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.018980842620487808,
      "stddev": 0.006945342535718754,
      "median": 0.01754308534,
      "user": 0.010018155609756106,
      "system": 0.009879990975609753,
      "min": 0.010017342840000002,
      "max": 0.050395905840000005
    },
    {
      "command": "pnpr@main",
      "mean": 0.011625762387263686,
      "stddev": 0.0021522562258200254,
      "median": 0.01106318484,
      "user": 0.006424800796019896,
      "system": 0.005977880597014925,
      "min": 0.00867501684,
      "max": 0.01885299284
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 3.463 ± 0.230 3.133 3.807 2.00 ± 0.19
pacquet@main 3.277 ± 0.072 3.182 3.404 1.89 ± 0.14
pnpr@HEAD 1.940 ± 0.120 1.708 2.100 1.12 ± 0.10
pnpr@main 1.734 ± 0.120 1.589 1.975 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 3.4630367529400004,
      "stddev": 0.22955383123379575,
      "median": 3.42397774974,
      "user": 3.83160502,
      "system": 2.82876604,
      "min": 3.1327836177400004,
      "max": 3.80690949974
    },
    {
      "command": "pacquet@main",
      "mean": 3.27734303584,
      "stddev": 0.07167325527875835,
      "median": 3.26650250474,
      "user": 3.6255271199999997,
      "system": 2.75666704,
      "min": 3.18182022474,
      "max": 3.4036024187400002
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.9404659591400002,
      "stddev": 0.11960880821262666,
      "median": 1.9599302837400001,
      "user": 2.0926290199999995,
      "system": 2.17976144,
      "min": 1.7075027217399998,
      "max": 2.1002670837400004
    },
    {
      "command": "pnpr@main",
      "mean": 1.7336069590399998,
      "stddev": 0.1203007273980838,
      "median": 1.69883229874,
      "user": 1.9807507199999996,
      "system": 2.00042564,
      "min": 1.58899421474,
      "max": 1.9751190937399998
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 646.0 ± 72.1 515.5 787.8 1.29 ± 0.20
pacquet@main 673.4 ± 92.8 547.1 862.4 1.35 ± 0.24
pnpr@HEAD 499.8 ± 54.4 410.8 584.1 1.00
pnpr@main 503.7 ± 34.0 472.8 585.6 1.01 ± 0.13
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.64600487434,
      "stddev": 0.07207157031419552,
      "median": 0.6484910042400001,
      "user": 0.9392749199999999,
      "system": 0.93315126,
      "min": 0.51546425224,
      "max": 0.7877655292400001
    },
    {
      "command": "pacquet@main",
      "mean": 0.67341119934,
      "stddev": 0.09280178359150315,
      "median": 0.68335410974,
      "user": 0.9994037199999999,
      "system": 0.97526896,
      "min": 0.5470693752400001,
      "max": 0.8624092212400001
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.49976985764000015,
      "stddev": 0.05439199117413661,
      "median": 0.48850449774000004,
      "user": 0.4554609199999999,
      "system": 0.78400896,
      "min": 0.41084753924000006,
      "max": 0.58410628224
    },
    {
      "command": "pnpr@main",
      "mean": 0.50367477114,
      "stddev": 0.0340338418440445,
      "median": 0.4939471712400001,
      "user": 0.46450401999999996,
      "system": 0.7858983599999999,
      "min": 0.4727706802400001,
      "max": 0.58558722324
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.831 ± 0.112 1.698 2.097 5.06 ± 0.65
pacquet@main 1.948 ± 0.086 1.823 2.101 5.39 ± 0.65
pnpr@HEAD 0.426 ± 0.060 0.336 0.493 1.18 ± 0.21
pnpr@main 0.362 ± 0.041 0.299 0.433 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.8314845891999998,
      "stddev": 0.11231504981993724,
      "median": 1.8134950699999999,
      "user": 1.2742767,
      "system": 1.0523540799999997,
      "min": 1.6976471245,
      "max": 2.0972168225
    },
    {
      "command": "pacquet@main",
      "mean": 1.9482518495999996,
      "stddev": 0.08572463082213293,
      "median": 1.926650106,
      "user": 1.5028551999999997,
      "system": 1.1244656799999997,
      "min": 1.8230519985,
      "max": 2.1010263824999997
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.4255005691,
      "stddev": 0.0597102671764733,
      "median": 0.447526458,
      "user": 0.36117889999999997,
      "system": 0.71977778,
      "min": 0.3358842375,
      "max": 0.4932188325
    },
    {
      "command": "pnpr@main",
      "mean": 0.3617073902,
      "stddev": 0.040628887467973655,
      "median": 0.3682611265,
      "user": 0.31254339999999997,
      "system": 0.6504394800000001,
      "min": 0.2987775795,
      "max": 0.4325771925
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 246.6 ± 20.7 225.4 287.3 2.58 ± 0.24
pacquet@main 237.5 ± 24.4 212.5 301.3 2.48 ± 0.27
pnpr@HEAD 100.9 ± 7.3 92.9 118.1 1.05 ± 0.09
pnpr@main 95.7 ± 3.4 89.3 105.4 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.24659957761666665,
      "stddev": 0.020743516502379027,
      "median": 0.23893658620000002,
      "user": 0.26195508666666667,
      "system": 0.08352183333333331,
      "min": 0.2253711952,
      "max": 0.28729231920000003
    },
    {
      "command": "pacquet@main",
      "mean": 0.23751876096923083,
      "stddev": 0.02438889646095837,
      "median": 0.2300867262,
      "user": 0.2476151123076923,
      "system": 0.07471611538461537,
      "min": 0.21248030220000003,
      "max": 0.3012955842
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.10087646576666667,
      "stddev": 0.007320090511154137,
      "median": 0.0977849107,
      "user": 0.040970653333333336,
      "system": 0.017646366666666666,
      "min": 0.09289324820000001,
      "max": 0.1181424902
    },
    {
      "command": "pnpr@main",
      "mean": 0.09566691842222222,
      "stddev": 0.0034367589651631693,
      "median": 0.09591849020000001,
      "user": 0.03404986444444445,
      "system": 0.0164902037037037,
      "min": 0.08929290520000001,
      "max": 0.1053593002
    }
  ]
}

Scenario: Isolated linker: peer-heavy resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 985.5 ± 144.6 718.8 1198.3 1.04 ± 0.25
pacquet@main 946.6 ± 176.0 602.7 1162.4 1.00
pnpm@HEAD 4693.2 ± 608.2 3860.5 5710.5 4.96 ± 1.12
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.985526849748889,
      "stddev": 0.14456974184613,
      "median": 1.02316152286,
      "user": 1.000816624444444,
      "system": 0.2912160244444444,
      "min": 0.7187743508600001,
      "max": 1.19827278386
    },
    {
      "command": "pacquet@main",
      "mean": 0.9465724175266668,
      "stddev": 0.17602727367359638,
      "median": 0.9608770308600001,
      "user": 0.9401688466666668,
      "system": 0.26844357999999996,
      "min": 0.60274878486,
      "max": 1.1623506488600002
    },
    {
      "command": "pnpm@HEAD",
      "mean": 4.693224320637778,
      "stddev": 0.6082489257654011,
      "median": 4.50455242586,
      "user": 7.043356735555555,
      "system": 0.4307170244444445,
      "min": 3.8604628118599997,
      "max": 5.71053769386
    }
  ]
}

Scenario: Isolated linker: linked-workspace resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 289.2 ± 53.3 228.5 394.2 1.00
pacquet@main 325.6 ± 46.4 260.9 380.9 1.13 ± 0.26
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.28915167476000003,
      "stddev": 0.05333250079660625,
      "median": 0.27654811676,
      "user": 0.24320249666666663,
      "system": 0.10740704333333334,
      "min": 0.22846215326000002,
      "max": 0.39420991826
    },
    {
      "command": "pacquet@main",
      "mean": 0.32561586116,
      "stddev": 0.046380276934914394,
      "median": 0.33522517376000005,
      "user": 0.26017908,
      "system": 0.13557446,
      "min": 0.26092925226,
      "max": 0.38094703726
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.674 ± 0.209 4.429 5.029 1.28 ± 0.08
pacquet@main 4.708 ± 0.294 4.458 5.375 1.29 ± 0.10
pnpr@HEAD 3.654 ± 0.167 3.464 3.959 1.00
pnpr@main 3.845 ± 0.208 3.609 4.210 1.05 ± 0.07
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.674244034760001,
      "stddev": 0.20868990861880155,
      "median": 4.618932861859999,
      "user": 2.1418519399999996,
      "system": 1.8326986600000001,
      "min": 4.42947572836,
      "max": 5.02945968336
    },
    {
      "command": "pacquet@main",
      "mean": 4.70836181336,
      "stddev": 0.29359891762434814,
      "median": 4.63189643686,
      "user": 2.16330984,
      "system": 1.88169956,
      "min": 4.45782622236,
      "max": 5.37542519336
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.65385514046,
      "stddev": 0.1668600710402365,
      "median": 3.62533745586,
      "user": 1.94520814,
      "system": 1.7959794599999999,
      "min": 3.4642317183599998,
      "max": 3.95914177936
    },
    {
      "command": "pnpr@main",
      "mean": 3.8447432831599997,
      "stddev": 0.208124406149008,
      "median": 3.80292022486,
      "user": 2.26450734,
      "system": 2.1029941599999997,
      "min": 3.60918943536,
      "max": 4.20971035736
    }
  ]
}

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

Same install as the isolated fresh-restore hot/hot scenario, into the shared virtual store, the layout pnpm 12 installs into by default. Scenarios run on separate machines, so compare main and branch within each table.

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 131.2 ± 9.5 117.0 156.5 1.00
pacquet@main 151.9 ± 24.3 122.2 215.5 1.16 ± 0.20
pnpr@HEAD 144.8 ± 5.9 134.2 153.4 1.10 ± 0.09
pnpr@main 149.0 ± 11.2 132.2 170.4 1.14 ± 0.12
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.13118450287789477,
      "stddev": 0.009540867164587845,
      "median": 0.13092233472,
      "user": 0.16778081894736843,
      "system": 0.13477114736842102,
      "min": 0.11696238472,
      "max": 0.15649939672000002
    },
    {
      "command": "pacquet@main",
      "mean": 0.15194610881999998,
      "stddev": 0.024263740429552615,
      "median": 0.14777369372000002,
      "user": 0.18920004000000004,
      "system": 0.13940034999999998,
      "min": 0.12224426172000001,
      "max": 0.21554053772
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.1447953418964706,
      "stddev": 0.005850255085920143,
      "median": 0.14438971972,
      "user": 0.17298306352941176,
      "system": 0.13749196470588232,
      "min": 0.13416148672,
      "max": 0.15343445172
    },
    {
      "command": "pnpr@main",
      "mean": 0.14898801005333334,
      "stddev": 0.011244595096652472,
      "median": 0.14387806972,
      "user": 0.17751710666666665,
      "system": 0.14652533333333334,
      "min": 0.13217372372000002,
      "max": 0.17037660972000002
    }
  ]
}

@zkochan
zkochan marked this pull request as ready for review September 24, 2026 19:24
@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Register atomic temp files before creation

🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Register atomic-write temporary paths before creation to close the interrupt cleanup race.
• Preserve exclusive creation and Unix 0600 permissions through custom file opening.
• Strengthen interruption coverage while reducing lockfile test memory and increasing retry
 opportunities.
Diagram

sequenceDiagram
    participant W as Atomic Writer
    participant B as Temp Builder
    participant R as Cleanup Registry
    participant F as Filesystem
    actor S as Interrupt Signal
    W->>B: request temp file
    B->>R: register chosen path
    B->>F: create new 0600
    W->>F: write and sync
    alt Interrupted
        S->>R: trigger cleanup
        R->>F: unlink temp file
    else Write succeeds
        W->>F: persist target
    end
Loading
High-Level Assessment

The current approach is optimal: tempfile::Builder::make_in retains the library's random-name and collision-retry behavior while exposing the selected path early enough for registration. A manual random-name retry loop would duplicate tempfile logic, while retaining NamedTempFile::new_in cannot eliminate the create-before-register race. The custom opener correctly preserves exclusive creation and Unix mode 0600.

Files changed (3) +27 / -19

Bug fix (1) +22 / -5
write_atomic.rsRegister temporary paths before exclusive file creation +22/-5

Register temporary paths before exclusive file creation

• Replaces direct 'NamedTempFile' creation with 'Builder::make_in', registering each selected path before it becomes visible. Adds an exclusive private-file opener that preserves Unix mode 0600 and supports collision retries under newly registered names.

pnpm/crates/fs/src/write_atomic.rs

Tests (2) +5 / -14
atomic_write_holder.rsInterrupt atomic writes immediately after temp-file creation +3/-12

Interrupt atomic writes immediately after temp-file creation

• Changes the cross-process SIGINT test to proceed as soon as a staged temporary file exists rather than waiting for written content. This directly covers the earliest interrupt window after creation.

pnpm/crates/fs/tests/atomic_write_holder.rs

tests.rsReduce lockfile cleanup payload and increase race attempts +2/-2

Reduce lockfile cleanup payload and increase race attempts

• Reduces the interrupted lockfile test payload from 256 MiB to 64 MiB while increasing attempts from five to ten. This lowers per-attempt resource usage while improving the chance of observing an in-flight save.

pnpm/crates/lockfile/src/save_lockfile/tests.rs

@qodo-code-review

qodo-code-review Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Regression passes without the fix ✗ Dismissed 📜 Skill insight ▣ Testability
Description
wait_for_temp_file returns when it observes any .tmp entry, but observation in the parent
process does not prove the signal arrived between the child's file creation and subsequent
registration. With the production change reverted, the child can create and register the file before
the polling thread is scheduled, so cleanup still succeeds without exercising the original defect.
Code

pnpm/crates/fs/tests/atomic_write_holder.rs[58]

+            .any(|entry| {
Relevance

●●● Strong

Recent history accepts strengthening concurrency regressions when scheduling does not
deterministically exercise the intended failure window.

PR-#15394

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Compliance rule 3365251 requires a bug-fix regression test to fail when the production fix is
removed. The test merely polls for the file from another process, while the changed implementation
shows registration and creation are consecutive operations, leaving scheduling free to observe the
file only after both have completed.

pnpm/crates/fs/tests/atomic_write_holder.rs[50-65]
pnpm/crates/fs/src/write_atomic.rs[65-70]
Skill: review-code

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 regression test relies on process scheduling after detecting the temporary file, so it can pass against the pre-fix create-then-register ordering.

## Fix Focus Areas
- pnpm/crates/fs/tests/atomic_write_holder.rs[50-65]
- pnpm/crates/fs/src/write_atomic.rs[65-70]

## Recommended Fix
Add deterministic test synchronization at the file-creation boundary so the writer pauses immediately after creation and before any post-create registration could occur. Signal the child while it is paused, then assert that cleanup removes the staged file; verify the test fails when registration is moved back after creation.

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



Remediation recommended

2. Interrupts can delete unrelated files 🐞 Bug ⛨ Security
Description
write_tmp_over registers each candidate pathname before create_private_file establishes
ownership through exclusive creation, so cleanup treats a colliding existing file as this process's
temporary file. If a terminating signal arrives while create_new(true) is handling that collision,
the signal handler unlinks the pre-existing file before the retry can replace the registration.
Code

pnpm/crates/fs/src/write_atomic.rs[R68-69]

+            _pending_temp = Some(crate::pending_temp::track_temp_file(path));
+            create_private_file(path)
Relevance

●●● Strong

Recent accepted TOCTOU precedent supports preventing cleanup from deleting files not owned by the
current operation.

PR-#13375

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The changed callback publishes the candidate to track_temp_file before create_private_file,
while the latter uses create_new(true) and therefore rejects an existing candidate rather than
acquiring it. The registry stores that exact path, and interrupt cleanup unconditionally passes
every registered path to unlink, so the collision window reaches deletion of a file the write
never created.

pnpm/crates/fs/src/write_atomic.rs[44-52]
pnpm/crates/fs/src/write_atomic.rs[65-70]
pnpm/crates/fs/src/pending_temp.rs[97-108]
pnpm/crates/fs/src/pending_temp.rs[110-127]
pnpm/crates/fs/src/pending_temp.rs[196-204]

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 cleanup registry is armed before exclusive creation proves that the candidate pathname belongs to this write. On a random-name collision, interrupt cleanup can therefore unlink an unrelated existing file.

## Fix Focus Areas
- pnpm/crates/fs/src/write_atomic.rs[65-70]
- pnpm/crates/fs/src/pending_temp.rs[101-127]

## Recommended Fix
Ensure interrupt cleanup cannot unlink a candidate until exclusive creation has established ownership. Register only after successful creation, or redesign the pending entry with ownership-aware state that the signal-safe cleanup checks; also add a deterministic collision-and-interrupt regression test proving the colliding file survives.

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


Grey Divider

Context sources
✅ Compliance rules (platform): 64 rules
✅ Skills: review-code
✅ Cross-repo context — repo relationships
Review mode: ⚖️ Balanced: This changes Rust atomic-file creation and interrupt cleanup semantics on a filesystem-sensitive path, so it carries genuine correctness and security risk despite its localized scope.

Grey Divider

Tip of the day
💡 Did you know, you can choose which labels appear on a finding, and whether they show icons or text

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

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

@zkochan

zkochan commented Sep 24, 2026

Copy link
Copy Markdown
Member Author

On Qodo's summary finding 2 (registering before create_new could unlink a colliding file on interrupt): not changing this. It is the tradeoff discussed in #15486 (comment). Registering only after the create reopens a window in which an interrupt strands our own temp file. To hit the reverse case, an unrelated file would need the same random .tmpXXXXXX name in the target's directory, and the interrupt would have to land between the registration and the failed create in the same closure call.


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

@zkochan

zkochan commented Sep 24, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@zkochan

zkochan commented Sep 24, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@zkochan
zkochan merged commit 96f014b into main Sep 24, 2026
69 of 71 checks passed
@zkochan
zkochan deleted the fix/pending-temp-register-before-create branch September 24, 2026 19:59
u9g pushed a commit to u9g/pnpm that referenced this pull request Sep 25, 2026
…#15593)

write_atomic let NamedTempFile pick the random name while creating the
file, so the registration could only follow the create and an interrupt
in between left the temp file behind. tempfile's Builder::make_in hands
the chosen name to a closure, which now registers it and then creates
the file exclusively with mode 0600, as NamedTempFile did. The
cross-process test now interrupts as soon as the temp file exists,
which covers that earliest window.

Also shrink the lockfile cleanup test's payload to 64 MiB and allow it
ten attempts to catch a save in flight.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants