#16176: Fix Groq TPM limits misidentified as context overflow
agents
size: XS
Cluster:
Context Window Fixes
Groq uses HTTP 413 for TPM (tokens per minute) limit errors. These were being incorrectly identified as context window overflows, causing OpenClaw to try resetting the session in an infinite loop. This fix excludes errors containing 'tpm' or 'tokens per minute' from being identified as context overflows and correctly classifies them as rate limits.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Fixed Groq TPM (tokens per minute) rate limit errors being misidentified as context overflow errors. Groq returns HTTP 413 with "too large" messages for rate limits, which was matching the context overflow pattern `(lower.includes("413") && lower.includes("too large"))` in `isContextOverflowError()`. This caused infinite retry loops as OpenClaw attempted to reset sessions for what it thought were context overflows. The fix adds early exclusion checks for "tpm" and "tokens per minute" strings in both `isContextOverflowError()` and `isLikelyContextOverflowError()`, and adds these patterns to the rate limit classifier.
- Prevented TPM errors from triggering incorrect context overflow handling
- Ensured TPM errors are properly classified as rate limits in `ERROR_PATTERNS.rateLimit`
- Applied consistent exclusion logic across both context overflow detection functions
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The fix is targeted, logical, and solves a specific misidentification bug without introducing new risks. The changes are minimal (adding exclusion checks and updating pattern arrays), the logic is sound (checking for rate-limit-specific terms before general overflow patterns), and the implementation is consistent across related functions. No breaking changes or side effects expected.
- No files require special attention
<sub>Last reviewed commit: fd20686</sub>
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#23279: fix: show correct context limit in status when runtime model differs
by Imccccc · 2026-02-22
76.4%
#20539: fix: detect additional context overflow error patterns to prevent l...
by echoVic · 2026-02-19
75.5%
#8661: fix: display rate limit errors correctly instead of as context over...
by dbottme · 2026-02-04
75.1%
#18997: fix: improve context overflow error messages and docs
by realhoratiobot · 2026-02-17
74.4%
#11416: fix: clamp timeout values to avoid 32-bit overflow warning
by seojoonkim · 2026-02-07
74.0%
#15749: fix: improve context overflow error with diagnostic details
by superlowburn · 2026-02-13
73.7%
#19764: fix(security): OC-65 fix compaction counter reset to prevent contex...
by aether-ai-agent · 2026-02-18
73.3%
#10636: fix: setTimeout integer overflow causing server crash
by devmangel · 2026-02-06
73.0%
#11174: Fix/fried chicken error
by jfgrissom · 2026-02-07
72.8%
#9620: fix: increase auto-compaction reserve buffer to 40k tokens
by Arlo83963 · 2026-02-05
72.7%