Repository navigation
feat(cron): unattended-run preamble and watcher-authoring guidance - #110949
Conversation
Isolated cron and hook agent turns received only the job tag, message, and time line — no operating contract for unattended execution. Runs ended in questions, plans, or bare acknowledgements (the runtime even re-prompts once for interim acks). Append a static per-class preamble: the final reply is the deliverable, HEARTBEAT_OK when idle, plain failure statements. Trusted jobs additionally defer to the job's own instructions on conflict and learn removal-only self-cleanup; external-hook runs get only the common core so fenced webhook content cannot use an override clause or a destructive affordance advertised in the trusted suffix. Free-form job names stay out for the same reason.
Trigger-script guidance covered only the return contract. Add the operating rules that keep watchers trustworthy: fire on every actionable state including failures (success-only watchers go silent when broken), dedupe via returned state, keep scripts read-only with actions in the payload, and make the fired message self-contained.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 907b6a8345
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| function appendCronUnattendedRunPreamble(commandBody: string, opts: { externalHook: boolean }) { | ||
| const core = `This is an unattended scheduled run. Nobody is present to clarify or approve, so complete the task with what you have. Your final reply is the deliverable — not a plan, an acknowledgement, or a request for input. If nothing needs doing, reply exactly ${HEARTBEAT_TOKEN}. If something failed, state plainly what failed and what you tried — the scheduler owns retries and failure alerts.`; | ||
| const trustedExtra = | ||
| " Where the job's own instructions conflict with this preamble, the job's instructions win (a question or plan the job explicitly requests is a valid deliverable). If this job is no longer needed, you may remove it with the cron tool."; |
There was a problem hiding this comment.
Advertise self-removal only when the cron tool is available
When an isolated job sets payload.toolsAllow to [] or to a list that omits cron, this unconditional preamble still tells the agent that it may remove the job. The allowlist is forwarded by src/cron/isolated-agent/run.ts:1108 and enforced by applyEmbeddedAttemptToolsAllow in src/agents/embedded-agent-runner/run/attempt-tool-construction-plan.ts:59, so those runs have no cron tool. A recurring job deemed unnecessary can therefore remain scheduled—and continue consuming runs—while the agent attempts an unavailable cleanup action; condition this sentence on effective cron-tool availability.
Useful? React with 👍 / 👎.
|
Merged via squash.
|
…penclaw#110949) * feat(cron): add unattended-run preamble to isolated agent turns Isolated cron and hook agent turns received only the job tag, message, and time line — no operating contract for unattended execution. Runs ended in questions, plans, or bare acknowledgements (the runtime even re-prompts once for interim acks). Append a static per-class preamble: the final reply is the deliverable, HEARTBEAT_OK when idle, plain failure statements. Trusted jobs additionally defer to the job's own instructions on conflict and learn removal-only self-cleanup; external-hook runs get only the common core so fenced webhook content cannot use an override clause or a destructive affordance advertised in the trusted suffix. Free-form job names stay out for the same reason. * feat(cron): teach watcher authoring rules in the cron tool description Trigger-script guidance covered only the return contract. Add the operating rules that keep watchers trustworthy: fire on every actionable state including failures (success-only watchers go silent when broken), dedupe via returned state, keep scripts read-only with actions in the payload, and make the fired message self-contained.
…penclaw#110949) * feat(cron): add unattended-run preamble to isolated agent turns Isolated cron and hook agent turns received only the job tag, message, and time line — no operating contract for unattended execution. Runs ended in questions, plans, or bare acknowledgements (the runtime even re-prompts once for interim acks). Append a static per-class preamble: the final reply is the deliverable, HEARTBEAT_OK when idle, plain failure statements. Trusted jobs additionally defer to the job's own instructions on conflict and learn removal-only self-cleanup; external-hook runs get only the common core so fenced webhook content cannot use an override clause or a destructive affordance advertised in the trusted suffix. Free-form job names stay out for the same reason. * feat(cron): teach watcher authoring rules in the cron tool description Trigger-script guidance covered only the return contract. Add the operating rules that keep watchers trustworthy: fire on every actionable state including failures (success-only watchers go silent when broken), dedupe via returned state, keep scripts read-only with actions in the payload, and make the fired message self-contained.
## 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.
What Problem This Solves
Isolated cron and hook agent turns receive only
[cron:<id> <name>] <message>plus a time line — no operating contract for unattended execution. Runs end in clarification questions, plans, or bare acknowledgements; the runtime even carries a backstop that re-prompts once when the reply is an interim ack. Watcher authors similarly get only the{fire, message, state}return contract, so condition scripts tend to fire on success only — silent through exactly the failures they exist to catch.Why This Change Was Made
First deliverable of the automation-guidance track (precursor to the cron unification RFC):
src/cron/isolated-agent/run.ts): a static per-class suffix appended after external-content wrapping and before the delivery instruction. Common core: nobody is present to clarify or approve; the final reply is the deliverable (not a plan, acknowledgement, or request for input);HEARTBEAT_OKwhen idle; plain failure statements — the scheduler owns retries/alerts. Trusted jobs additionally defer to the job's own instructions on conflict (question/plan-shaped deliverables stay valid) and learn removal-only self-cleanup (matching the restricted isolated-run grant, which allows remove but not update). External-hook runs get only the core: an override clause or removal affordance in the trusted suffix would hand fenced webhook content a lever. Free-form job names stay out of the suffix for the same reason; per-class static text also keeps prompt caching effective.src/agents/tools/cron-tool.tsdescription, +44 words): fire on every actionable state including failures (success-only watchers go silent when broken, which looks healthy); dedupe via returned state, never memory; keep scripts read-only with actions in the payload; makemessageself-contained — it is the fired run's entire context.User Impact
Scheduled runs stop ending in questions/acknowledgements nobody will answer; agent-authored watchers monitor failure states instead of only success. No config, API, or scheduling behavior changes — prompt/description text only.
Evidence
node scripts/run-vitest.mjs src/cron/isolated-agent/run.message-tool-policy.test.ts→ 57/57 (includes new assertions: preamble ordering after the safe external wrapper and before delivery instructions; hook variant omits both the override clause and the removal sentence).node scripts/run-vitest.mjs src/agents/tools/cron-tool.test.ts src/agents/tools/cron-tool.schema.test.ts test/scripts/prompt-snapshots.test.ts→ all pass; six Codex prompt-snapshot fixtures regenerated viascripts/generate-prompt-snapshots.ts(not hand-edited).