Skip to content

Fix guard daemon not following session changes on restart#12

Open
conal wants to merge 1 commit intoRuya-AI:mainfrom
conal:fix-guard-session-follow
Open

Fix guard daemon not following session changes on restart#12
conal wants to merge 1 commit intoRuya-AI:mainfrom
conal:fix-guard-session-follow

Conversation

@conal
Copy link

@conal conal commented Mar 9, 2026

Summary

  • When Claude Code restarts (new session), the guard daemon now detects session mismatch and replaces itself instead of silently watching the stale session.
  • Adds a companion session file alongside the PID file to track which session_id the guard is monitoring.
  • On mismatch: SIGTERM the old guard, clean up PID/session files, start a new guard.
  • When session_id is None or matches, behavior is unchanged (backward compatible).

Fixes #11

Test plan

  • Existing test suite passes (98 tests, verified locally)
  • Manual test: start Claude Code, verify guard starts. Restart Claude Code, verify old guard is replaced and new guard monitors the new session.
  • Manual test: verify that same-session restarts (e.g. guard crash recovery) still report already_running without killing anything.

Generated with Claude Code

When Claude Code restarts, start_guard_daemon now detects that the
existing guard is watching a stale session and replaces it. A companion
session file alongside the PID file tracks which session_id the guard
is monitoring. On session mismatch, the old guard is killed via SIGTERM
and a new one starts for the current session.

Fixes Ruya-AI#11

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Guard daemon doesn't follow session changes — watches stale session after restart

1 participant