fix: reap stale background processes to prevent gateway starvation (#76115) - #76183
Closed
RelaxJonh wants to merge 1 commit into
Closed
fix: reap stale background processes to prevent gateway starvation (#76115)#76183RelaxJonh wants to merge 1 commit into
RelaxJonh wants to merge 1 commit into
Conversation
…ousResearch#76115) Add a background sweep thread to ProcessRegistry that kills running background processes exceeding MAX_ACTIVE_PROCESS_AGE (default 24h). Without this, abandoned or stuck tool subprocesses (e.g. pnpm build) run indefinitely, consuming unbounded memory until the gateway cgroup hits MemoryHigh — starving the asyncio event loop and causing all platforms and crons to time out. Changes: - Add STALE_SWEEP_INTERVAL constant (300s / 5 min) - Add _stale_sweep_loop() daemon thread started at registry init - Add _reap_stale_running() method using existing kill_process() which handles process-tree teardown (SIGKILL/SIGTERM POSIX, taskkill /T /F Windows) Fixes NousResearch#76115
6 tasks
Collaborator
Contributor
|
Thanks for addressing a verified process-lifetime gap. Problems
Suggested changes
Automated hermes-sweeper review. |
Collaborator
|
Closing as duplicate of #76188 (@JoaoMarcos44) — that PR implements turn-scoped reaping (only kills processes the abandoned turn created) with 4 test files and gateway integration, vs the age-based blind sweep here which would kill legitimate long-running background processes older than 24h. Your PR was also byte-for-byte identical to #76172. Thanks for the contribution! |
4 tasks
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
Fixes #76115.
When an agent turn spawns a background subprocess (e.g.
pnpm build) and that turn gets abandoned, the subprocess runs indefinitely inside thehermes-gatewaycgroup. A single runaway build can push the cgroup past itsMemoryHighlimit, causing kernel throttling and swap-thrashing that starves the gateway event loop — every messaging platform disconnects and every cron fails with "provider timeout".Changes
tools/process_registry.py: Added a background daemon thread (_stale_sweep_loop) that periodically checks for running processes exceedingMAX_ACTIVE_PROCESS_AGE(24h default). Long-running processes are killed via the existingkill_processinfrastructure (handles SIGKILL/SIGTERM on POSIX, taskkill /T /F on Windows). AddedSTALE_SWEEP_INTERVALconstant (300s). Added_reap_stale_running()method with logging.Design
threading.Event.wait()for clean shutdown — no busy-wait loopkill_process()for proper process-tree teardownMAX_ACTIVE_PROCESS_AGE(configurable viasession_reset.bg_process_max_age_hours)