fix(cron): emit load-time warning for non-dict origin in jobs.json#20767
Open
Beandon13 wants to merge 1 commit into
Open
fix(cron): emit load-time warning for non-dict origin in jobs.json#20767Beandon13 wants to merge 1 commit into
Beandon13 wants to merge 1 commit into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Relates to #20725.
The scheduler's
_resolve_originalready silently treats non-dictoriginvalues (strings, ints, lists written by migration scripts or hand-edits ofjobs.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 incron/jobs.pyis called insideload_jobs()for both the normal JSON parse path and thestrict=Falseauto-repair path. It emits alogger.warningfor every job whoseoriginis non-null and non-dict, naming the job, its id, and the offending value. Nulloriginand well-formed dictoriginare 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 incron/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 badoriginvalues without needing to wait for a run-time error.Example warning output
Tests added (
tests/cron/test_jobs.py)test_string_origin_emits_warning— string origin triggers warningtest_various_non_dict_origins_emit_warning— parametrised: str / int / list / floattest_null_origin_does_not_warn— null origin is silenttest_dict_origin_does_not_warn— valid dict origin is silentTest plan
python3 -m py_compile cron/jobs.pypassespython3 -m py_compile tests/cron/test_jobs.pypassesTestLoadJobsNonDictOriginWarningtests pass (pytest tests/cron/test_jobs.py -k NonDictOrigin -v)origin: "phase-tag"on a job injobs.json, restart gateway — confirm warning appears in logs before any job fires🤖 Generated with Claude Code