Repository navigation
fix: lock the session registry across processes and stop stale overwrites (#55) - #140
Merged
Merged
Conversation
…ites (#55) persist() let every in-memory record win over disk, so a copy of another instance's recording loaded at boot could undo that instance's later stop. Only records this instance changed now override the disk copy. Read-merge-write runs under an O_EXCL lockfile with stale-lock takeover, reads take the lock too, and the temp-file rename retries on Windows sharing errors. A delete-pending lock (EPERM on Windows) is treated as busy instead of as permission to write unlocked. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Closes #55.
Bugs fixed
persist()merged with disk but let every in-memory record win, including another instance's records loaded at boot and never touched. If A loaded B's live recording and B then stopped it, A's next unrelated write flipped it back torecording. Now adirtyset means only records this instance created/changed override disk; the in-memory view is refreshed from what was written. A test reproduces it and failed before the fix (expected 'recording' to be 'stopped').sessions.json.lock(O_EXCL, contents{pid, at}). A stale lock (owner dead, or >10 s old) is taken over. After 2 s of contention it writes anyway with a stderr warning rather than failing a recording.EPERMcrash. Found by the new multi-process test: renaming the temp file oversessions.jsonfails while another process has it open.load()now reads under the lock too, and the rename retries briefly onEPERM/EBUSY/EACCES.Debugging notes (two more lock bugs, both caught by the stress test)
isAlive()reported as dead, so it was stolen. A lock with no readable pid is now judged by age only.openSync('wx')fails withEPERM, notEEXIST. The old code took any non-EEXISTerror as "can't lock here" and wrote unlocked, silently. Before the fix, 6 of 10 runs lost a record mid-sequence; after it, 0 of 15.Tests
isLockStalerules (dead / old / unreadable-but-fresh).node --import tsxworkers × 25 records into one registry; asserts all 150 present and no leftover lock. Passes 15/15 locally on Windows.Version 0.14.3.
🤖 Generated with Claude Code