openclaw - ✅(Solved) Fix fix(agents): context overflow not detected for Bedrock, Ollama, and Cohere providers [2 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#58839Fetched 2026-04-08 02:32:00
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
0
Participants
Timeline (top)
cross-referenced ×2commented ×1

Error Message

| Provider | Error Message | Detected? |

Fix Action

Fixed

PR fix notes

PR #58847: fix(agents): handle context overflow consistently across providers

Description (problem / solution / changelog)

Fixes #58839

Summary

isContextOverflowError() detects context overflow for Anthropic and OpenAI but misses several other providers. When overflow goes undetected, the agent retries with the same oversized payload instead of triggering compaction, wasting API credits.

  • Add Bedrock patterns: ValidationException + input too long, ModelStreamErrorException
  • Add Ollama pattern: context length errors
  • Add Cohere pattern: total tokens exceeds model max
  • Add generic patterns: "input is too long for model", "maximum number of input tokens"
  • Add isDefiniteContextOverflowError() for high-confidence detection (HTTP 400 + explicit message)

Test plan

  • Bedrock: ValidationException, ModelStreamErrorException (3 variants)
  • Ollama: context length exceeded
  • Cohere: total tokens exceeds model max
  • Generic: input too long for model, maximum input tokens
  • Existing patterns still work (context length exceeded, prompt is too long)
  • False positive checks (rate limit, TPM not matched)
  • isDefiniteContextOverflowError: HTTP 400 requirement verified
  • Existing failover tests pass (35 tests)

Changed files

  • src/agents/pi-embedded-helpers/context-overflow-detection.test.ts (added, +127/-0)
  • src/agents/pi-embedded-helpers/errors.ts (modified, +31/-1)

PR #58859: fix(agents): handle context overflow consistently across providers

Description (problem / solution / changelog)

Fixes #58839

Summary

isContextOverflowError() detects context overflow for Anthropic and OpenAI but misses several other providers. When overflow goes undetected, the agent retries with the same oversized payload instead of triggering compaction, wasting API credits.

  • Add Bedrock patterns: ValidationException + input too long, ModelStreamErrorException
  • Add Ollama pattern: context length errors
  • Add Cohere pattern: total tokens exceeds model max
  • Add generic patterns: "input is too long for model", "maximum number of input tokens"
  • Add isDefiniteContextOverflowError() for high-confidence detection (HTTP 400 + explicit message)

Test plan

  • Bedrock: ValidationException, ModelStreamErrorException (4 variants)
  • Ollama: context length exceeded
  • Cohere: total tokens exceeds model max
  • Generic: input too long for model, maximum input tokens
  • Existing patterns still work (context length exceeded, prompt is too long)
  • False positive checks (rate limit, TPM not matched)
  • isDefiniteContextOverflowError: HTTP 400 requirement verified
  • Existing failover tests pass (35 tests)
  • tsgo --noEmit clean, oxlint clean, oxfmt --check clean

Changed files

  • src/agents/pi-embedded-helpers/context-overflow-detection.test.ts (added, +127/-0)
  • src/agents/pi-embedded-helpers/errors.ts (modified, +35/-1)
RAW_BUFFERClick to expand / collapse

Bug Description

isContextOverflowError() and isLikelyContextOverflowError() in src/agents/pi-embedded-helpers/errors.ts detect context window overflow for major providers (Anthropic, OpenAI, Groq) but miss several others. When context overflow goes undetected, the agent retries with the same oversized payload instead of triggering compaction — wasting API credits on requests that will always fail.

Missing Provider Patterns

ProviderError MessageDetected?
AWS BedrockValidationException: The input is too longNo
AWS BedrockValidationException: Input exceeds the max input token limitNo
AWS BedrockModelStreamErrorException: Input is too longNo
Ollamaollama: context length exceeded for llama3No
Coheretotal tokens exceeds the model's max of 4096No
Genericinput is too long for model gpt-5.4No
Genericmaximum number of input tokensNo

Impact

  • Users on Bedrock, Ollama, or Cohere hit context limits and see repeated retry failures instead of automatic compaction
  • Each failed retry wastes input tokens (the full oversized context is sent to the provider)
  • With 3 retries per attempt, a single undetected overflow wastes 3x the context window in tokens

Expected Behavior

isContextOverflowError() should detect provider-specific context overflow messages so the compaction pipeline can trigger automatically.

Affected Code

  • src/agents/pi-embedded-helpers/errors.ts:194isContextOverflowError()
  • src/agents/pi-embedded-helpers/errors.ts:248isLikelyContextOverflowError()

extent analysis

TL;DR

Update the isContextOverflowError() and isLikelyContextOverflowError() functions in src/agents/pi-embedded-helpers/errors.ts to include patterns for missing providers.

Guidance

  • Identify and add the missing error message patterns for AWS Bedrock, Ollama, Cohere, and Generic providers to the isContextOverflowError() function.
  • Update the isLikelyContextOverflowError() function to account for the new patterns and ensure it correctly identifies likely context overflow errors.
  • Verify the updated functions by testing with the provided error messages and checking if the compaction pipeline triggers automatically.
  • Consider adding a fallback mechanism to handle unknown error messages and prevent retries with oversized payloads.

Example

// Example of adding a new pattern to isContextOverflowError()
const isContextOverflowError = (error: string) => {
  // Existing patterns...
  const awsBedrockPattern = /ValidationException: The input is too long|ValidationException: Input exceeds the max input token limit|ModelStreamErrorException: Input is too long/;
  const ollamaPattern = /ollama: context length exceeded for llama3/;
  const coherePattern = /total tokens exceeds the model's max of 4096/;
  const genericPattern = /input is too long for model|maximum number of input tokens/;

  return (
    // Existing conditions...
    awsBedrockPattern.test(error) ||
    ollamaPattern.test(error) ||
    coherePattern.test(error) ||
    genericPattern.test(error)
  );
};

Notes

The updated functions should be thoroughly tested to ensure they correctly identify context overflow errors for all providers and trigger the compaction pipeline as expected.

Recommendation

Apply workaround by updating the isContextOverflowError() and isLikelyContextOverflowError() functions to include the missing provider patterns, as this will allow the compaction pipeline to trigger automatically and prevent wasted API credits.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING