fix: verify PID belongs to claude before SIGKILL (#160) #163

Merged
guettlibot merged 1 commits from issue-160-fix into main 2026-05-24 10:55:12 +00:00
guettlibot commented 2026-05-23 09:02:40 +00:00 (Migrated from codeberg.org)

Summary

  • Add _is_claude_process(pid) that reads /proc/{pid}/comm to verify a process is claude or node before sending SIGKILL
  • Update _kill_agent() to call _is_claude_process() and skip the kill (with a warning) if the PID was recycled
  • Add TestIsClaudeProcess test class and update TestKillAgent tests to patch the new guard

Fixes the TOCTOU/PID-recycling risk described in #160: if the original claude process exits between cron ticks and the kernel reuses its PID, the loop will now refuse to kill the unrelated process instead of blindly sending SIGKILL.

Test plan

  • python3 scripts/test_agent_loop.py -v passes all new and existing tests (pre-existing failure in test_ci_fix_preserves_pending_issue_in_state is unrelated to this PR)
  • task check passes in CI
## Summary - Add `_is_claude_process(pid)` that reads `/proc/{pid}/comm` to verify a process is `claude` or `node` before sending SIGKILL - Update `_kill_agent()` to call `_is_claude_process()` and skip the kill (with a warning) if the PID was recycled - Add `TestIsClaudeProcess` test class and update `TestKillAgent` tests to patch the new guard Fixes the TOCTOU/PID-recycling risk described in #160: if the original claude process exits between cron ticks and the kernel reuses its PID, the loop will now refuse to kill the unrelated process instead of blindly sending SIGKILL. ## Test plan - [ ] `python3 scripts/test_agent_loop.py -v` passes all new and existing tests (pre-existing failure in `test_ci_fix_preserves_pending_issue_in_state` is unrelated to this PR) - [ ] `task check` passes in CI
Sign in to join this conversation.