fix(watch): single-instance lock to prevent duplicate daemons#8
Merged
Conversation
複数 tmux shell + autostart のレースで cogsync watch が多重起動し deepwork を二重計上していた。runWatch 冒頭に O_EXCL pidfile ロックを追加(--once 診断は対象外)。stale な pidfile は process.kill(pid,0) の死活判定で回収。ロックはシグナルを横取りせず exit クリーンアップのみに徹し、watch 終了時の deepwork 保存を奪わない。テスト5件。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
なぜ
cogsync watchに多重起動ガードが無く(本体に flock/pidfile/O_EXCL 不在を確認)、複数 tmux shell + bashrc autostart の素朴なpgrepガードはレースで重複起動する。結果 deepwork が二重計上され通知も重複する。起動方法に依らず単一インスタンスにするため watch 本体でロックを取る。何を
src/util/singleton-lock.ts(新規):acquireSingleInstanceLock= O_EXCL pidfile(アトミック)+process.kill(pid,0)死活判定で stale 回収。releaseは自 pid のロックのみ削除。src/watch.ts:runWatch冒頭で<XDG_STATE_HOME or ~/.local/state>/cogsync/watch.lockを取得。取れなければメッセージを出して return。--once診断は対象外。tests/singleton-lock.test.ts: 取得 / 二重 null / stale 回収 / 壊れ pid / release 冪等 / シグナル非干渉 の5件。設計判断
--onceはロック対象外: 診断用の1回 poll は daemon 稼働中でも実行できるべき(初回 feed は +0 分で二重計上にならない)。stop(deepwork 保存)より先に発火しprocess.exit()で保存を奪う回帰になる。ロックはexitクリーンアップのみに徹し、シグナルは watch に委ねる。← 独立敵対レビューで検出した回帰を修正し回帰テストで pin。スコープ外
state.jsonの read-modify-write 競合(lost-update)は本 PR の射程外。検証方法
npm test: 38 pass / 0 fail(既存33+新規5)。tsc --noEmit: 0。依存
🤖 Generated with Claude Code