Skip to content

fix: update lock PID with Worker's real process PID after spawn#295

Merged
clonable-eden merged 3 commits intomainfrom
issue/294-fix-spawn-sh-lock-pid-stale
Mar 11, 2026
Merged

fix: update lock PID with Worker's real process PID after spawn#295
clonable-eden merged 3 commits intomainfrom
issue/294-fix-spawn-sh-lock-pid-stale

Conversation

@clonable-eden
Copy link
Owner

closes #294

概要

spawn.shissue_lock_acquire$$(自身の PID)を lock に記録するが、spawn.sh は Worker 起動後すぐに終了する短命プロセスのため、lock の PID が常に dead 状態になる。これにより stale 検知(kill -0)が誤動作し、同一 issue に対して重複 Worker が spawn される可能性があった。

変更内容

  • issue-lock.sh: issue_lock_update_pid 関数を追加(既存 lock の PID を更新)
  • backends/headless.sh: backend_get_pid 追加(handle がそのまま PID)
  • backends/tmux.sh: backend_get_pid 追加(tmux list-panes -F '#{pane_pid}'
  • backends/wezterm.sh: backend_get_pid 追加(wezterm cli list --format json からパース)
  • backend-adapter.sh: External API ドキュメントを 4→5 に更新
  • spawn.sh: spawn 後に backend_get_pid + issue_lock_update_pid で実 PID に更新

テスト

  • test-issue-lock.sh: issue_lock_update_pid のテスト 3 件追加(更新成功、lock なし失敗、check との連携)
  • test-backend-headless.sh: backend_get_pid のテスト 2 件追加
  • test-backend-dispatch.sh: API 関数チェックを 4→5 に更新

spawn.sh records its own PID ($$) in the issue lock, but it exits
immediately after launching the Worker. This causes stale detection
(kill -0) to always see a dead PID, potentially allowing duplicate
Worker spawns for the same issue.

Add backend_get_pid to all backends (headless, tmux, wezterm) and
issue_lock_update_pid to issue-lock.sh. After backend_spawn_worker,
spawn.sh now retrieves the Worker's actual PID and updates the lock.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Owner Author

@clonable-eden clonable-eden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

レビュー結果: Approve ✅

良い点

  • Issue の要件(spawn.sh の $$ → Worker 実 PID への更新)を正確に実装
  • issue_lock_update_pid は既存の lock API パターンに忠実で、引数バリデーション・エラーハンドリングが適切
  • spawn.sh での PID 更新が || true で保護されており、backend_get_pid が失敗しても spawn プロセス全体は壊れない
  • テストは正常系(PID 更新)、異常系(lock なし)、連携(lock_check との統合)を網羅
  • CI パス済み

軽微な指摘(non-blocking)

  • headless.shtmux.shwezterm.sh のファイルヘッダーコメントが Implements 4 external API functions のまま。backend_get_pid 追加で 5 になったので、余裕があれば更新をお勧めします
  • backend_get_pid の handle ファイル探索(type 省略時の ls ... | head -1)が 3 バックエンドで重複しているが、これは既存の backend_worker_alive / backend_kill_worker でも同じパターンなのでスコープ外(将来のリファクタリング候補)

clonable-eden and others added 2 commits March 11, 2026 23:52
backend_get_pid was added but file headers still said "4 external API functions".

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
spawn.sh is used for both Worker and Reviewer spawning, so the variable
name should be agent-type neutral. BACKEND_PID clearly indicates the
value comes from backend_get_pid and works for any agent type.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@clonable-eden clonable-eden merged commit d2798db into main Mar 11, 2026
3 checks passed
@clonable-eden clonable-eden deleted the issue/294-fix-spawn-sh-lock-pid-stale branch March 11, 2026 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: spawn.sh が lock に自身の PID を記録するため stale 検知が誤動作する

1 participant