← Back to PRs

#21693: feat(gateway): expose session entry id on chat history messages

by tlxue open 2026-02-20 07:40 View on GitHub →
gateway size: S
## Summary - `readSessionMessages()` now copies the Pi session entry `id` onto each message object returned to clients - Enables the WebChat UI to use a stable, server-assigned identifier for exact message dedup during history reconciliation — replacing the current fuzzy heuristic (role + content + timestamp ±30s) - Entry id is only added when the message does not already carry its own `id` field, so existing messages are never clobbered ## Test plan - [x] Added test: entry IDs are preserved on messages when present in transcript - [x] Added test: messages without entry IDs are returned unchanged - [x] Added test: a message's own `id` field is never overwritten by the entry ID - [x] All 38 existing tests in `session-utils.fs.test.ts` continue to pass - [x] Lint and format hooks pass with 0 warnings 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- greptile_comment --> <h3>Greptile Summary</h3> This PR adds session entry IDs to chat history messages returned by `readSessionMessages()`, enabling the WebChat UI to use stable server-assigned identifiers for exact message deduplication instead of the current fuzzy heuristic based on role + content + timestamp. **Changes:** - Modified `readSessionMessages()` in `session-utils.fs.ts` to copy the Pi session entry `id` field onto message objects when the entry has an ID and the message doesn't already have its own `id` field - Added two comprehensive tests validating that entry IDs are preserved when present and that existing message `id` fields are never overwritten - All 38 existing tests continue to pass **Implementation quality:** - The logic correctly checks both that `parsed.id` is a string and that the message doesn't already have an `id` field using the `in` operator - Safe spread operator usage creates a shallow copy with the new field - Proper handling of edge cases (non-string IDs, missing IDs, existing message IDs) - Follows existing code patterns in the file <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - The implementation is straightforward, defensive, and well-tested. It adds a non-breaking feature (copying entry IDs to messages) with proper guards to prevent overwriting existing IDs. The change is backward-compatible, has comprehensive test coverage including edge cases, and all existing tests pass. The code follows repository conventions and handles all identified edge cases correctly. - No files require special attention <sub>Last reviewed commit: 3f68622</sub> <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs