feat(cron): support structured script payloads - #26474
Conversation
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the focused cron extension. The structured-output feature is not present on current main, so this is worth salvaging, but it needs updates for the current scheduler flow.
Problems
cron/scheduler.py:891recordscleanup_pathsonly while building the prompt. Current main exits on a successfulwakeAgent=falseresult atcron/scheduler.py:2632-2645, before prompt construction, so those artifacts are never registered or removed.- Current main marks ordinary script stdout as injected data at
cron/scheduler.py:2177-2200; that selects the runtime-data scanner atcron/scheduler.py:2412-2425. The structured branches need the same treatment, otherwise command-shaped feed data inprepend_contextcan be blocked despite the established contract intests/cron/test_cron_prompt_injection_skill.py:359-395.
Suggested changes
- Register cleanup metadata before the wake-gate return and add a
wakeAgent:falsecleanup regression test. - Carry the injected-data state through structured payload handling, with tests for command-shaped context and genuine injection directives.
- Document the JSON payload fields in
website/docs/user-guide/features/cron.md.
Automated hermes-sweeper review.
| template_vars = script_payload.get("template_vars") or {} | ||
| if isinstance(template_vars, dict): | ||
| prompt = _replace_script_template_vars(prompt, template_vars) | ||
| cleanup_paths = script_payload.get("cleanup_paths") or [] |
There was a problem hiding this comment.
run_job performs the wakeAgent=false return before it calls _build_job_prompt on current main (cron/scheduler.py:2632-2645). A payload that includes cleanup_paths and suppresses the agent never reaches this assignment, so the final cleanup has nothing to unlink. Parse/register cleanup metadata before that gate and add a wake-gated regression test.
| if isinstance(template_vars, dict): | ||
| prompt = _replace_script_template_vars(prompt, template_vars) | ||
| cleanup_paths = script_payload.get("cleanup_paths") or [] | ||
| if isinstance(cleanup_paths, list): |
There was a problem hiding this comment.
When salvaging onto current main, structured prepend_context must set the same has_injected_data state used for ordinary script stdout (cron/scheduler.py:2177-2200). Without it, the assembled prompt takes the strict scanner path instead of the runtime-data path covered by tests/cron/test_cron_prompt_injection_skill.py:359-395.
Summary
{{ var }}prompt placeholders viatemplate_vars.prepend_context, while preserving the existing raw stdout context behavior for non-JSON output.cleanup_pathsfrom structured payloads and remove those temporary script artifacts after the cron job finishes.Test Plan
python -m pytest tests/cron/test_scheduler.py -qpython -m py_compile cron/scheduler.pyPlatforms Tested
Related / competing PRs
Searches run for
cron structured payload,script payload,scheduled job script,cron script, anddeliverfound no PR that fully supersedes this structured payload contract.Adjacent cron script/delivery PRs:
no_agentscript-only cron jobs; this PR keeps the LLM-backed pre-run script path and only shapes script output before prompt execution.Notes/Risks
pathlib.Pathand only unlinks paths that currently exist as files.