#23370: fix: strip [[reply_to_current]] tags from WebChat + validate invoke cwd
app: web-ui
gateway
size: S
Cluster:
Model Reasoning Fixes
Split from #23186.
## Changes
### WebChat: Strip directive tags only from assistant messages
- Previously, `[[reply_to_current]]` and other inline directive tags were stripped from all messages in the WebChat chat history
- Now only strips from assistant messages, preserving user message content
- Also strips directive tags from text blocks within array-style content for assistant messages
### Node Host: Validate working directory for system.run
- Adds `validateWorkingDirectory` function to return a clear error when the specified cwd doesn't exist
- Adds cross-platform test coverage for cwd validation
Closes #23053
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Splits WebChat directive tag stripping to only affect assistant messages (preserving user message content) and adds clear error handling for invalid `cwd` in `system.run`.
**Issues Found:**
- **Critical:** `sanitizeChatHistoryContentBlock` at src/gateway/server-methods/chat.ts:107 unconditionally strips directive tags from all content blocks, breaking the intent to preserve user message content when messages have array-style content
- The function needs an `isAssistant` parameter to conditionally strip tags based on message role
**Node-host changes:**
- `validateWorkingDirectory` implementation is correct and well-tested
- Cross-platform test coverage is appropriate (uses `fileURLToPath` for path handling)
<h3>Confidence Score: 2/5</h3>
- This PR has a critical logical bug that prevents it from achieving its stated goal
- The WebChat changes have a critical flaw where `sanitizeChatHistoryContentBlock` unconditionally strips directive tags from all text blocks in array-style content, regardless of message role. This means user messages with array content will still lose their directive tags, contradicting the PR's purpose. The node-host validation changes are solid and well-tested.
- src/gateway/server-methods/chat.ts requires fixes to properly preserve user message directive tags in array-style content
<sub>Last reviewed commit: 54c63e0</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#22832: fix: strip [[reply_to_current]] directive from chat history
by willkriski · 2026-02-21
83.6%
#23144: fix(ui): strip reply directive tags from assistant messages in WebC...
by echoVic · 2026-02-22
82.8%
#20164: fix(webchat): strip reply directive tags before rendering assistant...
by Limitless2023 · 2026-02-18
82.4%
#23073: fix(ui): strip reply directive tags from assistant messages in WebC...
by x4v13r1120 · 2026-02-22
82.0%
#16733: fix(ui): avoid injected newlines when tool output is hidden
by jp117 · 2026-02-15
79.4%
#20231: fix: strip untrusted metadata blocks from chat history
by MisterGuy420 · 2026-02-18
79.0%
#8742: fix(webchat): hide internal system messages from UI (#7440)
by revenuestack · 2026-02-04
78.9%
#3721: fix(ui): webchat not displaying chat responses
by maxmaxrouge-rgb · 2026-01-29
78.6%
#8334: fix(webchat): Filter NO_REPLY messages from chat history
by vishaltandale00 · 2026-02-03
77.8%
#14966: fix(webchat): preserve user message visibility after chat.send
by BenediktSchackenberg · 2026-02-12
77.6%