Repository navigation
fix(cron): blocked scheduled runs are recorded as ok - #162391
Conversation
… no-delivery jobs
|
🦞👀 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. |
|
@clawsweeper review |
|
🦞👀 Re-review progress:
|
|
Codex review: blocked before merge. Reviewed October 1, 2026, 7:13 AM ET / 11:13 UTC (Revision 6). ClawSweeper reviewWhat this changesThe PR lets scheduled agents report failure with an AUTOMATION_FAILED first line, records an execution error, and delivers the explanation without the token through existing notification policies. Merge readiness⛔ Blocked before merge - 1 item remains This PR remains useful: current main still records an agent-reported blocker as success. No blocking defect remains in the reviewed patch; the prior migration concern does not apply to its unchanged stored-data contract. Likely related people: obviyus and steipete, based on recent merged cron work. Priority: P1 Review scores
Verification
How this fits togetherCron runs scheduled agent tasks and converts their replies into execution outcomes and delivery payloads. Those outcomes feed run history, completion reporting, scheduling policy, and configured failure notifications. flowchart TD
A[Scheduled job] --> B[Agent task and unattended instructions]
B --> C[Final reply and runtime errors]
C --> D[Cron outcome resolution]
D --> E[Run history and completion]
D --> F[Configured output delivery]
E --> G[Existing backoff and failure notifications]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +60, Tests +22, Docs 0, Other +149. Total +231 across 10 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep failure reporting in the existing cron outcome owner while preserving intentional silence, execution-versus-delivery separation, and configured notification routes. Do we have a high-confidence way to reproduce the issue? Yes, from source: a scheduled reply reporting a blocker without runtime error metadata remains successful on current main. The submitted Gateway before/after observations corroborate that path; this review did not execute it. Is this the best way to solve the issue? Yes. An explicit control line parsed by the existing outcome owner avoids classifying ordinary prose and feeds existing failure policy without adding notification routing or persisted state. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d417b5202305. 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 (5 earlier review cycles)
|
|
After-fix QA (isolated gateway, mock-openai, @clawsweeper review |
|
🦞👀 Re-review progress:
|
|
Owner note on the remaining "data-model compatibility" item: this PR changes no stored data. No SQLite schema, migration, store codec, or persisted job/run fields are touched; @clawsweeper review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper Maintainer decision (Ayaan, repository maintainer): the data-model item comes from |
|
@clawsweeper approve |
|
@clawsweeper re-review |
|
🦞👀 I queued a lightweight read-only assist pass. It will post a separate answer comment and will not edit the durable ClawSweeper review comment or trigger close, merge, repair, label, or branch changes. Request: Maintainer decision (Ayaan, repository maintainer): the data-model item comes from |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed in 855bba4.
|
…et auto-disabled (#162686) Related: #162391 ## What Problem This Solves Fixes two follow-ups to #162391: - A scheduled run that hands its work to a subagent can deliver the child's `AUTOMATION_FAILED` reply verbatim and still record the run as `ok`. This happens on announce jobs, and on `delivery: none` jobs since #162474 started recording the child's answer. - A silent (`delivery: none`) job whose agent keeps reporting a blocked task gets auto-disabled after 10 runs, and that posts an auto-disable notice even though the job has nowhere to notify. ## User Impact - When a delegated run's settled child answer starts with `AUTOMATION_FAILED`, the run is recorded as an error with the child's explanation. Announce and current-session delivery send only the explanation, never the token. `delivery: none` runs record it without sending anything, and keep the run transcript as other failed executions do. - A `delivery: none` job with no failure-alert route still records agent-reported failures in run history, job status, and error backoff (escalating to hourly, like any failing job). Those failures never auto-disable the job or post the auto-disable notice, so the job stays silent. - Unchanged: - Runtime errors on silent jobs still auto-disable at 10 as before. - Announce and webhook jobs, and jobs with a configured failure route, still auto-disable on agent-reported failures. - `NO_REPLY` behavior. ## Why This Change Was Made - **Settled child answers.** #162391 classified the token in `resolveCronPayloadOutcome`, which runs on the parent's reply before #117308's descendant settlement. Two places in `dispatchCronDelivery` then adopt the settled child's reply as the run's answer: the announce settlement (#117308) and the no-delivery settlement (#162474). Neither classified it. Both now go through one adoption helper that calls the shared parser `readAutomationFailedReport`, so the run's effective terminal answer is classified after settlement. `buildDeliveryState` derives one execution-failed flag from that result and uses it for both the completion status and the transcript-cleanup decision, so a failed no-delivery run is no longer cleaned up as a quiet success. `run-finalize` consumes the result the same way it already handles `pendingPresentationWarningError`: error status, permanent classification, explanation as the summary. - **Auto-disable.** Maintainer decision: an agent-reported blocked outcome on a job with no notification owner must not lead to auto-disable. The permanent error classification now carries `reportedByAgent`. `applyJobResult` in `timer-outcomes.ts` still counts every error in `consecutiveErrors`, so status and error backoff are unchanged. It skips only the auto-disable decision, and only when all of these hold: the failure was agent-reported, `resolveFailureAlert` finds no route, and the delivery mode is `none` (webhook jobs still auto-disable). - Hermes handles the same protocol the same way (`[CRON_FAILURE]`): its cron hint asks the agent to report a delegated child's failure on the first line. No new tool is needed. ## Bounded cost - No new turns, runs, waits, or notifications. Parsing happens once per settled answer inside the existing finalization. - Agent-reported failures stay permanent, so the scheduler never retries them early. - A silent blocked job keeps the normal error backoff (30 s, 1 min, 5 min, 15 min, then hourly), so it can never run more often than an identical job on origin/main. The only difference is that it keeps running at that backed-off cadence after the 10th failure instead of being disabled. ## Evidence ### Live model, Telegram Test Server (`telegram-e2e-userbot`, DM) Setup: the repo runner unchanged (`run-mock-sut-user-e2e.mjs --backend mock --source-gateway --dm`, Convex lease). `E2E_MOCK_SERVER_PATH` points to a throwaway proxy that stands in for the mock provider and forwards every request unchanged to the real OpenAI API. The proxy reads the key from a private file, so the Gateway only ever holds the runner's dummy key. `E2E_ROOT_CONFIG_PATCH` selects `openai/gpt-6-astra` (`tools.toolSearch: false`). A scenario `command` step creates the jobs with `openclaw automations add` and runs them. No model output was steered: the live parent chose `sessions_spawn`, and the live child and the live silent job wrote their own `AUTOMATION_FAILED` reports because they had no shell tool. The only steer is timing in case (b): before each run, `cron.update` sets `nextRunAtMs` to now and moves `lastRunAtMs` back 2 h, so the error backoff (up to 1 h) counts as served. The Gateway's own scheduler then runs the job as a normal scheduled (not forced) run. Before = origin/main `d8a110b1a15`, plus this PR's exact base `5c4e9aba929` for case (a). After = this head `8b77715ba4f`, with all three cases in one Gateway run. **(a) Announce job, live parent delegates to one child, the child reports `AUTOMATION_FAILED`** - before (`d8a110b1a15`): `cron run --wait` took 99.4 s. Run `ok`, `completionStatus: succeeded`, `deliveryStatus: delivered`. The DM received bot message 43601: `AUTOMATION_FAILED` / `The command could not run because no shell execution tool is available in this session.` The token is visible. - before (`5c4e9aba929`, the PR base): 80.7 s. Same result: run `ok`, `delivered`, and bot message 43705 reads `AUTOMATION_FAILED` / `The command could not run because no shell execution tool is available in this session.` - after: 63.5 s. Run `error`, `completionStatus: failed`, `deliveryStatus: delivered`. Error and summary are both the explanation. The DM received bot message 43712 with only `The command could not run because no shell execution tool is available in this session.` No token. - Pre-existing flake, not in this diff: on both sides, the announce settlement sometimes ends with `cron child-session handoff completed without a final assistant payload` even though the live child answered. That happened on 1 of 3 origin/main-side attempts (a second `d8a110b1a15` run) and on 2 of 4 attempts on this branch (both on `bfe1f0f2169`). In those cases nothing reaches the chat. The PR's change only runs after a reply has been read, so it is not involved. The no-delivery path (case c) settled on every attempt. **(c) Same delegated job with `delivery: none` (the #162474 path)** - before: 55.2 s. Run `ok`, `succeeded`, `deliveryStatus: not-requested`, summary `AUTOMATION_FAILED ⏎ The command could not run because no shell execution tool is available in this session.` The token is recorded as an ok answer. - after: 36.3 s. Run `error`, `failed`, `not-requested`. Error and summary are both `The command could not run because no shell execution tool is available in this session.` The job stays enabled. No chat message. **(b) `delivery: none` job, no failure-alert route, the live model reports `AUTOMATION_FAILED` on every run (11 scheduled runs)** - before: runs 1–10 were all `error` (`Could not run \`node scripts/ledger-sync.mjs\`: this session only provides a file-reading tool…`), with `consecutiveErrors` 1…10. After run 10 the job was `enabled: false` with `autoDisabled: {reason: "consecutive-failures", consecutiveErrors: 10}`, so run 11 never happened. The DM received bot message 43644 (heartbeat relay): `⚠️ Your "Nightly ledger sync" automation was automatically disabled after 10 consecutive failures. … openclaw automations enable <id>`. 10 runs took 504 s. - after: all 11 runs were `error` with the same explanation, and `consecutiveErrors` went 1…11, which keeps feeding backoff. After run 11 the job was still `enabled: true` with no `autoDisabled`. History shows 11 `error` entries. Across the whole run, the DM received exactly one bot message: 43712 from case (a). Cases (c) and (b) sent none, including during a 120 s wait after the loop. 11 runs took 526 s. Provider evidence (proxy log): before had 1 parent `sessions_spawn` turn, 1 child turn, 10 silent-job turns, and 1 relay turn carrying the auto-disable notice. After had 2 parent `sessions_spawn` turns, 2 child turns, 11 silent-job turns, no auto-disable relay turn, and only one routine heartbeat poll, which answered `NO_REPLY`. Environment note: in `--source-gateway` mode on both refs, Telegram inbound polling could not start (the ingress worker's plugin capture has no `dist/plugin-sdk`). So the opening DM turn was not processed, and the jobs are owned by `agent:main:main`, the DM's owner session under the default `dmScope`. Outbound delivery and relays reached the DM normally. This is the same for before and after. ### Tests Each new test fails on the code it fixes and passes on this head: - `delivery-dispatch.double-announce.test.ts`, real `dispatchCronDelivery`: - Announce settlement: a settled child reply `AUTOMATION_FAILED ⏎ …` is delivered as the explanation only and recorded as `agentReportedFailure`. - No-delivery settlement: uses the real `waitForDescendantSubagentResult`, with the registry mocked only at its edge. The child's report is recorded as `agentReportedFailure` with the explanation as output and summary. Nothing is sent, and the `deleteAfterRun` transcript is not deleted. Classification fails without the shared adoption helper (checked on the rebased predecessor commit), and retention fails on `bfe1f0f2169`. - `timer-outcomes.regression.test.ts`, real `applyJobResult`, 11 agent-reported failures from a clean streak: - `delivery: none`: still enabled, streak 11, no auto-disable notice, backoff delays 5 min, 15 min, 1 h, 1 h. This fails on `ee6d9e07fdf` (no streak, no backoff). - Webhook and announce jobs: auto-disabled at 10 with one notice, same backoff. Measured on this head, run separately (vitest `Duration`): - `delivery-dispatch.double-announce`: 84 tests, 22.1 s. - `timer-outcomes.regression`: 20 tests, 15.5 s. - `run.meta-error-status`: 14 tests, 20.0 s. All pass. `pnpm tsgo:core` passes, and oxlint and oxfmt on the changed files are clean. Docs: `delivery.md` documents the silent agent-failure exception to the 10-failure auto-disable. `payloads.md` notes that a delegated run's settled answer is classified the same way. LOC vs origin/main: production +54/−25, tests +100/−1, docs +2/−2. ### Review - Adversarial re-review round 1 (on `0530dc9f`): fixed the one real finding. Webhook jobs had been exempted too; the exemption now requires delivery mode `none`, with a webhook test case. - Round 2 (on `ee6d9e07fdf`): NOT LAND, one finding. Skipping the increment also froze error backoff, so a silent blocked job could keep running every minute. Fixed per maintainer decision with no second counter: the streak always increments, and the exemption moved to the auto-disable decision. - Round 3 (on `bfe1f0f2169`, rebased): LAND, no findings. The rebase onto origin/main also routes the #162474 no-delivery settlement through the same adoption helper. - ClawSweeper on `bfe1f0f2169`: fixed both findings. (P2) A failed no-delivery child run deleted its transcript; it is now kept. (P3) The auto-disable exception is now documented. Also added per-file test timings. - Round 4 (on `8b77715ba4f`): LAND, no findings. - Accepted tradeoffs: the exemption is not re-derived during finalized-run startup recovery. A silent job whose streak is already 10 or more from reported failures auto-disables on its next runtime error. Co-authored-by: Ayaan Zaidi <[email protected]>
## What Problem This Solves Follow-up to #160996. The cron authoring guidance (docs `payloads.md` and the automations tool description) said failure notifications wait for consecutive failed runs, "so a one-off outage stays quiet". That isn't true, so the guidance taught models a wrong cost for failing loudly: - A command payload with announce delivery still delivers its output when it exits non-zero: `runCommandJob` in `src/gateway/server-cron.ts` passes the summary to completion delivery without checking the exit status. - Since #162391, an agent's `AUTOMATION_FAILED` explanation is delivered for announce jobs. ## Solution Only the failure alert waits for consecutive failures; the run's own output still follows the job's delivery setting. Both places now say exactly that. The tool description stays static (prompt-cache stable) and grows by 12 characters. Prompt snapshots are regenerated. ## User Impact No runtime behavior change. Models writing automations get accurate guidance about what a failed run sends. ## Evidence The automations tool description an agent actually receives, taken from the regenerated prompt snapshot (`codex-dynamic-tools.telegram-direct.json`, built by the real prompt builder): - Before: `throw from the script so the run records the failure (returning {error} still succeeds); failure alerts already wait for consecutive failures, so a one-off failure stays quiet.` - After: `throw from the script so the run records the failure (returning {error} still succeeds); only the failure alert waits for consecutive failures, run output still follows the job's delivery.` Checks on the exact head: - `pnpm run prompt:snapshots:check`: snapshots are current (7 files). - `node scripts/run-vitest.mjs src/agents/tools/cron-tool.test.ts`: 72 passed. Text-only change, so no live channel proof applies: no message, delivery or runtime path changes. Runtime output from a real OpenClaw setup on head `15919727aaa`: the actual `createCronTool()` builder run in an isolated state dir (default config), printing the failure-guidance sentences of the `automations` tool description an agent receives: ```text tool: automations When a run fails, throw from the script so the run records the failure (returning {error} still succeeds); only the failure alert waits for consecutive failures, run output still follows the job's delivery. FAILURE ALERTS: jobs with a failure route default to alerting after 2 consecutive execution failures with a 1h cooldown. ``` The same sentence on `origin/main` read: `…failure alerts already wait for consecutive failures, so a one-off failure stays quiet.` Co-authored-by: Ayaan Zaidi <[email protected]>
## What Problem This Solves Fixes: a scheduled agent run that could not do its task is recorded as `ok`, so run history, `--wait`, and the configured failure alerts treat it as a success. In our setup, a monthly isolated job delivered nothing for two months and every receipt said `ok`. One month the turn knew it was blocked (no shell tool) and said so in plain text, but nothing structured recorded that. ## User Impact - A run can now fail itself. A final reply whose first line is exactly `AUTOMATION_FAILED` records the run as `error`, with the lines that follow as the error text. The existing failure handling then applies: error backoff, plus failure alerts and owner-conversation repair for jobs that already have a failure route or `failureAlert` config. - Announce jobs still deliver the agent's explanation, with the token removed. - These stay ok: `NO_REPLY` runs, and replies that mention the token anywhere other than as the exact first line. - **No change to notification contracts.** An unconfigured `delivery: none` job still sends nothing to chat (no alert, no repair request). It now records the error in run history and job status (`lastRunStatus`, `consecutiveErrors`). **Not fixed here:** - A delegated (spawn-only) `delivery: none` run still ends `ok` and drops its child's result. The parent never sees the child's reply, so it can't report that failure with the token. Since openclaw#135318, cron turns also can't `sessions_yield`. A separate PR fixes settlement at openclaw#117308's spawn-only path. - Notifying owners of failing `delivery: none` jobs is a pending product decision and is not part of this PR. ## Why This Change Was Made Provenance: - openclaw#110949 added the unattended-run preamble. It tells the model "If something failed, state plainly what failed … the scheduler owns retries and failure alerts", but no structured fact carried that statement. The scheduler only fails runs on run-level errors, error payloads, or exec-denied tool errors (`failure-signal.ts`, `execution_denied`). - openclaw#126164 and openclaw#131228 deliberately keep execution status separate from delivery outcome. This PR keeps that separation: the token is an execution outcome the agent reports. It is parsed in the existing cron outcome owner (`resolveCronPayloadOutcome`), next to `failureSignal`, and is never derived from delivery. The token is a strict control line, like `NO_REPLY`. Only an exact first line counts, so ordinary prose is never classified. Hermes Agent uses the same mechanism for cron (`[CRON_FAILURE]` on the first line; `cron/scheduler_prompt.py`, `cron/scheduler.py`). The preamble sentence is reworded in place: similar length, still static for prompt caching. ## Bounded cost New or changed paths that could lead to a model call or a job run: - **The token parse.** No new turns, runs, or notifications. It only changes the recorded status of the run that produced the reply. It is parsed only in cron finalization for that run. The delivered explanation is outbound text, never inbound, so there is no self-trigger. - **Error status → scheduler.** - One-shot jobs: an agent-reported failure carries `errorClassification: { kind: "permanent" }`, so it never enters the transient-retry path. This also means wording like "network timeout" in the explanation is never text-classified into a retry or an error reason. **Tested** in `run.meta-error-status.test.ts`. - Recurring jobs: the existing error backoff only delays the next run (natural schedule or later), and the existing auto-disable stops the job after 10 consecutive errors. Nothing runs sooner than scheduled. - **Repair turns.** Unchanged. They still happen only for jobs with an existing chat failure route (openclaw#161007): at most one per failure incident, and the incident marker is persisted in job state. A repair turn can't start runs, because automation control is owner-only and the request carries no sender identity. It is an ordinary conversation turn, not a cron run, so its own failure can't open another repair. - **The preamble text.** Static; it adds no turns. ## Evidence Isolated Gateway, qa-lab mock-openai, new scenario `qa/scenarios/scheduling/cron-blocked-outcome.yaml`: - **Before** (origin/main): a `delivery: none` job whose reply starts with `AUTOMATION_FAILED` → `status: "ok"`, `completionStatus: "succeeded"`, and the summary holds the blocker text. - **After:** see the result comment below. The scenario checks: - An owned `delivery: none` job, run 3 times → each run is `error` with the reported reason; no repair request and no chat message. - An unowned announce job, run twice → `error`; the reason is delivered without the token, and the existing `failed 2 times` alert fires. - A mid-text quote, and `NO_REPLY` (with and without announce) → `ok`. Focused tests (fail before, pass after): `src/cron/isolated-agent/run.meta-error-status.test.ts` covers token → `error` + permanent classification, and a mid-text quote → `ok` (two cases, about 1.7 s each in the shared harness). Also passing: `failure-alerts.{account-routing,persistence,recovery}`, `service.failure-repair`, and `run.message-tool-policy` (116 tests). `pnpm tsgo:core` and oxlint on the changed files are clean. `run.message-tool-policy.test.ts` no longer pins the full preamble wording; it keeps the ordering assertion. LOC vs origin/main: production +36/−7, unit tests +24/−2, QA scenario and mock about +180, docs +1/−1. ## Upgrade compatibility No migration is required. The diff touches no schema, store, codec or persisted type file. Run history keeps the existing `CronRunStatus` values (`ok | error | skipped`) and the existing error/permanent classification fields, so rows written before and after this change go through the same unchanged readers. The QA scenario's "repair" wording refers to the scheduler's automation repair request, not a data repair. Existing-state compatibility is verified by the unchanged `failure-alerts.persistence` and `service.failure-repair` suites passing on this head.
…et auto-disabled (openclaw#162686) Related: openclaw#162391 ## What Problem This Solves Fixes two follow-ups to openclaw#162391: - A scheduled run that hands its work to a subagent can deliver the child's `AUTOMATION_FAILED` reply verbatim and still record the run as `ok`. This happens on announce jobs, and on `delivery: none` jobs since openclaw#162474 started recording the child's answer. - A silent (`delivery: none`) job whose agent keeps reporting a blocked task gets auto-disabled after 10 runs, and that posts an auto-disable notice even though the job has nowhere to notify. ## User Impact - When a delegated run's settled child answer starts with `AUTOMATION_FAILED`, the run is recorded as an error with the child's explanation. Announce and current-session delivery send only the explanation, never the token. `delivery: none` runs record it without sending anything, and keep the run transcript as other failed executions do. - A `delivery: none` job with no failure-alert route still records agent-reported failures in run history, job status, and error backoff (escalating to hourly, like any failing job). Those failures never auto-disable the job or post the auto-disable notice, so the job stays silent. - Unchanged: - Runtime errors on silent jobs still auto-disable at 10 as before. - Announce and webhook jobs, and jobs with a configured failure route, still auto-disable on agent-reported failures. - `NO_REPLY` behavior. ## Why This Change Was Made - **Settled child answers.** openclaw#162391 classified the token in `resolveCronPayloadOutcome`, which runs on the parent's reply before openclaw#117308's descendant settlement. Two places in `dispatchCronDelivery` then adopt the settled child's reply as the run's answer: the announce settlement (openclaw#117308) and the no-delivery settlement (openclaw#162474). Neither classified it. Both now go through one adoption helper that calls the shared parser `readAutomationFailedReport`, so the run's effective terminal answer is classified after settlement. `buildDeliveryState` derives one execution-failed flag from that result and uses it for both the completion status and the transcript-cleanup decision, so a failed no-delivery run is no longer cleaned up as a quiet success. `run-finalize` consumes the result the same way it already handles `pendingPresentationWarningError`: error status, permanent classification, explanation as the summary. - **Auto-disable.** Maintainer decision: an agent-reported blocked outcome on a job with no notification owner must not lead to auto-disable. The permanent error classification now carries `reportedByAgent`. `applyJobResult` in `timer-outcomes.ts` still counts every error in `consecutiveErrors`, so status and error backoff are unchanged. It skips only the auto-disable decision, and only when all of these hold: the failure was agent-reported, `resolveFailureAlert` finds no route, and the delivery mode is `none` (webhook jobs still auto-disable). - Hermes handles the same protocol the same way (`[CRON_FAILURE]`): its cron hint asks the agent to report a delegated child's failure on the first line. No new tool is needed. ## Bounded cost - No new turns, runs, waits, or notifications. Parsing happens once per settled answer inside the existing finalization. - Agent-reported failures stay permanent, so the scheduler never retries them early. - A silent blocked job keeps the normal error backoff (30 s, 1 min, 5 min, 15 min, then hourly), so it can never run more often than an identical job on origin/main. The only difference is that it keeps running at that backed-off cadence after the 10th failure instead of being disabled. ## Evidence ### Live model, Telegram Test Server (`telegram-e2e-userbot`, DM) Setup: the repo runner unchanged (`run-mock-sut-user-e2e.mjs --backend mock --source-gateway --dm`, Convex lease). `E2E_MOCK_SERVER_PATH` points to a throwaway proxy that stands in for the mock provider and forwards every request unchanged to the real OpenAI API. The proxy reads the key from a private file, so the Gateway only ever holds the runner's dummy key. `E2E_ROOT_CONFIG_PATCH` selects `openai/gpt-6-astra` (`tools.toolSearch: false`). A scenario `command` step creates the jobs with `openclaw automations add` and runs them. No model output was steered: the live parent chose `sessions_spawn`, and the live child and the live silent job wrote their own `AUTOMATION_FAILED` reports because they had no shell tool. The only steer is timing in case (b): before each run, `cron.update` sets `nextRunAtMs` to now and moves `lastRunAtMs` back 2 h, so the error backoff (up to 1 h) counts as served. The Gateway's own scheduler then runs the job as a normal scheduled (not forced) run. Before = origin/main `88f22a318b4`, plus this PR's exact base `2ae97b30828` for case (a). After = this head `8b77715ba4f`, with all three cases in one Gateway run. **(a) Announce job, live parent delegates to one child, the child reports `AUTOMATION_FAILED`** - before (`88f22a318b4`): `cron run --wait` took 99.4 s. Run `ok`, `completionStatus: succeeded`, `deliveryStatus: delivered`. The DM received bot message 43601: `AUTOMATION_FAILED` / `The command could not run because no shell execution tool is available in this session.` The token is visible. - before (`2ae97b30828`, the PR base): 80.7 s. Same result: run `ok`, `delivered`, and bot message 43705 reads `AUTOMATION_FAILED` / `The command could not run because no shell execution tool is available in this session.` - after: 63.5 s. Run `error`, `completionStatus: failed`, `deliveryStatus: delivered`. Error and summary are both the explanation. The DM received bot message 43712 with only `The command could not run because no shell execution tool is available in this session.` No token. - Pre-existing flake, not in this diff: on both sides, the announce settlement sometimes ends with `cron child-session handoff completed without a final assistant payload` even though the live child answered. That happened on 1 of 3 origin/main-side attempts (a second `88f22a318b4` run) and on 2 of 4 attempts on this branch (both on `bfe1f0f2169`). In those cases nothing reaches the chat. The PR's change only runs after a reply has been read, so it is not involved. The no-delivery path (case c) settled on every attempt. **(c) Same delegated job with `delivery: none` (the openclaw#162474 path)** - before: 55.2 s. Run `ok`, `succeeded`, `deliveryStatus: not-requested`, summary `AUTOMATION_FAILED ⏎ The command could not run because no shell execution tool is available in this session.` The token is recorded as an ok answer. - after: 36.3 s. Run `error`, `failed`, `not-requested`. Error and summary are both `The command could not run because no shell execution tool is available in this session.` The job stays enabled. No chat message. **(b) `delivery: none` job, no failure-alert route, the live model reports `AUTOMATION_FAILED` on every run (11 scheduled runs)** - before: runs 1–10 were all `error` (`Could not run \`node scripts/ledger-sync.mjs\`: this session only provides a file-reading tool…`), with `consecutiveErrors` 1…10. After run 10 the job was `enabled: false` with `autoDisabled: {reason: "consecutive-failures", consecutiveErrors: 10}`, so run 11 never happened. The DM received bot message 43644 (heartbeat relay): `⚠️ Your "Nightly ledger sync" automation was automatically disabled after 10 consecutive failures. … openclaw automations enable <id>`. 10 runs took 504 s. - after: all 11 runs were `error` with the same explanation, and `consecutiveErrors` went 1…11, which keeps feeding backoff. After run 11 the job was still `enabled: true` with no `autoDisabled`. History shows 11 `error` entries. Across the whole run, the DM received exactly one bot message: 43712 from case (a). Cases (c) and (b) sent none, including during a 120 s wait after the loop. 11 runs took 526 s. Provider evidence (proxy log): before had 1 parent `sessions_spawn` turn, 1 child turn, 10 silent-job turns, and 1 relay turn carrying the auto-disable notice. After had 2 parent `sessions_spawn` turns, 2 child turns, 11 silent-job turns, no auto-disable relay turn, and only one routine heartbeat poll, which answered `NO_REPLY`. Environment note: in `--source-gateway` mode on both refs, Telegram inbound polling could not start (the ingress worker's plugin capture has no `dist/plugin-sdk`). So the opening DM turn was not processed, and the jobs are owned by `agent:main:main`, the DM's owner session under the default `dmScope`. Outbound delivery and relays reached the DM normally. This is the same for before and after. ### Tests Each new test fails on the code it fixes and passes on this head: - `delivery-dispatch.double-announce.test.ts`, real `dispatchCronDelivery`: - Announce settlement: a settled child reply `AUTOMATION_FAILED ⏎ …` is delivered as the explanation only and recorded as `agentReportedFailure`. - No-delivery settlement: uses the real `waitForDescendantSubagentResult`, with the registry mocked only at its edge. The child's report is recorded as `agentReportedFailure` with the explanation as output and summary. Nothing is sent, and the `deleteAfterRun` transcript is not deleted. Classification fails without the shared adoption helper (checked on the rebased predecessor commit), and retention fails on `bfe1f0f2169`. - `timer-outcomes.regression.test.ts`, real `applyJobResult`, 11 agent-reported failures from a clean streak: - `delivery: none`: still enabled, streak 11, no auto-disable notice, backoff delays 5 min, 15 min, 1 h, 1 h. This fails on `ee6d9e07fdf` (no streak, no backoff). - Webhook and announce jobs: auto-disabled at 10 with one notice, same backoff. Measured on this head, run separately (vitest `Duration`): - `delivery-dispatch.double-announce`: 84 tests, 22.1 s. - `timer-outcomes.regression`: 20 tests, 15.5 s. - `run.meta-error-status`: 14 tests, 20.0 s. All pass. `pnpm tsgo:core` passes, and oxlint and oxfmt on the changed files are clean. Docs: `delivery.md` documents the silent agent-failure exception to the 10-failure auto-disable. `payloads.md` notes that a delegated run's settled answer is classified the same way. LOC vs origin/main: production +54/−25, tests +100/−1, docs +2/−2. ### Review - Adversarial re-review round 1 (on `0530dc9f`): fixed the one real finding. Webhook jobs had been exempted too; the exemption now requires delivery mode `none`, with a webhook test case. - Round 2 (on `ee6d9e07fdf`): NOT LAND, one finding. Skipping the increment also froze error backoff, so a silent blocked job could keep running every minute. Fixed per maintainer decision with no second counter: the streak always increments, and the exemption moved to the auto-disable decision. - Round 3 (on `bfe1f0f2169`, rebased): LAND, no findings. The rebase onto origin/main also routes the openclaw#162474 no-delivery settlement through the same adoption helper. - ClawSweeper on `bfe1f0f2169`: fixed both findings. (P2) A failed no-delivery child run deleted its transcript; it is now kept. (P3) The auto-disable exception is now documented. Also added per-file test timings. - Round 4 (on `8b77715ba4f`): LAND, no findings. - Accepted tradeoffs: the exemption is not re-derived during finalized-run startup recovery. A silent job whose streak is already 10 or more from reported failures auto-disables on its next runtime error. Co-authored-by: Ayaan Zaidi <[email protected]>
…w#162695) ## What Problem This Solves Follow-up to openclaw#160996. The cron authoring guidance (docs `payloads.md` and the automations tool description) said failure notifications wait for consecutive failed runs, "so a one-off outage stays quiet". That isn't true, so the guidance taught models a wrong cost for failing loudly: - A command payload with announce delivery still delivers its output when it exits non-zero: `runCommandJob` in `src/gateway/server-cron.ts` passes the summary to completion delivery without checking the exit status. - Since openclaw#162391, an agent's `AUTOMATION_FAILED` explanation is delivered for announce jobs. ## Solution Only the failure alert waits for consecutive failures; the run's own output still follows the job's delivery setting. Both places now say exactly that. The tool description stays static (prompt-cache stable) and grows by 12 characters. Prompt snapshots are regenerated. ## User Impact No runtime behavior change. Models writing automations get accurate guidance about what a failed run sends. ## Evidence The automations tool description an agent actually receives, taken from the regenerated prompt snapshot (`codex-dynamic-tools.telegram-direct.json`, built by the real prompt builder): - Before: `throw from the script so the run records the failure (returning {error} still succeeds); failure alerts already wait for consecutive failures, so a one-off failure stays quiet.` - After: `throw from the script so the run records the failure (returning {error} still succeeds); only the failure alert waits for consecutive failures, run output still follows the job's delivery.` Checks on the exact head: - `pnpm run prompt:snapshots:check`: snapshots are current (7 files). - `node scripts/run-vitest.mjs src/agents/tools/cron-tool.test.ts`: 72 passed. Text-only change, so no live channel proof applies: no message, delivery or runtime path changes. Runtime output from a real OpenClaw setup on head `15919727aaa`: the actual `createCronTool()` builder run in an isolated state dir (default config), printing the failure-guidance sentences of the `automations` tool description an agent receives: ```text tool: automations When a run fails, throw from the script so the run records the failure (returning {error} still succeeds); only the failure alert waits for consecutive failures, run output still follows the job's delivery. FAILURE ALERTS: jobs with a failure route default to alerting after 2 consecutive execution failures with a 1h cooldown. ``` The same sentence on `origin/main` read: `…failure alerts already wait for consecutive failures, so a one-off failure stays quiet.` Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Fixes: a scheduled agent run that could not do its task is recorded as
ok, so run history,--wait, and the configured failure alerts treat it as a success.In our setup, a monthly isolated job delivered nothing for two months and every receipt said
ok. One month the turn knew it was blocked (no shell tool) and said so in plain text, but nothing structured recorded that.User Impact
AUTOMATION_FAILEDrecords the run aserror, with the lines that follow as the error text. The existing failure handling then applies: error backoff, plus failure alerts and owner-conversation repair for jobs that already have a failure route orfailureAlertconfig.NO_REPLYruns, and replies that mention the token anywhere other than as the exact first line.delivery: nonejob still sends nothing to chat (no alert, no repair request). It now records the error in run history and job status (lastRunStatus,consecutiveErrors).Not fixed here:
delivery: nonerun still endsokand drops its child's result. The parent never sees the child's reply, so it can't report that failure with the token. Since fix(agents): keep sessions_yield away from isolated automation turns #135318, cron turns also can'tsessions_yield. A separate PR fixes settlement at fix(cron): deliver spawned child results when scheduled agents emit no text #117308's spawn-only path.delivery: nonejobs is a pending product decision and is not part of this PR.Why This Change Was Made
Provenance:
failure-signal.ts,execution_denied).resolveCronPayloadOutcome), next tofailureSignal, and is never derived from delivery.The token is a strict control line, like
NO_REPLY. Only an exact first line counts, so ordinary prose is never classified. The preamble sentence is reworded in place: similar length, still static for prompt caching.Bounded cost
New or changed paths that could lead to a model call or a job run:
errorClassification: { kind: "permanent" }, so it never enters the transient-retry path. This also means wording like "network timeout" in the explanation is never text-classified into a retry or an error reason. Tested inrun.meta-error-status.test.ts.Evidence
Isolated Gateway, qa-lab mock-openai, new scenario
qa/scenarios/scheduling/cron-blocked-outcome.yaml:delivery: nonejob whose reply starts withAUTOMATION_FAILED→status: "ok",completionStatus: "succeeded", and the summary holds the blocker text.delivery: nonejob, run 3 times → each run iserrorwith the reported reason; no repair request and no chat message.error; the reason is delivered without the token, and the existingfailed 2 timesalert fires.NO_REPLY(with and without announce) →ok.Focused tests (fail before, pass after):
src/cron/isolated-agent/run.meta-error-status.test.tscovers token →error+ permanent classification, and a mid-text quote →ok(two cases, about 1.7 s each in the shared harness). Also passing:failure-alerts.{account-routing,persistence,recovery},service.failure-repair, andrun.message-tool-policy(116 tests).pnpm tsgo:coreand oxlint on the changed files are clean.run.message-tool-policy.test.tsno longer pins the full preamble wording; it keeps the ordering assertion.LOC vs origin/main: production +36/−7, unit tests +24/−2, QA scenario and mock about +180, docs +1/−1.
Upgrade compatibility
No migration is required. The diff touches no schema, store, codec or persisted type file. Run history keeps the existing
CronRunStatusvalues (ok | error | skipped) and the existing error/permanent classification fields, so rows written before and after this change go through the same unchanged readers. The QA scenario's "repair" wording refers to the scheduler's automation repair request, not a data repair. Existing-state compatibility is verified by the unchangedfailure-alerts.persistenceandservice.failure-repairsuites passing on this head.