Handle 413 context overflow errors gracefully#395
Closed
alejandroOPI wants to merge 1 commit intoopenclaw:mainfrom
Closed
Handle 413 context overflow errors gracefully#395alejandroOPI wants to merge 1 commit intoopenclaw:mainfrom
alejandroOPI wants to merge 1 commit intoopenclaw:mainfrom
Conversation
When the conversation context exceeds the model's limit, instead of throwing an opaque error or returning raw JSON, we now: 1. Detect context overflow errors (413, request_too_large, etc.) 2. Return a user-friendly message explaining the issue 3. Suggest using /new or /reset to start fresh This prevents the assistant from becoming completely unresponsive when context grows too large (e.g., from many screenshots or long tool outputs). Addresses issue openclaw#394
Contributor
|
Landed on main via fast-forward. Commits: d5547122 (context overflow handling + helper tests), 43f72aea (tool errors concise, requested), 24ee7c47 (changelog + clawtributors credit for PR #395).\n\nGate: pnpm lint && pnpm build && pnpm test && pnpm docs:list |
steipete
added a commit
that referenced
this pull request
Jan 7, 2026
dgarson
added a commit
to dgarson/clawdbot
that referenced
this pull request
Feb 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When the conversation context exceeds the model's limit, the gateway returns a raw 413 error that makes the assistant completely unresponsive. Users have no indication of what went wrong or how to fix it.
This happened to me on Jan 6-7, 2026 - the assistant was stuck returning 413 errors for hours until I manually cleared the context.
Solution
This PR adds graceful handling of context overflow errors:
New helper function
isContextOverflowError()inpi-embedded-helpers.tsdetects various forms of the error (413, request_too_large, context length exceeded, etc.)User-friendly error message in
formatAssistantErrorText()returns a helpful message instead of raw JSONEarly return in runner - When
session.prompt()throws a context overflow error, we return a helpful response instead of propagating the errorChanges
src/agents/pi-embedded-helpers.ts: AddedisContextOverflowError()function and updatedformatAssistantErrorText()to detect and handle 413 errorssrc/agents/pi-embedded-runner.ts: Import the new helper and catch context overflow errors in the prompt execution pathTesting
pnpm build)request_too_large,request exceeds the maximum size,context length exceeded,maximum context lengthFuture Improvements
This is a minimal fix. A more complete solution could:
Addresses #394