Skip to content

fix(cron): skip AI call when script produces no output - #15223

Closed
hex-clawd wants to merge 1 commit into
NousResearch:mainfrom
hex-clawd:fix/cron-skip-empty-script
Closed

hex-clawd wants to merge 1 commit into
NousResearch:mainfrom
hex-clawd:fix/cron-skip-empty-script

Conversation

@hex-clawd

Copy link
Copy Markdown
Contributor

Problem

When a cron job has a pre-run script that runs successfully but produces no output (e.g., an email checker with an empty inbox), the scheduler injects [Script ran successfully but produced no output.] into the prompt and still calls the AI model. For jobs running every 5 minutes, that's 288 API calls/day of pure waste — burning tokens even when there is genuinely nothing to report.

Fix

  • _build_job_prompt() now returns None when the script succeeds with empty output
  • run_job() checks for None and short-circuits with (True, "", SILENT_MARKER, None) — returning the standard 4-tuple with a silent response
  • The existing [SILENT] delivery suppression path handles the rest
  • Zero API calls when there is nothing to report

Example

An email checker script that prints nothing when there are no new emails:

  • Before: AI called every 5 min → tokens burned → AI generates [SILENT] → delivery suppressed (but tokens already spent)
  • After: Script prints nothing → scheduler returns early → no AI call at all

Edge Cases

  • Script errors are unaffected — they still get reported to the AI as before
  • Script with output works exactly as before — output gets prepended to the prompt
  • Script gate (wakeAgent=false) already had its own early-return; this is separate

Fixes: N/A (new issue discovered in production use)

When a cron job has a pre-run script that runs successfully but produces
no output (e.g. email checker with no new mail), the scheduler previously
injected "[Script ran successfully but produced no output.]" into the
prompt and still called the AI model. This wastes tokens on every cycle.

Now _build_job_prompt() returns None when script output is empty, and
run_job() short-circuits with a SILENT response - zero API calls when
there is nothing to report.
@alt-glitch alt-glitch added type/perf Performance improvement or optimization P2 Medium — degraded but workaround exists comp/cron Cron scheduler and job management labels Apr 24, 2026
@alt-glitch

Copy link
Copy Markdown
Contributor

Competing with #10855 and #9300 (same skip-on-empty-output approach). Related feature request: #10656.

@teknium1

teknium1 commented May 4, 2026

Copy link
Copy Markdown
Collaborator

Salvaged via #19628 onto current main - your commit authorship was preserved. Thanks!

@teknium1 teknium1 closed this May 4, 2026
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/perf Performance improvement or optimization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants