Skip to content

feat(cron): support structured script payloads - #26474

Open
JackALaing wants to merge 1 commit into
NousResearch:mainfrom
JackALaing:feat/cron-structured-script-payloads
Open

feat(cron): support structured script payloads#26474
JackALaing wants to merge 1 commit into
NousResearch:mainfrom
JackALaing:feat/cron-structured-script-payloads

Conversation

@JackALaing

Copy link
Copy Markdown

Summary

  • Teach cron pre-run scripts to return a structured JSON object that can replace {{ var }} prompt placeholders via template_vars.
  • Allow structured payloads to prepend explicit context with prepend_context, while preserving the existing raw stdout context behavior for non-JSON output.
  • Track cleanup_paths from structured payloads and remove those temporary script artifacts after the cron job finishes.

Test Plan

  • python -m pytest tests/cron/test_scheduler.py -q
  • python -m py_compile cron/scheduler.py

Platforms Tested

  • macOS / Darwin arm64, Python 3.13.13

Related / competing PRs

Searches run for cron structured payload, script payload, scheduled job script, cron script, and deliver found no PR that fully supersedes this structured payload contract.

Adjacent cron script/delivery PRs:

  • PR #19709 merged no_agent script-only cron jobs; this PR keeps the LLM-backed pre-run script path and only shapes script output before prompt execution.
  • PR #20354, PR #19810, PR #20323, and PR #21397 touch cron script invocation details such as arguments, environment, failure status, and workdir. They are complementary to this PR's stdout payload contract.
  • PR #21438 and PR #21441 adjust Discord/Slack threading and delivery mirroring. This PR intentionally avoids delivery routing, Discord thread semantics, media attachments, and mirror history.

Notes/Risks

  • Cross-platform impact: this touches cron script output handling and cleanup of files named by script payloads. Cleanup uses pathlib.Path and only unlinks paths that currently exist as files.
  • Structured payload parsing only applies when the script stdout is a JSON object. Non-JSON stdout continues to be prepended as the existing script-output context block.

@alt-glitch alt-glitch added P3 Low — cosmetic, nice to have type/feature New feature or request comp/cron Cron scheduler and job management labels May 15, 2026

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:891 records cleanup_paths only while building the prompt. Current main exits on a successful wakeAgent=false result at cron/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 at cron/scheduler.py:2412-2425. The structured branches need the same treatment, otherwise command-shaped feed data in prepend_context can be blocked despite the established contract in tests/cron/test_cron_prompt_injection_skill.py:359-395.

Suggested changes

  • Register cleanup metadata before the wake-gate return and add a wakeAgent:false cleanup 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.

Comment thread cron/scheduler.py
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 []

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread cron/scheduler.py
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):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@teknium1 teknium1 added sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 13, 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 sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants