Skip to content

fix: keep Code Mode tasks running after tool failures - #138044

Merged
steipete merged 5 commits into
mainfrom
codex/remove-code-mode-recovery
Sep 4, 2026
Merged

steipete merged 5 commits into
mainfrom
codex/remove-code-mode-recovery

Conversation

@steipete

@steipete steipete commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users working in Code Mode could get stuck after a tool failure, even with Full Access. A source-inspection shell command could consume the recovery path's single mutation allowance, leaving the agent unable to finish the requested edits.

Related: #131340, #132437. Removes the continuation policy introduced by #128071 and #132583.

Why This Change Was Made

Removes forced read-only reconciliation, recovery_resume, the one-mutation limit, exact-repeat fencing, tool-surface overrides, and their private provenance plumbing. Failed cells return through the normal agent loop, so the model can inspect partial effects and continue with its configured tools. This is the maintainer-requested complete removal of the policy.

Normal permissions, approvals, cancellation, execution ownership, explicit terminal outcomes, public lifecycle receipts, and separate automatic whole-run replay protection remain. OpenClaw asks the model for its next action after an error; it does not automatically rerun the failed program. Model-selected repetition has the same partial-effect risk as ordinary tool use, and the documentation requires inspecting authoritative state before repeating work.

User Impact

Multi-step tasks can finish in the same session after recoverable Code Mode errors. There is no extra recovery mode, budget, setting, or permission-mode exception to manage. The Code Mode docs describe ordinary continuation and inspection of partial effects.

Evidence

  • Final CI: Required CI run33863730356 passes on b5287705391586f47de0f446fa487dec88ff81bf:119 successful jobs,14 intentional skips, including all six Android jobs and openclaw/ci-gate.

  • Before/after: the byte-identical final embedded-runner regression fails against 0ff5f24d73349e1bae464bb990e05e9f07fc0e11: six model turns expected, one observed. It uses the original production hook installation. It and the real-file worker regression pass after removal.

  • Tests: 761 tests across 30 selected files pass, covering continuation, sandbox/approval denials, cancellation, explicit terminal outcomes, nested lifecycle records, harness selection, suspended/headless Code Mode, whole-run replay safety, and the QA catalog/retained-reply flows.

  • Live: real agent exec, openai/gpt-5.6-sol, QuickJS, and filesystem in Blacksmith Testbox. A first write succeeded, its outer cell deliberately failed, then the model inspected state, completed two later writes in distinct cells, and verified all three files. Six assistant turns, seven nested calls, 12/12 assertions passed; the first write happened exactly once and the failed result retained isError: true. Live run. Temporary lease stopped.

  • Source identity: the live run verified all 60 changed paths against manifest 2c0f1d18cfb797ceffce5a37c8714f150ba3800c160f2dbfc6527e6ed35a175d, matching commit 7d8f18bbdae6b4e8cdaafac7dbbd321182573716. Follow-ups use pinned oxfmt 0.65 to format one callback (identical TypeScript syntax tree) update two QA catalog source references, and correct an Android test observation race. These follow-ups do not change production behavior; QA scenario execution and assertions are unchanged.

  • Build/checks before rebase: clean local build-all.mts sourcePerformance passes, including 90 plugin builds and 53 native control-plane module loads. Core/extension typechecks, lint, formatting, boundaries, unused-export scans, and remaining guards pass. CI before rebase is green on 76068c36d2e6ea7ebffdc78b258a7a648c203b47: 119 passing jobs, 14 intentional skips. The failed-job-only retry cleared an npm advisory outage and interrupted Matrix binary download; test jobs passed on their first execution. Earlier GitHub startup failures required a fresh dispatch. Initial pinned-formatter and QA source-reference failures were corrected and reviewed. An additional hosted run also completed successfully for that head, including Windows and Android.

  • Android flake proof: the exact follow-up test bytes match a prior repair whose diagnostic reproduced a late startup GET with connection admissions unchanged at 2 → 2. A deliberate reconnect negative control failed correctly, and 134 Play/ThirdParty service/session sibling tests passed. Android runtime, Gradle definitions, and dependency pins match that prior proof; local Kotlin lint passes, and all six Android jobs in CI33857853523 passed before rebase, including Play/ThirdParty tests, Wear tests, builds, and lint. Local test execution was unavailable because this host has no SDK.

  • Review: fresh independent Codex autoreview found no accepted/actionable P0–P2 issues in the removal, formatter follow-up, QA metadata correction, Android test correction, or current-main conflict resolution.

Current-main integration: rebased to 0c2da1da0315665a42d66241528ba0733c5a22c8; current head is b5287705391586f47de0f446fa487dec88ff81bf. Three conflicts overlapped #137606's session setup. Resolution preserves its persisted-user replay validation, synchronous ownership/cancellation admission, cleanup ownership, and new regression cases while removing only Code Mode recovery plumbing. All 100 focused cases across eight affected files pass, including 30 interrupted-user replay cases, both continuation regressions, and transcript cleanup. The formatter, QA metadata, and Android follow-ups replay unchanged. The full local changed-file gate also passes after resolution. Fresh exact-head CI33863730356 passed after the contextual patch ID changed. The next CI run exposed a stale ClawHub QA docsRef after main removed its local publishing page in #138157. A one-line metadata follow-up points to the surviving plugin-building guide; all 58 catalog tests and independent review pass, and merged-tree validation proves the missing reference is repaired without changing scenario execution or assertions.

Production net -784 lines; tests/support -1073; docs -26. No configuration, database, protocol, or public SDK shape changes. Related effect-receipt work may still be useful for diagnostics and automatic whole-run replay; those broader items remain open.

Review disposition

The maintainer explicitly requested complete removal of the recovery policy and accepts the documented return to ordinary continuation after partial failures. This resolves the intentional-behavior merge-risk item in the September 4 ClawSweeper review; ordinary permissions and automatic whole-run replay protection remain.

The stored-data migration flag is not applicable. The deleted journal was a process-local WeakMap; repair authority used WeakSets, and recovery state was allocated for each run by createEmbeddedRunTerminalRetryState. Parked cells also live in the process-local activeRuns Map. No database schema, stored record representation, persistence codec, configuration key, or public receipt shape changes, so there is nothing to migrate or backfill. The existing transcript/lifecycle path remains the owner of recorded tool outcomes.

Named follow-up from the expanded CI run: test/scripts/direct-run-entrypoints.test.ts hit an unrelated Windows subprocess close/drain timeout after producing its expected output. Its production/test owners are unchanged, and the responsible handle is not yet established; preserve the drainage contract while investigating that flake.

Named follow-up from the ClawHub documentation move: the maturity renderer indexes only local documentation, so a future regeneration can drop valid mirrored ClawHub publishing links. Make that route index aware of the canonical mirror; retain the taxonomy’s public-route meaning.

Supplemental hosted fallback33865109539 observed an unrelated mocked-Gateway UI assertion: copied plain-HTTP outbox state remained waiting-reconnect instead of unconfirmed. The PR changes no UI files and this fixture uses a synthetic WebSocket without an agent/model/tool executor. Record follow-up Stabilize copied-tab plain-HTTP outbox adoption proof and asset-route cleanup; lazy-module socket errors in the log do not establish the root cause. The fallback is being stopped after all118 execution jobs in the primary exact-head run passed; its failed UI job is not counted as passing proof.

@steipete steipete self-assigned this Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review September 4, 2026 07:46
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR extensions: qa-lab labels Sep 4, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 4, 2026, 6:45 AM ET / 10:45 UTC.

ClawSweeper review

What this changes

The branch removes Code Mode’s special post-error reconciliation and restores ordinary model turns and tool availability after failed cells, with regression, documentation, QA-reference, and Android-test updates.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep open. This active maintainer-owned PR removes a current-main recovery policy that still terminates failed Code Mode cells; the reviewed patch coherently returns those failures to the normal agent loop and has no discrete correctness finding.

Priority: P2
Reviewed head: b5287705391586f47de0f446fa487dec88ff81bf

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent net-negative owner-boundary deletion with focused regression coverage and no supported correctness finding.
Proof confidence 🌊 off-meta tidepool Not applicable: Not applicable to this member-authored PR; it nevertheless supplies a linked Testbox after-fix run through agent execution, QuickJS, a live model, and filesystem actions, while the focused regression covers the same continuation boundary.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Not applicable to this member-authored PR; it nevertheless supplies a linked Testbox after-fix run through agent execution, QuickJS, a live model, and filesystem actions, while the focused regression covers the same continuation boundary.
Evidence reviewed 6 items Current-main baseline: Current main still contains the dedicated reconciliation implementation, including the recovery-resume path and one-mutation budget that this PR removes; the central requested behavior is therefore not already implemented on main.
Owner-boundary change: The embedded run loop no longer invokes the special reconciliation advance after a failed assistant attempt, leaving the ordinary agent loop as the continuation owner.
Ordinary-loop contract: Agent core preserves the finalized result when no outcome hook overrides it; the removed Code Mode outcome hook was the layer that had converted unsafe failed cells into terminal outcomes.
Findings None None.
Security None None.

How this fits together

Code Mode executes guest JavaScript that calls OpenClaw tools through the embedded agent runner. Tool outcomes feed back into the agent loop, which either requests another model turn or finalizes the user-facing run.

flowchart LR
  A[User task] --> B[Model turn]
  B --> C[Code Mode cell]
  C --> D[Tool bridge and lifecycle]
  D --> E[Failed or successful tool result]
  E --> F[Normal agent loop]
  F --> G[Next model turn or final reply]
Loading

Before merge

  • Resolve merge risk (P1) - Merging deliberately replaces the existing post-failure recovery fence with ordinary continuation after a possibly partial action; the PR documents inspect-before-repeat guidance, while normal policy and approval checks remain the enforcement boundary.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source -784, Tests -1075, Docs -26, Other +2. Total -1883 across 63 files.

View PR surface stats
Area Files Added Removed Net
Source 34 29 813 -784
Tests 25 323 1398 -1075
Docs 1 20 46 -26
Config 0 0 0 0
Generated 0 0 0 0
Other 3 5 3 +2
Total 63 377 2260 -1883

Review metrics

Metric Value Why it matters
Production versus test delta production +29/-813 (net -784); tests/support +328/-1401 (net -1073); docs +20/-46 (net -26) The change is a net deletion of the special recovery mechanism rather than an added parallel continuation path.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/agents/code-mode-execution.ts, migration/backfill/repair: src/agents/code-mode.ts, migration/backfill/repair: src/agents/embedded-agent-runner/run/attempt-tool-prepare.ts, migration/backfill/repair: src/agents/embedded-agent-runner/run/code-mode-outcome.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Land the accepted continuation policy (recommended)
    Accept the documented default change so later model turns use their ordinary configured tools and approvals after a failed Code Mode cell.
  2. Pause for a replacement policy decision
    Keep this PR open only if maintainers reverse the recorded removal decision and want a separately scoped post-failure safety policy.

Technical review

Best possible solution:

Keep one canonical normal continuation path after failed Code Mode cells, retain existing terminal, cancellation, policy, approval, and whole-run replay protections, and land after normal exact-head validation completes.

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

Yes: the new focused embedded-runner scenario precisely exercises a partial failure followed by inspection and multiple edits on the ordinary Code Mode surface; it was source-reviewed but not executed in this read-only environment.

Is this the best way to solve the issue?

Yes: deleting the recovery owner and its private provenance plumbing is the cleanest solution because agent core already owns normal failed-tool continuation and retains terminal/tool-policy behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 329c6f907f68.

Labels

Label justifications:

  • P2: This fixes a bounded but user-visible Code Mode task interruption without evidence of an emergency availability or security failure.
  • merge-risk: 🚨 compatibility: Existing users encounter a deliberately different default after a possibly partial Code Mode failure.
  • 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: Not applicable to this member-authored PR; it nevertheless supplies a linked Testbox after-fix run through agent execution, QuickJS, a live model, and filesystem actions, while the focused regression covers the same continuation boundary.

Evidence

What I checked:

  • Current-main baseline: Current main still contains the dedicated reconciliation implementation, including the recovery-resume path and one-mutation budget that this PR removes; the central requested behavior is therefore not already implemented on main. (src/agents/embedded-agent-runner/run/code-mode-reconciliation.ts:20, 329c6f907f68)
  • Owner-boundary change: The embedded run loop no longer invokes the special reconciliation advance after a failed assistant attempt, leaving the ordinary agent loop as the continuation owner. (src/agents/embedded-agent-runner/run-loop.ts:551, b52877053915)
  • Ordinary-loop contract: Agent core preserves the finalized result when no outcome hook overrides it; the removed Code Mode outcome hook was the layer that had converted unsafe failed cells into terminal outcomes. (packages/agent-core/src/agent-loop.ts:1389, b52877053915)
  • Regression coverage: The new embedded-runner regression drives a partially applied failure, then verifies the next turns retain Code Mode, inspect state, perform two further edits, preserve the failed result, and record each nested activity once. (src/agents/embedded-agent-runner/run/attempt.code-mode-continuation.test.ts:87, b52877053915)
  • User guidance: The updated documentation tells the model to inspect authoritative state after a possibly partial failure, not replay completed actions, and notes that normal hooks and approvals run again. Public docs: docs/tools/code-mode.md. (docs/tools/code-mode.md:280, b52877053915)
  • Review-environment limitation: The required documentation index command could not run because Corepack attempted to create its cache on the read-only filesystem; direct source review and diff checks remained available, and this is not a contributor-proof gap.

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Marvinthebored: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • shakkernerd: 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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-04T09:14:31.700Z sha 572a835 :: blocked before merge. :: none
  • reviewed 2026-09-04T09:54:59.232Z sha 76068c36d2e6ea7ebffdc78b258a7a648c203b47 :: blocked before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added the app: android App: android label Sep 4, 2026
Remove forced read-only reconciliation, recovery_resume, and the one-mutation continuation limit. Failed cells return to the normal agent loop so users can inspect partial effects and complete multi-step work with their configured tools. Preserve cancellation, permissions, explicit terminal outcomes, lifecycle receipts, and automatic whole-run replay protection.
A startup WebSocket request can reach MockWebServer after Stop retires it,
causing the foreground-reentry assertion to report a reconnect that never
happened. Reuse the existing call-through session shadow to observe actual
connection admissions while preserving the real runtime and offline checks.

The same test bytes have a reproduced before failure, a rejected deliberate
reconnect, and 134 passing service/session sibling tests. Android lint passes;
the updated PR CI will verify this candidate before landing.
@steipete
steipete force-pushed the codex/remove-code-mode-recovery branch from 76068c3 to 9685c7f Compare September 4, 2026 10:15
@steipete
steipete merged commit 085641a into main Sep 4, 2026
379 of 392 checks passed
@steipete
steipete deleted the codex/remove-code-mode-recovery branch September 4, 2026 11:08
@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Sep 4, 2026
Adopt the canonical fixture correction from #138044 (085641a)
after main removed the former publishing page. Scenario behavior stays
unchanged. Verified all 58 catalog tests, complete changed-file checks,
and independent review.
steipete added a commit that referenced this pull request Sep 4, 2026
* fix(gateway): recover in-flight replies across restart

Bind reply and session admission ownership to the Gateway host, including
lifetime-wrapped plugin dispatch and queued delivery retries. Mark exact
active owners durably, revalidate at commit and cancellation, then abort
retiring parents before tool and channel teardown.

The unchanged Linux scenario now completes three restarts with three
retained recovery policies and one final delivery in 19 seconds.

* fix(test): keep Gateway admission on the fixture lifecycle generation

Expose the registry generation from the same mutable fixture state used by
agent events and lifecycle rotation. Gateway agent-handler admission now
reaches the intended behavior assertions after the restart ownership fix.

* test: reuse isolated memory tools in recall tracking

Adopt the already-landed canonical fixture repair from #138123 so the
Gateway restart forward-port can run its memory CI shard without loading
real plugins in the first recall-tracking case. Preserve all assertions,
test order, and deadlines. No production changes.

Source: 0209921
Validation: all four recall cases in original order; complete changed-file
gate including extension test types, lint, and dead-export scans; independent
P0-P2 review clean.

* test(qa): refresh ClawHub release policy docs reference

Adopt the canonical fixture correction from #138044 (085641a)
after main removed the former publishing page. Scenario behavior stays
unchanged. Verified all 58 catalog tests, complete changed-file checks,
and independent review.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
* fix: keep Code Mode tasks running after tool failures

Remove forced read-only reconciliation, recovery_resume, and the one-mutation continuation limit. Failed cells return to the normal agent loop so users can inspect partial effects and complete multi-step work with their configured tools. Preserve cancellation, permissions, explicit terminal outcomes, lifecycle receipts, and automatic whole-run replay protection.

* style: format Code Mode callback with pinned oxfmt

* test: update failed-tool QA references after recovery removal

* test(android): observe connection admission after stop

A startup WebSocket request can reach MockWebServer after Stop retires it,
causing the foreground-reentry assertion to report a reconnect that never
happened. Reuse the existing call-through session shadow to observe actual
connection admissions while preserving the real runtime and offline checks.

The same test bytes have a reproduced before failure, a rejected deliberate
reconnect, and 134 passing service/session sibling tests. Android lint passes;
the updated PR CI will verify this candidate before landing.

* test: repair ClawHub QA documentation reference
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
* fix(gateway): recover in-flight replies across restart

Bind reply and session admission ownership to the Gateway host, including
lifetime-wrapped plugin dispatch and queued delivery retries. Mark exact
active owners durably, revalidate at commit and cancellation, then abort
retiring parents before tool and channel teardown.

The unchanged Linux scenario now completes three restarts with three
retained recovery policies and one final delivery in 19 seconds.

* fix(test): keep Gateway admission on the fixture lifecycle generation

Expose the registry generation from the same mutable fixture state used by
agent events and lifecycle rotation. Gateway agent-handler admission now
reaches the intended behavior assertions after the restart ownership fix.

* test: reuse isolated memory tools in recall tracking

Adopt the already-landed canonical fixture repair from openclaw#138123 so the
Gateway restart forward-port can run its memory CI shard without loading
real plugins in the first recall-tracking case. Preserve all assertions,
test order, and deadlines. No production changes.

Source: 2fddacd
Validation: all four recall cases in original order; complete changed-file
gate including extension test types, lint, and dead-export scans; independent
P0-P2 review clean.

* test(qa): refresh ClawHub release policy docs reference

Adopt the canonical fixture correction from openclaw#138044 (62e4d4d)
after main removed the former publishing page. Scenario behavior stays
unchanged. Verified all 58 catalog tests, complete changed-file checks,
and independent review.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: android App: android docs Improvements or additions to documentation extensions: qa-lab maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. 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

Development

Successfully merging this pull request may close these issues.

1 participant