Skip to content

fix(cron): ignore pathlib division in lifecycle guard - #77137

Closed
Rashoooodi wants to merge 3 commits into
NousResearch:mainfrom
Rashoooodi:rashoooodi/fix-77131-pathlib-guard
Closed

fix(cron): ignore pathlib division in lifecycle guard#77137
Rashoooodi wants to merge 3 commits into
NousResearch:mainfrom
Rashoooodi:rashoooodi/fix-77131-pathlib-guard

Conversation

@Rashoooodi

Copy link
Copy Markdown

Summary

  • avoid treating the standalone / arithmetic operator in Python pathlib expressions as an executable script path
  • add regression coverage for no-agent Python cron scripts using Path.home() / ...

Fixes #77131.

Verification

  • direct lifecycle-guard regression checks pass
  • python3 -m compileall -q cron/lifecycle_guard.py tests/hermes_cli/test_gateway_restart_loop.py
  • git diff --check passes

The repository checkout did not have pytest installed, so the focused pytest command was attempted but could not run (No module named pytest).

Copilot AI review requested due to automatic review settings August 2, 2026 22:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a regression in the cron lifecycle guard where Python pathlib expressions containing a standalone / token (e.g., Path.home() / ".hermes") were mistakenly treated as executable script references, causing no_agent=True Python cron job creation to be blocked.

Changes:

  • Adjust referenced-shell-script detection to ignore a standalone "/" token during scanning.
  • Add a regression test ensuring a Python script containing Path.home() / ... is not blocked by check_gateway_lifecycle().

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
cron/lifecycle_guard.py Refines _iter_referenced_shell_scripts() to avoid treating a standalone / token as an executable path.
tests/hermes_cli/test_gateway_restart_loop.py Adds a regression test covering Python pathlib division (Path.home() / ...) to prevent the false-positive block.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cron/lifecycle_guard.py Outdated
Comment on lines +222 to +226
# A standalone slash is a Python arithmetic operator in expressions
# such as ``Path.home() / ".hermes"``. It is not an executable path;
# treating it as one makes the scanner resolve ``/`` and fail closed
# on every ordinary pathlib-based Python cron script.
if (executable != "/" and "/" in executable) or executable.endswith(
@alt-glitch alt-glitch added type/bug Something isn't working comp/cron Cron scheduler and job management P1 High — major feature broken, no workaround labels Aug 2, 2026

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for isolating the standalone-/ pathlib failure; that false positive is real on current main.

Problems

  • cron/lifecycle_guard.py:226 only excludes the exact / token. Path("/tmp") / "x" tokenizes into /tmp and /; /tmp still enters the referenced-script walk and fails closed because it is a directory. The existing Copilot inline review identifies this same case.
  • The new test at tests/hermes_cli/test_gateway_restart_loop.py:631 covers Path.home() but not an absolute-string pathlib operand.

Suggested changes

  • Align the guard with cron/scheduler.py:2204-2284: shell-reference traversal should be scoped to scripts the scheduler invokes through Bash, while retaining direct lifecycle-command detection for Python scripts.
  • Add a regression case for Path("/tmp") / "x".

Automated hermes-sweeper review.

Comment thread cron/lifecycle_guard.py Outdated
# such as ``Path.home() / ".hermes"``. It is not an executable path;
# treating it as one makes the scanner resolve ``/`` and fail closed
# on every ordinary pathlib-based Python cron script.
if (executable != "/" and "/" in executable) or executable.endswith(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only exempts the exact / token. Path("/tmp") / "x" tokenizes into /tmp and /, so /tmp still reaches the referenced-script walk and fails closed as a directory. Please cover absolute-path pathlib operands or scope shell-reference scanning to scripts actually run through Bash.

@teknium1 teknium1 added sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Aug 2, 2026
@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Merged via #77332 which salvaged @criptogus's implementation from #77201 — the most thorough of the three competing fixes. Your approach (removing "/" in executable entirely) would have weakened shell-script chain detection; #77201's executable.strip("/") approach preserved that defense-in-depth. Thanks for the contribution!

#77332

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cron Cron scheduler and job management P1 High — major feature broken, no workaround sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cron lifecycle guard blocks ALL .py no-agent job creation (pathlib '/' false positive)

5 participants