Auto-reset Claude session on context-window overflow (prompt too long)
A resumed Claude session that grew past the model's context limit failed every turn with "Prompt is too long" — even auto-compaction could not shrink it — so the same oversized session was reused indefinitely and the channel looped forever on that error (no Claude reset pattern matched, unlike Codex). Add "prompt is too long" / context-limit patterns to SESSION_RESET_PATTERNS so the poisoned session is cleared and the next turn starts fresh. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -60,6 +60,26 @@ describe('shouldResetSessionOnAgentFailure', () => {
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('resets the session on context-window overflow (prompt too long)', () => {
|
||||
expect(
|
||||
shouldResetSessionOnAgentFailure({
|
||||
result: null,
|
||||
error:
|
||||
'API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"prompt is too long: 215000 tokens > 200000 maximum"}}',
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('resets the session when max_tokens exceeds the context limit', () => {
|
||||
expect(
|
||||
shouldResetSessionOnAgentFailure({
|
||||
result:
|
||||
'input length and `max_tokens` exceed context limit: 190000 + 20000 > 200000',
|
||||
error: undefined,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('shouldRetryFreshSessionOnAgentFailure', () => {
|
||||
|
||||
@@ -9,6 +9,12 @@ const SESSION_RESET_PATTERNS = [
|
||||
/400[^\n]*thinking/i,
|
||||
/thinking[^\n]*block[^\n]*(?:invalid|error|signature)/i,
|
||||
/invalid[^\n]*signature[^\n]*thinking/i,
|
||||
// Context-window overflow: the resumed session has grown past the model's
|
||||
// limit, so even auto-compaction fails with "Prompt is too long". Without
|
||||
// this, the same oversized session is reused every turn and the channel
|
||||
// loops forever on the same error. Drop it so the next turn starts fresh.
|
||||
/prompt is too long/i,
|
||||
/input length and .*exceed context limit/i,
|
||||
];
|
||||
|
||||
const SESSION_RETRY_PATTERNS = [
|
||||
|
||||
Reference in New Issue
Block a user