Skip to content

Fix/98101 429 overloaded classification - #98202

Closed
hanZeng-08 wants to merge 2 commits into
openclaw:mainfrom
hanZeng-08:fix/98101-429-overloaded-classification
Closed

hanZeng-08 wants to merge 2 commits into
openclaw:mainfrom
hanZeng-08:fix/98101-429-overloaded-classification

Conversation

@hanZeng-08

Copy link
Copy Markdown
Contributor

Fixes #98101

Summary

Fixes issue #98101: when a provider returns HTTP 429 with a body that explicitly says "overloaded", OpenClaw misclassified it as rate_limit and showed users "⚠️ API rate limit reached. Please try again later.". It now correctly classifies as overloaded and shows "The AI service is temporarily overloaded. Please try again in a moment.".

Real Behavior Proof

Before the fix, the new regression test failed on the old code:

$ pnpm test src/agents/embedded-agent-helpers/failover-matches.test.ts
 FAIL  |unit-fast| src/agents/embedded-agent-helpers/failover-matches.test.ts > HTTP 429 overloaded body classification (#98101) > classifies a 429 body with overloaded text as overloaded
AssertionError: expected 'rate_limit' to be 'overloaded' // Object.is equality

Expected: "overloaded"
Received: "rate_limit"

The user-facing copy also returned the rate-limit message on the old code:

AssertionError: expected '⚠️ API rate limit reached. Please try…' to be 'The AI service is temporarily overloa…' // Object.is equality

Expected: "The AI service is temporarily overloaded. Please try again in a moment."
Received: "⚠️ API rate limit reached. Please try again later."

After the fix, all related tests pass:

$ pnpm test src/agents/embedded-agent-helpers

 Test Files  6 passed (6)
      Tests  91 passed (91)

Negative control: a real rate-limit 429 is still classified as rate_limit (existing test rate limit still classified correctly passes).

Regression Test Plan

Added the following tests in src/agents/embedded-agent-helpers/failover-matches.test.ts:

  1. classifies a 429 body with overloaded text as overloaded — verifies classifyFailoverReason returns overloaded for z.ai 1305-style responses.
  2. returns overloaded user-facing copy for a 429 body with overloaded text — verifies formatRateLimitOrOverloadedErrorCopy returns the overloaded user copy.

Root Cause

  1. In classifyFailoverClassificationFromMessage, isRateLimitErrorMessage was checked before isOverloadedErrorMessage. Because ERROR_PATTERNS.rateLimit contains a 429 wildcard, any non-billing 429 message hit the rate-limit branch first.
  2. classifyFailoverClassificationFromHttpStatus unconditionally returned rate_limit at the end of its status === 429 branch, overriding the message-level classification.
  3. formatRateLimitOrOverloadedErrorCopy also checked isRateLimitErrorMessage first, so users saw the rate-limit copy.

Implementation Plan Details

  • In classifyFailoverClassificationFromMessage, prefer overloaded when the leading HTTP status is 429 and isOverloadedErrorMessage matches.
  • In classifyFailoverClassificationFromHttpStatus, check isOverloadedErrorMessage before returning rate_limit for status 429.
  • In formatRateLimitOrOverloadedErrorCopy, return OVERLOADED_ERROR_USER_MESSAGE first when the leading status is 429 and the message is overloaded.

Change Details

  • src/agents/embedded-agent-helpers/errors.ts
    • classifyFailoverClassificationFromMessage: added 429 + overloaded priority check.
    • classifyFailoverClassificationFromHttpStatus: added overloaded check in the 429 branch.
  • src/agents/embedded-agent-helpers/sanitize-user-facing-text.ts
    • formatRateLimitOrOverloadedErrorCopy: added 429 + overloaded priority check.
  • src/agents/embedded-agent-helpers/failover-matches.test.ts
    • Added 2 regression tests.

Test Points

  • 429 + "overloaded" body → overloaded
  • 429 + "rate limit" body → rate_limit (unchanged)
  • Non-429 overloaded text → still handled by isOverloadedErrorMessage

Next Steps

Environment: Linux, Node 22.23.1, pnpm 11.2.2

…_limit

HTTP 429 responses that explicitly contain "overloaded" (e.g. z.ai code 1305)
were misclassified as rate_limit because the 429 token matched the broad
rate-limit pattern before the overloaded check ran. Check overloaded first
for 429 messages in both classification and user-facing copy paths.

Fixes openclaw#98101
@hanZeng-08
hanZeng-08 requested a review from a team as a code owner June 30, 2026 15:15
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Jun 30, 2026
@github-actions

github-actions Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Security-sensitive changes are blocked

OpenClaw does not accept security-sensitive file changes through PRs unless a repository admin or security explicitly authorizes the current head SHA.

Detected security-sensitive changes:

  • .gitignore: Controls ignored secret and local files, including common .env files, before they can be accidentally committed.

If this PR intentionally needs these changes, ask a repository admin or member of @openclaw/openclaw-secops to comment:

/allow-security-sensitive-change

The action will approve the current head SHA (214bc5eb25615cc095f3a0415dd3c17205fa6ca7) when it reruns. A later push requires a fresh approval.

@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jun 30, 2026
@clawsweeper

clawsweeper Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close this PR as superseded: it targets a real bug, but a cleaner open canonical PR covers the same status/message behavior plus the user-facing copy path, has proof-sufficient review state, and avoids this branch's unrelated security-sensitive .gitignore churn.

Root-cause cluster
Relationship: superseded
Canonical: #98165
Summary: This PR is a duplicate candidate for the overloaded-429 bug; a cleaner proof-positive PR is the better canonical landing path.

Members:

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

Canonical path: Use #98165 as the canonical landing path for the overloaded-429 fix, then close the linked issue and duplicate PRs after it merges.

So I’m closing this here and keeping the remaining discussion on #98165.

Review details

Best possible solution:

Use #98165 as the canonical landing path for the overloaded-429 fix, then close the linked issue and duplicate PRs after it merges.

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

Yes. Source inspection and the linked issue logs show that current main checks generic 429/rate-limit before overloaded and the explicit 429 status branch defaults to rate_limit after billing checks.

Is this the best way to solve the issue?

No for this PR as the landing branch. The failover change is plausible, but #98165 is a cleaner proof-positive candidate covering the same bug without the unrelated ignore-file churn.

Security review:

Security review needs attention: The PR touches .gitignore, which the repository's security-sensitive guard blocks unless removed or explicitly authorized.

  • [low] Unrelated security-sensitive ignore rule — .gitignore:18
    Adding comment-*.md to .gitignore changes a repository-level ignore surface unrelated to the failover bug and triggered the security-sensitive guard.
    Confidence: 0.92

AGENTS.md: found and applied where relevant.

What I checked:

Likely related people:

  • 0xghost42: Authored the merged Zhipu/GLM overload classifier and test commits that touched the same overload matcher surface. (role: recent adjacent classifier contributor; confidence: high; commits: a30de0d27477, b1f2691edab4; files: src/agents/embedded-agent-helpers/failover-matches.ts, src/agents/embedded-agent-helpers/failover-matches.test.ts, src/agents/model-fallback.test.ts)
  • steipete: Merged PR 93241 and authored its provider-neutral overload matcher refactor in the same classification area. (role: recent adjacent refactor author and merger; confidence: high; commits: db79e94c89dc, 6c1041339da6; files: src/agents/embedded-agent-helpers/failover-matches.ts, src/agents/embedded-agent-helpers/failover-matches.test.ts, src/agents/model-fallback.test.ts)
  • Pick-cat: Local blame attributes the current classifier, matcher, and copy snapshot to PR 97812's merge commit, though earlier overload-specific history is more informative. (role: recent current-main carrier; confidence: medium; commits: eb5fb2aa69f4; files: src/agents/embedded-agent-helpers/errors.ts, src/agents/embedded-agent-helpers/failover-matches.ts, src/agents/embedded-agent-helpers/sanitize-user-facing-text.ts)

Codex review notes: model internal, reasoning high; reviewed against 6cb82eaab865.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jun 30, 2026
@clawsweeper

clawsweeper Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

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: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. security-sensitive-changed size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: HTTP 429 + 'overloaded' body (e.g. z.ai code 1305) misclassified as rate_limit → false 'API rate limit reached' instead of overloaded

1 participant