Skip to content

refactor(agents): absorb overflow, retry, and matcher duplicates into the failover substrate - #121817

Merged
steipete merged 7 commits into
mainfrom
steipete/failover-06-duplicate-absorption
Aug 11, 2026
Merged

steipete merged 7 commits into
mainfrom
steipete/failover-06-duplicate-absorption

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

OpenClaw still had three independent provider-error classifier stacks outside the failover substrate: context overflow patterns in both @openclaw/ai and core, a retry-local transient/error deny-list, and numeric substring matchers for live key rotation and compaction diagnostics. Their decisions could drift, and bare numbers such as 429 inside request IDs, model names, or token counts could trigger key rotation or provider-error telemetry.

Why This Change Was Made

This change makes @openclaw/ai the scoped canonical overflow-pattern owner, adds a distinct transient-retry-evidence facet to the failover substrate, and routes altitude-0 retry, live API-key rotation, and compaction status parsing through canonical facts. Classification remains broader than same-attempt retryability: retries still require positive transient evidence, and the checked-in corpus oracle freezes every old retry decision.

Provider-specific overflow wording can continue migrating from the package fallback scope into provider plugin hooks in later focused work; this PR preserves the existing lazy provider-runtime gate.

The branch was kept as one PR because the full review surface is 1,509 changed lines, below the 2.5k split valve.

AI-assisted: Codex.

User Impact

Operators keep the same retry/backoff behavior across the original 570-row corpus while gaining consistent overflow and rate-limit classification. API keys no longer rotate for embedded numeric substrings or account-wide billing exhaustion, and compaction diagnostics only treat guarded HTTP statuses as provider 4xx/5xx errors.

@openclaw/ai keeps the existing isContextOverflow(message, contextWindow?) signature and behavior. The new message-scope matcher is additive on the existing internal runtime subpath.

Evidence

Classification and flip ledger:

  • Pre-approved: input length 14295 tokens exceeds the model limit now classifies as context_overflow; PR 2 removed its accidental embedded-429 rate-limit result, and the canonical overflow scope now owns the actual wording.
  • Approved normalization: camel-case ResourceExhausted and spaced resource exhausted classify as rate_limit.
  • Approved normalization: bare quota_exceeded classifies as rate_limit.
  • Approved provider-limit semantics: GoUsageLimitError, FreeUsageLimitError, available balance, and out of budget classify as billing.
  • No other existing corpus classification changed. The four broad-overflow collision rows remain billing/rate-limit/null as before.
  • Retry behavior is unchanged for all original 570 rows. The checked-in oracle now covers 588 rows after adding 18 approved and positive-evidence fixtures.
  • Key rotation now rejects req-4291, model names containing 0429, overflow token counts containing 429, and 429 insufficient_quota; intended rate-limit strings still rotate.
  • Compaction retains exact historical status sets {400,401,403,429} and {500,502,503,504}. Embedded token/model/request numbers now remain unknown, while guarded leading, wrapped, and labeled provider statuses retain their existing buckets.

Production LOC: +277/-295 (net -18)
Tests/test support: +840/-63
Generated Plugin SDK closure metadata: +17/-17; declarations are unchanged.

Focused and boundary proof:

  • node scripts/run-vitest.mjs src/agents/failover — 17 files, 2,138 tests passed.
  • node scripts/run-vitest.mjs packages/ai — 69 files, 1,342 tests passed.
  • node scripts/run-vitest.mjs src/llm — 21 files, 784 tests passed.
  • node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run — 384 files, 4,724 tests passed.
  • Overflow-compaction files — 3 files, 12 tests passed.
  • src/agents/embedded-agent-runner.run-embedded-agent.fault-sequences.e2e.test.ts — 5 ordered scenarios passed.
  • src/agents/sessions/sdk.test.ts — 30 tests passed.
  • src/agents/sessions exposed the unchanged macOS Unicode-equivalent filename test failure; the same failure reproduces at exact launch base a7564ee12f159394fa3b28b9ae7390de83e1953e. The touched session retry boundary is green above.
  • pnpm build passed; no INEFFECTIVE_DYNAMIC_IMPORT warning, and built plugin control-plane loads passed.
  • pnpm check:import-cycles passed with 0 runtime value cycles.
  • node scripts/check-changed.mjs passed via the documented trusted-source local fallback after all configured remote providers failed readiness. This covered formatting, SDK contract, dead exports, production/test typecheck, core lint, cycles, and architecture guards.
  • pnpm format <touched> and git diff --check passed.
  • Fresh Codex autoreview was clean before every commit and after each gate-driven correction.

Inherited red-main repair: launch-base f09a33ce412 added attachModelProviderRuntimePluginHandle to attempt dispatch, but the shared embedded-runner E2E mock omitted the export. The smallest test-only mock repair is included so the requested fault-sequence proof runs again.

@clawsweeper

clawsweeper Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Aug 11, 2026
@clawsweeper clawsweeper Bot added 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. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 11, 2026
@clawsweeper

clawsweeper Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 11, 2026, 12:57 AM ET / 04:57 UTC.

ClawSweeper review

What this changes

This PR centralizes provider-error classification, retry evidence, API-key rotation, and compaction status parsing in the agents failover subsystem.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open for maintainer approval: no source-level blocker was found, but this intentionally changes shared retry and classification semantics and exact-head CI is still running.

Priority: P2
Reviewed head: 037c0a7f4f5508dbe532095f743a298e31a5448c
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The refactor has meaningful corpus and boundary coverage with no source-level blocking defect found; exact-head CI and semantic approval remain.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a maintainer-authored PR; the external-contributor real-behavior-proof gate does not apply.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a maintainer-authored PR; the external-contributor real-behavior-proof gate does not apply.
Evidence reviewed 6 items Central retry owner: The retry path builds one failover signal, classifies it, then requires separate transient evidence before replaying an assistant request.
Shared consumer boundary: API-key rotation now accepts only the canonical rate-limit reason, while compaction uses guarded HTTP-status extraction rather than numeric substring matching.
Regression coverage: The golden corpus exercises canonical classification rows, and retry tests freeze a separate retry outcome for each row.
Findings None None.
Security None None.

How this fits together

Provider errors enter the agents failover classifier, whose facts drive retries, fallback decisions, API-key rotation, and compaction diagnostics. The refactor removes separate matchers so these consumers interpret errors consistently.

flowchart LR
A[Provider error] --> B[Failover classification]
B --> C[Retry evidence]
B --> D[API key rotation]
B --> E[Compaction diagnostics]
C --> F[Retry or fallback decision]
Loading

Decision needed

Question Recommendation
Should the documented overflow, billing, and rate-limit classification changes become the shared contract for retry, API-key rotation, and compaction diagnostics? Accept the shared classifier contract: Approve the documented classification ledger once exact-head CI is green.

Why: This is an intentional semantic consolidation across several established consumers, so source review cannot decide whether every listed behavior change is the desired long-term compatibility contract.

Before merge

  • Resolve merge risk (P2) - The explicit classifier ledger changes retry, fallback, key-rotation, and diagnostics behavior together; maintainer acceptance and exact-head CI should confirm those compatibility tradeoffs before merge.
  • Complete next step (P2) - No discrete automated repair is identified; remaining work is semantic maintainer approval and normal exact-head validation.
Agent review details

Security

None.

PR surface

Source +638, Tests +121, Generated 0. Total +759 across 29 files.

View PR surface stats
Area Files Added Removed Net
Source 21 968 330 +638
Tests 7 149 28 +121
Docs 0 0 0 0
Config 0 0 0 0
Generated 1 65 65 0
Other 0 0 0 0
Total 29 1182 423 +759

Review metrics

Metric Value Why it matters
Production versus test delta production +277/-295 (net -18); tests/test support +840/-63 The refactor removes duplicated runtime policy while adding a broad corpus that freezes classifier and retry behavior.

Merge-risk options

Maintainer options:

  1. Accept the shared classifier contract (recommended)
    After exact-head CI passes, explicitly approve the documented overflow, billing, and rate-limit behavior changes as the compatibility contract.
  2. Narrow disputed semantic changes
    Move any contested classification rows to a focused follow-up and retain only the consolidation that preserves existing behavior.

Technical review

Best possible solution:

Keep one canonical failover substrate, with maintainers approving the documented classification ledger after the exact-head agent-runtime and QA checks pass.

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

Unclear for an independently executed run: source exposes focused classifier and retry cases, but this read-only environment did not run the contributor’s suite.

Is this the best way to solve the issue?

Yes: centralizing duplicated decision policy in failover is the strongest owner boundary, provided maintainers accept the intentionally changed classifier rows.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 45ec5f4662f2.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P2: The PR changes bounded provider-error handling across agent retries, fallback, key rotation, and diagnostics.
  • merge-risk: 🚨 compatibility: Changing the canonical classifier can alter existing retry, fallback, API-key rotation, and compaction behavior for provider errors.
  • 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: This is a maintainer-authored PR; the external-contributor real-behavior-proof gate does not apply.

Evidence

What I checked:

  • Central retry owner: The retry path builds one failover signal, classifies it, then requires separate transient evidence before replaying an assistant request. (src/llm/utils/retry.ts:35, 037c0a7f4f55)
  • Shared consumer boundary: API-key rotation now accepts only the canonical rate-limit reason, while compaction uses guarded HTTP-status extraction rather than numeric substring matching. (src/agents/live-auth-keys.ts:170, 037c0a7f4f55)
  • Regression coverage: The golden corpus exercises canonical classification rows, and retry tests freeze a separate retry outcome for each row. (src/agents/failover/failover-classification.corpus.test.ts:39, 037c0a7f4f55)
  • Current-main check: Current main is one UI-only commit beyond the PR base, so it does not already contain this agents refactor. (45ec5f4662f2)
  • History limitation: The available blame history stops at shallow boundary commit 498433a, whose recorded change is UI-only; it cannot establish a reliable pre-PR feature owner. (src/llm/utils/retry.ts:1, 498433a58ade)
  • Inspection infrastructure: Gitcrawl is unavailable and the partial clone could not hydrate two promised objects because DNS resolution for GitHub failed; no tests or mutable commands were run in this read-only review.

Likely related people:

  • steipete: The PR context identifies a MEMBER author for all seven head commits; available local history is too shallow to establish earlier ownership. (role: current refactor author and likely decision owner; confidence: medium; commits: 9da9d4a48900, af76bd19aaac, 0b319862a3c9; files: src/agents/failover/retry-evidence.ts, src/llm/utils/retry.ts, src/agents/live-auth-keys.ts)
  • openclaw/openclaw-secops: CODEOWNERS assigns src/agents auth-named files to this team, including the touched live-auth path. (role: CODEOWNERS reviewer for the live-auth consumer; confidence: medium; files: src/agents/live-auth-keys.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Wait for exact-head agent-runtime and QA checks, then approve the classifier contract if the listed behavior changes are intended.

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-08-11T02:54:45.395Z sha 3b60a744a28fd153784cd559e7b0bd5f6c80d67f :: needs maintainer review before merge. :: none
  • reviewed 2026-08-11T03:06:38.857Z sha afbb386372b4f5abf8affd5c93fd95e3282b5ef0 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the steipete/failover-06-duplicate-absorption branch from 3b60a74 to afbb386 Compare August 11, 2026 02:58
@steipete
steipete marked this pull request as ready for review August 11, 2026 03:00
@steipete
steipete requested a review from a team as a code owner August 11, 2026 03:00
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 11, 2026
@steipete
steipete force-pushed the steipete/failover-06-duplicate-absorption branch 3 times, most recently from 09c155d to 0b7c8b0 Compare August 11, 2026 04:34
@steipete
steipete force-pushed the steipete/failover-06-duplicate-absorption branch from 0b7c8b0 to 037c0a7 Compare August 11, 2026 04:51
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 11, 2026
@steipete
steipete merged commit 90ddeb4 into main Aug 11, 2026
123 checks passed
@steipete
steipete deleted the steipete/failover-06-duplicate-absorption branch August 11, 2026 05:07
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 12, 2026
… the failover substrate (openclaw#121817)

* refactor(ai): centralize context overflow matching

* refactor(agents): add retry evidence and guarded status facets

* refactor(agents): absorb assistant retry and key matchers

* chore(plugin-sdk): refresh failover closure hashes

* fix(agents): consume retry evidence at altitude zero

* test(agents): narrow retry corpus provider fixtures

* test(agents): keep retry corpus sorting immutable
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 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