Skip to content

fix(cli): take a stale sign-in lock over one run at a time; test: no random id in the #479 match - #727

Merged
eizedev merged 4 commits into
mainfrom
fix/cli-lock-takeover
Nov 22, 2026
Merged

eizedev merged 4 commits into
mainfrom
fix/cli-lock-takeover

Conversation

@eizedev

@eizedev eizedev commented Nov 22, 2026

Copy link
Copy Markdown
Owner

Fixes #717
Fixes #721

#717, the CLI's sign-in lock:

  • A run that reads a lock as stale takes it over only while it holds a second lock, <lock>.takeover, made with O_EXCL. Holding it, the run reads the lock's age again and removes the lock only if it is still stale. Nothing renames a lock aside any more, so a lock made since is never moved.
  • A run that makes its lock while a takeover lock is there removes its own and waits. So a lock made between the takeover's age read and its removal is never used.
  • A waiting run does not spin while another run takes over: it waits lockPollMs and gives up after lockWaitMs, as for any held lock.
  • A takeover lock older than 10 s is a crashed run's and is removed.
  • New tests: a late takeover with a third run trying O_EXCL the whole time (it got in 5 of 5 times with the old code); five takeovers at once remove the stale lock once; a waiting run during a takeover neither spins nor enters and ends with LOCKED; a lock made during a takeover backs off until it ends.

#721: the #479 hardening test leaves out the answer's random requestId before it looks for a "3".

Places checked: docs/reference/cli.md (the lock's description still holds), the CLI CHANGELOG.

Tests: npm test -w pivotkit-cli, the server's hardening tests, lint, types; the lock tests 10 times in a row.

🤖 Generated with Claude Code

eizedev and others added 4 commits November 22, 2026 06:44
…random id in the #479 match

- credential-store.js: a run takes over a stale lock only while it holds
  a second O_EXCL lock (<lock>.takeover), and only if the lock is still
  stale then. It no longer renames a lock aside, so a lock another run
  made since is never moved and a third run cannot get in beside it.
  A takeover lock of a crashed run is removed after lockStaleMs.
- hardening.test.js: the #479 check leaves out the answer's random
  requestId, which may hold a "3".

Fixes #717
Fixes #721

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…during one backs off

- takeOver says whether it removed the lock; the caller waits otherwise.
- A run whose new lock meets a takeover lock removes its own and waits,
  so a removal between the age read and the unlink never lets two in.
- A takeover lock counts as crashed after 10 s, not lockStaleMs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@eizedev
eizedev merged commit 5849d41 into main Nov 22, 2026
25 checks passed
@eizedev
eizedev deleted the fix/cli-lock-takeover branch November 22, 2026 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant