#10792: Agents: avoid context overflow false positives
agents
stale
Fixes a false-positive sanitizer rewrite where normal text that *mentions* "Context overflow" gets replaced with the generic overflow error message.
What changed:
- Only rewrite "context overflow" when the text looks like a standalone error line (error prefix, HTTP status prefix, or starts with "Context overflow:" / "Context overflow-" / "Context overflow—").
- Added tests for both the false-positive case and real overflow error lines.
Tests:
- pnpm check
- pnpm vitest run src/agents/pi-embedded-helpers.sanitizeuserfacingtext.test.ts
Fixes: #8847
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
- Tightens `sanitizeUserFacingText()` so “context overflow” is only rewritten when the input resembles a standalone error line (error prefix, HTTP status prefix, or `Context overflow:`/dash forms).
- Adds Vitest coverage to ensure normal conversational mentions of “Context overflow” are not clobbered.
- Adds Vitest coverage verifying real standalone overflow error lines still get rewritten to the generic user-facing overflow guidance.
- Change is localized to PI embedded helpers error sanitization; other error formatting paths remain unchanged.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk.
- Change is narrowly scoped to sanitization heuristics, uses existing prefix regexes, and includes targeted tests covering the regression and expected rewrite cases; no broader behavior changes were observed in related error formatting paths.
- No files require special attention
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#13318: fix(agents): prevent sanitizeUserFacingText from rewriting conversa...
by hleliofficiel · 2026-02-10
88.9%
#18997: fix: improve context overflow error messages and docs
by realhoratiobot · 2026-02-17
80.4%
#8661: fix: display rate limit errors correctly instead of as context over...
by dbottme · 2026-02-04
79.6%
#15749: fix: improve context overflow error with diagnostic details
by superlowburn · 2026-02-13
78.3%
#12965: fix: suggest /clear in context overflow error message
by asklee-klawd · 2026-02-10
77.7%
#6353: fix(agents): detect Anthropic 'exceed context limit' error for auto...
by Glucksberg · 2026-02-01
76.1%
#9829: Fix MCP transport reconnect and SSE header handling
by mabengda · 2026-02-05
76.0%
#7085: test: skip flaky workspace-paths & safe-bins tests on non-Linux/CI ...
by ThinkIbrokeIt · 2026-02-02
75.8%
#15395: Auto-reply: strip leaked protocol transcript lines from inbound con...
by kiranjd · 2026-02-13
75.1%
#19271: fix: remove false-positive billing text rewrite in sanitizeUserFaci...
by MisterGuy420 · 2026-02-17
75.0%