#16330: fix(gateway): preserve conversation history on gateway restart
gateway
size: XS
Fixes #10018
> Re-submitted from a clean branch. The previous PR #10060 was automatically closed due to a noisy commit history.
## Problem
When the gateway restarts, it sends a notification message (e.g., "Gateway restarted") to external channels via `deliverOutboundPayloads`. However, this message was **not** being written to the session transcript. This caused a gap in the conversation history — the boot message had no `parentId`, effectively creating a new tree root and orphaning all previous conversation history.
## Solution
This PR implements a lightweight fix by calling the existing `appendAssistantMessageToSessionTranscript` function from `src/config/sessions/transcript.ts` right before `deliverOutboundPayloads`. This ensures the restart message is written directly to the session transcript, which automatically handles the `parentId` chain and preserves the conversation history. This approach reuses existing infrastructure, including error handling and real-time UI updates (`emitSessionTranscriptUpdate`), and avoids code duplication.
## Behavior Changes
* Boot/restart messages are now recorded in the session transcript with a correct `parentId`, preserving the conversation tree.
* No AI agent run is triggered. No additional token consumption.
* External notification delivery behavior is completely unchanged.
## Files Changed
| File | Change |
| :--------------------------------------- | :---------------------------------------------------------------------------------- |
| `src/gateway/server-restart-sentinel.ts` | **Modified** — calls `appendAssistantMessageToSessionTranscript` before delivering the notification |
*(Self-correction based on Greptile's feedback to reuse existing functions and remove the custom `transcript-writer.ts`)*
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Adds `appendAssistantMessageToSessionTranscript` call before `deliverOutboundPayloads` to preserve conversation history on gateway restart by writing the restart message to the session transcript with proper `parentId` chaining.
- The function call is missing error handling—if the transcript write fails, the bug will still occur silently
- Consider wrapping the transcript call in the existing try/catch or checking the return value
<h3>Confidence Score: 2/5</h3>
- This PR has a critical logic error that prevents it from achieving its stated goal
- The transcript write function returns an error result object that is never checked. If the write fails (e.g., missing session, disk error), the conversation history gap will persist silently—exactly the bug this PR aims to fix. The previous review thread mentioned adding error handling, but the implementation doesn't actually check the result
- Pay close attention to `src/gateway/server-restart-sentinel.ts`—the error handling must be added before merge
<sub>Last reviewed commit: 3566274</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#13104: fix: persist user command message in chat transcript
by mcaxtr · 2026-02-10
77.9%
#15050: fix: transcript corruption resilience — strip aborted tool_use bloc...
by yashchitneni · 2026-02-12
76.4%
#22465: fix: preserve session history after API error (400/503) in mid-conv...
by hhy5562877 · 2026-02-21
76.1%
#3182: fix(gateway): use canonical session key in chat.send
by chrisherold · 2026-01-28
75.8%
#12953: fix: defer gateway restart until all replies are sent
by zoskebutler · 2026-02-10
75.7%
#3517: fix: trigger agent response for webchat sessions after restart
by dovewars · 2026-01-28
74.9%
#21828: fix: acquire session write lock in delivery mirror and gateway chat...
by inkolin · 2026-02-20
74.8%
#7100: fix(chat): add parentId to injected transcript entries
by josscit · 2026-02-02
74.7%
#22469: fix(gateway): avoid stale whatsapp labels on direct sessions
by loganprit · 2026-02-21
74.7%
#7128: feat: add gateway.restart RPC for graceful in-process restart
by AkashaBot · 2026-02-02
74.5%