mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 10:27:38 +00:00
fix: detect additional context overflow error patterns to prevent leak to user (#20539)
* fix: detect additional context overflow error patterns to prevent leak to user Fixes #9951 The error 'input length and max_tokens exceed context limit: 170636 + 34048 > 200000' was not caught by isContextOverflowError() and leaked to users via formatAssistantErrorText()'s invalidRequest fallback. Add three new patterns to isContextOverflowError(): - 'exceed context limit' (direct match) - 'exceeds the model\'s maximum context' - max_tokens/input length + exceed + context (compound match) These are now rewritten to the friendly context overflow message. * Overflow: add regression tests and changelog credits * Update CHANGELOG.md * Update pi-embedded-helpers.isbillingerrormessage.test.ts --------- Co-authored-by: echoVic <AkiraVic@outlook.com> Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
This commit is contained in:
@@ -189,6 +189,18 @@ describe("isContextOverflowError", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("matches exceed/context/max_tokens overflow variants", () => {
|
||||
const samples = [
|
||||
"input length and max_tokens exceed context limit (i.e 156321 + 48384 > 200000)",
|
||||
"This request exceeds the model's maximum context length",
|
||||
"LLM request rejected: max_tokens would exceed context window",
|
||||
"input length would exceed context budget for this model",
|
||||
];
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user