Skip to content

Agents: scope sanitizeUserFacingText rewrites to errorContext#12988

Merged
Takhoffman merged 3 commits intomainfrom
codex/wip/2026-02-10/pi-sanitize-false-positives
Feb 10, 2026
Merged

Agents: scope sanitizeUserFacingText rewrites to errorContext#12988
Takhoffman merged 3 commits intomainfrom
codex/wip/2026-02-10/pi-sanitize-false-positives

Conversation

@Takhoffman
Copy link
Contributor

@Takhoffman Takhoffman commented Feb 10, 2026

Summary

Fix false positives where normal assistant prose containing error-like phrases (e.g. "Context overflow") gets rewritten/swallowed on outbound channel delivery.

Repro Steps

  1. Ask the agent to describe a changelog / explain “context overflow”.
  2. Agent reply includes the literal phrase.
  3. Outbound channel delivery rewrites the reply to the canned context overflow error.

Root Cause

sanitizeUserFacingText() was applying keyword-based error rewrites to normal assistant text during outbound normalization.

Behavior Changes

  • Keyword-based error rewrites in sanitizeUserFacingText() now require explicit error context.
  • Outbound normalization passes error context from ReplyPayload.isError.
  • Also threads error context into assistant-text extraction helpers so real error turns still rewrite appropriately.

Codebase and GitHub Search

Tests

  • pnpm build
  • pnpm check
  • pnpm test

Manual Testing

  • Telegram (before): agent reply that mentioned/quoted "Context overflow" was swallowed and replaced with the canned context overflow error.
  • Telegram (after): same prompt delivered normally; no rewrite/swallows.

Sign-Off

  • Models used: GPT-5 Codex
  • Submitter effort: agent-assisted
  • Agent notes: scopes keyword-based rewrites to error-only payloads to avoid false positives on normal assistant prose

References
Issues: #12889 #12309 #3594 #7483 #10094 #10368 #11317 #11359 #11649 #12022 #12432 #12676 #12711
PRs: #7567 #10220 #10601 #10620 #10760 #11680 #11685 #12052 #12226 #12433 #12702 #12720 #12726 #12777

@openclaw-barnacle openclaw-barnacle bot added agents Agent runtime and tooling maintainer Maintainer-authored PR labels Feb 10, 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, 1 comment

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 10, 2026

Additional Comments (1)

src/agents/pi-embedded-utils.ts
Missed errorContext propagation

sanitizeUserFacingText() now gates its error-pattern rewrites behind opts.errorContext, but this call site still uses the default (false). If extractAssistantText() can ever be used on provider error strings (or on assistant messages that contain raw error payloads that should be normalized), those rewrites will no longer happen and the UI will show the raw payload instead of the friendly formatted message. This looks inconsistent with the other updated call sites that thread payload.isError.

Also appears in: src/agents/tools/sessions-helpers.ts:393 (transcript extraction path).

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-utils.ts
Line: 221:223

Comment:
**Missed errorContext propagation**

`sanitizeUserFacingText()` now gates its error-pattern rewrites behind `opts.errorContext`, but this call site still uses the default (`false`). If `extractAssistantText()` can ever be used on provider error strings (or on assistant messages that contain raw error payloads that should be normalized), those rewrites will no longer happen and the UI will show the raw payload instead of the friendly formatted message. This looks inconsistent with the other updated call sites that thread `payload.isError`.

Also appears in: `src/agents/tools/sessions-helpers.ts:393` (transcript extraction path).

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

@Takhoffman Takhoffman added the bug Something isn't working label Feb 10, 2026
@Takhoffman Takhoffman merged commit 54315ae into main Feb 10, 2026
21 of 24 checks passed
@Takhoffman Takhoffman deleted the codex/wip/2026-02-10/pi-sanitize-false-positives branch February 10, 2026 01:52
This was referenced Feb 10, 2026
maximalmargin added a commit to maximalmargin/openclaw that referenced this pull request Feb 17, 2026
Fixes openclaw#19258

sanitizeUserFacingText was rewriting normal assistant replies containing
words like 'billing' or 'payment' into error messages, even when there
was no actual API error.

The root cause was an unconditional shouldRewriteBillingText check that
ran on ALL text, not just errors. This was a leftover from before the
errorContext scoping was added in openclaw#12988.

The billing error pattern is already correctly handled inside the
errorContext block (line 542), so the outer check was redundant and
harmful.

Changes:
- Removed shouldRewriteBillingText call outside errorContext
- Removed unused shouldRewriteBillingText function (dead code)

Now billing error rewrites only happen when errorContext=true, preventing
false positives when users legitimately discuss billing/payment topics.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling bug Something isn't working maintainer Maintainer-authored PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments