Skip to content

fix(cron): prevent lifecycle guard crash on binary remote-read paths - #79041

Closed
o269 wants to merge 1 commit into
NousResearch:mainfrom
o269:fix/lifecycle-guard-null-byte-godmode-bus-t_89477e96
Closed

fix(cron): prevent lifecycle guard crash on binary remote-read paths#79041
o269 wants to merge 1 commit into
NousResearch:mainfrom
o269:fix/lifecycle-guard-null-byte-godmode-bus-t_89477e96

Conversation

@o269

@o269 o269 commented Aug 5, 2026

Copy link
Copy Markdown

Summary

  • Fixes ValueError: embedded null byte crash in cron/lifecycle_guard.py when the gateway terminal tool scans shell scripts that reference system binaries (e.g. /usr/bin/flock in godmode-bus/bin/disk-watchdog.sh)
  • Root cause: _read_referenced_script correctly skips local binary reads, but the read_remote_script callback (used by terminal_tool.py in _HERMES_GATEWAY sessions) decodes ELF contents with NUL bytes intact; tokenizing that machine code produced paths with embedded NULs, crashing os.open
  • Workaround before fix: copy script to /tmp first (bypasses the recursive binary scan path)

Fix (3 defensive layers, same class as #76762)

Site Change
_iter_command_segments() Strip \x00 before tokenization
_read_referenced_script() except (OSError, ValueError) at os.open
_contains_unsafe_gateway_action() Skip remote-read content containing NUL bytes
_resolve_script_path() NUL-strip before Path() construction

Test plan

  • tests/hermes_cli/test_gateway_restart_loop.py84 passed
  • New regression: test_remote_read_of_binary_does_not_crash_the_guard (ELF via remote callback)
  • New regression: test_shell_script_referencing_system_binary_does_not_crash_guard (flock-shaped godmode-bus script)
  • Manual repro: bash ~/godmode-bus/bin/disk-watchdog.sh with read_remote_script callback → no crash

Made with Cursor

When the gateway terminal tool scans shell scripts that reference system
binaries (e.g. /usr/bin/flock in godmode-bus watchdog scripts), the
remote-read callback decodes ELF contents with NUL bytes intact. Tokenizing
that machine code produced paths with embedded NULs, causing os.open to
raise ValueError and block every terminal command until gateway recovery.

- Catch ValueError alongside OSError in _read_referenced_script os.open
- Skip remote-read content that contains NUL bytes (binary → nothing to scan)
- Strip NUL bytes in _iter_command_segments before tokenization
- Strip NUL bytes in _resolve_script_path for cron script values

Fixes godmode-bus/bin/*.sh execution via Hermes terminal tool (NousResearch#76762).

Co-authored-by: Cursor <cursoragent@cursor.com>
@alt-glitch alt-glitch added type/bug Something isn't working comp/cron Cron scheduler and job management tool/terminal Terminal execution and process management P2 Medium — degraded but workaround exists needs-decision Awaiting maintainer decision before any implementation labels Aug 5, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Related: #79038 repairs the same lifecycle-guard crash by preventing remote binary fallback; this PR uses NUL sanitization plus a defensive catch. These are competing mechanisms for #77780 and need maintainer selection.

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Closing as superseded by #80258, which fixes this whole bug class architecturally rather than per-callsite: path candidates are sanitized once at the ingestion boundary (NUL/empty/unexpandable tokens rejected before any OS call), text from any read_remote_script callback is sanitized at the recursion boundary (NUL = binary = nothing to scan; >1 MiB = fail closed), the remote fallback read is bounded at the source (head -c, so oversized binaries never cross the wire), and the public guard is total by construction — an unexpected walk failure logs and falls back to the direct-scan verdict instead of breaking every terminal command.

Your report and fix targeted a real member of this class — thank you. The per-callsite patches kept leaving sibling frames exposed (#76762#77703#77780#78256 each crashed one frame away from the previous fix), which is why we went with the boundary fix instead of merging the fragments individually. #80258 carries regression tests for the NUL-path, binary-callback, oversized-read, unset-HOME, and walk-crash cases plus an adversarial never-raises sweep.

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 needs-decision Awaiting maintainer decision before any implementation P2 Medium — degraded but workaround exists tool/terminal Terminal execution and process management type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants