← Back to PRs

#16015: fix(gateway): truncate oversized message content in chat.history response

by fagemx open 2026-02-14 05:22 View on GitHub →
app: web-ui gateway stale size: S
## Summary - Add `truncateMessagesForChatHistory()` that caps each message's content fields to 50K chars before the response is byte-capped - A single message with huge thinking output or tool response can dominate the entire `chat.history` payload, causing the Control UI to freeze - Runs in the existing pipeline: `stripEnvelopeFromMessages → truncateMessagesForChatHistory → capArrayByJsonBytes` - Truncated content ends with `… [content truncated for display]` so users know data was trimmed ## Test plan - [x] 5 new tests in `chat-sanitize.test.ts` covering string content, content arrays, text field, no-op passthrough, and empty array - [x] Build + lint clean Ref #15992 lobster-biscuit > 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> Added `truncateMessagesForChatHistory()` to cap message content fields at 50K characters before the response is byte-capped, preventing the Control UI from freezing when a single message with huge thinking output or tool response dominates the entire `chat.history` payload. The function runs in the existing sanitization pipeline: `stripEnvelopeFromMessages → truncateMessagesForChatHistory → capArrayByJsonBytes`. Truncated content includes `… [content truncated for display]` suffix to inform users of trimming. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - The implementation follows existing patterns in the codebase, has comprehensive test coverage with 5 new tests covering various edge cases (string content, content arrays, text field, no-op passthrough, empty array), and the changes are well-isolated to a specific utility function. The truncation logic is straightforward and defensive, handling null/undefined cases properly. The function integrates seamlessly into the existing pipeline without disrupting other functionality. - No files require special attention <sub>Last reviewed commit: 185379a</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs