Skip to content

fix: detect additional context overflow error patterns to prevent leak to user#20539

Merged
vincentkoc merged 4 commits intoopenclaw:mainfrom
echoVic:fix/context-overflow-detection-gap
Feb 23, 2026
Merged

fix: detect additional context overflow error patterns to prevent leak to user#20539
vincentkoc merged 4 commits intoopenclaw:mainfrom
echoVic:fix/context-overflow-detection-gap

Conversation

@echoVic
Copy link

@echoVic echoVic commented Feb 19, 2026

Problem

Fixes #9951

The context overflow error format used by some providers:

LLM request rejected: input length and max_tokens exceed context limit: 170636 + 34048 > 200000, decrease input length or max_tokens and try again

was not caught by isContextOverflowError(). It fell through to formatAssistantErrorText()'s invalidRequest regex fallback, which returned the raw error verbatim as LLM request rejected: ... — leaking internal token counts and context limits to the user.

Solution

Add three new patterns to isContextOverflowError():

  1. "exceed context limit" — direct substring match
  2. "exceeds the model's maximum context" — alternate provider wording
  3. max_tokens / input length + exceed + context — compound match for variations

These errors are now rewritten to the standard friendly message:

Context overflow: prompt too large for the model. Try /reset (or /new) to start a fresh session, or use a larger-context model.

Impact

Since isContextOverflowError() is checked before the invalidRequest regex in formatAssistantErrorText(), these patterns are now caught early and never leak raw details.

Greptile Summary

Added four new error pattern detections to isContextOverflowError() to catch provider error formats that were previously falling through to the generic error handler, which leaked internal token counts and context limits to users. The new patterns detect errors containing "exceed context limit", "exceeds the model's maximum context", and compound patterns matching max_tokens/input length + exceed + context.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes add four new substring checks to an existing error detection function. The logic is straightforward and defensive - the compound patterns require multiple keywords to match, reducing false positive risk. The change prevents information leakage by catching errors earlier in the error handling flow, which is a security improvement. No breaking changes or complex logic introduced.
  • No files require special attention

Last reviewed commit: 3e36a0f

@openclaw-barnacle openclaw-barnacle bot added agents Agent runtime and tooling size: XS labels Feb 19, 2026
echoVic and others added 2 commits February 23, 2026 09:38
…k to user

Fixes openclaw#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.
@vincentkoc
Copy link
Member

Rebase + readiness update:

  • Rebases cleanly onto current main.
  • Added regression coverage in pi-embedded-helpers.isbillingerrormessage.test.ts for the new exceed/context/max_tokens variants.
  • Added changelog entry under 2026.2.22 (Unreleased) -> Fixes with contributor credits.

Given this, this should remain the canonical overflow-pattern PR. #6353 has been closed as duplicate with credit preserved.

@vincentkoc vincentkoc merged commit 69692d0 into openclaw:main Feb 23, 2026
8 checks passed
jaydiamond42 pushed a commit to jaydiamond42/bloomtbot that referenced this pull request Feb 23, 2026
…k to user (openclaw#20539)

* fix: detect additional context overflow error patterns to prevent leak to user

Fixes openclaw#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>
carlosrivera pushed a commit to myascendai/meshiclaw that referenced this pull request Feb 23, 2026
…k to user (openclaw#20539)

* fix: detect additional context overflow error patterns to prevent leak to user

Fixes openclaw#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>
mreedr pushed a commit to mreedr/openclaw-custom that referenced this pull request Feb 24, 2026
…k to user (openclaw#20539)

* fix: detect additional context overflow error patterns to prevent leak to user

Fixes openclaw#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>
plgs2005 pushed a commit to plgs2005/openclaw that referenced this pull request Feb 24, 2026
…k to user (openclaw#20539)

* fix: detect additional context overflow error patterns to prevent leak to user

Fixes openclaw#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>
margulans pushed a commit to margulans/Neiron-AI-assistant that referenced this pull request Feb 25, 2026
…k to user (openclaw#20539)

* fix: detect additional context overflow error patterns to prevent leak to user

Fixes openclaw#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>
brianleach pushed a commit to brianleach/openclaw that referenced this pull request Feb 26, 2026
…k to user (openclaw#20539)

* fix: detect additional context overflow error patterns to prevent leak to user

Fixes openclaw#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>
Yuyang-0 pushed a commit to Yuyang-0/openclaw that referenced this pull request Feb 26, 2026
…k to user (openclaw#20539)

* fix: detect additional context overflow error patterns to prevent leak to user

Fixes openclaw#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>
mylukin pushed a commit to mylukin/openclaw that referenced this pull request Feb 26, 2026
…k to user (openclaw#20539)

* fix: detect additional context overflow error patterns to prevent leak to user

Fixes openclaw#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>
r4jiv007 pushed a commit to r4jiv007/openclaw that referenced this pull request Feb 28, 2026
…k to user (openclaw#20539)

* fix: detect additional context overflow error patterns to prevent leak to user

Fixes openclaw#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>
hughdidit pushed a commit to hughdidit/DAISy-Agency that referenced this pull request Mar 1, 2026
…k to user (openclaw#20539)

* fix: detect additional context overflow error patterns to prevent leak to user

Fixes openclaw#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>
(cherry picked from commit 69692d0)

# Conflicts:
#	CHANGELOG.md
#	src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts
hughdidit pushed a commit to hughdidit/DAISy-Agency that referenced this pull request Mar 3, 2026
…k to user (openclaw#20539)

* fix: detect additional context overflow error patterns to prevent leak to user

Fixes openclaw#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>
(cherry picked from commit 69692d0)

# Conflicts:
#	CHANGELOG.md
#	src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
…k to user (openclaw#20539)

* fix: detect additional context overflow error patterns to prevent leak to user

Fixes openclaw#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling dedupe:parent Primary canonical item in dedupe cluster size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Context overflow errors leak to user via messaging channels

2 participants