Skip to content

fix(webchat): strip reply directive tags from finalized messages - #23108

Closed
PinoHouse wants to merge 1 commit into
openclaw:mainfrom
PinoHouse:fix/webchat-strip-reply-tags
Closed

PinoHouse wants to merge 1 commit into
openclaw:mainfrom
PinoHouse:fix/webchat-strip-reply-tags

Conversation

@PinoHouse

@PinoHouse PinoHouse commented Feb 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • WebChat displays [[reply_to_current]] (and [[reply_to:<id>]]) tags in chat bubbles after a message finishes streaming, even though the tags are invisible during streaming
  • Root cause: during streaming, the Pi agent strips reply directive tags before emitting text to the UI; however, when finalized messages are loaded from chat history, the raw text (with tags intact) is returned, and the UI's extractText() only stripped thinking tags — not reply directive tags
  • Fix: apply parseInlineDirectives() (already used by the backend delivery path in reply-directives.ts) to assistant messages inside extractText(), so reply tags are stripped regardless of whether the message arrives via streaming or history retrieval

Changes

File What
ui/src/ui/chat/message-extract.ts Import parseInlineDirectives and chain it after stripThinkingTags() in all 3 assistant-message branches of extractText()
ui/src/ui/chat/message-extract.test.ts Add 4 test cases: string content, array content, .text field, and user-message passthrough

Test plan

  • pnpm format:check — passes
  • pnpm tsgo — type-check passes with zero errors
  • pnpm test -- src/auto-reply/reply/reply-utils.test.ts — 64 related tests pass
  • Open Control UI WebChat, send a message, verify [[reply_to_current]] no longer appears after streaming completes
  • Verify tags are still invisible during streaming (no regression)
  • Verify user messages are unaffected

Closes #23053

🤖 Generated with Claude Code

Greptile Summary

Fixes a bug where reply directive tags like [[reply_to_current]] and [[reply_to:<id>]] were visible in finalized WebChat messages loaded from history, even though they were correctly hidden during streaming.

The root cause was that during streaming, the backend already strips these tags via parseInlineDirectives() before emitting text, but when messages are loaded from history, the raw text (with tags intact) is returned and the UI's extractText() function only stripped thinking tags.

The fix applies parseInlineDirectives() to all three assistant-message branches in extractText() (string content, array content, and text field), ensuring reply tags are stripped consistently regardless of whether the message arrives via streaming or history retrieval. User messages are correctly left unchanged.

  • Adds proper handling for reply directive tags in extractText() by chaining parseInlineDirectives() after stripThinkingTags()
  • Includes 4 test cases covering all message content formats and verifying user messages are not affected
  • Aligns UI message processing with backend delivery path behavior

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix is well-targeted, addresses a clear bug in a UI display layer, and follows the existing pattern already used in the backend. The change reuses an existing utility function (parseInlineDirectives) that is already being used for the same purpose in reply-directives.ts, ensuring consistency. Tests cover all message content formats and verify the fix works correctly. The modification is purely additive (chaining an additional processing step) with no breaking changes.
  • No files require special attention

Last reviewed commit: e1aade3

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

@PinoHouse
PinoHouse force-pushed the fix/webchat-strip-reply-tags branch from e1aade3 to 1be8a58 Compare February 22, 2026 01:38
@PinoHouse

Copy link
Copy Markdown
Contributor Author

Context on prior art

This is a recurrence of #18079. The original UI-side fix (PR #18093, commit e24e465) added a local stripDirectiveTags() helper that manually duplicated the regex from src/utils/directive-tags.ts. That fix was reverted in PR #19188, which noted a preference for moving tag stripping to the server side — but the server-side fix in chat.history never landed, so the bug resurfaced as #23053.

How this PR differs from the reverted approach

Instead of duplicating the regex, this PR imports parseInlineDirectives() directly from src/utils/directive-tags.ts — the same function the backend delivery path already uses in reply-directives.ts. This keeps a single source of truth for the directive tag grammar and avoids the maintenance risk flagged in the revert.

If the team prefers a server-side fix in the chat.history sanitization pipeline instead, happy to move the stripping there — just let me know.

During streaming the Pi agent strips [[reply_to_current]] and
[[reply_to:<id>]] tags before emitting text, so the WebChat UI
displays clean output. However, when finalized messages are loaded
from chat history, the raw text (with tags still present) is
returned to the UI layer. The extractText() function in the
message renderer only stripped thinking tags but not reply
directive tags, causing [[reply_to_current]] to appear in the
rendered chat bubble once the stream completes.

Apply parseInlineDirectives() (already used by the backend
delivery path) to assistant messages in extractText(), so reply
tags are consistently stripped regardless of whether the message
arrives via streaming or history retrieval.

Closes openclaw#23053

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@PinoHouse
PinoHouse force-pushed the fix/webchat-strip-reply-tags branch from c043a9c to e206475 Compare February 22, 2026 15:26
@PinoHouse

Copy link
Copy Markdown
Contributor Author

Closing — this was independently fixed by steipete in f6c7e09 which landed before this PR was reviewed. Thanks!

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: WebChat shows [[reply_to_current]] tag after message completes (not during streaming)

1 participant