mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-21 06:02:13 +00:00
fix(agents): detect Kimi model-token-limit overflows
Co-authored-by: Danilo Falcão <danilo@falcao.org>
This commit is contained in:
@@ -29,6 +29,12 @@ describe("formatAssistantErrorText", () => {
|
||||
);
|
||||
expect(formatAssistantErrorText(msg)).toContain("Context overflow");
|
||||
});
|
||||
it("returns context overflow for Kimi 'model token limit' errors", () => {
|
||||
const msg = makeAssistantError(
|
||||
"error, status code: 400, message: Invalid request: Your request exceeded model token limit: 262144 (requested: 291351)",
|
||||
);
|
||||
expect(formatAssistantErrorText(msg)).toContain("Context overflow");
|
||||
});
|
||||
it("returns a friendly message for Anthropic role ordering", () => {
|
||||
const msg = makeAssistantError('messages: roles must alternate between "user" and "assistant"');
|
||||
expect(formatAssistantErrorText(msg)).toContain("Message ordering conflict");
|
||||
|
||||
@@ -178,6 +178,17 @@ describe("isContextOverflowError", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("matches Kimi 'model token limit' context overflow errors", () => {
|
||||
const samples = [
|
||||
"Invalid request: Your request exceeded model token limit: 262144 (requested: 291351)",
|
||||
"error, status code: 400, message: Invalid request: Your request exceeded model token limit: 262144 (requested: 291351)",
|
||||
"Your request exceeded model token limit",
|
||||
];
|
||||
for (const sample of samples) {
|
||||
expect(isContextOverflowError(sample)).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("ignores normal conversation text mentioning context overflow", () => {
|
||||
// These are legitimate conversation snippets, not error messages
|
||||
expect(isContextOverflowError("Let's investigate the context overflow bug")).toBe(false);
|
||||
|
||||
@@ -51,6 +51,7 @@ export function isContextOverflowError(errorMessage?: string): boolean {
|
||||
lower.includes("maximum context length") ||
|
||||
lower.includes("prompt is too long") ||
|
||||
lower.includes("exceeds model context window") ||
|
||||
lower.includes("model token limit") ||
|
||||
(hasRequestSizeExceeds && hasContextWindow) ||
|
||||
lower.includes("context overflow:") ||
|
||||
(lower.includes("413") && lower.includes("too large"))
|
||||
|
||||
Reference in New Issue
Block a user