Skip to content

fix: stop repeating HTTP 400 requests with transient inner codes - #159221

Merged
obviyus merged 3 commits into
mainfrom
fix/http400-inner-code-retry-159184
Sep 27, 2026
Merged

obviyus merged 3 commits into
mainfrom
fix/http400-inner-code-retry-159184

Conversation

@obviyus

@obviyus obviyus commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #159184

What Problem This Solves

Fixes repeated same-model requests when an HTTP 400 rejection carries a generic transient inner code such as rate_limit_exceeded.

User Impact

A rejected request now returns promptly or advances to a configured fallback instead of waiting through nine identical failures. Genuine throttling and server errors still retry.

This deliberately preserves existing rate-limit presentation, logging, cooldown and fallback reasons; it does not change the generic rate-limit error copy to prompt-size guidance. No settings, defaults, protocol or storage changes.

Why This Change Was Made

The classifier records that a non-transient 4xx is not eligible for same-model retry when only its generic inner code makes it transient. The existing recovery gate consumes that fact for assistant failures and thrown provider exceptions, including coerced failover errors. HTTP 408/409/410/429/499 retain their previous policy. Independent transient message/detail evidence, Bedrock's structured ThrottlingException, and prepared provider-hook decisions remain eligible.

A blanket 400 => format change would break intentional behavior: #133772 preserved structured-code presentation, including RESOURCE_EXHAUSTED behind a generic HTTP 400 invalid-request wrapper, and the existing corpus covers real Bedrock-style HTTP 400 throttling. Both remain unchanged and green. JSON error prose is evaluated separately from its code so the code cannot count as independent evidence for retrying itself.

Ayaan accepted this broader retry policy, including immediate fallback/failure for a genuine throttle that supplies only a generic transient code behind a non-transient 4xx.

Evidence

Real isolated Gateway turns, using fresh builds and a local scripted OpenAI-compatible HTTP provider; no paid provider calls. Baseline: 4b225bae; measured fix: e02adc94.

Response Baseline requests Fixed requests Observed result
HTTP 400 + rate_limit_exceeded + reported prompt-size prose 10 1 CLI completes in 1.54 s instead of 118.26 s; no same-model backoff
HTTP 400 + same code + generic Request rejected — 1 Error surfaces in 1.33 s
HTTP 400 without an inner code 1 1 Same schema-rejection result
HTTP 429, twice, then success 3 3 Recovers successfully
HTTP 503, twice, then success 3 3 Recovers successfully
HTTP 400 ThrottlingException, twice, then success 3 3 Recovers successfully

Baseline failing-request offsets were 0, 1053, 2220, 4972, 11518, 21524, 51629, 66995, 85563 and 115957 ms. The fixed fallback runs each made one rejected request followed by one successful next-model request, both with and without the inner code. The Bedrock control uses its response shape through the local compatible transport, not a live AWS call.

  • The three classifier rejection cases fail on baseline and pass with the fix. Recovery-boundary tests also failed for raw and coerced prompt exceptions before repair; both now advance to fallback without backoff. Independent detail prose remains retryable, while the SDK's flat JSON {code,message} cannot promote its code into prose.
  • 947 tests across seven classifier, classification corpus, structured presentation, error-normalization, attempt recovery and retry-controller suites passed in 26.66 s on e02adc94, then passed again in 42.19 s on c606f7e9 after merging current main once. Existing chore(deps): refresh eligible seven-day npm dependencies #133772 copy and Bedrock corpus assertions were not changed.
  • Fresh baseline and e02adc94 builds, core types, scoped type-aware Oxlint, Oxfmt and whitespace checks passed. The merged head is covered by the fresh focused tests and required CI; the earlier runtime/build measurements are not a rebuild of that later merge.

@clawsweeper

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

@obviyus
obviyus marked this pull request as ready for review September 26, 2026 22:35
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Sep 26, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. labels Sep 27, 2026
@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 26, 2026, 10:44 PM ET / September 27, 2026, 02:44 UTC (Revision 2).

ClawSweeper review

What this changes

The branch prevents same-model retries for certain rejected HTTP 4xx requests whose only transient signal is an inner error code, while retaining their failover reason and adding classifier and recovery tests.

Merge readiness

✅ Ready for maintainer review

The fix remains absent from current main and has convincing before-and-after Gateway proof. The previously flagged compatibility tradeoff has been explicitly accepted by a repository maintain-permission holder. The linked report’s error-copy concern remains separate.

Priority: P1
Reviewed head: c606f7e9d4c50a585db82203f8ec51cd35526921

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Direct before-and-after Gateway evidence and focused recovery coverage support a bounded patch with no remaining actionable finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The changed classifier and embedded-runner recovery path were exercised by isolated Gateway turns against a scripted local OpenAI-compatible provider: the reported HTTP 400 made ten baseline requests and one patched request, while transient controls recovered. The tested production files are identical at the reviewed head; no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed classifier and embedded-runner recovery path were exercised by isolated Gateway turns against a scripted local OpenAI-compatible provider: the reported HTTP 400 made ten baseline requests and one patched request, while transient controls recovered. The tested production files are identical at the reviewed head; no stored-data contract changes.
Evidence reviewed 8 items Current main lacks the retry distinction: Current main retains the code-derived failover classification without the branch’s same-model retry eligibility signal.
Introduced classifier decision: The introduced classifier distinguishes a generic transient code from independent transient prose for non-transient 4xx responses, with exceptions for the specified statuses and Bedrock throttling code.
Recovery consumes retry eligibility: The embedded runner retains the failover reason but skips its same-model retry controller when classification explicitly rejects another attempt.
Findings None None.
Security None None.

How this fits together

Provider failures enter OpenClaw’s failover classifier as HTTP status, code, and error text. The embedded agent runner uses that classification to retry, rotate credentials, try a configured fallback, or surface an error.

flowchart LR
  A[Provider HTTP failure] --> B[Status, code, and message]
  B --> C[Failover classification]
  C --> D{Same-model retry eligible?}
  D -->|Yes| E[Retry current model]
  D -->|No| F[Profile or model fallback]
  F --> G[Result or visible error]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +64, Tests +100. Total +164 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 4 73 9 +64
Tests 3 100 0 +100
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 173 9 +164

Review metrics

Metric Value Why it matters
Production versus test growth production +73/-9, net +64; tests/support +100/-0 Production growth is confined to carrying retry eligibility through the existing classifier and recovery path, with focused regression coverage.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #159184
Summary: This PR is a candidate fix for the linked issue’s repeated-request behavior; the issue’s error-copy concern remains open.

Members:

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

Technical review

Best possible solution:

Land the bounded retry fix after normal gates complete, then address the linked report’s misleading prompt-size error copy with sanitized, actionable guidance.

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

Yes, with high confidence: the reported HTTP 400 shape follows current main’s code-to-rate-limit path, and the PR records measured baseline and patched Gateway turns. This read-only review did not execute that flow.

Is this the best way to solve the issue?

Yes for the repeated-request defect: separating retry eligibility from the failover reason preserves fallback and presentation behavior while stopping futile same-model retries. The misleading error copy needs separate work.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 9447cc6685d6.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The reported agent turn made ten rejected provider requests and remained delayed for roughly two minutes before the fix.
  • merge-risk: 🚨 compatibility: A genuine throttle reported only as a generic inner code behind a non-transient 4xx will now fall back or fail promptly; the repository maintain-permission holder explicitly accepted that tradeoff.
  • 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 (terminal): The changed classifier and embedded-runner recovery path were exercised by isolated Gateway turns against a scripted local OpenAI-compatible provider: the reported HTTP 400 made ten baseline requests and one patched request, while transient controls recovered. The tested production files are identical at the reviewed head; no stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed classifier and embedded-runner recovery path were exercised by isolated Gateway turns against a scripted local OpenAI-compatible provider: the reported HTTP 400 made ten baseline requests and one patched request, while transient controls recovered. The tested production files are identical at the reviewed head; no stored-data contract changes.

Evidence

What I checked:

  • Current main lacks the retry distinction: Current main retains the code-derived failover classification without the branch’s same-model retry eligibility signal. (src/agents/failover/classify-core.ts:335, 9447cc6685d6)
  • Introduced classifier decision: The introduced classifier distinguishes a generic transient code from independent transient prose for non-transient 4xx responses, with exceptions for the specified statuses and Bedrock throttling code. (src/agents/failover/classify-core.ts:362, c606f7e9d4c5)
  • Recovery consumes retry eligibility: The embedded runner retains the failover reason but skips its same-model retry controller when classification explicitly rejects another attempt. (src/agents/embedded-agent-runner/run/attempt-recovery.ts:393, c606f7e9d4c5)
  • Focused regression coverage: Added cases cover assistant, raw prompt, and coerced prompt errors, plus code-only rejections, genuine throttling, and prepared provider decisions. (src/agents/embedded-agent-runner/run/attempt-recovery.per-day-rate-limit.test.ts:68, c606f7e9d4c5)
  • Real behavior proof in captured PR body: The reviewed body records isolated Gateway turns against a scripted local HTTP provider: the reported HTTP 400 shape made 10 requests on baseline 4b225ba and one on tested fix e02adc9; HTTP 429, 503, and Bedrock-shaped controls recovered. The changed production files are identical between tested e02adc9 and the reviewed head. (c606f7e9d4c5)
  • Accepted compatibility tradeoff: The PR comment explicitly accepts immediate fallback or failure for a genuine throttle signaled only by a generic transient inner code behind a non-transient 4xx. The commenter’s repository permission is maintain; the PR body records the same limitation.

Likely related people:

  • obviyus: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • amittell: 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 (1 earlier review cycle)
  • reviewed 2026-09-26T23:37:47.478Z sha e02adc9 :: blocked before merge. :: none

@obviyus

obviyus commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer decision (Ayaan): accepting the broader retry policy: a 4xx (other than 408/409/410/429/499) whose only transient signal is a generic inner code (rate_limit/overloaded/timeout) no longer retries the same model and falls back immediately; throttling prose, provider-owned signals and Bedrock ThrottlingException still retry.

@obviyus

obviyus commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

Current head c606f7e incorporates main once and passes all 947 focused tests. The broader-policy maintainer decision is recorded at #159221 (comment). The PR retains Related: #159184 for the remaining presentation concern; the body distinguishes original runtime/build proof from merged-head testing.

@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus
obviyus merged commit e1238c2 into main Sep 27, 2026
207 checks passed
@obviyus
obviyus deleted the fix/http400-inner-code-retry-159184 branch September 27, 2026 03:04
@obviyus

obviyus commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in e1238c2. HTTP 400 requests with only a transient inner code now skip same-model backoff while preserving genuine throttling and next-model fallback. The isolated Gateway reproduction fell from 10 requests/118.26s to one request/1.54s; 429, 503, Bedrock-shaped throttling and fallback controls passed. All 947 focused tests passed again after merging main, followed by green exact-head CI and hosted review. Thanks @NovaUnboundAi for the detailed report. #159184 remains open for the separate prompt-size error-copy concern.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
…nclaw#159221)

Related: openclaw#159184

## What Problem This Solves

Fixes repeated same-model requests when an HTTP 400 rejection carries a generic transient inner code such as `rate_limit_exceeded`.

## User Impact

A rejected request now returns promptly or advances to a configured fallback instead of waiting through nine identical failures. Genuine throttling and server errors still retry.

This deliberately preserves existing rate-limit presentation, logging, cooldown and fallback reasons; it does not change the generic rate-limit error copy to prompt-size guidance. No settings, defaults, protocol or storage changes.

## Why This Change Was Made

The classifier records that a non-transient 4xx is not eligible for same-model retry when only its generic inner code makes it transient. The existing recovery gate consumes that fact for assistant failures and thrown provider exceptions, including coerced failover errors. HTTP 408/409/410/429/499 retain their previous policy. Independent transient message/detail evidence, Bedrock's structured `ThrottlingException`, and prepared provider-hook decisions remain eligible.

A blanket `400 => format` change would break intentional behavior: openclaw#133772 preserved structured-code presentation, including `RESOURCE_EXHAUSTED` behind a generic HTTP 400 invalid-request wrapper, and the existing corpus covers real Bedrock-style HTTP 400 throttling. Both remain unchanged and green. JSON error prose is evaluated separately from its code so the code cannot count as independent evidence for retrying itself.

[Ayaan accepted this broader retry policy](openclaw#159221 (comment)), including immediate fallback/failure for a genuine throttle that supplies only a generic transient code behind a non-transient 4xx.

## Evidence

Real isolated Gateway turns, using fresh builds and a local scripted OpenAI-compatible HTTP provider; no paid provider calls. Baseline: `3d129a06`; measured fix: `e02adc94`.

| Response | Baseline requests | Fixed requests | Observed result |
| --- | ---: | ---: | --- |
| HTTP 400 + `rate_limit_exceeded` + reported prompt-size prose | 10 | 1 | CLI completes in 1.54 s instead of 118.26 s; no same-model backoff |
| HTTP 400 + same code + generic `Request rejected` | — | 1 | Error surfaces in 1.33 s |
| HTTP 400 without an inner code | 1 | 1 | Same schema-rejection result |
| HTTP 429, twice, then success | 3 | 3 | Recovers successfully |
| HTTP 503, twice, then success | 3 | 3 | Recovers successfully |
| HTTP 400 `ThrottlingException`, twice, then success | 3 | 3 | Recovers successfully |

Baseline failing-request offsets were 0, 1053, 2220, 4972, 11518, 21524, 51629, 66995, 85563 and 115957 ms. The fixed fallback runs each made one rejected request followed by one successful next-model request, both with and without the inner code. The Bedrock control uses its response shape through the local compatible transport, not a live AWS call.

- The three classifier rejection cases fail on baseline and pass with the fix. Recovery-boundary tests also failed for raw and coerced prompt exceptions before repair; both now advance to fallback without backoff. Independent detail prose remains retryable, while the SDK's flat JSON `{code,message}` cannot promote its code into prose.
- 947 tests across seven classifier, classification corpus, structured presentation, error-normalization, attempt recovery and retry-controller suites passed in 26.66 s on `e02adc94`, then passed again in 42.19 s on `c606f7e9` after merging current main once. Existing openclaw#133772 copy and Bedrock corpus assertions were not changed.
- Fresh baseline and `e02adc94` builds, core types, scoped type-aware Oxlint, Oxfmt and whitespace checks passed. The merged head is covered by the fresh focused tests and required CI; the earlier runtime/build measurements are not a rebuild of that later merge.

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 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: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant