fix(cron): catch RuntimeError from Path.expanduser() in lifecycle guard - #56517
Open
srojk34 wants to merge 1 commit into
Open
fix(cron): catch RuntimeError from Path.expanduser() in lifecycle guard#56517srojk34 wants to merge 1 commit into
srojk34 wants to merge 1 commit into
Conversation
cron/lifecycle_guard.py::_resolve_script_path calls Path(script_path).expanduser() to resolve a cron job's script path before scanning it for gateway-lifecycle commands. Path.expanduser() raises RuntimeError (not OSError) for a ~user-shaped path with no matching system user -- e.g. an LLM-authored script value that happens to start with ~someuser/... -- but _read_script_for_scanning only caught OSError, so the RuntimeError propagated uncaught through cron.jobs.create_job, crashing cron job creation (reachable via both the CLI and the agent's cronjob model tool) instead of degrading to "can't scan it". Same bug class already fixed in agent/subdirectory_hints.py (c126a99). Add RuntimeError to the caught exceptions, verified live: the new regression test fails with an uncaught RuntimeError before this change and passes after.
Open
4 tasks
13 tasks
teknium1
reviewed
Jul 15, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for isolating the creation-time failure and adding a targeted regression test. The premise is confirmed on current main: cron/lifecycle_guard.py:89 expands the supplied script path while :108 catches only OSError; cron/jobs.py:1158-1159 invokes that guard from the shared creation chokepoint.
Problems
- The same accepted
scriptvalue still reaches an unguardedPath(script_path).expanduser()incron/scheduler.py:2050, before_run_job_script's error-to-result handling. With this PR, a~unknown-user/...script no longer fails at creation but can still raise when the job fires.
Suggested changes
- Convert that scheduler-side
RuntimeErrorinto the normal failed-script result and cover the runtime path with the same unknown-user tilde input. - Add a
create_job-level assertion for the new creation-time contract, in addition to the direct guard test.
Automated hermes-sweeper review.
| "utf-8", errors="replace" | ||
| ) | ||
| except OSError: | ||
| except (OSError, RuntimeError): |
Contributor
There was a problem hiding this comment.
Please handle the same ~unknown-user input in cron/scheduler.py:2050: _run_job_script() calls Path(script_path).expanduser() before its exception-to-result handling. This catch now permits creation, but the scheduled run can still raise RuntimeError instead of returning the documented failed-script tuple.
This was referenced Jul 31, 2026
13 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
cron/lifecycle_guard.py::_resolve_script_pathcallsPath(script_path).expanduser()to resolve a cron job'sscriptpath before scanning it for gateway-lifecycle commands (check_gateway_lifecycle, enforced incron.jobs.create_job— reachable via bothhermes cron createand the agent'scronjobmodel tool directly).Path.expanduser()raisesRuntimeError(notOSError) for a~user-shaped path with no matching system user:_read_script_for_scanning'sexcept OSError:doesn't catch this, so an LLM-authoredscriptvalue that happens to start with~someuser/...(a plausible thing for an agent to produce — the same trigger shape already fixed foragent/subdirectory_hints.pyin #c126a99fc, "LLMs use~for 'approximately'" or a guessed/malformed path) crashes cron job creation with an unhandledRuntimeErrorinstead of the intended gracefulGatewayLifecycleBlocked/pass-through behavior the module is designed around.Fix
Add
RuntimeErrorto the caught exceptions in_read_script_for_scanning, mirroring the exact fix already applied toagent/subdirectory_hints.py's threePath.expanduser()/Path.home()call sites in #c126a99fc.Test plan
test_tilde_unknown_user_script_does_not_crash— confirmed it fails with an uncaughtRuntimeErroron the pre-fix code (viagit stash) and passes after the fixpytest tests/hermes_cli/test_gateway_restart_loop.py -q— 66 passedruff checkon all changed files — cleancron/jobs.py,cron/scheduler.py) that does not includecron/lifecycle_guard.py— confirmed viagh pr view --json files. No overlap.