feat(FN-1462): add context window exceeds limit pattern to context-limit-detector

- Add new regex pattern /context\s+window\s+exceeds/i to match provider JSON error
  envelope variant: "context window exceeds limit (2013)"
- Add 4 new test cases for the variant pattern
- Pattern is conservative: requires both "context window" and "exceeds" present
This commit is contained in:
gsxdsm
2026-04-10 03:02:38 -07:00
parent dd77c79718
commit f246fe4896
2 changed files with 23 additions and 0 deletions

View File

@@ -68,6 +68,26 @@ describe("isContextLimitError", () => {
expect(isContextLimitError("token limit reached for context window")).toBe(true);
});
// ── Provider JSON envelope variants ────────────────────────────────
it("matches 'context window exceeds limit' variant from provider JSON envelope", () => {
// This is the specific error from the bug report:
// 400 {"type":"error","error":{"type":"invalid_request_error","message":"invalid params, context window exceeds limit (2013)"}}
expect(isContextLimitError("invalid params, context window exceeds limit (2013)")).toBe(true);
});
it("matches 'context window exceeds limit' without surrounding text", () => {
expect(isContextLimitError("context window exceeds limit")).toBe(true);
});
it("matches 'context window exceeds limit' with error code", () => {
expect(isContextLimitError("context window exceeds limit (2003)")).toBe(true);
});
it("matches 'context window exceeds' in mixed case", () => {
expect(isContextLimitError("Context Window Exceeds limit")).toBe(true);
});
// ── Negative matches: must NOT trigger ─────────────────────────────
it("returns false for empty string", () => {

View File

@@ -39,6 +39,9 @@ const CONTEXT_OVERFLOW_PATTERNS: RegExp[] = [
/too many tokens/i,
// Anthropic variant: "messages with that many tokens would exceed"
/tokens? would exceed/i,
// Provider JSON error envelope variant: "context window exceeds limit (2013)"
// Matches when "context window" and "exceeds" appear together (order-flexible)
/context\s+window\s+exceeds/i,
];
/**