Skip to content

fix(cron): emit load-time warning for non-dict origin in jobs.json#20767

Open
Beandon13 wants to merge 1 commit into
NousResearch:mainfrom
Beandon13:fix/hermes-20725-cron-string-origin-guard
Open

fix(cron): emit load-time warning for non-dict origin in jobs.json#20767
Beandon13 wants to merge 1 commit into
NousResearch:mainfrom
Beandon13:fix/hermes-20725-cron-string-origin-guard

Conversation

@Beandon13

Copy link
Copy Markdown
Contributor

Summary

Relates to #20725.

The scheduler's _resolve_origin already silently treats non-dict origin values (strings, ints, lists written by migration scripts or hand-edits of jobs.json) as missing — no crash occurs on tick. However, operators had no visibility into the bad field until it appeared in the run-time error log after the first failed fire.

What this adds

A new _warn_non_dict_origins() helper in cron/jobs.py is called inside load_jobs() for both the normal JSON parse path and the strict=False auto-repair path. It emits a logger.warning for every job whose origin is non-null and non-dict, naming the job, its id, and the offending value. Null origin and well-formed dict origin are unaffected.

This surfaces the problem at load time (gateway startup, daemon tick) rather than waiting for the job to fire.

Relationship to prior fix

The isinstance(origin, dict) guard in cron/scheduler.py's _resolve_origin (added for #18722) prevents the crash. This PR adds the operator-facing early warning that lets users discover and repair bad origin values without needing to wait for a run-time error.

Example warning output

WARNING cron.jobs: Job 'Phase job' (id=abc123) has a non-dict 'origin' field ('phase-a.5');
it will be treated as missing.  Update the job's origin to a dict with 'platform' and
'chat_id' keys, or set it to null.

Tests added (tests/cron/test_jobs.py)

  • test_string_origin_emits_warning — string origin triggers warning
  • test_various_non_dict_origins_emit_warning — parametrised: str / int / list / float
  • test_null_origin_does_not_warn — null origin is silent
  • test_dict_origin_does_not_warn — valid dict origin is silent

Test plan

  • python3 -m py_compile cron/jobs.py passes
  • python3 -m py_compile tests/cron/test_jobs.py passes
  • New TestLoadJobsNonDictOriginWarning tests pass (pytest tests/cron/test_jobs.py -k NonDictOrigin -v)
  • Existing cron/jobs tests unaffected
  • Manual: set origin: "phase-tag" on a job in jobs.json, restart gateway — confirm warning appears in logs before any job fires

🤖 Generated with Claude Code

…ousResearch#20725)

The scheduler's _resolve_origin already silently treats non-dict origin
values (strings, ints, lists written by migration scripts or hand-edits
of jobs.json) as missing — no crash occurs on tick.  However, operators
had no visibility into the bad field until it surfaced in the run-time
error log after the first failed fire.

Add _warn_non_dict_origins() to cron/jobs.py and call it inside
load_jobs() for both the normal JSON parse path and the strict=False
auto-repair path.  A logger.warning is emitted for every job whose
origin is non-null and non-dict, naming the job, its id, and the
offending value.  Null origin and well-formed dict origin are unaffected.

Complements the existing _resolve_origin isinstance guard in
cron/scheduler.py (introduced for the same class of error in NousResearch#18722)
with an operator-facing early warning that fires at gateway startup /
daemon tick rather than at job execution time.

Adds four regression tests in tests/cron/test_jobs.py:
- string origin emits warning
- parametrised: str / int / list / float all emit warning
- null origin does not warn
- dict origin does not warn

Fixes NousResearch#20725

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/cron Cron scheduler and job management labels May 6, 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 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.

2 participants