Skip to content

fix(heartbeat): stop reporting success after tool failures - #107735

Merged
joshavant merged 11 commits into
mainfrom
fix/heartbeat-tool-failure-truth
Jul 16, 2026
Merged

joshavant merged 11 commits into
mainfrom
fix/heartbeat-tool-failure-truth

Conversation

@joshavant

@joshavant joshavant commented Jul 14, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #102206

AI-assisted PR. Implemented with Codex, manually directed and validated against the OpenClaw and upstream Codex runtime contracts.

What Problem This Solves

Fixes an issue where a heartbeat could report success after a mutating tool call—most visibly a message send—had failed. With the default cross-provider safety policy, a Codex-backed internal heartbeat correctly denied a Discord send, but a later successful heartbeat_respond masked that denial. Operators therefore saw a successful heartbeat even though the notification was never delivered.

Why This Change Was Made

The cross-provider guard remains unchanged: cross-provider delivery still requires explicit operator opt-in. Instead, one host-owned, attempt-scoped terminal observer now accepts portable tool facts and returns the accumulated terminal outcome. Mutation classification, execution-boundary evidence, and recovery matching stay in core; plugin harnesses report terminal facts only. Codex adds protocol-native mutation identity where its native tools bypass OpenClaw definitions, while a bounded Codex-internal snapshot preserves hook-adjusted arguments across timeout races without exposing host mutation policy through the plugin SDK.

Both the standard embedded runner and Codex app-server bridge distinguish calls that never started from calls that actually executed, preserve multiple failures, clear a failure only after a matching successful action, and keep Codex-only metadata private rather than changing the upstream app-server protocol.

Heartbeat execution treats an unresolved mutating-tool failure as the terminal outcome. It returns failed with reason agent-tool-failure, avoids successful heartbeat bookkeeping, preserves retry cadence and timestamps, and emits a warning only when delivery is configured. If that warning represents only part of a composite pending final, the unmatched content remains queued; an exact delivered pending final is still cleared to avoid duplicates.

This boundary matches the upstream Codex contract: dynamic tool calls/results expose the call identity, tool name, arguments, and success/error result, while OpenClaw remains responsible for its channel policy, mutation classification, and heartbeat terminal semantics.

User Impact

Operators no longer get a false-success heartbeat after a notification or other mutating action fails. The original failure remains visible and retryable, while existing cross-provider containment stays secure by default. Operators who intentionally enable cross-provider sends continue to get delivery, and normal heartbeat_respond notifications are unchanged.

The part of #102206 requesting implicit cross-provider delivery is intentionally not implemented; that behavior remains an explicit configuration choice. This PR fixes the concrete breakage in the report: the denial can no longer be swallowed by a later success.

Evidence

  • Rebased without conflicts onto main at 766742c67463648f58c3494d72037c55294264b7; final branch HEAD is f95645d373ddb8a27955f5f6e3919550386d37a3.
  • Fresh Autoreview initially found two timeout-edge issues. Both were fixed with explicit regression coverage; the mandatory rerun reported no accepted/actionable findings and judged the patch correct.
  • Post-rebase Blacksmith Testbox proof passed 636 focused tests across terminal state, hook execution boundaries, heartbeat delivery, and Codex projection. Provider blacksmith-testbox, id tbx_01kxkspb3f1bx2a4nwne6a1tfb, workflow run 29450807245.
  • The full remote pnpm check:changed passed on the rebased branch, including five TypeScript lanes, full core/extension/scripts lint, the plugin SDK API baseline, plugin boundaries, dependency guards, database-first checks, and zero runtime import cycles.
  • The final remote pnpm build passed, including published plugin SDK declaration validation and Control UI performance checks.
  • Live Discord proof on the behavior-bearing branch used runtime codex with model openai/gpt-5.5:
    • default internal-heartbeat → Discord send: cross-provider guard denied the marker, Discord received nothing, heartbeat returned { status: "failed", reason: "agent-tool-failure" };
    • ordinary heartbeat_respond notification: Discord received the marker and heartbeat returned sent;
    • explicit tools.message.crossContext.allowAcrossProviders=true: Discord received the marker and heartbeat completed without failure.
  • Upstream Codex contract checked directly in sibling source: codex-rs/app-server-protocol/src/protocol/v2/item.rs, codex-rs/app-server/src/bespoke_event_handling.rs, and codex-rs/app-server/src/dynamic_tools.rs.

No Telegram credential was leased or used. Live proof used a Convex-leased discord credential obtained through 1Password-backed broker access; all active project leases and owned Crabbox compute were released after proof.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling extensions: codex size: XL maintainer Maintainer-authored PR labels Jul 14, 2026
@joshavant
joshavant force-pushed the fix/heartbeat-tool-failure-truth branch from 5b9ac3f to 471a130 Compare July 14, 2026 20:34
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jul 15, 2026
@clawsweeper

clawsweeper Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 15, 2026, 4:46 AM ET / 08:46 UTC.

Summary
The PR tracks unresolved mutating-tool failures across the standard and Codex runtimes and makes heartbeat execution return agent-tool-failure instead of recording success.

PR surface: Source +624, Tests +953. Total +1577 across 39 files.

Reproducibility: yes. The PR provides a live Codex app-server path where a default-policy Discord send is denied and undelivered but the pre-fix heartbeat reports success, plus an after-fix run showing the new failed outcome.

Review metrics: 2 noteworthy metrics.

  • Plugin-harness runtime surface: 2 optional fields added. toolMutationRuntime and toolExecutionRuntime become additive host-to-plugin contracts that require explicit ownership approval.
  • Heartbeat terminal reasons: 1 reason added. agent-tool-failure becomes an observable result value for callers and operational reporting.

Stored data model
Persistent data-model change detected: serialized state: src/agents/tool-error-state.test.ts, vector/embedding metadata: src/auto-reply/heartbeat-reply-payload.test.ts, vector/embedding metadata: src/infra/heartbeat-runner.tool-response.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #102206
Summary: This PR is the concrete candidate fix for the linked canonical heartbeat false-success and message-loss report.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster ✨ media proof bonus
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Obtain explicit owner approval for the two optional plugin-harness runtime fields and the new heartbeat failure reason.

Risk before merge

  • [P1] The branch adds two optional host-runtime fields to the exported plugin-harness attempt contract; even though additive, that becomes an SDK boundary external harnesses may rely on.
  • [P1] The heartbeat result surface gains the agent-tool-failure reason, so downstream exhaustive consumers or operational dashboards should be confirmed to tolerate the new terminal value.

Maintainer options:

  1. Approve the additive runtime contracts (recommended)
    An owner confirms the optional harness callbacks and new heartbeat reason are intended durable contracts, after which the patch can proceed with its existing proof.
  2. Narrow the contract before merge
    Refactor the implementation to preserve the same terminal semantics without adding public plugin-harness fields, then repeat the focused Codex and heartbeat proof.

Next step before merge

  • No automated repair is indicated: the branch has no concrete review finding, carries a protected maintainer label, and only needs explicit contract ownership plus normal landing review.

Maintainer decision needed

  • Question: Should toolMutationRuntime, toolExecutionRuntime, and the agent-tool-failure heartbeat reason become the approved generic host/plugin-harness contract for this invariant?
  • Rationale: The implementation is technically coherent, but these additive SDK and terminal-result surfaces become durable contracts whose ownership cannot be decided from tests alone.
  • Likely owner: pashpashpash — Their merged structured-heartbeat and Codex-response work introduced the central contract this PR extends.
  • Options:
    • Approve the generic host contract (recommended): Accept the two optional harness runtime fields and new failure reason as the canonical cross-runtime boundary, then land the proven patch.
    • Keep the public SDK unchanged: Require a narrower owner-approved mechanism that preserves the same standard/Codex behavior without exposing new harness attempt fields.

Security
Cleared: The patch preserves the existing cross-provider denial boundary, adds no dependency or workflow execution source, and keeps OpenClaw-only metadata out of the upstream Codex protocol.

Review details

Best possible solution:

Land the host-owned, cross-runtime failure invariant after an owner explicitly approves the additive plugin-harness fields and heartbeat failure reason, while retaining the secure cross-provider default and the demonstrated fresh-install/live behavior.

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

Yes. The PR provides a live Codex app-server path where a default-policy Discord send is denied and undelivered but the pre-fix heartbeat reports success, plus an after-fix run showing the new failed outcome.

Is this the best way to solve the issue?

Yes, subject to owner approval of the additive contracts. Preserving the cross-provider security policy while carrying host-owned mutation failure state through both runtimes is narrower and safer than implicitly allowing the denied send or special-casing Discord.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 3bd9e280e47e.

Label changes

Label changes:

  • add P1: This PR fixes a reproduced workflow where a failed notification was silently reported as a successful heartbeat, causing real message loss.
  • add merge-risk: 🚨 compatibility: Merging adds two plugin-harness attempt fields and a new heartbeat failure reason that downstream integrations may begin consuming as durable contracts.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR provides linked live before/after Codex heartbeat runs against real Discord delivery, including denied, normal, and explicitly allowed cases, with exact-head build and focused remote validation.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The PR provides linked live before/after Codex heartbeat runs against real Discord delivery, including denied, normal, and explicitly allowed cases, with exact-head build and focused remote validation.

Label justifications:

  • P1: This PR fixes a reproduced workflow where a failed notification was silently reported as a successful heartbeat, causing real message loss.
  • merge-risk: 🚨 compatibility: Merging adds two plugin-harness attempt fields and a new heartbeat failure reason that downstream integrations may begin consuming as durable contracts.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The PR provides linked live before/after Codex heartbeat runs against real Discord delivery, including denied, normal, and explicitly allowed cases, with exact-head build and focused remote validation.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR provides linked live before/after Codex heartbeat runs against real Discord delivery, including denied, normal, and explicitly allowed cases, with exact-head build and focused remote validation.
Evidence reviewed

PR surface:

Source +624, Tests +953. Total +1577 across 39 files.

View PR surface stats
Area Files Added Removed Net
Source 26 958 334 +624
Tests 13 973 20 +953
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 39 1931 354 +1577

What I checked:

  • Live reproduction and after-fix proof: The PR records a live Codex app-server baseline where a WebChat-bound Discord send was denied and undelivered while the heartbeat returned success, followed by an AWS Crabbox run where the same denial produced { status: "failed", reason: "agent-tool-failure" }; normal and explicitly allowed delivery paths also succeeded. (471a130a6a65)
  • Heartbeat terminal outcome: The new terminal-failure handler restores timestamp state, avoids success bookkeeping, optionally delivers the warning, and consistently emits and returns the agent-tool-failure result. (src/infra/heartbeat-terminal-tool-failure.ts:4, d36403462f9b)
  • Standard-runtime execution boundary: The wrapped tool path records whether execution reached the synchronous tool-body boundary, and the subscriber consumes that evidence when classifying mutation failures and successful recovery. (src/agents/agent-tools.before-tool-call.ts:1742, d36403462f9b)
  • Codex runtime projection: Codex dynamic-tool results carry OpenClaw-only execution and argument metadata into host mutation classification while the protocol response remains limited to the upstream response fields. (extensions/codex/src/app-server/dynamic-tool-result-projection.ts:7, d36403462f9b)
  • Upstream Codex contract: Direct inspection of upstream Codex confirms dynamic-tool requests expose threadId, turnId, callId, namespace, tool, and arguments, while responses contain only contentItems and success; keeping execution metadata private to OpenClaw matches that contract. (../codex/codex-rs/app-server-protocol/schema/typescript/v2/DynamicToolCallResponse.ts:1)
  • Regression coverage: The branch adds focused coverage for pre-execution cancellation, multiple unresolved mutations, matching-action recovery, Codex result projection, heartbeat payload metadata, terminal failure delivery, and scheduler cadence. (src/infra/heartbeat-runner.tool-response.test.ts:183, d36403462f9b)

Likely related people:

  • joshavant: Prior merged history includes the heartbeat-runner failure-copy change in commit 39a9a34, independently connecting this contributor to the current-main behavior beyond this PR. (role: recent heartbeat contributor; confidence: high; commits: 39a9a34; files: src/infra/heartbeat-runner.ts)
  • pashpashpash: Commit 439d8ed introduced structured heartbeat responses and Codex tool replies, the central behavior whose terminal precedence this PR extends. (role: structured heartbeat and Codex response feature owner; confidence: high; commits: 439d8ed, 5bcc321, 8f4eaa9; files: src/infra/heartbeat-runner.ts, src/auto-reply/heartbeat-tool-response.ts, extensions/codex/src/app-server)
  • steipete: Recent history shows repeated integration work across heartbeat delivery, scheduling, source-reply behavior, and message delivery APIs adjacent to this patch. (role: recent heartbeat delivery integrator; confidence: medium; commits: bea4f0d, c0fe7ab, a4b17d6; files: src/infra/heartbeat-runner.ts, src/agents/embedded-agent-subscribe.handlers.tools.ts)
  • vignesh07: Recent merged work includes Codex safety coverage and heartbeat conflict resolution near the runtime and payload surfaces touched here. (role: adjacent Codex and heartbeat contributor; confidence: medium; commits: b277ae3, 7451415, 8e4035d; files: extensions/codex/src/app-server, src/infra/heartbeat-runner.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@joshavant
joshavant force-pushed the fix/heartbeat-tool-failure-truth branch from d364034 to ec1351a Compare July 15, 2026 18:52
@joshavant

Copy link
Copy Markdown
Collaborator Author

Addressed the two local ClawSweeper findings in d29d367491b:

  • unresolved mutating failures now survive in-turn compaction retries until the matching actions recover;
  • Codex native failures and successes now use the same host-owned merge/resolve policy as dynamic tools.

Validation:

  • Blacksmith Testbox tbx_01kxkkte74j6j0j52ytyfxzv2e: 221 focused tests passed (run 29444405951);
  • pnpm plugin-sdk:surface:check: passed;
  • full remote pnpm check:changed: passed;
  • fresh Autoreview: clean, no accepted/actionable findings (patch is correct, confidence 0.88).

@joshavant
joshavant force-pushed the fix/heartbeat-tool-failure-truth branch from d29d367 to f95645d Compare July 15, 2026 21:37
@joshavant joshavant self-assigned this Jul 15, 2026
@joshavant
joshavant force-pushed the fix/heartbeat-tool-failure-truth branch from d67a3f9 to e0fc345 Compare July 16, 2026 03:14
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Jul 16, 2026
@joshavant
joshavant force-pushed the fix/heartbeat-tool-failure-truth branch from e0fc345 to 05e8095 Compare July 16, 2026 06:53
@joshavant

Copy link
Copy Markdown
Collaborator Author

Final exact-HEAD proof for 05e80957e7b9807dc98a2e295c1099ed486e5018:

  • Full remote pnpm check:changed passed on Blacksmith Testbox tbx_01kxmszh7adkvmydffcxsdfpcd (run 29476973387).
  • Fresh full-branch Autoreview completed with no accepted or actionable findings (patch is correct, confidence 0.84).
  • Hosted PR CI is complete with zero failing or pending checks; openclaw/ci-gate passed.
  • Exact-HEAD live AWS Crabbox proof passed against Codex app-server, OpenAI gpt-5.5, and real Discord delivery (run run_2b74049c3fd5):
    • default WebChat-bound Discord send was denied and undelivered; the later successful heartbeat_respond did not mask it, and the heartbeat ended failed with reason agent-tool-failure;
    • explicit cross-provider opt-in delivered to Discord and ended ok-token;
    • a clean heartbeat_respond-only control ended ok-token without Discord delivery.

Current main drift was also checked without rebasing: the merge tree is clean, and the only touched-path overlap is docs/docs_map.md.

@joshavant
joshavant merged commit aaf5d23 into main Jul 16, 2026
116 checks passed
@joshavant
joshavant deleted the fix/heartbeat-tool-failure-truth branch July 16, 2026 08:23
@joshavant

Copy link
Copy Markdown
Collaborator Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 17, 2026
…107735)

* fix(heartbeat): preserve terminal tool failures

* fix(heartbeat): handle absent failure payloads

* test(agents): align execution-state consumers

* fix(heartbeat): retain unmatched pending finals

* fix(heartbeat): preserve failures across retries

* refactor(agents): narrow terminal outcome boundary

* fix(copilot): preserve terminal tool failures

* fix(agents): bound tool execution tracking

* docs(plugins): document harness terminal outcomes

* fix(codex): preserve exact terminal boundaries

* test(codex): harden abort race fixtures
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
…107735)

* fix(heartbeat): preserve terminal tool failures

* fix(heartbeat): handle absent failure payloads

* test(agents): align execution-state consumers

* fix(heartbeat): retain unmatched pending finals

* fix(heartbeat): preserve failures across retries

* refactor(agents): narrow terminal outcome boundary

* fix(copilot): preserve terminal tool failures

* fix(agents): bound tool execution tracking

* docs(plugins): document harness terminal outcomes

* fix(codex): preserve exact terminal boundaries

* test(codex): harden abort race fixtures
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]>
obviyus added a commit that referenced this pull request Nov 29, 2026
…l recovered from (#180922)

Root cause: `src/agents/tool-terminal-outcome.ts:110` (main `ba0a7a5fac`). The terminal observer lets a failed tool call be recovered only by a later success of the same tool name. A run whose `read` or `web_fetch` fails, and that then does other work that succeeds, still ends holding that failure. In a cron run that ends on `NO_REPLY`, `payloads.ts:488` turns it into `⚠️ <Tool> failed` and the run is recorded as `error`.

Fixes #207683

## What Problem This Solves

A scheduled run reads or fetches something that fails, keeps working, and ends on `NO_REPLY` with `stopReason: stop`. It is still recorded as failed. That counts toward the error streak, fires failure alerts (each starts a repair turn) and auto-disables one-shot jobs.

Reports:
- @jaxonparrott, 2026.10.7: 9 of 9 failed runs of one hourly job had this shape (`Web Fetch`, `Wait`, plugin tools). The model kept working after the error, and the next run succeeded.
- @abacha, 2026.11.6 and main `cb59aaa3106`, plus #207683: a `web_fetch` inside a Code Mode `exec` cell returns 403 and the cell catches it. The outer `exec` completes and the turn ends on `NO_REPLY`, yet the run is recorded as `error` and the one-shot job is disabled. The nested failure fills the same last-tool-error slot, and the successful outer `exec` cannot clear it because it has a different name.

## Why This Change Was Made

The fix is in the observer, where recovery is already decided. Recovery by a later, different call applies only when the failed call actually ran, was not mutating, and its tool has the catalog's static replay-safe fact: `isReplaySafeToolCall(toolName, {})`, which is true for `read`, `ls`, `web_search`, `web_fetch`, `memory_get` and `sessions_*`. Such a call changed nothing, so the next successful executed call recovers it. Nothing else changes:
- A failed mutation (a send, write, edit or spawn) still recovers only through the same tool. A failed message send is not undone by a later read (#107735, #139037).
- Tools with no catalog read-only fact keep the same-tool rule. A failed browser `act` followed by a successful `read` still reports the browser failure. An `exec`, including one denied with `SYSTEM_RUN_DENIED` after it started, still keeps the cron execution-denied signal.
- A call blocked before it ran, the missing-tool rule (#201638) and the dispatch catalog-target rule are unchanged.
- The cron `NO_REPLY` guard at `payloads.ts:488` is unchanged. A tool failure followed by `NO_REPLY` with no later successful call still fails the run (#116731, #120056), and so does a missing tool followed by `NO_REPLY` (#201638).

No new field, state, config or wording.

Limits:
- The tool is classified with empty arguments. `subagents`, `session_status` and `presence` count as replay-safe when no action is given, but the stored `mutatingAction` still keeps their mutating actions. A failed `subagents wait` would be recovered, which is harmless.
- Tools that are replay-safe only for a specific instance (plugin tools, `replaySafeToolNames`) and read-only `exec` commands such as a failed `cat` keep today's same-tool rule. Recoveries from those still record `error`, as they do on main.

Non-cron chat runs: `buildFailureWarning` only adds `⚠️ <Tool> failed` when the turn has no user-facing reply. The one chat change: a turn where one of those catalog read-only calls failed, a different call then ran and succeeded, and the turn ended with no reply text at all no longer gets that warning. Turns with a visible reply or `NO_REPLY` already showed no warning and are unchanged. So are failed mutations, browser and exec failures, and blocked calls.

## User Impact

A scheduled job that recovers from a failed `read` or `web_fetch`, including one caught inside a Code Mode cell, and then ends silently now records `ok`. It no longer sends a false failure alert, starts a repair turn or disables itself. A job whose tool failed and that did nothing successful afterwards still fails and alerts.

## Evidence

Built Gateway in secretless Docker, real isolated `agentTurn` cron jobs, scripted model. Captures: [evidence comment](#180922 (comment)).

| Scenario | main `ba0a7a5fac` | this PR `de3a57c978` |
|---|---|---|
| (a) `read` fails, `write` succeeds, `NO_REPLY` | `error` `⚠️ Read failed`, consecutiveErrors 1 | `ok`, `succeeded`, 0 |
| (b) Code Mode cell catches a failed nested `read`, cell completes, `NO_REPLY` | `error` `⚠️ Read failed`, consecutiveErrors 1 | `ok`, `succeeded`, 0 |
| #116731 shape: `read` fails, `NO_REPLY`, nothing else | `error` `⚠️ Read failed` | `error` `⚠️ Read failed` |
| #201638 control: missing tool, `NO_REPLY`, nothing else | `error` `⚠️ Cream Exec blocked` | `error` `⚠️ Cream Exec blocked` |
| review regression: browser `act` fails, `read` succeeds, `NO_REPLY` | `error` `⚠️ Browser failed` | `error` `⚠️ Browser failed` |
| normal run | `ok`, `succeeded` | `ok`, `succeeded` |

New observer regressions in `tool-terminal-outcome.test.ts`:
- A failed `read` is cleared by a later successful `write` or `exec`. This fails on main.
- A failed `exec` (`SYSTEM_RUN_DENIED`, started, read-only command) and a failed browser `act` are both kept after a successful `read`. The previous head failed both.

The existing failed-send case still keeps its warning. The payload, cron, subscribe and Codex dynamic-tool suites pass. The draft's QA scenario, mock planners and extra cron test are dropped.

Production: +11/-4 in `src/agents/tool-terminal-outcome.ts` (4 code lines, the rest comment). Tests: +19/-1.

Merge danger: two-way door. No state, config or schema changes; a revert restores the old recovery rule. Blast radius: which earlier tool failure a run still reports after later successful work, in cron outcomes and the no-reply chat warning.

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 29, 2026
…l recovered from (#180922)

Root cause: `src/agents/tool-terminal-outcome.ts:110` (main `ba0a7a5fac`). The terminal observer lets a failed tool call be recovered only by a later success of the same tool name. A run whose `read` or `web_fetch` fails, and that then does other work that succeeds, still ends holding that failure. In a cron run that ends on `NO_REPLY`, `payloads.ts:488` turns it into `⚠️ <Tool> failed` and the run is recorded as `error`.

Fixes #207683

## What Problem This Solves

A scheduled run reads or fetches something that fails, keeps working, and ends on `NO_REPLY` with `stopReason: stop`. It is still recorded as failed. That counts toward the error streak, fires failure alerts (each starts a repair turn) and auto-disables one-shot jobs.

Reports:
- @jaxonparrott, 2026.10.7: 9 of 9 failed runs of one hourly job had this shape (`Web Fetch`, `Wait`, plugin tools). The model kept working after the error, and the next run succeeded.
- @abacha, 2026.11.6 and main `cb59aaa3106`, plus #207683: a `web_fetch` inside a Code Mode `exec` cell returns 403 and the cell catches it. The outer `exec` completes and the turn ends on `NO_REPLY`, yet the run is recorded as `error` and the one-shot job is disabled. The nested failure fills the same last-tool-error slot, and the successful outer `exec` cannot clear it because it has a different name.

## Why This Change Was Made

The fix is in the observer, where recovery is already decided. Recovery by a later, different call applies only when the failed call actually ran, was not mutating, and its tool has the catalog's static replay-safe fact: `isReplaySafeToolCall(toolName, {})`, which is true for `read`, `ls`, `web_search`, `web_fetch`, `memory_get` and `sessions_*`. Such a call changed nothing, so the next successful executed call recovers it. Nothing else changes:
- A failed mutation (a send, write, edit or spawn) still recovers only through the same tool. A failed message send is not undone by a later read (#107735, #139037).
- Tools with no catalog read-only fact keep the same-tool rule. A failed browser `act` followed by a successful `read` still reports the browser failure. An `exec`, including one denied with `SYSTEM_RUN_DENIED` after it started, still keeps the cron execution-denied signal.
- A call blocked before it ran, the missing-tool rule (#201638) and the dispatch catalog-target rule are unchanged.
- The cron `NO_REPLY` guard at `payloads.ts:488` is unchanged. A tool failure followed by `NO_REPLY` with no later successful call still fails the run (#116731, #120056), and so does a missing tool followed by `NO_REPLY` (#201638).

No new field, state, config or wording.

Limits:
- The tool is classified with empty arguments. `subagents`, `session_status` and `presence` count as replay-safe when no action is given, but the stored `mutatingAction` still keeps their mutating actions. A failed `subagents wait` would be recovered, which is harmless.
- Tools that are replay-safe only for a specific instance (plugin tools, `replaySafeToolNames`) and read-only `exec` commands such as a failed `cat` keep today's same-tool rule. Recoveries from those still record `error`, as they do on main.

Non-cron chat runs: `buildFailureWarning` only adds `⚠️ <Tool> failed` when the turn has no user-facing reply. The one chat change: a turn where one of those catalog read-only calls failed, a different call then ran and succeeded, and the turn ended with no reply text at all no longer gets that warning. Turns with a visible reply or `NO_REPLY` already showed no warning and are unchanged. So are failed mutations, browser and exec failures, and blocked calls.

## User Impact

A scheduled job that recovers from a failed `read` or `web_fetch`, including one caught inside a Code Mode cell, and then ends silently now records `ok`. It no longer sends a false failure alert, starts a repair turn or disables itself. A job whose tool failed and that did nothing successful afterwards still fails and alerts.

## Evidence

Built Gateway in secretless Docker, real isolated `agentTurn` cron jobs, scripted model. Captures: [evidence comment](#180922 (comment)).

| Scenario | main `ba0a7a5fac` | this PR `de3a57c978` |
|---|---|---|
| (a) `read` fails, `write` succeeds, `NO_REPLY` | `error` `⚠️ Read failed`, consecutiveErrors 1 | `ok`, `succeeded`, 0 |
| (b) Code Mode cell catches a failed nested `read`, cell completes, `NO_REPLY` | `error` `⚠️ Read failed`, consecutiveErrors 1 | `ok`, `succeeded`, 0 |
| #116731 shape: `read` fails, `NO_REPLY`, nothing else | `error` `⚠️ Read failed` | `error` `⚠️ Read failed` |
| #201638 control: missing tool, `NO_REPLY`, nothing else | `error` `⚠️ Cream Exec blocked` | `error` `⚠️ Cream Exec blocked` |
| review regression: browser `act` fails, `read` succeeds, `NO_REPLY` | `error` `⚠️ Browser failed` | `error` `⚠️ Browser failed` |
| normal run | `ok`, `succeeded` | `ok`, `succeeded` |

New observer regressions in `tool-terminal-outcome.test.ts`:
- A failed `read` is cleared by a later successful `write` or `exec`. This fails on main.
- A failed `exec` (`SYSTEM_RUN_DENIED`, started, read-only command) and a failed browser `act` are both kept after a successful `read`. The previous head failed both.

The existing failed-send case still keeps its warning. The payload, cron, subscribe and Codex dynamic-tool suites pass. The draft's QA scenario, mock planners and extra cron test are dropped.

Production: +11/-4 in `src/agents/tool-terminal-outcome.ts` (4 code lines, the rest comment). Tests: +19/-1.

Merge danger: two-way door. No state, config or schema changes; a revert restores the old recovery rule. Blast radius: which earlier tool failure a run still reports after later successful work, in cron outcomes and the no-reply chat warning.

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

(cherry picked from commit ee377fc)

Release adaptation: Apply replay-safe later-tool recovery to the dispatch-by-target observer already backported earlier in this lane.

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
…l recovered from (#180922)

Root cause: `src/agents/tool-terminal-outcome.ts:110` (main `ba0a7a5fac`). The terminal observer lets a failed tool call be recovered only by a later success of the same tool name. A run whose `read` or `web_fetch` fails, and that then does other work that succeeds, still ends holding that failure. In a cron run that ends on `NO_REPLY`, `payloads.ts:488` turns it into `⚠️ <Tool> failed` and the run is recorded as `error`.

Fixes #207683

## What Problem This Solves

A scheduled run reads or fetches something that fails, keeps working, and ends on `NO_REPLY` with `stopReason: stop`. It is still recorded as failed. That counts toward the error streak, fires failure alerts (each starts a repair turn) and auto-disables one-shot jobs.

Reports:
- @jaxonparrott, 2026.10.7: 9 of 9 failed runs of one hourly job had this shape (`Web Fetch`, `Wait`, plugin tools). The model kept working after the error, and the next run succeeded.
- @abacha, 2026.11.6 and main `cb59aaa3106`, plus #207683: a `web_fetch` inside a Code Mode `exec` cell returns 403 and the cell catches it. The outer `exec` completes and the turn ends on `NO_REPLY`, yet the run is recorded as `error` and the one-shot job is disabled. The nested failure fills the same last-tool-error slot, and the successful outer `exec` cannot clear it because it has a different name.

## Why This Change Was Made

The fix is in the observer, where recovery is already decided. Recovery by a later, different call applies only when the failed call actually ran, was not mutating, and its tool has the catalog's static replay-safe fact: `isReplaySafeToolCall(toolName, {})`, which is true for `read`, `ls`, `web_search`, `web_fetch`, `memory_get` and `sessions_*`. Such a call changed nothing, so the next successful executed call recovers it. Nothing else changes:
- A failed mutation (a send, write, edit or spawn) still recovers only through the same tool. A failed message send is not undone by a later read (#107735, #139037).
- Tools with no catalog read-only fact keep the same-tool rule. A failed browser `act` followed by a successful `read` still reports the browser failure. An `exec`, including one denied with `SYSTEM_RUN_DENIED` after it started, still keeps the cron execution-denied signal.
- A call blocked before it ran, the missing-tool rule (#201638) and the dispatch catalog-target rule are unchanged.
- The cron `NO_REPLY` guard at `payloads.ts:488` is unchanged. A tool failure followed by `NO_REPLY` with no later successful call still fails the run (#116731, #120056), and so does a missing tool followed by `NO_REPLY` (#201638).

No new field, state, config or wording.

Limits:
- The tool is classified with empty arguments. `subagents`, `session_status` and `presence` count as replay-safe when no action is given, but the stored `mutatingAction` still keeps their mutating actions. A failed `subagents wait` would be recovered, which is harmless.
- Tools that are replay-safe only for a specific instance (plugin tools, `replaySafeToolNames`) and read-only `exec` commands such as a failed `cat` keep today's same-tool rule. Recoveries from those still record `error`, as they do on main.

Non-cron chat runs: `buildFailureWarning` only adds `⚠️ <Tool> failed` when the turn has no user-facing reply. The one chat change: a turn where one of those catalog read-only calls failed, a different call then ran and succeeded, and the turn ended with no reply text at all no longer gets that warning. Turns with a visible reply or `NO_REPLY` already showed no warning and are unchanged. So are failed mutations, browser and exec failures, and blocked calls.

## User Impact

A scheduled job that recovers from a failed `read` or `web_fetch`, including one caught inside a Code Mode cell, and then ends silently now records `ok`. It no longer sends a false failure alert, starts a repair turn or disables itself. A job whose tool failed and that did nothing successful afterwards still fails and alerts.

## Evidence

Built Gateway in secretless Docker, real isolated `agentTurn` cron jobs, scripted model. Captures: [evidence comment](#180922 (comment)).

| Scenario | main `ba0a7a5fac` | this PR `de3a57c978` |
|---|---|---|
| (a) `read` fails, `write` succeeds, `NO_REPLY` | `error` `⚠️ Read failed`, consecutiveErrors 1 | `ok`, `succeeded`, 0 |
| (b) Code Mode cell catches a failed nested `read`, cell completes, `NO_REPLY` | `error` `⚠️ Read failed`, consecutiveErrors 1 | `ok`, `succeeded`, 0 |
| #116731 shape: `read` fails, `NO_REPLY`, nothing else | `error` `⚠️ Read failed` | `error` `⚠️ Read failed` |
| #201638 control: missing tool, `NO_REPLY`, nothing else | `error` `⚠️ Cream Exec blocked` | `error` `⚠️ Cream Exec blocked` |
| review regression: browser `act` fails, `read` succeeds, `NO_REPLY` | `error` `⚠️ Browser failed` | `error` `⚠️ Browser failed` |
| normal run | `ok`, `succeeded` | `ok`, `succeeded` |

New observer regressions in `tool-terminal-outcome.test.ts`:
- A failed `read` is cleared by a later successful `write` or `exec`. This fails on main.
- A failed `exec` (`SYSTEM_RUN_DENIED`, started, read-only command) and a failed browser `act` are both kept after a successful `read`. The previous head failed both.

The existing failed-send case still keeps its warning. The payload, cron, subscribe and Codex dynamic-tool suites pass. The draft's QA scenario, mock planners and extra cron test are dropped.

Production: +11/-4 in `src/agents/tool-terminal-outcome.ts` (4 code lines, the rest comment). Tests: +19/-1.

Merge danger: two-way door. No state, config or schema changes; a revert restores the old recovery rule. Blast radius: which earlier tool failure a run still reports after later successful work, in cron outcomes and the no-reply chat warning.

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

Companion audit: No later source follow-up; retain the previously ported semantic dispatcher identity and expand only executed read-only recovery.

Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 30, 2026
…l recovered from (openclaw#180922)

Root cause: `src/agents/tool-terminal-outcome.ts:110` (main `ccb01ee458`). The terminal observer lets a failed tool call be recovered only by a later success of the same tool name. A run whose `read` or `web_fetch` fails, and that then does other work that succeeds, still ends holding that failure. In a cron run that ends on `NO_REPLY`, `payloads.ts:488` turns it into `⚠️ <Tool> failed` and the run is recorded as `error`.

Fixes openclaw#207683

## What Problem This Solves

A scheduled run reads or fetches something that fails, keeps working, and ends on `NO_REPLY` with `stopReason: stop`. It is still recorded as failed. That counts toward the error streak, fires failure alerts (each starts a repair turn) and auto-disables one-shot jobs.

Reports:
- @jaxonparrott, 2026.10.7: 9 of 9 failed runs of one hourly job had this shape (`Web Fetch`, `Wait`, plugin tools). The model kept working after the error, and the next run succeeded.
- @abacha, 2026.11.6 and main `7f1f3242f09`, plus openclaw#207683: a `web_fetch` inside a Code Mode `exec` cell returns 403 and the cell catches it. The outer `exec` completes and the turn ends on `NO_REPLY`, yet the run is recorded as `error` and the one-shot job is disabled. The nested failure fills the same last-tool-error slot, and the successful outer `exec` cannot clear it because it has a different name.

## Why This Change Was Made

The fix is in the observer, where recovery is already decided. Recovery by a later, different call applies only when the failed call actually ran, was not mutating, and its tool has the catalog's static replay-safe fact: `isReplaySafeToolCall(toolName, {})`, which is true for `read`, `ls`, `web_search`, `web_fetch`, `memory_get` and `sessions_*`. Such a call changed nothing, so the next successful executed call recovers it. Nothing else changes:
- A failed mutation (a send, write, edit or spawn) still recovers only through the same tool. A failed message send is not undone by a later read (openclaw#107735, openclaw#139037).
- Tools with no catalog read-only fact keep the same-tool rule. A failed browser `act` followed by a successful `read` still reports the browser failure. An `exec`, including one denied with `SYSTEM_RUN_DENIED` after it started, still keeps the cron execution-denied signal.
- A call blocked before it ran, the missing-tool rule (openclaw#201638) and the dispatch catalog-target rule are unchanged.
- The cron `NO_REPLY` guard at `payloads.ts:488` is unchanged. A tool failure followed by `NO_REPLY` with no later successful call still fails the run (openclaw#116731, openclaw#120056), and so does a missing tool followed by `NO_REPLY` (openclaw#201638).

No new field, state, config or wording.

Limits:
- The tool is classified with empty arguments. `subagents`, `session_status` and `presence` count as replay-safe when no action is given, but the stored `mutatingAction` still keeps their mutating actions. A failed `subagents wait` would be recovered, which is harmless.
- Tools that are replay-safe only for a specific instance (plugin tools, `replaySafeToolNames`) and read-only `exec` commands such as a failed `cat` keep today's same-tool rule. Recoveries from those still record `error`, as they do on main.

Non-cron chat runs: `buildFailureWarning` only adds `⚠️ <Tool> failed` when the turn has no user-facing reply. The one chat change: a turn where one of those catalog read-only calls failed, a different call then ran and succeeded, and the turn ended with no reply text at all no longer gets that warning. Turns with a visible reply or `NO_REPLY` already showed no warning and are unchanged. So are failed mutations, browser and exec failures, and blocked calls.

## User Impact

A scheduled job that recovers from a failed `read` or `web_fetch`, including one caught inside a Code Mode cell, and then ends silently now records `ok`. It no longer sends a false failure alert, starts a repair turn or disables itself. A job whose tool failed and that did nothing successful afterwards still fails and alerts.

## Evidence

Built Gateway in secretless Docker, real isolated `agentTurn` cron jobs, scripted model. Captures: [evidence comment](openclaw#180922 (comment)).

| Scenario | main `ccb01ee458` | this PR `de3a57c978` |
|---|---|---|
| (a) `read` fails, `write` succeeds, `NO_REPLY` | `error` `⚠️ Read failed`, consecutiveErrors 1 | `ok`, `succeeded`, 0 |
| (b) Code Mode cell catches a failed nested `read`, cell completes, `NO_REPLY` | `error` `⚠️ Read failed`, consecutiveErrors 1 | `ok`, `succeeded`, 0 |
| openclaw#116731 shape: `read` fails, `NO_REPLY`, nothing else | `error` `⚠️ Read failed` | `error` `⚠️ Read failed` |
| openclaw#201638 control: missing tool, `NO_REPLY`, nothing else | `error` `⚠️ Cream Exec blocked` | `error` `⚠️ Cream Exec blocked` |
| review regression: browser `act` fails, `read` succeeds, `NO_REPLY` | `error` `⚠️ Browser failed` | `error` `⚠️ Browser failed` |
| normal run | `ok`, `succeeded` | `ok`, `succeeded` |

New observer regressions in `tool-terminal-outcome.test.ts`:
- A failed `read` is cleared by a later successful `write` or `exec`. This fails on main.
- A failed `exec` (`SYSTEM_RUN_DENIED`, started, read-only command) and a failed browser `act` are both kept after a successful `read`. The previous head failed both.

The existing failed-send case still keeps its warning. The payload, cron, subscribe and Codex dynamic-tool suites pass. The draft's QA scenario, mock planners and extra cron test are dropped.

Production: +11/-4 in `src/agents/tool-terminal-outcome.ts` (4 code lines, the rest comment). Tests: +19/-1.

Merge danger: two-way door. No state, config or schema changes; a revert restores the old recovery rule. Blast radius: which earlier tool failure a run still reports after later successful work, in cron outcomes and the no-reply chat warning.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation extensions: codex extensions: copilot maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

1 participant