Skip to content

fix: stop marking delivered scheduled reports as failed - #152165

Merged
pash-openai merged 2 commits into
mainfrom
codex/cron-delivered-report-completion
Sep 18, 2026
Merged

pash-openai merged 2 commits into
mainfrom
codex/cron-delivered-report-completion

Conversation

@pash-openai

Copy link
Copy Markdown
Contributor

A scheduled report can be posted successfully through the message tool, followed by a rate-limited verification read and an intentional NO_REPLY. OpenClaw currently turns that completed run into a failure and sends a misleading automation alert.

Treat an authored silent finish as completion when the run already has confirmed, visible message-tool delivery. Runs without delivery evidence, aborted runs, and heartbeats retain their failure reporting. The change reuses existing delivery evidence and leaves retry and execution policy unchanged.

The regression reproduces the false failure before this change and passes afterward, including the isolated scheduler path. Missing delivery, empty sends, missing final answers, aborted runs, and heartbeats still report errors.

@clawsweeper

clawsweeper Bot commented Sep 18, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-18T20:59:51.694711Z f61b32c PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Sep 18, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f61b32cac1

ℹ️ 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".

@pash-openai
pash-openai enabled auto-merge (squash) September 18, 2026 21:00
@pash-openai
pash-openai enabled auto-merge (squash) September 18, 2026 21:04
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 18, 2026
@clawsweeper

clawsweeper Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 18, 2026, 5:09 PM ET / 21:09 UTC.

ClawSweeper review

What this changes

Preserve successful scheduled-report completion after a tool error when the agent intentionally finishes silently and has confirmed, visible, completed message delivery.

Merge readiness

✅ Ready for maintainer review

This remains a useful fix: current main still misclassifies this completion path. The latest commit resolves the earlier progress-only finding, and no additional blocking defect was found.

Priority: P2
Reviewed head: 9ce6fff394f4c783983f415f503bdf380d0217da

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with useful regression coverage and the earlier completion-marker defect addressed; local execution was outside this review.
Proof confidence 🌊 off-meta tidepool Not applicable: GitHub verifies a maintainer author, so the external-contributor proof gate does not apply. The supplied evidence exercises payload construction and scheduler classification through tests with a mocked agent result; it is not a live scheduled-report trace.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: GitHub verifies a maintainer author, so the external-contributor proof gate does not apply. The supplied evidence exercises payload construction and scheduler classification through tests with a mocked agent result; it is not a live scheduled-report trace.
Evidence reviewed 8 items Current main still needs the fix: Fetched main explicitly excludes cron triggers from intentional-silence handling, leaving the reported synthetic-warning path active.
Completion-aware suppression: The introduced condition requires intentional silence, visible committed delivery, completion evidence, and neither heartbeat nor abort. Existing completion evidence rejects explicit progress-only markers while retaining legacy unmarked delivery semantics.
Production input boundary: Terminal preparation passes the actual trigger, tool error, delivery targets, source-reply payloads, and interruption state into the changed payload builder. The codex_apps tool name in the new tests is inert error metadata; the patch does not invoke or test a Codex dependency contract.
Findings None None.
Security None None.

How this fits together

The agent runner converts assistant output and tool results into reply payloads. The scheduler uses those payloads to determine run success and whether failure notifications are warranted.

flowchart TD
  A[Scheduled agent run] --> B[Assistant answer and tool results]
  B --> C[Delivery evidence]
  C --> D{Silent finish with completed visible delivery?}
  D -->|Yes| E[Suppress synthetic tool warning]
  D -->|No| F[Retain failure reporting]
  E --> G[Scheduler outcome]
  F --> G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +7, Tests +135. Total +142 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 10 3 +7
Tests 2 135 0 +135
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 145 3 +142

Review metrics

None.

Technical review

Best possible solution:

Keep completion classification in the existing payload owner, using shared delivery evidence while preserving genuine scheduler failures.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: a cron run with confirmed delivery, a subsequent tool error, and an authored NO_REPLY still creates an error payload on current main. Runtime reproduction was not executed in this read-only review.

Is this the best way to solve the issue?

Yes. Reusing the existing visibility and completion predicates narrowly repairs the payload decision without adding scheduler policy, configuration, or another delivery owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 400d1f8d0fef.

Labels

Label changes:

  • add P2: False failure status and automation alerts after successful delivery are a bounded scheduler correctness problem.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: GitHub verifies a maintainer author, so the external-contributor proof gate does not apply. The supplied evidence exercises payload construction and scheduler classification through tests with a mocked agent result; it is not a live scheduled-report trace.

Label justifications:

  • P2: False failure status and automation alerts after successful delivery are a bounded scheduler correctness problem.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: GitHub verifies a maintainer author, so the external-contributor proof gate does not apply. The supplied evidence exercises payload construction and scheduler classification through tests with a mocked agent result; it is not a live scheduled-report trace.

Evidence

What I checked:

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • steipete: 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.

@pash-openai
pash-openai merged commit e731216 into main Sep 18, 2026
211 of 212 checks passed
@pash-openai
pash-openai deleted the codex/cron-delivered-report-completion branch September 18, 2026 21:26
pash-openai added a commit that referenced this pull request Sep 18, 2026
* fix(cron): exclude queue waits from heartbeat timeouts (#148876)

Closes #148874

Heartbeat cron jobs report execution timeouts while queued behind foreground work.

Queue entry pauses the cron watchdog; attempt start arms it. This state has one writer. Retries retain their final outcome, including after handler replacement.

Growth: `timer-job-runner.ts` +7 (deadline), `timer-execution.ts` +1 (handoff), `timer-execution-timeout.ts` +5 (type), `session-event-wake.ts` +18 (notifications).

Growth accepted under the owner's standing acceptance (2026-09-15).

Queue waits no longer create false errors. Actual failures and execution deadlines remain effective.

Real Gateway: hold a `chat.send` response for five seconds; call `cron.run` with a two-second heartbeat timeout; read `cron.runs`/`cron.get`.

Main expired at 2,010 ms before any heartbeat request, with one consecutive error. The fix stayed pending, then recorded the retained retry's success at 60.4 seconds. Separate controls recorded a failed retry and an executing timeout, each with one consecutive error.

Preserves #134464 outcome accounting. No config, schema, protocol or SDK change. #148333's next-cadence policy remains separate.

Scheduled monitors, heartbeat tasks and immediate cron events.

Enqueue pauses the deadline; attempts restart it; completion disposes it.

196 tests passed on a fresh merge with main; 27 focused tests also cover unlimited heartbeats. Original-code negative controls fail. Type-aware checks passed.

Immediate handoff, coalescing and cancellation remain unchanged and covered.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 4e88587)

* fix: stop marking delivered scheduled reports as failed (#152165)

* fix: preserve completed scheduled reports after tool read failures

* fix: keep cron failures after progress-only messages

(cherry picked from commit e731216)

---------

Co-authored-by: Sriram Natarajan <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
vincentkoc added a commit that referenced this pull request Sep 18, 2026
…n-20260918-v4

* origin/main: (81 commits)
  fix: retire failed setup plugins without replaying facade initialization (#152026)
  fix(test): select Node for built runtime recovery fixtures (#152162)
  refactor(auth): reuse privately assembled choice groups (#152166)
  fix: preserve chat media delivery and session boundaries (#152079)
  fix: keep stale Stop messages from canceling replacement sessions (#152116)
  improve(plugins): reduce mutable argument handling overhead (#152154)
  fix(scripts): prevent host tooling drift from blocking PR workflows (#152078)
  improve: reduce model capability preparation work (#152128)
  fix: stop marking delivered scheduled reports as failed (#152165)
  fix: start background context maintenance after durable turns (#151936)
  fix(models): avoid ambient state reads during prepared selection (#152119)
  feat: recover abandoned Crabbox source staging (#152006)
  chore(ui): refresh control ui locales (#152098)
  fix(ui): keep cloud startup prompts and progress in chat (#152024)
  fix: report completed subprocess cleanup after cancellation (#152107)
  perf(reply): reuse normalized inbound text (#152110)
  fix(cron): paused future one-shots disappear after Run now (#152126)
  perf(sessions): reuse rows and skip discarded terminal labels (#152109)
  fix(ui): keep keyboard-focused automation controls clear of sticky actions (#152135)
  fix(ui): load remote images in compact activity previews (#152045)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 19, 2026
)

* fix: preserve completed scheduled reports after tool read failures

* fix: keep cron failures after progress-only messages
obviyus added a commit that referenced this pull request Nov 19, 2026
…are recorded failed (#201638)

## What Problem This Solves

A scheduled run gets marked failed even after it recovers and finishes, if its first tool call named a tool the run does not have.

Production case: a daily automation, two days in a row. The model's first call went to `cream_exec`, a name that does not exist (`Tool cream_exec not found`, `executionStarted: false`). It then called `exec` 4 to 6 times, all of which succeeded. It recorded `no_change`, replied `NO_REPLY`, and the session ended `status: success`. Cron history still recorded the run as `error` with `⚠️ Cream Exec blocked`, and sent a "failed 2 times in a row" alert.

## Why This Change Was Made

The terminal tool observer (`src/agents/tool-terminal-outcome.ts`) keeps one slot for the last failed tool call. Since #126542, that slot clears only when **the same tool name** later succeeds. For a real tool that is the right identity: a failed `message` send is not undone by a later `read` (#107735, #139037).

A call to a missing tool has no tool identity. The model's retry always uses a different name (`exec`, not `cream_exec`), so the slot could never clear. The rest of the chain then works as designed:

- `payloads.ts` keeps the warning, because a scheduled run's `NO_REPLY` is not authoritative without message-tool delivery (#120056, #152165), and `no_change` is not a meaningful result (#186652).
- `resolveCronPayloadOutcome` finds an error payload with no later successful output, and `run-finalize.ts` records `error`.

The fix is in the observer, where recovery is decided:

- `agent-core` tags the "tool not found" outcome with a typed pre-execution `errorKind: "unknown-tool"`, beside the existing `"argument-validation"`.
- The embedded runner and the Codex dynamic-tool bridge (`Unknown OpenClaw tool` / `not available for this turn`) carry it as `unknownTool` on the failure.
- The observer treats an `unknownTool` failure as recovered by the next successful call that actually ran. Every other failure still recovers only through the same tool.

No warning, silence, `no_change` or cron payload rule changes. The bad state (a failure whose only recovery path is a name that cannot run) is no longer possible.

Accepted edge case: a model that calls a missing tool, then runs some unrelated tool successfully and ends silently without ever doing the intended work, now finishes `ok`. The failed call is still in the transcript and progress lane. A run that calls a missing tool and then stops still fails, as before.

## User Impact

- Scheduled runs that recover from calling a missing tool and finish their work are recorded `ok`, with no false failure alert.
- A run that calls a missing tool and then gives up silently still records `error` with `⚠️ <tool> blocked`.
- Failures of real tools are unchanged.

## Evidence

- New regression in `tool-terminal-outcome.test.ts`. It drives a real `Agent` loop and the subscription, then builds payloads with `isCronTrigger: true` and runs `resolveCronPayloadOutcome`. Case: missing tool, then `exec` succeeds, then `NO_REPLY`.
  - Red on the production commit `5fb23152` and on the base `67aacbb6`: `expected [ '⚠️ Cream Exec blocked' ] to deeply equal []`.
  - Green with the fix. The control (missing tool, then `NO_REPLY`) still warns and stays fatal on both sides.
- Codex bridge regression in `dynamic-tool-execution.test.ts`: a real bridge, missing tool, then `exec`, through `handleDynamicToolCallWithTimeout` with the contract observer. The missing call carries `unknownTool` and `executionStarted: false`, and the next `exec` clears the failure.
- Existing tables green: `payloads.errors.test.ts` (#186652 / #151042 silence table), `payloads.test.ts` (#152165 delivered-report cases), `cron/isolated-agent/helpers.test.ts`, subscribe ordering and session suites, Codex `dynamic-tool-execution` / `event-projector.dynamic-tools`, `agents-wait-tool`.
- `pnpm tsgo:core`, `pnpm check:test-types`, `pnpm check:baseline-ratchets`, oxlint and oxfmt on the changed files: clean.
- Real isolated Gateway (`ocx src`, random port, scratch state), real CronService, one-shot `at` job that came due on its own. Only model inference was scripted: a local Anthropic Messages server replays the production sequence (`cream_exec` → `exec` → `NO_REPLY`).

  | Arm | Model calls | Session | Cron history |
  | --- | --- | --- | --- |
  | `5fb23152` | `cream_exec` (not found) → `exec` ok → `NO_REPLY` | `success` | `error`, `⚠️ Cream Exec blocked` |
  | this PR | same | `success` | `ok` |
  | this PR, no recovery | `cream_exec` (not found) → `NO_REPLY` | `success` | `error`, `⚠️ Cream Exec blocked` (unchanged) |

- A real-model attempt (Claude Opus 5.5) would not call a tool missing from its list, even when told to. It called `exec` directly and ended `ok` on base. That is why the incident sequence was scripted.

Production delta: about +40 lines on the existing observer path (one typed tag at each producer, one recovery branch). Over-cap files do not grow. Tests: +65.

Co-authored-by: Ayaan Zaidi <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 19, 2026
…are recorded failed (#201638)

## What Problem This Solves

A scheduled run gets marked failed even after it recovers and finishes, if its first tool call named a tool the run does not have.

Production case: a daily automation, two days in a row. The model's first call went to `cream_exec`, a name that does not exist (`Tool cream_exec not found`, `executionStarted: false`). It then called `exec` 4 to 6 times, all of which succeeded. It recorded `no_change`, replied `NO_REPLY`, and the session ended `status: success`. Cron history still recorded the run as `error` with `⚠️ Cream Exec blocked`, and sent a "failed 2 times in a row" alert.

## Why This Change Was Made

The terminal tool observer (`src/agents/tool-terminal-outcome.ts`) keeps one slot for the last failed tool call. Since #126542, that slot clears only when **the same tool name** later succeeds. For a real tool that is the right identity: a failed `message` send is not undone by a later `read` (#107735, #139037).

A call to a missing tool has no tool identity. The model's retry always uses a different name (`exec`, not `cream_exec`), so the slot could never clear. The rest of the chain then works as designed:

- `payloads.ts` keeps the warning, because a scheduled run's `NO_REPLY` is not authoritative without message-tool delivery (#120056, #152165), and `no_change` is not a meaningful result (#186652).
- `resolveCronPayloadOutcome` finds an error payload with no later successful output, and `run-finalize.ts` records `error`.

The fix is in the observer, where recovery is decided:

- `agent-core` tags the "tool not found" outcome with a typed pre-execution `errorKind: "unknown-tool"`, beside the existing `"argument-validation"`.
- The embedded runner and the Codex dynamic-tool bridge (`Unknown OpenClaw tool` / `not available for this turn`) carry it as `unknownTool` on the failure.
- The observer treats an `unknownTool` failure as recovered by the next successful call that actually ran. Every other failure still recovers only through the same tool.

No warning, silence, `no_change` or cron payload rule changes. The bad state (a failure whose only recovery path is a name that cannot run) is no longer possible.

Accepted edge case: a model that calls a missing tool, then runs some unrelated tool successfully and ends silently without ever doing the intended work, now finishes `ok`. The failed call is still in the transcript and progress lane. A run that calls a missing tool and then stops still fails, as before.

## User Impact

- Scheduled runs that recover from calling a missing tool and finish their work are recorded `ok`, with no false failure alert.
- A run that calls a missing tool and then gives up silently still records `error` with `⚠️ <tool> blocked`.
- Failures of real tools are unchanged.

## Evidence

- New regression in `tool-terminal-outcome.test.ts`. It drives a real `Agent` loop and the subscription, then builds payloads with `isCronTrigger: true` and runs `resolveCronPayloadOutcome`. Case: missing tool, then `exec` succeeds, then `NO_REPLY`.
  - Red on the production commit `5fb23152` and on the base `67aacbb6`: `expected [ '⚠️ Cream Exec blocked' ] to deeply equal []`.
  - Green with the fix. The control (missing tool, then `NO_REPLY`) still warns and stays fatal on both sides.
- Codex bridge regression in `dynamic-tool-execution.test.ts`: a real bridge, missing tool, then `exec`, through `handleDynamicToolCallWithTimeout` with the contract observer. The missing call carries `unknownTool` and `executionStarted: false`, and the next `exec` clears the failure.
- Existing tables green: `payloads.errors.test.ts` (#186652 / #151042 silence table), `payloads.test.ts` (#152165 delivered-report cases), `cron/isolated-agent/helpers.test.ts`, subscribe ordering and session suites, Codex `dynamic-tool-execution` / `event-projector.dynamic-tools`, `agents-wait-tool`.
- `pnpm tsgo:core`, `pnpm check:test-types`, `pnpm check:baseline-ratchets`, oxlint and oxfmt on the changed files: clean.
- Real isolated Gateway (`ocx src`, random port, scratch state), real CronService, one-shot `at` job that came due on its own. Only model inference was scripted: a local Anthropic Messages server replays the production sequence (`cream_exec` → `exec` → `NO_REPLY`).

  | Arm | Model calls | Session | Cron history |
  | --- | --- | --- | --- |
  | `5fb23152` | `cream_exec` (not found) → `exec` ok → `NO_REPLY` | `success` | `error`, `⚠️ Cream Exec blocked` |
  | this PR | same | `success` | `ok` |
  | this PR, no recovery | `cream_exec` (not found) → `NO_REPLY` | `success` | `error`, `⚠️ Cream Exec blocked` (unchanged) |

- A real-model attempt (Claude Opus 5.5) would not call a tool missing from its list, even when told to. It called `exec` directly and ended `ok` on base. That is why the incident sequence was scripted.

Production delta: about +40 lines on the existing observer path (one typed tag at each producer, one recovery branch). Over-cap files do not grow. Tests: +65.

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit f5958f4)

Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 20, 2026
…are recorded failed (openclaw#201638)

## What Problem This Solves

A scheduled run gets marked failed even after it recovers and finishes, if its first tool call named a tool the run does not have.

Production case: a daily automation, two days in a row. The model's first call went to `cream_exec`, a name that does not exist (`Tool cream_exec not found`, `executionStarted: false`). It then called `exec` 4 to 6 times, all of which succeeded. It recorded `no_change`, replied `NO_REPLY`, and the session ended `status: success`. Cron history still recorded the run as `error` with `⚠️ Cream Exec blocked`, and sent a "failed 2 times in a row" alert.

## Why This Change Was Made

The terminal tool observer (`src/agents/tool-terminal-outcome.ts`) keeps one slot for the last failed tool call. Since openclaw#126542, that slot clears only when **the same tool name** later succeeds. For a real tool that is the right identity: a failed `message` send is not undone by a later `read` (openclaw#107735, openclaw#139037).

A call to a missing tool has no tool identity. The model's retry always uses a different name (`exec`, not `cream_exec`), so the slot could never clear. The rest of the chain then works as designed:

- `payloads.ts` keeps the warning, because a scheduled run's `NO_REPLY` is not authoritative without message-tool delivery (openclaw#120056, openclaw#152165), and `no_change` is not a meaningful result (openclaw#186652).
- `resolveCronPayloadOutcome` finds an error payload with no later successful output, and `run-finalize.ts` records `error`.

The fix is in the observer, where recovery is decided:

- `agent-core` tags the "tool not found" outcome with a typed pre-execution `errorKind: "unknown-tool"`, beside the existing `"argument-validation"`.
- The embedded runner and the Codex dynamic-tool bridge (`Unknown OpenClaw tool` / `not available for this turn`) carry it as `unknownTool` on the failure.
- The observer treats an `unknownTool` failure as recovered by the next successful call that actually ran. Every other failure still recovers only through the same tool.

No warning, silence, `no_change` or cron payload rule changes. The bad state (a failure whose only recovery path is a name that cannot run) is no longer possible.

Accepted edge case: a model that calls a missing tool, then runs some unrelated tool successfully and ends silently without ever doing the intended work, now finishes `ok`. The failed call is still in the transcript and progress lane. A run that calls a missing tool and then stops still fails, as before.

## User Impact

- Scheduled runs that recover from calling a missing tool and finish their work are recorded `ok`, with no false failure alert.
- A run that calls a missing tool and then gives up silently still records `error` with `⚠️ <tool> blocked`.
- Failures of real tools are unchanged.

## Evidence

- New regression in `tool-terminal-outcome.test.ts`. It drives a real `Agent` loop and the subscription, then builds payloads with `isCronTrigger: true` and runs `resolveCronPayloadOutcome`. Case: missing tool, then `exec` succeeds, then `NO_REPLY`.
  - Red on the production commit `30c2ded2` and on the base `78f5d6e6`: `expected [ '⚠️ Cream Exec blocked' ] to deeply equal []`.
  - Green with the fix. The control (missing tool, then `NO_REPLY`) still warns and stays fatal on both sides.
- Codex bridge regression in `dynamic-tool-execution.test.ts`: a real bridge, missing tool, then `exec`, through `handleDynamicToolCallWithTimeout` with the contract observer. The missing call carries `unknownTool` and `executionStarted: false`, and the next `exec` clears the failure.
- Existing tables green: `payloads.errors.test.ts` (openclaw#186652 / openclaw#151042 silence table), `payloads.test.ts` (openclaw#152165 delivered-report cases), `cron/isolated-agent/helpers.test.ts`, subscribe ordering and session suites, Codex `dynamic-tool-execution` / `event-projector.dynamic-tools`, `agents-wait-tool`.
- `pnpm tsgo:core`, `pnpm check:test-types`, `pnpm check:baseline-ratchets`, oxlint and oxfmt on the changed files: clean.
- Real isolated Gateway (`ocx src`, random port, scratch state), real CronService, one-shot `at` job that came due on its own. Only model inference was scripted: a local Anthropic Messages server replays the production sequence (`cream_exec` → `exec` → `NO_REPLY`).

  | Arm | Model calls | Session | Cron history |
  | --- | --- | --- | --- |
  | `30c2ded2` | `cream_exec` (not found) → `exec` ok → `NO_REPLY` | `success` | `error`, `⚠️ Cream Exec blocked` |
  | this PR | same | `success` | `ok` |
  | this PR, no recovery | `cream_exec` (not found) → `NO_REPLY` | `success` | `error`, `⚠️ Cream Exec blocked` (unchanged) |

- A real-model attempt (Claude Opus 5.5) would not call a tool missing from its list, even when told to. It called `exec` directly and ended `ok` on base. That is why the incident sequence was scripted.

Production delta: about +40 lines on the existing observer path (one typed tag at each producer, one recovery branch). Over-cap files do not grow. Tests: +65.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 23, 2026
…are recorded failed (openclaw#201638)

## What Problem This Solves

A scheduled run gets marked failed even after it recovers and finishes, if its first tool call named a tool the run does not have.

Production case: a daily automation, two days in a row. The model's first call went to `cream_exec`, a name that does not exist (`Tool cream_exec not found`, `executionStarted: false`). It then called `exec` 4 to 6 times, all of which succeeded. It recorded `no_change`, replied `NO_REPLY`, and the session ended `status: success`. Cron history still recorded the run as `error` with `⚠️ Cream Exec blocked`, and sent a "failed 2 times in a row" alert.

## Why This Change Was Made

The terminal tool observer (`src/agents/tool-terminal-outcome.ts`) keeps one slot for the last failed tool call. Since openclaw#126542, that slot clears only when **the same tool name** later succeeds. For a real tool that is the right identity: a failed `message` send is not undone by a later `read` (openclaw#107735, openclaw#139037).

A call to a missing tool has no tool identity. The model's retry always uses a different name (`exec`, not `cream_exec`), so the slot could never clear. The rest of the chain then works as designed:

- `payloads.ts` keeps the warning, because a scheduled run's `NO_REPLY` is not authoritative without message-tool delivery (openclaw#120056, openclaw#152165), and `no_change` is not a meaningful result (openclaw#186652).
- `resolveCronPayloadOutcome` finds an error payload with no later successful output, and `run-finalize.ts` records `error`.

The fix is in the observer, where recovery is decided:

- `agent-core` tags the "tool not found" outcome with a typed pre-execution `errorKind: "unknown-tool"`, beside the existing `"argument-validation"`.
- The embedded runner and the Codex dynamic-tool bridge (`Unknown OpenClaw tool` / `not available for this turn`) carry it as `unknownTool` on the failure.
- The observer treats an `unknownTool` failure as recovered by the next successful call that actually ran. Every other failure still recovers only through the same tool.

No warning, silence, `no_change` or cron payload rule changes. The bad state (a failure whose only recovery path is a name that cannot run) is no longer possible.

Accepted edge case: a model that calls a missing tool, then runs some unrelated tool successfully and ends silently without ever doing the intended work, now finishes `ok`. The failed call is still in the transcript and progress lane. A run that calls a missing tool and then stops still fails, as before.

## User Impact

- Scheduled runs that recover from calling a missing tool and finish their work are recorded `ok`, with no false failure alert.
- A run that calls a missing tool and then gives up silently still records `error` with `⚠️ <tool> blocked`.
- Failures of real tools are unchanged.

## Evidence

- New regression in `tool-terminal-outcome.test.ts`. It drives a real `Agent` loop and the subscription, then builds payloads with `isCronTrigger: true` and runs `resolveCronPayloadOutcome`. Case: missing tool, then `exec` succeeds, then `NO_REPLY`.
  - Red on the production commit `5fb23152` and on the base `67aacbb6`: `expected [ '⚠️ Cream Exec blocked' ] to deeply equal []`.
  - Green with the fix. The control (missing tool, then `NO_REPLY`) still warns and stays fatal on both sides.
- Codex bridge regression in `dynamic-tool-execution.test.ts`: a real bridge, missing tool, then `exec`, through `handleDynamicToolCallWithTimeout` with the contract observer. The missing call carries `unknownTool` and `executionStarted: false`, and the next `exec` clears the failure.
- Existing tables green: `payloads.errors.test.ts` (openclaw#186652 / openclaw#151042 silence table), `payloads.test.ts` (openclaw#152165 delivered-report cases), `cron/isolated-agent/helpers.test.ts`, subscribe ordering and session suites, Codex `dynamic-tool-execution` / `event-projector.dynamic-tools`, `agents-wait-tool`.
- `pnpm tsgo:core`, `pnpm check:test-types`, `pnpm check:baseline-ratchets`, oxlint and oxfmt on the changed files: clean.
- Real isolated Gateway (`ocx src`, random port, scratch state), real CronService, one-shot `at` job that came due on its own. Only model inference was scripted: a local Anthropic Messages server replays the production sequence (`cream_exec` → `exec` → `NO_REPLY`).

  | Arm | Model calls | Session | Cron history |
  | --- | --- | --- | --- |
  | `5fb23152` | `cream_exec` (not found) → `exec` ok → `NO_REPLY` | `success` | `error`, `⚠️ Cream Exec blocked` |
  | this PR | same | `success` | `ok` |
  | this PR, no recovery | `cream_exec` (not found) → `NO_REPLY` | `success` | `error`, `⚠️ Cream Exec blocked` (unchanged) |

- A real-model attempt (Claude Opus 5.5) would not call a tool missing from its list, even when told to. It called `exec` directly and ended `ok` on base. That is why the incident sequence was scripted.

Production delta: about +40 lines on the existing observer path (one typed tag at each producer, one recovery branch). Over-cap files do not grow. Tests: +65.

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit f5958f4)
Release adaptation: approved 2026.11.7 models replay; see models-hook-safe-v2/REPORT.md.
Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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