Repository navigation
feat(cron): let trigger and script automations call MCP servers named in toolsAllow - #160995
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 29, 2026, 2:00 PM ET / 18:00 UTC (Revision 7). ClawSweeper reviewWhat this changesScheduled condition scripts and script payloads can call explicitly allowed MCP server tools and retire each evaluation’s MCP runtime afterward. Merge readiness✅ Ready for maintainer review Keep open. Current main excludes MCP tools from headless cron scripts, and this PR provides distinct, supported behavior. Earlier outage, server-name, and eager-start findings are addressed at the current head; no new blocking defect is established. Priority: P2 Review scores
Verification
How this fits togetherCron runs scheduled jobs and evaluates condition scripts before deciding whether to run their payloads. The headless script executor receives the job’s tool limits and returns a quiet, fired, completed, or error result to the scheduler. flowchart LR
A[Scheduled job] --> B[Condition or payload script]
B --> C[Per-job tool limits]
C --> D[Allowed MCP servers]
D --> E[Agent tool policy and hooks]
E --> F[Script result]
F --> G[Scheduler outcome]
D --> H[Runtime retirement]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +224, Tests +257, Docs +19. Total +500 across 5 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep MCP access scoped to explicitly named servers, the owning agent’s final tool policy, and evaluation-owned cleanup, then land through ordinary exact-head review and CI gates. Do we have a high-confidence way to reproduce the issue? Not applicable as a bug: current main explicitly excludes MCP tools from headless cron scripts, so the requested capability is absent by source inspection. Is this the best way to solve the issue? Yes. The branch extends cron’s existing headless executor and reuses the session MCP runtime and final tool policy instead of introducing a competing tool owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 670e3fb4ea20. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (6 earlier review cycles)
|
|
@clawsweeper review |
|
🦞👀 Re-review progress:
|
|
Owner decision on the "canceled run can still start an MCP server" finding: we are intentionally not fencing MCP launch against cancellation. The servers are ones the operator configured and the job's owner named in |
|
@clawsweeper review |
|
🦞👀 Re-review progress:
|
a9d91a3 to
d2326f8
Compare
…unavailable servers
…ll server prefixes
d2326f8 to
0198233
Compare
|
Landed as 3c2c989 (squash of 0198233). Trigger and script automations can now call MCP servers opted in through Proof: focused cron trigger-script suites 67/67, Merged with admin bypass of the required
|
…#160996) ## What Problem This Solves Agents build recurring automations that redo all their bookkeeping in the prompt on every fire (discovering tools, re-reading state files, diffing listings by hand), which makes quiet hourly runs take 7–16 model responses and time out on slow networks, and they post raw errors to the chat on one-off outages. ## User Impact When the model creates or edits a recurring automation, the automations tool now tells it to keep the model for judgment only: repeatable logic goes in a workspace script run in one `exec`, detailed instructions live in a workspace file the message references ("Follow scripts/<job>.md") so most fixes are file edits rather than job updates, the message names exact tools and arguments, `toolsAllow` is capped, and a trigger or script payload skips the model on quiet fires. A failed run should fail with a signal the scheduler records (throw from trigger or script payload JavaScript, or, for CLI-authored jobs in the docs, exit non-zero from a command payload; a script that returns an error field still succeeds), and failure accounting stays with the scheduler: failure alerts already wait for consecutive failed runs, so one-off outages stay quiet without scripts counting failures themselves. The docs describe the same pattern. ## Why This Change Was Made On a live gateway, rewriting two hourly MCP-backed sync jobs this way (a helper script owning diff, dedupe, checkpoints and failure counting; exact tool calls; a tight `toolsAllow`) cut quiet runs from 7–16 model responses to 3–4 and from minutes to 25–70 s. The tool description is the owner for this guidance because it is only present when the automations tool is available, so it adds no cost elsewhere. The script sentence, including the failure signal, is omitted when `cron.triggers.enabled` is false (scripts are unavailable then), and it does not mention command payloads because the agent automations tool cannot create them. LOC vs `origin/main` on top of #160995: production +5 (tool description), docs +26, regenerated prompt snapshots ±25. ## Evidence - Failure signals checked against source: trigger evaluation errors return `status: "error"` (`src/cron/service/timer-execution.ts`), a thrown script payload takes the headless failure path, and `parseScriptPayloadResult` treats a returned `{ error }` object as completed. - `pnpm prompt:snapshots:check`: current (4 fixture files regenerated with `pnpm prompt:snapshots:gen`). - `src/agents/tools/cron-tool.test.ts`: 71/71 pass. `pnpm docs:check-links`: 0 broken. `git diff --check` clean. - Adds about 210 tokens to the automations tool description when triggers are enabled. No overlap with Pash/Sarah changes (their commits on the shared prompt snapshot fixtures cover Codex attribution and developer instructions, not the automations description). Co-authored-by: Ayaan Zaidi <[email protected]>
… in toolsAllow (openclaw#160995) ## What Problem This Solves Scheduled condition triggers and script payloads cannot call configured MCP servers, so an automation whose "is there anything new?" check needs an MCP tool (Wispr, Plaud, Composio, GBrain…) has to start a full model turn every fire, even when nothing changed. ## User Impact A trigger or script payload can now call `MCP.<server>.<tool>(...)` for servers the job's `toolsAllow` names explicitly (`<server>__<tool>` or `<server>__*`, matched against the full configured safe server name, which may itself contain `__`), so an MCP-backed job can return `fire: false` on quiet fires without any model call. Existing jobs are unchanged: a script whose source never mentions `MCP` starts no server (even when `toolsAllow` names one for an agent-turn payload), and `*`, absent, or unprefixed caps expose no `MCP` at all. A named server that fails to start is simply absent from `MCP`, so an outage of a server the script does not call cannot block it; if the script then fails, the run error ends with `MCP server "<name>" is unavailable: <reason>`. ## Why This Change Was Made The exclusion was not a policy decision: the v1 trigger PR (openclaw#101195) never acquired the session MCP runtime, and a comment described the bridge incorrectly. Each evaluation now gets its own MCP runtime through the same acquisition, `toolsAllow`, final tool policy, `before_tool_call` hooks and approvals as embedded runs, and retires it when the evaluation ends. Teardown holds a finished evaluation for at most a fixed 1 s grace (success, failure, timeout or abort alike) through the existing agent cleanup owner; a hung connect or slow shutdown keeps retiring as tracked background work instead of holding the result or a trigger slot. Trigger (30 s / 5 calls) and payload budgets are unchanged; connect time counts against them. LOC vs `origin/main`: production +224, tests +257 (one new file), docs +19. ## Evidence - `src/cron/trigger-script.mcp.test.ts` (10 tests, real stdio MCP fixtures): trigger and payload calls to an allowed tool; disallowed and denylisted tools absent; a server named `team__sources` matched by `team__sources__*`; `*`, absent and unprefixed caps, and a script that never mentions `MCP` start 0 servers; a job naming a failed server still runs a script that uses only the healthy one, and a script calling the failed one fails with its startup reason; a successful and an aborted hung-connect evaluation both return while a SIGTERM-ignoring server is still alive, and the server is killed afterwards. The separator-name, never-mentions-MCP and failed-server cases fail without the fix; with a remaining-deadline cleanup wait both slow-teardown cases fail. - Measured cost of the new test file, `node scripts/run-vitest.mjs src/cron/trigger-script.mcp.test.ts --maxWorkers=1`: ~12 s of test time (the two slow-teardown cases are ~3.6 s each, waiting for the 3 s forced kill); ~45 s Vitest duration / ~48 s wall including a ~23 s cold worker-preparation step shared with other files in normal runs. - `trigger-script.mcp`, `trigger-script`, `trigger-script.admission`, `trigger-script.plugin-reload`: 67/67 pass. `pnpm tsgo:core` clean; `git diff --check` clean. - Isolated gateway smoke (own state/config dir, port 19877, local stdio MCP servers), script payloads run via `openclaw automations run --wait`: - `meetings__search_meetings`: `ok`, `listed 2 meetings`, 780 ms; the server started and exited within the run. - `meetings__*,broken__*`, script uses only `meetings`: `ok`, `partial listed 2`, 442 ms. - `meetings__*,broken__*`, script calls `MCP.broken.ping`: `error`, `TypeError: Cannot read properties of undefined (reading 'ping') … (MCP server "broken" is unavailable: MCP error -32000: Connection closed …)`. - `meetings__*`, script never mentions `MCP`: `ok`, 46 ms, no server start in the server log. - `stubborn__*` (server ignores SIGTERM): `ok`, ~1.27 s; the gateway logged `agent cleanup timed out … step=cron-script-mcp-retire timeoutMs=1000` and the process was gone afterwards. - A 30 s trigger gate with `meetings__*` fired once and then returned `fire:false` twice with no run-history rows or model calls.
…openclaw#160996) ## What Problem This Solves Agents build recurring automations that redo all their bookkeeping in the prompt on every fire (discovering tools, re-reading state files, diffing listings by hand), which makes quiet hourly runs take 7–16 model responses and time out on slow networks, and they post raw errors to the chat on one-off outages. ## User Impact When the model creates or edits a recurring automation, the automations tool now tells it to keep the model for judgment only: repeatable logic goes in a workspace script run in one `exec`, detailed instructions live in a workspace file the message references ("Follow scripts/<job>.md") so most fixes are file edits rather than job updates, the message names exact tools and arguments, `toolsAllow` is capped, and a trigger or script payload skips the model on quiet fires. A failed run should fail with a signal the scheduler records (throw from trigger or script payload JavaScript, or, for CLI-authored jobs in the docs, exit non-zero from a command payload; a script that returns an error field still succeeds), and failure accounting stays with the scheduler: failure alerts already wait for consecutive failed runs, so one-off outages stay quiet without scripts counting failures themselves. The docs describe the same pattern. ## Why This Change Was Made On a live gateway, rewriting two hourly MCP-backed sync jobs this way (a helper script owning diff, dedupe, checkpoints and failure counting; exact tool calls; a tight `toolsAllow`) cut quiet runs from 7–16 model responses to 3–4 and from minutes to 25–70 s. The tool description is the owner for this guidance because it is only present when the automations tool is available, so it adds no cost elsewhere. The script sentence, including the failure signal, is omitted when `cron.triggers.enabled` is false (scripts are unavailable then), and it does not mention command payloads because the agent automations tool cannot create them. LOC vs `origin/main` on top of openclaw#160995: production +5 (tool description), docs +26, regenerated prompt snapshots ±25. ## Evidence - Failure signals checked against source: trigger evaluation errors return `status: "error"` (`src/cron/service/timer-execution.ts`), a thrown script payload takes the headless failure path, and `parseScriptPayloadResult` treats a returned `{ error }` object as completed. - `pnpm prompt:snapshots:check`: current (4 fixture files regenerated with `pnpm prompt:snapshots:gen`). - `src/agents/tools/cron-tool.test.ts`: 71/71 pass. `pnpm docs:check-links`: 0 broken. `git diff --check` clean. - Adds about 210 tokens to the automations tool description when triggers are enabled. No overlap with Pash/Sarah changes (their commits on the shared prompt snapshot fixtures cover Codex attribution and developer instructions, not the automations description). Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Scheduled condition triggers and script payloads cannot call configured MCP servers, so an automation whose "is there anything new?" check needs an MCP tool (Wispr, Plaud, Composio, GBrain…) has to start a full model turn every fire, even when nothing changed.
User Impact
A trigger or script payload can now call
MCP.<server>.<tool>(...)for servers the job'stoolsAllownames explicitly (<server>__<tool>or<server>__*, matched against the full configured safe server name, which may itself contain__), so an MCP-backed job can returnfire: falseon quiet fires without any model call.Existing jobs are unchanged: a script whose source never mentions
MCPstarts no server (even whentoolsAllownames one for an agent-turn payload), and*, absent, or unprefixed caps expose noMCPat all. A named server that fails to start is simply absent fromMCP, so an outage of a server the script does not call cannot block it; if the script then fails, the run error ends withMCP server "<name>" is unavailable: <reason>.Why This Change Was Made
The exclusion was not a policy decision: the v1 trigger PR (#101195) never acquired the session MCP runtime, and a comment described the bridge incorrectly. Each evaluation now gets its own MCP runtime through the same acquisition,
toolsAllow, final tool policy,before_tool_callhooks and approvals as embedded runs, and retires it when the evaluation ends. Teardown holds a finished evaluation for at most a fixed 1 s grace (success, failure, timeout or abort alike) through the existing agent cleanup owner; a hung connect or slow shutdown keeps retiring as tracked background work instead of holding the result or a trigger slot. Trigger (30 s / 5 calls) and payload budgets are unchanged; connect time counts against them.LOC vs
origin/main: production +224, tests +257 (one new file), docs +19.Evidence
src/cron/trigger-script.mcp.test.ts(10 tests, real stdio MCP fixtures): trigger and payload calls to an allowed tool; disallowed and denylisted tools absent; a server namedteam__sourcesmatched byteam__sources__*;*, absent and unprefixed caps, and a script that never mentionsMCPstart 0 servers; a job naming a failed server still runs a script that uses only the healthy one, and a script calling the failed one fails with its startup reason; a successful and an aborted hung-connect evaluation both return while a SIGTERM-ignoring server is still alive, and the server is killed afterwards. The separator-name, never-mentions-MCP and failed-server cases fail without the fix; with a remaining-deadline cleanup wait both slow-teardown cases fail.node scripts/run-vitest.mjs src/cron/trigger-script.mcp.test.ts --maxWorkers=1: ~12 s of test time (the two slow-teardown cases are ~3.6 s each, waiting for the 3 s forced kill); ~45 s Vitest duration / ~48 s wall including a ~23 s cold worker-preparation step shared with other files in normal runs.trigger-script.mcp,trigger-script,trigger-script.admission,trigger-script.plugin-reload: 67/67 pass.pnpm tsgo:coreclean;git diff --checkclean.openclaw automations run --wait:meetings__search_meetings:ok,listed 2 meetings, 780 ms; the server started and exited within the run.meetings__*,broken__*, script uses onlymeetings:ok,partial listed 2, 442 ms.meetings__*,broken__*, script callsMCP.broken.ping:error,TypeError: Cannot read properties of undefined (reading 'ping') … (MCP server "broken" is unavailable: MCP error -32000: Connection closed …).meetings__*, script never mentionsMCP:ok, 46 ms, no server start in the server log.stubborn__*(server ignores SIGTERM):ok, ~1.27 s; the gateway loggedagent cleanup timed out … step=cron-script-mcp-retire timeoutMs=1000and the process was gone afterwards.meetings__*fired once and then returnedfire:falsetwice with no run-history rows or model calls.