Skip to content

fix: prevent error sanitizer from rewriting legitimate assistant replies - #5287

Closed
ayushozha wants to merge 89 commits into
openclaw:mainfrom
ayushozha:fix/error-text-rewriting-guard
Closed

ayushozha wants to merge 89 commits into
openclaw:mainfrom
ayushozha:fix/error-text-rewriting-guard

Conversation

@ayushozha

Copy link
Copy Markdown
Contributor

Summary

  • Add a length/structure guard to sanitizeUserFacingText() so only short, single-block error dumps get rewritten
  • Multi-paragraph assistant replies that start with "Error:" or "Failed:" are now passed through unchanged

Root Cause

sanitizeUserFacingText() applies error-pattern matching to ALL assistant reply text (streaming and final). When the assistant legitimately discusses error concepts (e.g., "Error handling in Node.js requires..."), the ERROR_PREFIX_RE regex matched the "Error" prefix and the text was rewritten to a generic error message like "The AI service is temporarily overloaded."

This happened because:

  1. ERROR_PREFIX_RE matches any text starting with "Error:", "Failed:", etc.
  2. If the remaining text also matches rate limit or timeout patterns, it gets replaced
  3. No guard distinguished raw API error dumps from legitimate multi-paragraph replies

Fix

Added a check: the error rewriting branch only activates when the text is short (<300 chars) and doesn't contain multiple paragraphs. Raw API error messages are always short single-block strings, while legitimate assistant replies discussing errors are typically longer and multi-paragraph.

Fixes #3594

@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Jan 31, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d76afbef55

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 337 to +342
if (ERROR_PREFIX_RE.test(trimmed)) {
if (isOverloadedErrorMessage(trimmed) || isRateLimitErrorMessage(trimmed)) {
return "The AI service is temporarily overloaded. Please try again in a moment.";
}
if (isTimeoutErrorMessage(trimmed)) {
return "LLM request timed out.";
// Only rewrite short, single-block text that looks like a raw error dump.
// Multi-paragraph replies that happen to start with "Error:" or "Failed:"
// are legitimate assistant content and should not be rewritten.
const isShortErrorDump = trimmed.length < 300 && !trimmed.includes("\n\n");
if (isShortErrorDump) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Keep sanitizing long error dumps

The new isShortErrorDump guard means any error-prefixed output longer than 300 chars skips all sanitization and falls through to collapseConsecutiveDuplicateBlocks. That’s a regression for common SDK/provider failures that start with Error: and include stack traces or verbose error bodies (often >300 chars but still single-block). In that case users now see raw error/stack content instead of the friendly message or truncation that formatRawAssistantErrorForUi provided. This triggers whenever the assistant emits a long error dump with an error prefix, so the sanitization is silently bypassed.

Useful? React with 👍 / 👎.

Fix SwiftFormat lint failures across 100 files in apps/macos/Sources.
Applies wrapMultilineStatementBraces, trailingCommas, blankLinesBetweenScopes,
hoistTry, hoistPatternLet, sortImports, and other formatting rules per .swiftformat config.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@ayushozha
ayushozha force-pushed the fix/error-text-rewriting-guard branch from d76afbe to c75dd98 Compare January 31, 2026 09:52
ayushozha and others added 26 commits January 31, 2026 18:42
…penclaw#4593)

OAuth credentials with a refresh token auto-renew on first API call,
so the doctor should not warn about access token expiration when a
refresh token is present. This avoids unnecessary "expired" warnings
that prompt users to re-auth when no action is needed.

Fixes openclaw#3032

Co-authored-by: Ayush Ojha <[email protected]>
What: swap sessions_list for agents_list in /tools/invoke tests
Why: avoid nested gateway calls that can hang under CI; still validates tool invocation + allowlist
Tests: not run (CI should cover)
- .pre-commit-config.yaml: update comment header
- AGENTS.md: update plugin-sdk import path and state directory paths
- skills/bluebubbles/SKILL.md: update plugin-sdk import reference
- skills/discord/SKILL.md: update example sticker name
…unce routing (openclaw#4957)

* fix: prefer requesterOrigin over stale session entry in subagent announce routing

When a subagent finishes and announces results back, resolveAnnounceOrigin
merged the session entry (primary) with requesterOrigin (fallback). If the
session store had a stale lastChannel (e.g. whatsapp) from a previous
interaction but the user was now on a different channel (e.g. bluebubbles),
the announce would route to the wrong channel.

Swap the merge order so requesterOrigin (captured at spawn time, reflecting
the actual current channel) takes priority, with the session entry as
fallback for any missing fields.

Error before fix:
  Delivery failed (whatsapp to bluebubbles:chat_guid:...): Unknown channel: whatsapp

Adds regression test for the stale-channel scenario.

* fix: match test to exact failure scenario and improve reliability (openclaw#4957) (thanks @tyler6204)

- Remove lastTo from stale session store to match the exact mismatch scenario described in the PR
- Replace 5ms setTimeout sleeps with expect.poll for better test reliability
- Prevents flakiness on slower CI machines
…xt+image messages (openclaw#4984)

* fix(bluebubbles): debounce by messageId to preserve attachments in text+image messages

BlueBubbles fires multiple webhook events for a single message - first
without attachment metadata, then ~350ms later with it. Previously,
messages with attachments bypassed debouncing and were processed
immediately, while the text-only version was also queued.

Now the debouncer uses messageId as the key when available, coalescing
all webhook events for the same message. The existing combineDebounceEntries
function merges attachments from all events.

Closes openclaw#4848

* fix: increase debounce and handle balloon messages

- Increase DEFAULT_INBOUND_DEBOUNCE_MS from 350ms to 500ms
- Update buildKey to use associatedMessageGuid for balloon messages
- Add regression test for debouncing behavior

Fixes issues identified in code review.

---------

Co-authored-by: Yurii Chukhlib <[email protected]>
Co-authored-by: Tyler Yust <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: bluebubbles Channel integration: bluebubbles channel: discord Channel integration: discord channel: imessage Channel integration: imessage channel: line Channel integration: line channel: matrix Channel integration: matrix channel: msteams Channel integration: msteams channel: nostr Channel integration: nostr channel: signal Channel integration: signal channel: slack Channel integration: slack channel: telegram Channel integration: telegram channel: voice-call Channel integration: voice-call channel: whatsapp-web Channel integration: whatsapp-web channel: zalo Channel integration: zalo channel: zalouser Channel integration: zalouser app: macos App: macos app: web-ui App: web-ui gateway Gateway runtime extensions: memory-lancedb Extension: memory-lancedb cli CLI command changes scripts Repository scripts commands Command implementations docker Docker and sandbox tooling labels Feb 1, 2026
@openclaw-barnacle

Copy link
Copy Markdown

The rebase completely failed. Please recreate the PR from a clean branch.

@openclaw-barnacle openclaw-barnacle Bot closed this Feb 1, 2026
@thewilloftheshadow thewilloftheshadow added the trigger-response Maintainer trigger to rerun Barnacle auto-response on an item. label Feb 12, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the trigger-response Maintainer trigger to rerun Barnacle auto-response on an item. label Feb 12, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing this PR because it has more than 20 labels, which usually means the branch is too noisy. Please recreate the PR from a clean branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: macos App: macos app: web-ui App: web-ui channel: bluebubbles Channel integration: bluebubbles channel: discord Channel integration: discord channel: imessage Channel integration: imessage channel: line Channel integration: line channel: matrix Channel integration: matrix channel: msteams Channel integration: msteams channel: nostr Channel integration: nostr channel: signal Channel integration: signal channel: slack Channel integration: slack channel: telegram Channel integration: telegram channel: voice-call Channel integration: voice-call channel: whatsapp-web Channel integration: whatsapp-web channel: zalo Channel integration: zalo channel: zalouser Channel integration: zalouser cli CLI command changes commands Command implementations docker Docker and sandbox tooling docs Improvements or additions to documentation extensions: memory-lancedb Extension: memory-lancedb gateway Gateway runtime scripts Repository scripts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: User messages containing error-pattern phrases get rewritten to error text