#7100: fix(chat): add parentId to injected transcript entries
app: web-ui
gateway
## Summary
When `injectSystemEvent()` creates transcript entries via `appendAssistantTranscriptMessage()`, they were missing the `parentId` field that is required for maintaining the conversation tree structure. This caused issues during compaction in default mode.
## Changes
This fix adds `getLastEntryId()` to read the last entry's id from the transcript file and uses it as `parentId` when creating new injected entries. If no previous entry exists, falls back to `sessionId`.
**File affected:**
- `src/gateway/server-methods/chat.ts` - Add `getLastEntryId()` and include `parentId`
Fixes #7059
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
Adds `getLastEntryId()` to read the tail of a transcript JSONL file and uses it to set `parentId` when `appendAssistantTranscriptMessage()` injects assistant messages, aiming to preserve conversation tree structure during compaction.
The change is localized to `src/gateway/server-methods/chat.ts`, affecting how injected transcript entries are written to the session transcript file.
<h3>Confidence Score: 3/5</h3>
- Mostly safe to merge, but there’s an unaddressed codepath that still writes injected entries without `parentId`.
- The new helper is simple and low-risk, but `chat.inject` continues to bypass the fixed helper and will still emit entries missing `parentId`, which likely preserves the reported compaction issue for that pathway.
- src/gateway/server-methods/chat.ts (chat.inject handler vs appendAssistantTranscriptMessage usage)
<!-- greptile_other_comments_section -->
<sub>(5/5) You can turn off certain types of comments like style [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#16330: fix(gateway): preserve conversation history on gateway restart
by openperf · 2026-02-14
74.7%
#13104: fix: persist user command message in chat transcript
by mcaxtr · 2026-02-10
74.4%
#7127: fix(webchat): add regenerate flag to prevent context leak on response…
by craihub · 2026-02-02
73.5%
#4922: fix(agents): ensure parallel tool results have correct parentId
by jduartedj · 2026-01-30
71.8%
#15792: fix: pass agentId to resolveSessionFilePath in additional call sites
by MisterGuy420 · 2026-02-13
71.6%
#18232: fix: webchat rapid messages create orphan sessions
by MisterGuy420 · 2026-02-16
71.2%
#6611: fix(webchat): persist assistant messages for CLI backends
by JorgeAlan · 2026-02-01
70.4%
#14309: fix(ui): resolve chat event session key mismatch
by justonlyforyou · 2026-02-11
70.1%
#3182: fix(gateway): use canonical session key in chat.send
by chrisherold · 2026-01-28
69.9%
#12974: fix: intermittent (no output) reported by users
by vincentkoc · 2026-02-10
69.9%