Skip to content

fix(cron): catch ValueError on os.open in lifecycle guard - #77974

Closed
Braincramps wants to merge 1 commit into
NousResearch:mainfrom
Braincramps:fix/lifecycle-guard-null-byte
Closed

fix(cron): catch ValueError on os.open in lifecycle guard#77974
Braincramps wants to merge 1 commit into
NousResearch:mainfrom
Braincramps:fix/lifecycle-guard-null-byte

Conversation

@Braincramps

Copy link
Copy Markdown

Summary

Fixes the null-byte hang in cron/lifecycle_guard.py that can freeze an agent turn for minutes.

Problem

  • Introduced in v0.20.0 (new file, added 2026-08-03).
  • _read_referenced_script calls os.open(path) but only caught OSError.
  • A path containing a NUL byte raises ValueError ("embedded null byte"), not OSError.
  • When the model emits such a path in a terminal command, the guard scans it as a referenced script, the uncaught ValueError propagates, and the whole turn hangs (~17 min observed).

Fix

Catch (OSError, ValueError) and return (None, False) so a malformed path is skipped gracefully instead of stalling the turn. Line 260 is the only os.open call site in the file, so this single patch covers the guard.

Verification

  • Confirmed os.open on a null-byte path previously raised ValueError; now returns gracefully.
  • Only call site; confirmed there are no sibling os.open call sites.

lifecycle_guard's _read_referenced_script only caught OSError around
os.open(), but a path containing a NUL byte raises ValueError ("embedded
null byte"). When the model emits such a path in a terminal command, the
uncaught ValueError propagates out of the guard and hangs the whole turn
for minutes (~17m observed) while the agent waits on a dead scan.

Catch (OSError, ValueError) and return (None, False) so a malformed path is
skipped gracefully instead of stalling the turn.
@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 duplicate This issue or pull request already exists labels Aug 3, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #77729: it contains the same os.open ValueError guard and also covers the remote-read binary fallback with regression tests.

@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 duplicate This issue or pull request already exists 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.

4 participants