Repository navigation
fix(lock): re-check the config under the lock; never break a lock mid-write (PHARN-03) - #197
Merged
Merged
Conversation
…-write (PHARN-03)
Two ways the single-writer lock let a stale plan land:
(a) `add`/`update`/`remove` load pharn.config.json BEFORE taking the lock (and
`update` / the `remove` picker prompt in between). A `remove` confirmed
after a concurrent `add` rewrote its stale snapshot, dropping the added
capability while its files and records stayed. Each now calls
`assertConfigUnchanged` first inside the lock and refuses with
`ProjectChangedError` (a `ProjectLockedError`: named refusal, exit 1,
nothing written).
(b) `tryCreate` writes the payload after the O_EXCL create, so a live lock is
briefly empty; `isStale(null)` read that as stale and a concurrent run
broke it (8 processes x 150 rounds: 26 rounds with 2+ holders). An
unparseable lock younger than MALFORMED_GRACE_MS (10 s) is now live
(0/150 after the fix).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TvcuVhk8hTeDskp5pAJhnc
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 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 |
Merged
8 of 11 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
This fixes two holes in the single-writer project lock (
.pharn.lock).(a) Changes planned against an outdated config.
add,updateandremoveloadpharn.config.jsonbefore they take the lock, andupdateand theremovepicker also show a confirm prompt in between. Reproduced: aremovepicker was confirmed after a concurrentaddhad finished. Theremovethen wrote the config it had loaded earlier, so the added capability disappeared from the config while its files and records stayed on disk. Both commands exited 0.→ Each of the three commands now calls
assertConfigUnchangedas its first step inside the lock. If the config changed, it throwsProjectChangedError, a subclass ofProjectLockedError, so every existing catch site already reports it as a named refusal: exit 1, nothing written.(b) A live lock broken while its owner is still writing it.
tryCreatecreates the lock file withO_EXCLand writes the payload in a second step, so a live lock is briefly empty.isStale(null)treated an empty file as stale, so a concurrent run could break a lock that was in use.→ A lock file that cannot be parsed and is younger than
MALFORMED_GRACE_MS(10 s) now counts as live. Older ones are still broken, so a corrupt lock cannot block the project for long.Evidence from the review's race harness (8 processes started in the same millisecond, 150 rounds), outside the test suite:
Docs:
README.md("One writer at a time") andCLAUDE.md.Built with
/pharn-dev-ship; stage artifacts are in.dev/features/lock-read-modify-write/. Results:no-regressionsPASSType of change
feat— new stack option, wizard step, or command capabilityfix— bug fixdocs— docs-only changechore/refactor— tooling or internal restructure, no behavior changeArea(s) touched
lib/project-lock | lib/pharn-config | commands/add, update, remove | docs
Checklist
.js-extension import convention.src/lib/validate.ts.Quality gates
npm run checkpasses locally (1303/1303 tests; non-root user, node 22).npm run buildsucceeds (left to CI).npm run test:coveragepasses (left to CI).Notes for the reviewer
🤖 Generated with Claude Code
https://claude.ai/code/session_01TvcuVhk8hTeDskp5pAJhnc
Generated by Claude Code