#16962: fix: make auth error detection contextual to prevent false positives
agents
stale
size: S
Cluster:
Error Handling Improvements
## Summary
- Replaces overly broad `\b401\b` and `\b403\b` regex patterns in auth error detection with contextual patterns that only match actual HTTP error contexts (e.g., `status: 401`, `http 403`, `got a 401`)
- Prevents false positives on legitimate content like "401k retirement plan" or "403 items in the database"
- Adds regression tests covering false positive scenarios and real auth errors
Fixes #16237
## Test plan
- [x] New test cases for false positives (401k, addresses, section numbers)
- [x] New test cases for real auth/billing errors still detected correctly
- [x] Full test suite passes (`pnpm test:fast`, `pnpm check`)
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Replaces overly broad word-boundary patterns (`\b401\b`, `\b403\b`) with contextual regex patterns that only match HTTP status codes in actual error contexts. The new patterns check for keywords like `status`, `code`, `http`, `error`, `got`, `returned`, or `received` before the status code, preventing false positives on legitimate content like "401k retirement plan" or "403 items in database". The changes include comprehensive regression tests covering both false positive scenarios and real auth error detection.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The changes are well-tested with comprehensive regression tests covering both false positives and true positives. The regex patterns are carefully crafted to match only legitimate error contexts. The implementation follows the same pattern already established for the 402 billing error (fixed in commit 4f329f92).
- No files require special attention
<sub>Last reviewed commit: 0b97447</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#12273: fix: prevent billing error false positive on bare '402' in chat con...
by Yida-Dev · 2026-02-09
79.9%
#19271: fix: remove false-positive billing text rewrite in sanitizeUserFaci...
by MisterGuy420 · 2026-02-17
75.4%
#15109: fix: distinguish transient API errors from billing errors
by jwchmodx · 2026-02-13
75.2%
#10530: fix: tighten skill scanner false positives and add vm module detection
by abdelsfane · 2026-02-06
75.2%
#22792: fix(failover): add word boundary to 429 pattern in ERROR_PATTERNS
by miloudbelarebia · 2026-02-21
75.1%
#20539: fix: detect additional context overflow error patterns to prevent l...
by echoVic · 2026-02-19
74.6%
#20262: fix: detect Venice 402 insufficient USD/Diem balance as billing fai...
by ZPTDclaw · 2026-02-18
74.2%
#8504: fix: prevent false positives in isSilentReplyText for CJK content
by hanxiao · 2026-02-04
74.2%
#16307: fix: surface billing/auth FailoverErrors as user-friendly messages
by petter-b · 2026-02-14
73.9%
#11880: fix: guard decodeURIComponent against malformed percent-encoding in...
by Yida-Dev · 2026-02-08
73.9%