Skip to content

fix(models): stop retrying permanent context overflow errors - #923

Open
daleselaji-dev wants to merge 1 commit into
SWE-agent:mainfrom
daleselaji-dev:agent/abort-context-overflow-retries
Open

fix(models): stop retrying permanent context overflow errors#923
daleselaji-dev wants to merge 1 commit into
SWE-agent:mainfrom
daleselaji-dev:agent/abort-context-overflow-retries

Conversation

@daleselaji-dev

Copy link
Copy Markdown

Summary

Fixes #921.

Context-window overflow responses are permanent request errors, but the model retry loop currently treats them like transient provider failures. A single oversized prompt can therefore resend the full history up to ten times before surfacing the original error.

This change:

  • classifies the documented context_length_exceeded and context_window_exceeded 400 responses as non-retryable;
  • applies the same behavior to OpenRouter's chat, text, and Responses API models and to Requesty;
  • adds a focused regression test that verifies each model makes exactly one request.

Root cause

Provider-specific model classes only excluded authentication errors and KeyboardInterrupt from Tenacity retries. Context overflow was raised as the generic API exception, so the retry policy resent an unchanged request even though retrying cannot reduce its size.

Validation

  • python -m pytest -q tests/models/test_context_length_retry.py tests/models/test_openrouter_textbased_model.py — 11 passed
  • real local HTTP 400 server reproduction — exactly 1 request
  • Ruff format and lint checks — passed
  • python -m compileall -q src/minisweagent/models tests/models/test_context_length_retry.py — passed

The broader model test collection still has six unrelated failures in tests that import the optional litellm dependency; no changed code is involved in those failures.

Compatibility

Only recognized context-overflow 400 responses change behavior. Authentication, rate-limit, network, and other provider errors keep their existing retry policies.

@daleselaji-dev
daleselaji-dev marked this pull request as ready for review August 4, 2026 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Permanent context-overflow (400) retried 10 times — full oversized history resent each attempt

1 participant