Skip to content

fix(cron): fail jobs when pre-run script fails instead of greenwashing as ok - #20326

Closed
konsisumer wants to merge 1 commit into
NousResearch:mainfrom
konsisumer:fix/cron-prerun-script-failure-greenwash
Closed

fix(cron): fail jobs when pre-run script fails instead of greenwashing as ok#20326
konsisumer wants to merge 1 commit into
NousResearch:mainfrom
konsisumer:fix/cron-prerun-script-failure-greenwash

Conversation

@konsisumer

Copy link
Copy Markdown
Contributor

Stop marking cron jobs as last_status=ok when their pre-run script failed.

What changed and why

  • cron/scheduler.py::run_job now short-circuits on pre-run script failure — when _run_job_script returns success=False, the job exits with success=False, the script output as the error, and a "pre-run script failed" status doc, instead of injecting the error into an agent prompt and burning an LLM call. mark_job_run already records last_status=error for success=False, and _process_job already delivers the failure message to the configured target.
  • This mirrors the existing no_agent path's failed-script handling (cron/scheduler.py:912-929), so both paths now behave consistently: a broken pre-run script always surfaces as error, never as ok.
  • Updated TestRunJobWakeGate.test_script_failure_does_not_trigger_gate (which previously asserted the old greenwashing behavior — "agent DID wake despite the gate-like text") to assert the new contract: agent is not invoked, success is False, and the script error is captured. The gate-bypass safety property the original test cared about (don't honor wakeAgent: false from a failed script's stderr) is still upheld — we just fail-fast instead of waking the agent.

How to test

  • pytest tests/cron/ -q — all 318 cron tests pass (one pre-existing failure on test_script_empty_output_noted reproduces on main, unrelated to this fix).
  • pytest tests/run_agent/test_exit_cleanup_interrupt.py -q — passes (these tests patch _build_job_prompt and exercise run_job cleanup paths).
  • Manual repro: create a cron job with script pointing to a script that exit 1s, run a tick, and check cron listlast_status is now error with the script's stderr in last_error.

What platforms tested on

  • macOS on darwin-arm64 (local)

Fixes #20301

…g as ok

When a cron job's pre-run script returned non-zero (or timed out), run_job
captured the error, injected it into the agent prompt, and let the LLM
generate a response — which then marked the job last_status=ok. Operators
saw "ok" while the data-collection step had crashed and the agent was
fabricating output from a polluted prompt.

Short-circuit run_job at the same point the no_agent path already does:
on script failure, return success=False with the script output as the
error and a "pre-run script failed" status in the job doc. mark_job_run
already records this as last_status=error, and _process_job already
delivers the error to the user.

Fixes NousResearch#20301
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cron Cron scheduler and job management labels May 5, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Competing fix with #20323 — both address #20301. This PR short-circuits on script failure; #20323 adds a _script_failed flag. This PR is more focused (only cron/scheduler.py + tests).

@konsisumer

Copy link
Copy Markdown
Contributor Author

Closing — deferring to #20323 by @liuhao1024 which addresses the same. Reopen if that PR stalls.

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 P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cron: pre-run script failures silently greenwashed as success (status=ok)

2 participants