Skip to content

isLikelyContextOverflowError regex misclassifies rate limit errors as context overflow #13735

@Lunar-actuary

Description

@Lunar-actuary

Bug Description

When Anthropic returns an HTTP 429 TPD (Tokens Per Day) rate limit error, OpenClaw incorrectly displays it as:

⚠️ Context overflow — prompt too large for this model. Try a shorter message or a larger-context model.

This is misleading because the actual issue is rate limiting, not context overflow.

Root Cause

The regex in isLikelyContextOverflowError() is too broad:

/(?:prompt|request).*(too (?:large|long)|exceed|over|limit|max(?:imum)?)/i

The Anthropic 429 error message:

request reached organization TPD rate limit, current: 1506556, limit: 1500000

This matches request + limit in the regex, causing it to be classified as a context overflow error.

Expected Behavior

Rate limit errors (HTTP 429) should be displayed as rate limit / quota errors, not as context overflow.

Steps to Reproduce

  1. Exceed the Anthropic TPD token limit (1.5M tokens/day)
  2. Send a message via Discord channel
  3. All fallback models fail with 429
  4. OpenClaw shows "Context overflow" instead of a rate limit error

Environment

  • OpenClaw version: 2026.2.9
  • Model: anthropic/claude-opus-4-6
  • Channel: Discord

Suggested Fix

Either:

  1. Add a negative lookahead/check to exclude rate limit errors before testing context overflow regex
  2. Check for rate limit errors first (higher priority) before falling through to context overflow classification
  3. Tighten the regex to require context-specific terms (e.g. require "context" or "token" near "limit")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions