Skip to content

refactor(agents): simplify failure recovery bookkeeping - #139362

Merged
steipete merged 1 commit into
mainfrom
codex/deslop-agent-recovery
Sep 5, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/deslop-agent-recovery

Conversation

@steipete

@steipete steipete commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Related: #139295

Additional instructions

Maintainers can edit this branch.

What Problem This Solves

Failure recovery carried duplicate error classification, policy argument construction, retry result construction, and logging payloads. That repetition obscured the ordering that keeps retries responsive while failed-account bookkeeping settles. This is the requested deeper cleanup following #139295.

Why This Change Was Made

Prompt recovery now reuses its classified failure and one policy resolver, and starts failure marking through one path while preserving the existing await/nonblocking split. Assistant recovery shares retry outcomes and counter logging. Decision unions express their actual shapes directly; dead abort plumbing, duplicate conditions, conditional type extraction, and repeated cooldown eligibility are removed. Automatic compaction has one equivalent dispatch path, with its existing default policy and cancellation behavior preserved.

The separate prompt/assistant timeout rules, prepared provider-owner classification distinction, and lifecycle/cleanup guards remain intact. Failure containment stays with its current callers so warning text and timing remain stable.

User Impact

Behavior-preserving cleanup. Retry budgets, account/model fallback, error messages, logging, failure-marking order, and compaction policies remain unchanged. No config, persistence schema, dependency, protocol, or public API changes.

Production: 121 fewer lines across seven modules. Tests: 12 unused fixture-argument lines removed; assertions and coverage retained.

Evidence

  • Compared the old and new decision policy using the actual unchanged CLI terminal-stop classifier across 70,754 generated inputs spanning failure reasons, terminal states, timeout/abort flags, fallback settings, and rotation state: identical results.
  • Independent Codex autoreview: no actionable P0–P2 findings.
  • Targeted formatting and git diff --check pass.
  • 359 focused tests passed across eight files, including all 183 compaction-hook cases and the account-rotation/failure-mark ordering regressions.
  • Targeted lint and local architecture guards passed. Local typechecking refuses dependencies linked from another checkout; exact-head CI passed and supplied the complete type/lint/build/test gates.

Consolidate repeated classification, decision inputs, retry/log payloads and compaction dispatch while preserving retry policy and failure-mark ordering. Follow-up to #139295.
@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Sep 5, 2026
@steipete
steipete marked this pull request as ready for review September 5, 2026 20:35
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 5, 2026, 4:39 PM ET / 20:39 UTC.

ClawSweeper review

What this changes

Simplifies agent failure classification, retry bookkeeping, decision types, and compaction dispatch while preserving existing recovery behavior.

Merge readiness

✅ Ready for maintainer review

Keep open: this is a coherent, maintainer-protected cleanup that remains distinct from the merged thinking-recovery fix. Source review found no blocking correctness defects.

Priority: P3
Reviewed head: cb0d6efe3b631ca66493d392dedf54145d3c3115

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused cleanup with preserved contracts, retained assertions, and no actionable defects found in source review.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored internal cleanup is exempt from the external-contributor proof gate and does not materially change authority; reported policy comparisons and focused tests are supplemental validation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored internal cleanup is exempt from the external-contributor proof gate and does not materially change authority; reported policy comparisons and focused tests are supplemental validation.
Evidence reviewed 9 items Verified introduced scope: The recorded head has parent 045524c. The test merge has the pinned base followed by the exact PR head; its delta contains only the eight declared agent files, excluding base-only media work.
Classification equivalence: isFailoverErrorMessage returns classifyFailoverReason(raw, opts) !== null. Prompt recovery already obtains that classification when no normalized reason exists, so removing the second classification preserves the failure predicate.
Failure-marking order retained: Prompt recovery starts failure marking after attempted rotation, returns without awaiting it when rotation succeeds, and awaits it otherwise. The production callback is async, so its failures reach the retained catch handler. Existing prompt and assistant tests explicitly hold marking pending and assert rotation returns first.
Findings None None.
Security None None.

How this fits together

The embedded agent runner handles failed model attempts and chooses retries, account rotation, model fallback, or a visible error. Its compaction path summarizes session history under existing timeout and cancellation controls.

flowchart TD
  A[Model attempt] --> B[Failure classification]
  B --> C[Recovery policy]
  C --> D[Retry or account rotation]
  C --> E[Model fallback or visible error]
  D --> A
  F[Session history] --> G[Compaction with timeout controls]
  G --> A
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -121, Tests -12. Total -133 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 7 83 204 -121
Tests 1 0 12 -12
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 83 216 -133

Review metrics

None.

Technical review

Best possible solution:

Keep recovery bookkeeping consolidated within its existing owners while retaining distinct prompt, assistant, and compaction policies.

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

Not applicable: this PR proposes behavior-preserving cleanup rather than a new bug fix; review checked source equivalence and retained regression assertions without executing tests.

Is this the best way to solve the issue?

Yes: local consolidation removes repeated bookkeeping without merging intentionally different recovery policies or introducing another abstraction layer.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 9c068e13bd18.

Labels

Label changes:

  • add P3: This is bounded internal cleanup with no intended user-facing behavior change.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer-authored internal cleanup is exempt from the external-contributor proof gate and does not materially change authority; reported policy comparisons and focused tests are supplemental validation.

Label justifications:

  • P3: This is bounded internal cleanup with no intended user-facing behavior change.
  • 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: The maintainer-authored internal cleanup is exempt from the external-contributor proof gate and does not materially change authority; reported policy comparisons and focused tests are supplemental validation.

Evidence

What I checked:

  • Verified introduced scope: The recorded head has parent 045524c. The test merge has the pinned base followed by the exact PR head; its delta contains only the eight declared agent files, excluding base-only media work. (a25fa611a63c)
  • Classification equivalence: isFailoverErrorMessage returns classifyFailoverReason(raw, opts) !== null. Prompt recovery already obtains that classification when no normalized reason exists, so removing the second classification preserves the failure predicate. (src/agents/failover/classify.ts:418, cb0d6efe3b63)
  • Failure-marking order retained: Prompt recovery starts failure marking after attempted rotation, returns without awaiting it when rotation succeeds, and awaits it otherwise. The production callback is async, so its failures reach the retained catch handler. Existing prompt and assistant tests explicitly hold marking pending and assert rotation returns first. (src/agents/embedded-agent-runner/run/prompt-failure.ts:252, cb0d6efe3b63)
  • Compaction contract checked: The OpenClaw-owned automatic-compaction method defaults its third argument to retry-invalid-once; explicitly passing undefined retains that default. abortCompaction returns void, preserving cancellation behavior. These changed calls depend on local session contracts rather than a Codex dependency contract. (src/agents/sessions/agent-session-compaction.ts:77, cb0d6efe3b63)
  • Internal type and policy boundaries: The simplified thinking-level type indexes the existing local runtime snapshot. Decision unions retain the same action sets, and the removed prompt aborted field was unused; external-abort, run-budget, terminal-stop, and format-failure checks remain. (src/agents/embedded-agent-runner/run/failover-policy.ts:21, cb0d6efe3b63)
  • Current-main necessity: Comparing all eight touched paths between the merge base and fetched main produced no differences: main retains the pre-cleanup implementation. The provided GitHub snapshot identifies fix(agents): preserve model errors during thinking recovery #139295 as merged, but its reasoning-error repair is distinct from this bookkeeping cleanup. (src/agents/embedded-agent-runner/run/prompt-failure.ts, 9c068e13bd18)

Likely related people:

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

@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Ready to land at cb0d6efe3b631ca66493d392dedf54145d3c3115.

This cleanup removes 121 production lines and 12 unused test-fixture arguments, with assertions retained. Prompt/assistant policy differences, provider-owner classification, cancellation/timeout guards, warning text, retry counters, and rotation-before-mark ordering remain intact.

Validation:

  • 359 focused tests passed across eight files, including all 183 compaction-hook cases and pending failure-mark ordering tests.
  • 70,754 old/new policy comparisons returned identical decisions. The comparison transpiled each version independently and used the real unchanged CLI terminal-stop classifier across reasons, terminal states, abort/timeout flags, fallback, and rotation state.
  • Targeted formatting, lint, diff checks, and local architecture guards passed. The prepared Vitest 5 install matched the repository lockfile exactly. Local typechecking refuses linked dependency roots; exact-head CI completed successfully and supplied the full type/build/test gates.
  • Independent Codex autoreview is clean at P0–P2. ClawSweeper's completed review has no findings or before-merge requests.

Focused test command:

OPENCLAW_VITEST_FS_MODULE_CACHE_PATH=/tmp/recovery-deslop-vitest-cache \
node scripts/run-vitest.mjs \
  src/agents/failover-policy.test.ts \
  src/agents/embedded-agent-helpers/thinking.test.ts \
  src/agents/embedded-agent-runner/run/failover-policy.test.ts \
  src/agents/embedded-agent-runner/run/prompt-failure.test.ts \
  src/agents/embedded-agent-runner/run/assistant-failover.test.ts \
  src/agents/embedded-agent-runner/run/assistant-failure.test.ts \
  src/agents/embedded-agent-runner/run/attempt-recovery.test.ts \
  src/agents/embedded-agent-runner/compact.hooks.test.ts

No public API, configuration, schema, dependency, or intended runtime behavior changes.

@steipete
steipete merged commit 693e8fb into main Sep 5, 2026
255 checks passed
@steipete
steipete deleted the codex/deslop-agent-recovery branch September 5, 2026 20:55
@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 6, 2026
)

Consolidate repeated classification, decision inputs, retry/log payloads and compaction dispatch while preserving retry policy and failure-mark ordering. Follow-up to openclaw#139295.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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