Skip to content

fix(cron): record no_agent runs as sessions so they show in run history - #53692

Closed
yingliang-zhang wants to merge 1 commit into
NousResearch:mainfrom
yingliang-zhang:fix/no-agent-cron-run-sessions
Closed

fix(cron): record no_agent runs as sessions so they show in run history#53692
yingliang-zhang wants to merge 1 commit into
NousResearch:mainfrom
yingliang-zhang:fix/no-agent-cron-run-sessions

Conversation

@yingliang-zhang

Copy link
Copy Markdown
Contributor

Problem

no_agent: true cron jobs short-circuit run_job() (cron/scheduler.py) before any SessionDB work, so they never produce the cron_{job_id}_{timestamp} session row that the run-history endpoint (GET /api/cron/jobs/{id}/runs, backed by SessionDB.list_cron_job_runs) is built from. Manually triggering such a job from the Desktop GUI gives zero feedback: no running indicator, no run record, no output — the script runs fine, the GUI just can't see it.

Reported in #44080 and #42433.

Fix

In the no_agent branch of run_job():

  • Before executing the script, create the run session (cron_{job_id}_{ts}, source='cron' — the exact shape the agent path produces) plus a short user message (no_agent script: <path>) that becomes the run's preview. Because the session is open while the script runs, the runs endpoint's existing is_active computation now yields a running indicator for in-flight manual triggers, with no frontend changes needed.
  • After execution, persist the outcome doc (status + script output, already redacted by _run_job_script) as an assistant message, title the session using the same scheme as the agent path, and end_session(..., "cron_complete").

This covers all four exit paths: success, script failure, empty-stdout silent run, and wakeAgent=false silent run.

Design notes

  • Best-effort recording. A missing/broken state store degrades to the old no-record behaviour and never blocks the script run (guarded the same way the agent path guards its SessionDB use).
  • The no_agent cost contract is preserved. run_agent/AIAgent are still never imported on this path (existing test_run_job_no_agent_never_invokes_aiagent still passes); the only addition is a cheap sqlite session write.
  • No new surface. The Desktop GUI, /runs endpoint, and list_cron_job_runs already do the right thing once the session rows exist — the fix is purely making the no_agent path produce the records everything else already consumes.

Tests

Added to tests/cron/test_cron_no_agent.py:

  • test_run_job_no_agent_success_records_run_session — success run appears in list_cron_job_runs with source='cron', ended state, cron_complete, and the script output persisted in the run's messages
  • test_run_job_no_agent_failure_records_run_session — failed run is recorded (not silent) with cron_failed end reason
  • test_run_job_no_agent_silent_records_run_session — silent run (empty stdout) still leaves a run record
  • test_run_job_no_agent_broken_session_store_does_not_break_run — a broken SessionDB raising doesn't break the run itself

The shared hermes_env fixture now also reloads hermes_state so DEFAULT_DB_PATH (bound at import time) points at the per-test HERMES_HOME — keeping the new tests hermetic.

tests/cron/: 22 passed, 0 failures.

Relationship to existing PR

Supersedes #44087 — same approach, rebased on current main (1479 commits ahead of #44087's base) so it merges cleanly without conflicts.

Fixes #44080.
Related: #42433, #41935.

no_agent cron jobs short-circuit run_job() before any SessionDB work,
so they never produce the cron_{job_id}_{timestamp} session row that the
run-history endpoint (GET /api/cron/jobs/{id}/runs, backed by
SessionDB.list_cron_job_runs) is built from. Manually triggering such a
job from the Desktop GUI gives zero feedback: no running indicator, no
run record, no output — the script runs fine, the GUI just can't see it.

Fix: in the no_agent branch of run_job(), create the run session
(cron_{job_id}_{ts}, source='cron') BEFORE executing the script so the
runs endpoint's is_active computation yields a running indicator for
in-flight manual triggers. After execution, persist the outcome doc as
an assistant message, title the session, and end_session. Covers all
four exit paths: success, script failure, empty-stdout silent run, and
wakeAgent=false silent run.

Best-effort: a missing/broken state store degrades to the old no-record
behaviour and never blocks the script run. The no_agent cost contract
is preserved — run_agent/AIAgent are still never imported on this path.

Supersedes NousResearch#44087 (same approach, rebased on current main).
Fixes NousResearch#44080, NousResearch#42433.
@alt-glitch alt-glitch added type/bug Something isn't working comp/cron Cron scheduler and job management P3 Low — cosmetic, nice to have duplicate This issue or pull request already exists labels Jun 27, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #44087 — same fix for #44080: both create the cron_{job}_{ts} session row in the no_agent branch of run_job() (cron/scheduler.py) so manually-triggered no_agent jobs show a running indicator + run record in the Desktop GUI, while preserving the no_agent cost contract. #44087 (open since 2026-06-11) is the earlier canonical PR. Flagging for a maintainer to pick the canonical fix.

@yingliang-zhang

Copy link
Copy Markdown
Contributor Author

Closing as duplicate of #44087 (open since 2026-06-11, earlier canonical). Both create the cron_{job}_{ts} session row in the no_agent branch of run_job() so manually-triggered no_agent jobs show in run history. Deferring to the earlier PR.

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 P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Desktop GUI shows no execution status/output after manually triggering no_agent cron jobs

2 participants