Repository navigation
fix(fs): distinguish an unavailable lock from a busy one - #13377
Conversation
`DirLock::acquire` folded a failure to write the owner record into `Ok(None)`, which is the same answer it gives when another process holds the lock. Those are different situations: one is the wait doing its job, the other means the locking mechanism itself is broken and the caller is about to run without the lock and without knowing why. That matters most at the engine install, where the lock exists to keep concurrent destructive installs out of a shared store slot. The write failure now propagates as `Err`, alongside the parent-directory failure that already did. The engine-install caller still proceeds — a lock it cannot take is not a reason to refuse to run — but logs what happened rather than silently reverting to the racy behavior. Follow-up to #13375, raised in review there after it merged. Not covered by a test: making `create_dir` succeed while a write inside it fails needs a filesystem fault-injection seam this crate does not have, and the alternatives are unportable enough to be worth less than the signature itself.
|
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 (1)
📝 WalkthroughWalkthroughThe lock implementation now distinguishes contention from mechanism failures. Engine installation warns when the lock cannot be acquired, continues without serialization, and documents the behavior in a patch Changeset. ChangesEngine lock failure reporting
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested labels: Suggested reviewers: ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoFix DirLock: surface lock mechanism failures separately from contention
AI Description
Diagram
High-Level Assessment
Files changed (3)
|
Confidence Score: 5/5The PR appears safe to merge. The previously invisible warning now reaches the normal default and NDJSON reporters, and no blocking failure remains. Reviews (4): Last reviewed commit: "test(fs): make the unrecordable-lock ass..." | Re-trigger Greptile |
Code Review by Qodo
Context used✅ Compliance rules (platform):
24 rules 1.
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Micro-Benchmark ResultsLinux |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #13377 +/- ##
==========================================
+ Coverage 87.22% 87.25% +0.03%
==========================================
Files 536 540 +4
Lines 92059 92662 +603
==========================================
+ Hits 80297 80854 +557
- Misses 11762 11808 +46 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
`tracing::warn!` only reaches a subscriber when `TRACE` is set, so the diagnostic this was supposed to add was dropped on every ordinary run — the caller went on installing without a lock and without saying so, which is the behavior the warning existed to avoid. It now goes through the reporter, as every other user-facing warning in the CLI does. Flattened while here: `DirLock::acquire` had grown to `loop` → `match` → arm → `match` → arm → block. Recording ownership of a directory this process just created is its own step, so it is its own function, and the `create_dir` match is back to one level of arms.
|
Code review by qodo was updated up to the latest commit c4679ff |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
The failure path was described in three places and asserted in none. Extracting `claim` for the nesting made it directly testable, so it is now tested — and the paragraphs restating what the test and the code already say are gone. What is left is the part neither can carry: `io::Result<Option<DirLock>>` does not say which of its two negative answers means what, and the reporter call does not say why it is not `tracing`.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pnpm/crates/fs/src/dir_lock/tests.rs`:
- Around line 90-102: Update claiming_a_directory_that_cannot_hold_the_record to
create an existing lock directory while making the owner-record write fail, then
assert claim propagates the error and removes the lock directory. Ensure the
test exercises the DirLock::acquire path so claim errors are not converted into
Ok(None); keep the missing-parent scenario separate if retained, and revise the
comment to describe the missing parent accurately.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 10c21371-cc5f-403c-b0e4-088e8d65d8bc
📒 Files selected for processing (3)
pnpm/crates/cli/src/cli_args/with/install_pnpm_to_store.rspnpm/crates/fs/src/dir_lock.rspnpm/crates/fs/src/dir_lock/tests.rs
💤 Files with no reviewable changes (1)
- pnpm/crates/cli/src/cli_args/with/install_pnpm_to_store.rs
🚧 Files skipped from review as they are similar to previous changes (1)
- pnpm/crates/fs/src/dir_lock.rs
|
Code review by qodo was updated up to the latest commit 7ef402a |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
The path handed to `claim` never existed, so asserting it was gone afterwards proved nothing — the test passed whether or not the cleanup ran. It now blocks the owner record with a directory of that name, so the lock directory is real and its removal is observable. Verified by deleting the cleanup: the old test still passed, this one fails.
|
Code review by qodo was updated up to the latest commit 2eda840 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
`DirLock::acquire` folded a failure to write the owner record into `Ok(None)`, which is the same answer it gives when another process holds the lock. Those are different situations: one is the wait doing its job, the other means the locking mechanism itself is broken and the caller is about to run without the lock and without knowing why. That matters most at the engine install, where the lock exists to keep concurrent destructive installs out of a shared store slot. The write failure now propagates as `Err`, alongside the parent-directory failure that already did. The engine-install caller still proceeds — a lock it cannot take is not a reason to refuse to run — but logs what happened rather than silently reverting to the racy behavior. Follow-up to pnpm#13375, raised in review there after it merged.
Summary
Follow-up to #13375. This was raised in review there (by Qodo) after the PR had already merged, so it lands on its own.
DirLock::acquirefolded a failure to write the lock's owner record intoOk(None)— the same answer it gives when another process holds the lock. Those are different situations. One is the wait doing its job; the other means the locking mechanism itself is broken and the caller is about to run without the lock and without knowing why. That distinction matters most at the engine install, which is exactly where the lock exists to keep concurrent destructive installs out of a shared global-virtual-store slot.The write failure now propagates as
Err, alongside the parent-directory failure that already did. The engine-install caller still proceeds — a lock it cannot take is not a reason to refuse to run — but logs what happened instead of silently reverting to the racy behavior that #13375 set out to fix.Notes for reviewers
create_dirsucceed while a write inside it fails needs a filesystem fault-injection seampacquet-fsdoes not have.pnpm/AGENTS.mdsanctions theSysseam for exactly this kind of error-kind branch, but adding one toDirLockfor a single assertion costs more than the signature change is worth. The existing fourdir_locktests still cover acquire/release, contention, takeover, and the stale-successor case.Ok(None).Squash Commit Body
Checklist
pnpm/port, or the description notes what still needs porting.(Rust-only:
DirLockhas no TypeScript counterpart.)pnpm changeset) if this PR changes any publishedpackage. Keep it short and written for pnpm users — it becomes a release note.
Written by an agent (Claude Code, claude-opus-5).
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit