fix(cron): close codex app-server session in teardown to prevent subprocess leak (#62101) - #62105
Open
liuhao1024 wants to merge 1 commit into
Open
fix(cron): close codex app-server session in teardown to prevent subprocess leak (#62101)#62105liuhao1024 wants to merge 1 commit into
liuhao1024 wants to merge 1 commit into
Conversation
…rocess leak (NousResearch#62101) Ephemeral cron agents leak the codex app-server subprocess because agent.close() does not cleanup _codex_session. This adds a cleanup helper in codex_runtime.py and calls it from cron's _teardown_cron_agent().
6 tasks
Contributor
|
Thanks for the focused cron cleanup. The premise is confirmed on current main: Problems
Suggested changes
Automated hermes-sweeper review. |
1 task
This was referenced Jul 30, 2026
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.
What does this PR do?
Fixes a subprocess leak in cron jobs when using the
codex_app_serverruntime. Each scheduled cron run creates a new ephemeral agent, which spawns acodex app-serversubprocess. The subprocess should be cleaned up when the job finishes, butagent.close()does not include_codex_sessioncleanup. This caused one leakedcodex app-serversubprocess per cron run until the gateway is restarted.The fix adds a
close_codex_session()helper inagent/codex_runtime.py(idempotent, safe to call multiple times) and calls it from cron's_teardown_cron_agent()function in thefinallyblock afteragent.close().Related Issue
Fixes #62101
Type of Change
Changes Made
agent/codex_runtime.py: Addclose_codex_session()helper function that safely closes the Codex app-server session if it existscron/scheduler.py: Callclose_codex_session()in_teardown_cron_agent()afteragent.close()to prevent subprocess leaksHow to Test
provider: openai-codexwithopenai_runtime: codex_app_serverhermes cron create "0 8,13,18 * * *" "echo test"hermes gateway --platform telegramcodex app-serverprocesses:ps -axo pid,ppid,lstart,command | grep "codex app-server"codex app-serversubprocesses remain after each cron job completesObserved result: The issue reporter verified locally that after this patch, a manual
hermes cron runleaves nocodex app-serverprocess behind once the job completes.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/A