Repository navigation
feat(cron): script payloads behind the trigger gate - #111112
Conversation
There was a problem hiding this comment.
💡 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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 👍 / 👎.
| const hasScriptPatch = | ||
| Boolean(scriptPath) || | ||
| scriptTimeoutSeconds !== undefined || | ||
| scriptToolBudget !== undefined; |
There was a problem hiding this comment.
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.
94b91d4 to
c4d2c47
Compare
There was a problem hiding this comment.
💡 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".
| cronScriptPayloadSchema({ | ||
| script: Type.String({ minLength: 1, maxLength: 65_536 }), | ||
| toolsAllow: Type.Array(Type.String()), | ||
| }), |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 👍 / 👎.
| if (hasAgentTurnSignal) { | ||
| payload.kind = "agentTurn"; | ||
| } else if (isNonEmptyString(payload.script)) { | ||
| payload.kind = "script"; |
There was a problem hiding this comment.
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 👍 / 👎.
|
Merged via squash.
|
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.
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.
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 existingcron.triggers.enableddangerous-config gate — creation rejected and execution errors when disabled. Result contract{ notify?, wake?, state?, nextCheck? }:statepersists 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);notifyflows 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);wakeenqueues a sanitized system event and wakes the main session via the shared cron wake helpers;nextCheckfeeds the identical clamped pacing path as agentnext_checkproposals; without pacing it errors rather than being ignored.sessionTargetlimited tomain/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