Repository navigation
fix(cron): required delivery failures no longer report success - #126164
Conversation
Record durable completion independently from payload execution so required delivery failure cannot delete one-shots or report successful waits.\n\nCloses #126163
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 18, 2026, 11:52 PM ET / August 19, 2026, 03:52 UTC. ClawSweeper reviewWhat this changesThe PR adds a durable cron completion outcome so required delivery failures remain distinct from payload execution success across cleanup, CLI waits, task history, Gateway notifications, and plugin hooks. Merge readinessNo blocking source defect was found in the reviewed head. Keep this active, maintainer-labeled PR open for normal exact-head CI handling and merge review; it is the linked candidate fix for the reported P1 cron completion bug. Priority: P1 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherCron executes a payload and then optionally delivers its output. The finalized run record controls CLI exit status, task history, one-shot retention, Gateway notifications, and plugin events. flowchart LR
A[Cron job] --> B[Payload execution]
B --> C[Delivery result]
C --> D[Durable completion outcome]
D --> E[Task and run history]
D --> F[CLI wait exit]
D --> G[One-shot retention]
D --> H[Gateway and plugin events]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +166, Tests +529, Docs +2. Total +697 across 40 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain one completion outcome authored from the admitted run snapshot, keep it optional on external contracts, and land after the exact PR head has a green required check set. Do we have a high-confidence way to reproduce the issue? Yes, from source and the supplied PR evidence: a successful payload with required delivery returning not-delivered reaches CLI, one-shot, and notification consumers; this read-only review did not execute the scenario. Is this the best way to solve the issue? Yes: authoring one durable outcome at the admitted execution boundary is safer than adapter-specific status rewriting or consumer-side inference from mutable job settings. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against a441431896b4. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Land-ready verification is complete on head Proof:
ClawSweeper rank-up moves on the completed review were applied: Known proof boundary: delivery failure is exercised with an unreachable loopback webhook rather than an authenticated external channel; this directly tests the cron-owned required-delivery and no-replay contract without external credentials. |
|
Merged via squash.
|
…law#126164) * fix(cron): preserve required delivery completion Record durable completion independently from payload execution so required delivery failure cannot delete one-shots or report successful waits.\n\nCloses openclaw#126163 * fix(cron): keep completion contracts acyclic * fix(cron): keep delivery predicate private
## 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 #135318, cron turns also can't `sessions_yield`. A separate PR fixes settlement at #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: - #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`). - #126164 and #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 (#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.
## 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.
Closes #126163
What Problem This Solves
Fixes an issue where an automation payload could complete successfully while explicitly required delivery failed, but one-shot cleanup,
openclaw cron run --wait, and Gateway completion notifications still treated the whole run as successful. Delete-after-run one-shots could lose their inspectable job record, and adapter-specific handling could incorrectly charge delivery failure to payload execution retry counters.Why This Change Was Made
Cron finalization now records one durable
completionStatus(succeeded,failed, orunknown) from the admitted delivery contract after execution and delivery settle. Payload execution status remains independent, legacy rows fail safely from stored immutable facts, one-shots delete only after successful completion, and CLI/Gateway consumers read the recorded fact rather than mutable job configuration.This is an additive run-history and plugin-hook field. It does not add a SQLite schema migration, change the Gateway protocol version, add a duplicate job-state field, or replay payload work after delivery failure.
User Impact
Operators can rely on
openclaw cron run --waitto fail when explicitly required delivery fails. Default announce delivery remains best-effort. Required-failed one-shots remain disabled and inspectable with no next run, execution retry counters remain execution-only, and Gateway restart does not replay the payload.AI-assisted implementation; maintainer-reviewed and understood.
Evidence
pnpm check:architecture,pnpm test:bundled, andpnpm protocol:checkpass; generated Swift protocol models include the additive field.ok, completionfailed;succeeded;Production LOC: +244/-64 (net +180). Tests: +577/-48. Docs: +6/-4. The production growth is the additive durable completion contract and required task/history/CLI/Gateway propagation; simplification removed divergent adapter policy, repeated delivery normalization, and mutable CLI inference.