Skip to content

fix: improve context overflow error with diagnostic details#15749

Open
superlowburn wants to merge 3 commits intoopenclaw:mainfrom
superlowburn:fix/9409-context-overflow-error-message
Open

fix: improve context overflow error with diagnostic details#15749
superlowburn wants to merge 3 commits intoopenclaw:mainfrom
superlowburn:fix/9409-context-overflow-error-message

Conversation

@superlowburn
Copy link
Contributor

@superlowburn superlowburn commented Feb 13, 2026

Summary

  • Replaces the generic "Context overflow: prompt too large" message with diagnostic details
  • Now includes provider/model name, context window limit, session identifier, and message count
  • Adds actionable recovery steps (run /reset, switch model, adjust contextTokens)

Before:

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

After:

Context overflow (anthropic/claude-opus-4-5, limit: 200,000 tokens)
  Session: discord:channel:123456789
  Messages: 47

Actions:
  • Run /reset to clear context and start fresh
  • Or switch to a model with a larger context window
  • Consider lowering contextTokens in config to trigger earlier compaction

Closes #9409

Test plan

  • Lint passes (oxlint, no warnings/errors)
  • Existing e2e tests check isError: true and error.kind, not exact text — unchanged
  • Manual test: trigger a context overflow and verify the new message format

🤖 Generated with Claude Code

Greptile Overview

Greptile Summary

This change updates the embedded PI agent’s context-overflow handling to return a multi-line error message with diagnostics (provider/model, context-window limit, session label, message count) and suggested recovery actions instead of the previous generic one-liner.

The behavior lives in src/agents/pi-embedded-runner/run.ts inside the overflow/compaction recovery branch, and affects what end users see when the runner detects a context overflow and can’t recover via auto-compaction/tool-result truncation.

Confidence Score: 3/5

  • This PR is close to safe to merge but has a couple of user-facing error-handling edge cases to fix first.
  • Core change is localized and straightforward, but the new formatting can throw if the context limit isn’t a number, and it may expose sensitive session identifiers and mislabel compaction failures as context overflows.
  • src/agents/pi-embedded-runner/run.ts

Last reviewed commit: 281f021

Include provider/model, context window limit, session identifier,
and message count in the overflow error. Add actionable recovery
steps (/reset, switch model, adjust contextTokens).

Closes openclaw#9409

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@openclaw-barnacle openclaw-barnacle bot added agents Agent runtime and tooling size: XS labels Feb 13, 2026
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

Comment on lines 603 to +606
const kind = isCompactionFailure ? "compaction_failure" : "context_overflow";
const contextLimit = ctxInfo.tokens;
const sessionLabel = params.sessionKey ?? params.sessionId;
const overflowDetails = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible crash on overflow

ctxInfo.tokens is used as a number (contextLimit.toLocaleString()), but resolveContextWindowInfo isn’t guaranteed to return a numeric tokens value in all configurations. If tokens is undefined/non-number, this will throw while handling a context overflow, masking the real error and preventing an error payload from being returned.

Consider guarding/normalizing ctxInfo.tokens before calling toLocaleString().

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/run.ts
Line: 603:606

Comment:
**Possible crash on overflow**

`ctxInfo.tokens` is used as a number (`contextLimit.toLocaleString()`), but `resolveContextWindowInfo` isn’t guaranteed to return a numeric `tokens` value in all configurations. If `tokens` is `undefined`/non-number, this will throw while handling a context overflow, masking the real error and preventing an error payload from being returned.

Consider guarding/normalizing `ctxInfo.tokens` before calling `toLocaleString()`.

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid — ctxInfo.tokens could be undefined depending on the provider/config, which would throw on .toLocaleString(). Will add a fallback: const contextLimit = ctxInfo.tokens ?? 'unknown' and skip the .toLocaleString() when it's not a number.

Comment on lines +605 to +609
const sessionLabel = params.sessionKey ?? params.sessionId;
const overflowDetails = [
`Context overflow (${provider}/${modelId}, limit: ${contextLimit.toLocaleString()} tokens)`,
sessionLabel ? ` Session: ${sessionLabel}` : null,
` Messages: ${msgCount}`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaks raw session identifier

The user-facing overflow text now includes Session: ${params.sessionKey ?? params.sessionId}. Elsewhere in this file session identifiers are redacted before logging (redactRunIdentifier(...)), so this appears to be sensitive/internal data that shouldn’t be echoed back to end users (especially if sessionId encodes channel IDs, phone numbers, etc.).

If the goal is diagnostics, consider either redacting here too or only including a short/hashed label intended for users.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/run.ts
Line: 605:609

Comment:
**Leaks raw session identifier**

The user-facing overflow text now includes `Session: ${params.sessionKey ?? params.sessionId}`. Elsewhere in this file session identifiers are redacted before logging (`redactRunIdentifier(...)`), so this appears to be sensitive/internal data that shouldn’t be echoed back to end users (especially if `sessionId` encodes channel IDs, phone numbers, etc.).

If the goal is diagnostics, consider either redacting here too or only including a short/hashed label intended for users.

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — the rest of this file redacts session identifiers before logging. Will remove the session line from the user-facing error. Diagnostic details should go to logs, not to the user.

Comment on lines +606 to +614
const overflowDetails = [
`Context overflow (${provider}/${modelId}, limit: ${contextLimit.toLocaleString()} tokens)`,
sessionLabel ? ` Session: ${sessionLabel}` : null,
` Messages: ${msgCount}`,
"",
"Actions:",
" \u2022 Run /reset to clear context and start fresh",
" \u2022 Or switch to a model with a larger context window",
" \u2022 Consider lowering contextTokens in config to trigger earlier compaction",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compaction failures misreported

This new message is returned for both context_overflow and compaction_failure (via kind), but the header always says Context overflow (...) and the suggested actions are overflow-specific. When isCompactionFailure is true (e.g., summarization/compaction request itself overflows), this text is misleading.

Consider branching the header/actions for compaction_failure vs context_overflow so users get the right recovery steps.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/run.ts
Line: 606:614

Comment:
**Compaction failures misreported**

This new message is returned for both `context_overflow` and `compaction_failure` (via `kind`), but the header always says `Context overflow (...)` and the suggested actions are overflow-specific. When `isCompactionFailure` is true (e.g., summarization/compaction request itself overflows), this text is misleading.

Consider branching the header/actions for `compaction_failure` vs `context_overflow` so users get the right recovery steps.

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid — the kind variable distinguishes the two cases but the user-facing message doesn't. Will add a conditional header: "Context overflow" vs "Compaction failure" based on isCompactionFailure, with appropriate actions for each.

superlowburn and others added 2 commits February 13, 2026 22:40
…ion vs overflow

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…paction vs overflow header

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@openclaw-barnacle
Copy link

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle bot added stale Marked as stale due to inactivity and removed stale Marked as stale due to inactivity labels Feb 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve context overflow error message with specifics

1 participant