Skip to content

fix: prevent false positive context overflow detection in conversation text#2078

Merged
quotentiroler merged 3 commits intoopenclaw:mainfrom
sbking:fix/context-overflow-false-positive
Feb 9, 2026
Merged

fix: prevent false positive context overflow detection in conversation text#2078
quotentiroler merged 3 commits intoopenclaw:mainfrom
sbking:fix/context-overflow-false-positive

Conversation

@sbking
Copy link
Contributor

@sbking sbking commented Jan 26, 2026

Problem

The isContextOverflowError check was too broad — it matched any text containing 'context overflow', including legitimate conversation discussing the topic.

This caused the sanitizeUserFacingText function to replace normal agent responses with error messages when the agent was discussing context overflow as a topic (e.g., debugging the compaction system).

Root Cause

Line 23 in errors.ts:

lower.includes("context overflow")

This matches any text containing the phrase, not just actual error messages.

Fix

Changed to require 'context overflow:' (with colon) to only match actual error messages like:

  • "Context overflow: Summarization failed"
  • "Context overflow: prompt too large..."

Normal conversation like "Let's investigate the context overflow bug" will no longer trigger false positives.

Testing

  • All existing tests pass
  • Added new test case to verify normal conversation text doesn't trigger false positives

Greptile Overview

Greptile Summary

This PR narrows isContextOverflowError’s heuristic by changing the substring match from "context overflow" to "context overflow:", preventing sanitizeUserFacingText / formatAssistantErrorText from rewriting normal conversation that happens to mention context overflow.

It also adds a regression test ensuring conversational mentions like “investigate the context overflow bug” are not classified as overflow errors.

Overall, the change is localized to the Pi embedded helpers error classifier (src/agents/pi-embedded-helpers/errors.ts) and its unit tests, and it reduces false positives in downstream user-facing error sanitization.

Confidence Score: 4/5

  • This PR is likely safe to merge and addresses a real false-positive classification issue.
  • The change is small and well-scoped (one substring match + a targeted regression test). Main risk is behavioral: requiring a colon could miss legitimate provider error strings that don’t include context overflow: exactly, which could reduce auto-compaction/UX handling in those cases.
  • src/agents/pi-embedded-helpers/errors.ts

(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!

Context used:

  • Context from dashboard - CLAUDE.md (source)
  • Context from dashboard - AGENTS.md (source)

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, 1 comment

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 3, 2026

Additional Comments (1)

src/agents/pi-embedded-helpers/errors.ts
[P2] context overflow: match may be too strict for some provider errors

isContextOverflowError now only matches the literal substring "context overflow:" (src/agents/pi-embedded-helpers/errors.ts:23). This fixes the false positive for normal conversation, but it can also miss real overflow errors that don’t include a colon (e.g. "context overflow", "Context overflow - ...", or "context overflow\n..."), depending on provider formatting. If you’ve seen non-colon variants in the wild, consider broadening this to a prefix/word-boundary match like context overflow\b with an additional “looks like an error header” guard, rather than requiring a colon.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-helpers/errors.ts
Line: 15:25

Comment:
[P2] `context overflow:` match may be too strict for some provider errors

`isContextOverflowError` now only matches the literal substring `"context overflow:"` (`src/agents/pi-embedded-helpers/errors.ts:23`). This fixes the false positive for normal conversation, but it can also miss real overflow errors that don’t include a colon (e.g. `"context overflow"`, `"Context overflow - ..."`, or `"context overflow\n..."`), depending on provider formatting. If you’ve seen non-colon variants in the wild, consider broadening this to a prefix/word-boundary match like `context overflow\b` with an additional “looks like an error header” guard, rather than requiring a colon.

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

Copy link
Contributor

@quotentiroler quotentiroler left a comment

Choose a reason for hiding this comment

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

LGTM! Simple heuristic fix - requiring the colon eliminates false positives from normal conversation while still catching actual error messages ("Context overflow: prompt too large..."). Good regression tests covering conversational mentions.

Stephen King and others added 3 commits February 8, 2026 23:15
…n text

The isContextOverflowError check was too broad - it matched any text containing
'context overflow', including legitimate conversation discussing the topic.

Changed to require 'context overflow:' (with colon) to only match actual error
messages like 'Context overflow: Summarization failed'.

Added test case to verify normal conversation text doesn't trigger false positives.
@quotentiroler quotentiroler force-pushed the fix/context-overflow-false-positive branch from 74a46bd to c7175d1 Compare February 9, 2026 07:21
@openclaw-barnacle openclaw-barnacle bot added the agents Agent runtime and tooling label Feb 9, 2026
@quotentiroler quotentiroler merged commit c984e6d into openclaw:main Feb 9, 2026
21 of 24 checks passed
yeboster pushed a commit to yeboster/openclaw that referenced this pull request Feb 9, 2026
NikolasP98 pushed a commit to NikolasP98/openclaw that referenced this pull request Feb 9, 2026
NikolasP98 added a commit to NikolasP98/openclaw that referenced this pull request Feb 9, 2026
Integrated upstream improvements:
- CRITICAL: Fix bundled hooks broken since 2026.2.2 (openclaw#9295)
- Grok web search provider (xAI) with inline citations
- Telegram video note support with tests and docs
- QMD model cache sharing optimization (openclaw#12114)
- Context overflow false positive fix (openclaw#2078)
- Model failover 400 status handling (openclaw#1879)
- Dynamic config loading per-message (openclaw#11372)
- Gateway post-compaction amnesia fix (openclaw#12283)
- Skills watcher: ignore Python venvs and caches
- Telegram send recovery from stale thread IDs
- Cron job parameter recovery (openclaw#12124)
- Auto-reply weekday timestamps (openclaw#12438)
- Utility consolidation refactoring (PNG, JSON, errors)
- Cross-platform test normalization (openclaw#12212)
- macOS Nix defaults support (openclaw#12205)

Preserved DEV enhancements:
- Docker multi-stage build with enhanced tooling (gh, gog, obsidian-cli, uv, nano-pdf, mcporter, qmd)
- Comprehensive .env.example documentation (371 lines)
- Multi-environment docker-compose support (DEV/PRD)
- GOG/Tailscale integration
- Fork-sync and openclaw-docs skills
- UI config editor (Svelte)
- Fork workflow documentation

Merge strategy: Cherry-picked 22 upstream commits, preserved DEV Docker architecture.
Docker files unchanged: Dockerfile, docker-compose.yml, docker-setup.sh, .env.example

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Ethermious pushed a commit to Ethermious/openclaw that referenced this pull request Feb 9, 2026
@westerlund
Copy link

Lol I fed the changelog of "openclaw 2026.2.9" and my agent responded with:

Context overflow: prompt too large for the model. Try again with less input or a larger-context model.

I guess it's not perfect yet

lucasmpramos pushed a commit to butley/openclaw that referenced this pull request Feb 10, 2026
huangxida added a commit to huangxida/openclaw that referenced this pull request Feb 11, 2026
1. A2UI 资源 503:构建工具将 a2ui.ts 打包为扁平 chunk(dist/gateway-cli-*.js),
   import.meta.url 指向 dist/ 而非 dist/canvas-host/,导致所有候选路径失配。
   新增 dist/canvas-host/a2ui 等候选路径,并基于 process.argv[1] 推导仓库根目录
   以兼容 launchd 无 WorkingDirectory 的场景。

2. Control UI 构建失败:scripts/ui.js 在 ui/ 子目录 spawn pnpm 时继承了父进程的
   NODE_OPTIONS(含 --import proxy-bootstrap.mjs),相对路径在子目录中解析失败。
   新增 cleanEnv() 在 spawn 前清理 --import 项。

3. 上下文溢出检测遗漏:OpenAI Codex 返回 "Your input exceeds the context window"
   但 isContextOverflowError() 只匹配 "exceeds model context window"(缺少 "the"),
   导致自动压缩/重试机制未触发。泛化 hasExceeds 检测条件,同时将 "context overflow"
   的裸匹配改为行首正则,修复 openclaw#2078 引入的对话文本误报回归。
yeboster pushed a commit to yeboster/openclaw that referenced this pull request Feb 13, 2026
skyhawk14 pushed a commit to skyhawk14/openclaw that referenced this pull request Feb 13, 2026
Wei-EVA pushed a commit to Wei-EVA/openclaw that referenced this pull request Feb 15, 2026
…v2026.2.9

- A1: fix post-compaction amnesia — use SessionManager.appendMessage() instead of raw fs.appendFileSync in chat.ts to preserve parentId chain (openclaw#12283)
- A2: recover from context overflow caused by oversized tool results — pre-emptive 400K char cap + session-level truncation fallback (openclaw#11579)
- A3: fix bundled hooks broken since tsdown migration — add hook handler entries + correct dist path (openclaw#9295)
- A4: prevent false positive context overflow detection — require colon in match (openclaw#2078)
- A5: treat HTTP 400 as failover-eligible for model fallback (openclaw#1879)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Comments