Skip to content

feat(cron): script payloads behind the trigger gate - #111112

Merged
steipete merged 1 commit into
mainfrom
claude/cron-script-payload
Jul 19, 2026
Merged

steipete merged 1 commit into
mainfrom
claude/cron-script-payload

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Implements script payloads for cron jobs (stage 4 of #110950).

What Problem This Solves

Cron work is either a model-backed agent turn or a raw shell command. There is no middle form: deterministic code that calls tools, processes data, keeps state, and only involves an agent (or a human) when it has something to say. Watchers approximate this with trigger scripts, but those are gates (30s/5 tools) — code cannot be the job.

Why This Change Was Made

payload.kind: "script" runs in the same headless QuickJS code-mode executor as trigger scripts (shared runtime, no second evaluator) with payload-grade budgets (default 300s/50 tool calls, capped 900s/200). Behind the existing cron.triggers.enabled dangerous-config gate — creation rejected and execution errors when disabled. Result contract { notify?, wake?, state?, nextCheck? }:

  • state persists via the trigger-state namespace (16KB, success-only, frozen prior state; script payload + condition trigger on one job is rejected since both would own that namespace);
  • notify flows through the standard delivery path — and absent notify delivers nothing, including webhook mode (silent scripts are silent everywhere; review caught the webhook completion-POST leaking and it now requires a summary for script payloads);
  • wake enqueues a sanitized system event and wakes the main session via the shared cron wake helpers;
  • nextCheck feeds the identical clamped pacing path as agent next_check proposals; without pacing it errors rather than being ignored.

sessionTarget limited to main/isolated (scripts have no conversational session). Errors/timeouts follow normal cron backoff + failure alerts; state does not persist on failure.

User Impact

Cron jobs can now be code: poll an API, diff against saved state, orchestrate subagents via sessions_send/delegate under normal tool policy, and surface only conclusions — without burning an agent turn per tick.

Evidence

  • Full cron + tool suites: 140 files / 1,715 tests, plus 249 focused delivery/webhook/gateway tests after the silence fix.
  • Whole-tree tsgo: zero errors outside known local net-policy noise. Generator sweep (prompt snapshots, protocol TS/Swift/Kotlin, docs map): clean, regenerated files committed. Knip clean. Heavy-suite run performed on a Blacksmith Testbox when the local heavy-check lock was contended (box stopped after).
  • Codex autoreview cycles: state-ownership, canonical-JSON persistence, thread routing, and the webhook-silence contract violation all caught and fixed; final run clean, "patch is correct (0.86)".
  • docs/automation/cron-jobs.md documents the payload, budgets, gate reuse, and result contract.

@steipete
steipete requested a review from a team as a code owner July 19, 2026 01:41
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime cli CLI command changes commands Command implementations agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Jul 19, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 94b91d4c9f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

import type { CronPayload } from "./types.js";

export const DEFAULT_CRON_SCRIPT_TIMEOUT_SECONDS = 300;
export const MAX_CRON_SCRIPT_TIMEOUT_SECONDS = 900;

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.

P2 Badge Honor script timeouts above five minutes

When a script job requests 301–900 seconds, this normalization accepts and persists that value, but runCodeModeScriptHeadless clamps wallClockMs to 300,000 ms in src/agents/code-mode.ts:1010. Consequently, a job configured for (for example) 600 seconds still times out after five minutes, contrary to the CLI and documented 900-second cap; either raise the executor limit or cap the script setting at 300 seconds.

Useful? React with 👍 / 👎.

export const DEFAULT_CRON_SCRIPT_TIMEOUT_SECONDS = 300;
export const MAX_CRON_SCRIPT_TIMEOUT_SECONDS = 900;
export const DEFAULT_CRON_SCRIPT_TOOL_BUDGET = 50;
export const MAX_CRON_SCRIPT_TOOL_BUDGET = 200;

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.

P2 Badge Honor script tool budgets above 128 calls

Script jobs accept and persist tool budgets up to 200 here, but the shared headless executor clamps maxToolCalls to 128 in src/agents/code-mode.ts:1011. Any configured budget from 129 through 200 therefore fails at 128 calls despite the stored value and public contract; align this maximum with the executor's actual limit or extend the executor.

Useful? React with 👍 / 👎.

Comment thread src/cli/cron-cli/register.cron-edit.ts Outdated
Comment on lines +509 to +512
const hasScriptPatch =
Boolean(scriptPath) ||
scriptTimeoutSeconds !== undefined ||
scriptToolBudget !== undefined;

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.

P2 Badge Route tool allowlist edits to script payloads

For an existing script job, cron edit <id> --tools exec or --clear-tools is still classified as an agent-turn patch by src/cli/cron-cli/register.cron-edit.ts:488-502, because the new script-patch predicate only recognizes script path, timeout, and budget. The CLI then sends an agentTurn patch without a message, which src/cron/service/payload-merge.ts rejects; combining --script with --tools instead triggers “Choose at most one payload change.” Include tool allowlist flags in script-patch routing when the stored or explicitly selected payload kind is script.

Useful? React with 👍 / 👎.

Run script payloads through the shared headless code-mode executor with payload-grade budgets and success-only trigger.state persistence.

Reuse cron delivery, wake, pacing, and dangerous trigger-gate contracts for notify, wake, and nextCheck results.
@steipete
steipete force-pushed the claude/cron-script-payload branch from 94b91d4 to c4d2c47 Compare July 19, 2026 02:13
@clawsweeper clawsweeper Bot added the rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. label Jul 19, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c4d2c47b18

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +269 to +272
cronScriptPayloadSchema({
script: Type.String({ minLength: 1, maxLength: 65_536 }),
toolsAllow: Type.Array(Type.String()),
}),

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.

P2 Badge Keep script jobs visible in Control UI

Adding this payload variant to the gateway response contract without updating the Control UI makes every script job disappear from its Cron page: ui/src/lib/cron/index.ts:80-93 rejects any payload kind other than systemEvent, agentTurn, or command, and ui/src/lib/cron/index.ts:571-573 filters rejected jobs out of the fetched list. Extend the UI CronPayload type and payload predicate/presentation for scripts, locking unsupported edit fields if full script editing is intentionally deferred.

Useful? React with 👍 / 👎.

const CRON_SCHEDULE_KINDS = ["at", "every", "cron"] as const;
const CRON_WAKE_MODES = ["now", "next-heartbeat"] as const;
const CRON_PAYLOAD_KINDS = ["systemEvent", "agentTurn"] as const;
const CRON_PAYLOAD_KINDS = ["systemEvent", "agentTurn", "script"] as const;

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.

P2 Badge Capture the creator route for isolated script jobs

When an agent creates the newly allowed isolated script payload without an explicit delivery target, the creation-delivery inference at src/agents/tools/cron-tool.ts:921-964 still runs only for agentTurn payloads. The isolated script also receives no session key, so a returned notify falls into the keyless implicit-delivery refusal at src/cron/isolated-agent/delivery-target.ts:304-340 and the cron run fails instead of notifying the conversation that created it. Include script payloads in the same route-capture path used for agent turns.

Useful? React with 👍 / 👎.

Comment on lines 248 to +251
if (hasAgentTurnSignal) {
payload.kind = "agentTurn";
} else if (isNonEmptyString(payload.script)) {
payload.kind = "script";

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.

P2 Badge Infer script kind before agent-only timeout hints

Because payload kind is optional in the model-facing schema, canonicalization is expected to infer it, but a payload such as { script: "return {}", timeoutSeconds: 300 } reaches the new script branch only after timeoutSeconds has already made hasAgentTurnSignal true. It is therefore rewritten to agentTurn, and gateway validation rejects it for lacking message. Check for a non-empty script before agent-turn-only hints (and keep its timeout/tool-budget fields with it).

Useful? React with 👍 / 👎.

@steipete
steipete merged commit 68771eb into main Jul 19, 2026
128 checks passed
@steipete
steipete deleted the claude/cron-script-payload branch July 19, 2026 02:24
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 19, 2026
Run script payloads through the shared headless code-mode executor with payload-grade budgets and success-only trigger.state persistence.

Reuse cron delivery, wake, pacing, and dangerous trigger-gate contracts for notify, wake, and nextCheck results.
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
Run script payloads through the shared headless code-mode executor with payload-grade budgets and success-only trigger.state persistence.

Reuse cron delivery, wake, pacing, and dangerous trigger-gate contracts for notify, wake, and nextCheck results.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui cli CLI command changes commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant