mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 11:17:40 +00:00
fix(agents): stabilize overflow compaction retries and session context accounting (openclaw#14102) thanks @vpesh
Verified:
- CI checks for commit 86a7ecb45e
- Rebase conflict resolution for compatibility with latest main
Co-authored-by: vpesh <9496634+vpesh@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
da55d70fb0
commit
957b883082
@@ -38,7 +38,9 @@ export function isContextOverflowError(errorMessage?: string): boolean {
|
||||
|
||||
const CONTEXT_WINDOW_TOO_SMALL_RE = /context window.*(too small|minimum is)/i;
|
||||
const CONTEXT_OVERFLOW_HINT_RE =
|
||||
/context.*overflow|context window.*(too (?:large|long)|exceed|over|limit|max(?:imum)?|requested|sent|tokens)|(?:prompt|request|input).*(too (?:large|long)|exceed|over|limit|max(?:imum)?)/i;
|
||||
/context.*overflow|context window.*(too (?:large|long)|exceed|over|limit|max(?:imum)?|requested|sent|tokens)|prompt.*(too (?:large|long)|exceed|over|limit|max(?:imum)?)|(?:request|input).*(?:context|window|length|token).*(too (?:large|long)|exceed|over|limit|max(?:imum)?)/i;
|
||||
const RATE_LIMIT_HINT_RE =
|
||||
/rate limit|too many requests|requests per (?:minute|hour|day)|quota|throttl|429\b/i;
|
||||
|
||||
export function isLikelyContextOverflowError(errorMessage?: string): boolean {
|
||||
if (!errorMessage) {
|
||||
@@ -56,6 +58,9 @@ export function isLikelyContextOverflowError(errorMessage?: string): boolean {
|
||||
if (isContextOverflowError(errorMessage)) {
|
||||
return true;
|
||||
}
|
||||
if (RATE_LIMIT_HINT_RE.test(errorMessage)) {
|
||||
return false;
|
||||
}
|
||||
return CONTEXT_OVERFLOW_HINT_RE.test(errorMessage);
|
||||
}
|
||||
|
||||
@@ -72,9 +77,13 @@ export function isCompactionFailureError(errorMessage?: string): boolean {
|
||||
if (!hasCompactionTerm) {
|
||||
return false;
|
||||
}
|
||||
// For compaction failures, also accept "context overflow" without colon
|
||||
// since the error message itself describes a compaction/summarization failure
|
||||
return isContextOverflowError(errorMessage) || lower.includes("context overflow");
|
||||
// Treat any likely overflow shape as a compaction failure when compaction terms are present.
|
||||
// Providers often vary wording (e.g. "context window exceeded") across APIs.
|
||||
if (isLikelyContextOverflowError(errorMessage)) {
|
||||
return true;
|
||||
}
|
||||
// Keep explicit fallback for bare "context overflow" strings.
|
||||
return lower.includes("context overflow");
|
||||
}
|
||||
|
||||
const ERROR_PAYLOAD_PREFIX_RE =
|
||||
|
||||
Reference in New Issue
Block a user