Skip to content

feat(cron): let trigger and script automations call MCP servers named in toolsAllow - #160995

Merged
obviyus merged 5 commits into
mainfrom
feat/cron-headless-mcp
Sep 30, 2026
Merged

obviyus merged 5 commits into
mainfrom
feat/cron-headless-mcp

Conversation

@obviyus

@obviyus obviyus commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

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 (#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.

@clawsweeper

clawsweeper Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: L labels Sep 29, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 29, 2026
@clawsweeper

clawsweeper Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 29, 2026, 2:00 PM ET / 18:00 UTC (Revision 7).

ClawSweeper review

What this changes

Scheduled 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
Reviewed head: 0198233fd7c7895624fb7354038540f2bf295a74

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused runtime reuse, process-backed tests, and real Gateway traces support this feature, with no current blocking finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The changed cron executor was exercised through an isolated Gateway and openclaw automations run --wait against real local stdio MCP servers; the captured terminal results show allowed calls, quiet ticks without model calls, failure isolation, and eventual process retirement. The PR changes no stored-data contract.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed cron executor was exercised through an isolated Gateway and openclaw automations run --wait against real local stdio MCP servers; the captured terminal results show allowed calls, quiet ticks without model calls, failure isolation, and eventual process retirement. The PR changes no stored-data contract.
Evidence reviewed 8 items Current main lacks the requested path: The fetched main revision explicitly says bundle MCP tools are excluded from the headless bridge; it does not acquire an MCP runtime for cron scripts.
Explicit server selection and final policy: The introduced helper starts only servers named by a full safe-name prefix in toolsAllow, then applies the existing final effective tool policy and before-tool-call hook to materialized tools.
Evaluation and cleanup boundary: The runner checks admitted authority before preparing tools, includes MCP connection time in the evaluation deadline, guards tool execution, and retires MCP work through tracked cleanup with a one-second result grace.
Findings None None.
Security None None.

How this fits together

Cron 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +224, Tests +257, Docs +19. Total +500 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 232 8 +224
Tests 1 257 0 +257
Docs 2 19 0 +19
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 508 8 +500

Review metrics

Metric Value Why it matters
Production and test growth production +224 lines, tests +257 lines The production growth has a stated purpose in runtime acquisition, policy application, and cleanup, with process-backed coverage.
New test cost 10 cases; approximately 48 seconds wall time reported The contributor measured the added process-backed suite’s per-PR cost.

Technical review

Best 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.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded cron capability improvement with useful user impact and limited blast radius.
  • merge-risk: 🚨 security-boundary: Merging lets unattended scripts launch configured MCP servers; explicit job caps and final policy constrain that authority, while the discussion accepts the bounded cancellation window.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed cron executor was exercised through an isolated Gateway and openclaw automations run --wait against real local stdio MCP servers; the captured terminal results show allowed calls, quiet ticks without model calls, failure isolation, and eventual process retirement. The PR changes no stored-data contract.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed cron executor was exercised through an isolated Gateway and openclaw automations run --wait against real local stdio MCP servers; the captured terminal results show allowed calls, quiet ticks without model calls, failure isolation, and eventual process retirement. The PR changes no stored-data contract.

Evidence

What I checked:

  • Current main lacks the requested path: The fetched main revision explicitly says bundle MCP tools are excluded from the headless bridge; it does not acquire an MCP runtime for cron scripts. (src/cron/trigger-script.ts:217, 670e3fb4ea20)
  • Explicit server selection and final policy: The introduced helper starts only servers named by a full safe-name prefix in toolsAllow, then applies the existing final effective tool policy and before-tool-call hook to materialized tools. (src/cron/trigger-script-mcp.ts:46, 0198233fd7c7)
  • Evaluation and cleanup boundary: The runner checks admitted authority before preparing tools, includes MCP connection time in the evaluation deadline, guards tool execution, and retires MCP work through tracked cleanup with a one-second result grace. (src/cron/trigger-script.ts:505, 0198233fd7c7)
  • Process-backed regression coverage: Ten cases use real local stdio MCP processes to cover allowed and denied tools, full server names, absent caps, failed servers, and eventual retirement after success or abort. (src/cron/trigger-script.mcp.test.ts:107, 0198233fd7c7)
  • Real Gateway behavior proof: The captured PR body reports isolated Gateway runs through openclaw automations run --wait with local stdio servers: allowed calls succeeded, an unrelated failed server did not block a script, a missing server produced an error, a quiet trigger avoided model calls, and a stubborn process was eventually killed. These are contributor-provided terminal observations, not commands run in this review.
  • Recorded security tradeoff: The PR discussion at feat(cron): let trigger and script automations call MCP servers named in toolsAllow #160995 (comment) explicitly accepts the bounded possibility of MCP launch after cancellation for operator-configured, job-allowed servers; the runtime still retires launched processes. The current review found no wider authority path.

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • joshavant: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (6 earlier review cycles)
  • reviewed 2026-09-29T05:50:27.826Z sha 0d1c650 :: blocked before merge. :: [P2] Bound MCP retirement after a successful script
  • reviewed 2026-09-29T12:20:35.891Z sha fbdc0be :: needs real behavior proof before merge. :: [P1] Preserve condition scripts during unrelated MCP outages | [P1] Prevent MCP startup after cron authority is revoked | [P2] Match the complete safe MCP server name
  • reviewed 2026-09-29T12:39:32.083Z sha b1151b3 :: needs changes before merge. :: none
  • reviewed 2026-09-29T15:56:03.059Z sha b1151b3 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-29T16:43:40.562Z sha a9d91a3 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-29T17:27:22.257Z sha d2326f8 :: needs maintainer review before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added size: M and removed agents Agent runtime and tooling size: L labels Sep 29, 2026
@obviyus

obviyus commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper review

@clawsweeper

clawsweeper Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 29, 2026
@obviyus

obviyus commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator Author

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 toolsAllow; starting one is the same action an interactive run with that job's policy would take, and any runtime started for an evaluation is retired as soon as that evaluation ends (the aborted hung-connect regression shows the launched process is killed afterwards). Adding an abort/assertion fence through the shared MCP acquisition path would be new machinery for a millisecond window with no authority gain for anyone. Per the repo's security guidance (prefer the least restrictive effective safeguard), the maintainer accepts this bounded risk within the existing trust model. The other findings (unrelated-outage regression, full safe-name matching, eager startup for existing jobs) are fixed in b1151b3.

@obviyus

obviyus commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper review

@clawsweeper

clawsweeper Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 29, 2026
@clawsweeper clawsweeper Bot added the status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. label Sep 29, 2026
@obviyus
obviyus marked this pull request as ready for review September 29, 2026 15:45
@obviyus
obviyus force-pushed the feat/cron-headless-mcp branch 3 times, most recently from a9d91a3 to d2326f8 Compare September 29, 2026 17:17
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Sep 29, 2026
@obviyus
obviyus force-pushed the feat/cron-headless-mcp branch from d2326f8 to 0198233 Compare September 29, 2026 17:52
@obviyus
obviyus merged commit 3c2c989 into main Sep 30, 2026
134 of 213 checks passed
@obviyus
obviyus deleted the feat/cron-headless-mcp branch September 30, 2026 01:47
@obviyus

obviyus commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as 3c2c989 (squash of 0198233).

Trigger and script automations can now call MCP servers opted in through toolsAllow (<server>__tool or <server>__*). Servers start only when the script references MCP, so existing jobs behave as before. Teardown waits a 1 s grace and then retires stubborn servers in the background.

Proof: focused cron trigger-script suites 67/67, pnpm tsgo:core clean, and an isolated-gateway smoke with real stdio MCP servers (named tool call, broken server alongside a healthy one, no-MCP script starts no server, SIGTERM-ignoring server returns in about 1.3 s). Hosted review was ready on the exact head.

Merged with admin bypass of the required openclaw/ci-gate after maintainer approval. CI run https://github.com/openclaw/openclaw/actions/runs/36608082557 failed only in tests outside this PR's files, which are red on main independently:

  • src/gateway/config-reload.activation.integration.test.ts (still expects the old "did not complete activation" message)
  • src/gateway/server.heartbeat-store-lifecycle.product-proof.test.ts ("handles a queued child notice after different store…", error vs ok)
  • src/cli/update-cli/update-command-run.test.ts ("disposes only the owned unchanged preview before SIGTERM exit", 60 s timeout)

obviyus added a commit that referenced this pull request Sep 30, 2026
…#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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 30, 2026
… 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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 30, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant