#13104: fix: persist user command message in chat transcript
app: web-ui
gateway
size: M
trusted-contributor
experienced-contributor
## Summary
Fixes #12934
When the Control UI sends a slash command (e.g. `/status`) via `chat.send`, the server processes the command without starting an agent run. In this code path, only the assistant's response was appended to the session transcript — the user's command message was never persisted. When the UI received the `final` chat event and called `loadChatHistory()`, it replaced its local messages with the server transcript, causing the user's command message to disappear.
### Root cause
In `src/gateway/server-methods/chat.ts`, the `.then()` handler for the `dispatchInboundMessage` promise (when `!agentRunStarted`) called `appendAssistantTranscriptMessage` for the command reply but never stored the user's input.
### Fix
Replace the single `appendAssistantTranscriptMessage` call with a new `appendCommandTranscriptMessages` function that appends **both** the user message and the assistant reply through a single `SessionManager` instance. Using one instance guarantees the `parentId` chain stays intact and both messages are written atomically.
## Test plan
- [x] New test `chat.command-user-message.test.ts` verifies that after `chat.send` handles a command without an agent run, the transcript contains both user and assistant messages in correct order
- [x] Test fails before the fix (only assistant message in transcript), passes after
- [x] `pnpm build` passes
- [x] `pnpm check` passes (format, types, lint)
- [x] Existing `appendAssistantTranscriptMessage` still used by `chat.inject` — not modified
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR fixes missing persistence of slash-command user messages in the `chat.send` path when no agent run is started. It introduces `appendCommandTranscriptMessages()` in `src/gateway/server-methods/chat.ts` to append both the user’s command message (including parsed image attachments) and the assistant’s final reply to the session transcript using a single `SessionManager` instance, preserving the parentId chain.
It also adds a regression test (`src/gateway/server-methods/chat.command-user-message.test.ts`) that simulates a command-only dispatch and asserts that the transcript JSONL contains both the user and assistant messages in the correct order after the `final` broadcast.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk.
- Changes are narrowly scoped to the command-only `chat.send` code path, follow the established transcript append pattern via `SessionManager`, and include a regression test exercising the exact bug scenario (user command disappearing after history refresh). No broken integrations or inconsistencies were found after tracing how `chat.history` reads transcript entries and comparing to existing `appendAssistantTranscriptMessage` behavior.
- No files require special attention.
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#14966: fix(webchat): preserve user message visibility after chat.send
by BenediktSchackenberg · 2026-02-12
83.5%
#6611: fix(webchat): persist assistant messages for CLI backends
by JorgeAlan · 2026-02-01
82.6%
#14309: fix(ui): resolve chat event session key mismatch
by justonlyforyou · 2026-02-11
81.1%
#3721: fix(ui): webchat not displaying chat responses
by maxmaxrouge-rgb · 2026-01-29
80.0%
#21828: fix: acquire session write lock in delivery mirror and gateway chat...
by inkolin · 2026-02-20
79.1%
#22465: fix: preserve session history after API error (400/503) in mid-conv...
by hhy5562877 · 2026-02-21
78.8%
#15050: fix: transcript corruption resilience — strip aborted tool_use bloc...
by yashchitneni · 2026-02-12
78.3%
#21271: fix(commands): pass channel/capabilities/shell/os to runtime in com...
by evansantos · 2026-02-19
78.1%
#16330: fix(gateway): preserve conversation history on gateway restart
by openperf · 2026-02-14
77.9%
#23144: fix(ui): strip reply directive tags from assistant messages in WebC...
by echoVic · 2026-02-22
77.9%