fix(tools): escalate SIGTERM→SIGKILL on browser daemon + periodic orphan reap#15008
Open
tkwong wants to merge 1 commit into
Open
fix(tools): escalate SIGTERM→SIGKILL on browser daemon + periodic orphan reap#15008tkwong wants to merge 1 commit into
tkwong wants to merge 1 commit into
Conversation
…han reap Builds on NousResearch#11843 (owner_pid cross-process tracking). Adds: 1. _terminate_browser_daemon(): SIGTERM with 2s grace, escalate to SIGKILL if daemon ignores SIGTERM. Verifies exit before returning True; returns False on survival so socket dir is left for next reap attempt. 2. _pid_exists(): helper that distinguishes alive / dead / foreign-owned. 3. Periodic orphan reap every 5 min from cleanup thread (not just once at startup + atexit). Catches daemons orphaned mid-session. 4. Tunable via BROWSER_DAEMON_TERM_GRACE_SECONDS (default 2.0) and BROWSER_ORPHAN_REAP_INTERVAL_SECONDS (default 300). Motivation: daemons with SIGTERM handlers that stall in cleanup survive reap. Without escalation, they leak indefinitely until machine reboot. Tests: 49/49 pass.
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.
Summary
Builds on #11843 (owner_pid cross-process tracking). Adds:
_terminate_browser_daemon(): SIGTERM with 2s grace, escalate to SIGKILL if the daemon ignores SIGTERM. Verifies exit before returningTrue; returnsFalseon survival so the socket dir is left in place for the next reap attempt._pid_exists(): helper that distinguishes alive / dead / foreign-owned viaos.kill(pid, 0)+PermissionError.BROWSER_DAEMON_TERM_GRACE_SECONDS(default2.0) andBROWSER_ORPHAN_REAP_INTERVAL_SECONDS(default300).Motivation
Agent-browser daemons with SIGTERM handlers that stall in cleanup survive reap. Without SIGKILL escalation they leak indefinitely until machine reboot — observed in a long-running gateway hitting EMFILE.
Composes with #11843 (owner_pid)
Orthogonal concerns — owner_pid decides whether to reap, this PR strengthens how the reap executes. Both live in
_reap_orphaned_browser_sessions; conflict resolution kept both behaviors.Test plan
pytest tests/tools/test_browser_cleanup.py tests/tools/test_browser_orphan_reaper.py tests/gateway/test_whatsapp_connect.py→ 49/49 passtest_dead_owner_triggers_reapmock to model a SIGTERM-honoring daemon (old mock modeled zombie daemon that never dies, which is now the unhappy path under this PR — socket dir retention is expected)🤖 Generated with Claude Code