#16006: fix(gateway): reduce chat.history byte cap from 6 MB to 2 MB
gateway
stale
size: XS
## Summary
- Lower `DEFAULT_MAX_CHAT_HISTORY_MESSAGES_BYTES` from 6 MiB to 2 MiB
- Sessions with large transcripts (~6 MB+) crash the browser tab because `chat.history` sends the full capped payload in a single WebSocket frame
- 2 MiB is still plenty for ~200 messages of normal conversation while staying within what browsers can comfortably parse and render
## Test plan
- [x] `session-utils.test.ts` (34 tests) — all pass, `capArrayByJsonBytes` uses custom limits unaffected by default change
- [x] Build + lint clean
Fixes #15992
lobster-biscuit
> 🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
Reduced `DEFAULT_MAX_CHAT_HISTORY_MESSAGES_BYTES` from 6 MiB to 2 MiB to prevent browser tab crashes when sending large chat history transcripts via WebSocket. The change addresses sessions with ~6 MB+ transcripts that were causing browser tabs to freeze when `chat.history` sent the full payload in a single WebSocket frame. 2 MiB still provides capacity for approximately 200 messages while staying within browser parsing limits.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The change is a simple constant value reduction that addresses a real browser performance issue. The new value (2 MiB) is still generous for typical use cases (~200 messages), and the `capArrayByJsonBytes` function already handles byte capping correctly. Tests pass and the change is well-justified in both the PR description and issue reference.
- No files require special attention
<sub>Last reviewed commit: 4d3bcde</sub>
<!-- 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
#16015: fix(gateway): truncate oversized message content in chat.history re...
by fagemx · 2026-02-14
84.9%
#20394: feat(gateway): make chat history byte limit configurable via gatewa...
by mgratch · 2026-02-18
78.3%
#14966: fix(webchat): preserve user message visibility after chat.send
by BenediktSchackenberg · 2026-02-12
76.1%
#6805: fix: increase WebSocket MAX_PAYLOAD_BYTES to 6MB for attachments
by cortexuvula · 2026-02-02
75.9%
#19343: Refactor chat state management: reset chat messages and queue on se...
by saurav470 · 2026-02-17
75.6%
#11647: fix(webchat): filter HEARTBEAT_OK messages from chat.history response
by liuxiaopai-ai · 2026-02-08
75.3%
#21693: feat(gateway): expose session entry id on chat history messages
by tlxue · 2026-02-20
75.2%
#8360: Gateway: cap oversized transcript entries
by halbot2010 · 2026-02-03
75.1%
#20381: feat(gateway): make chat history byte limit configurable via `gatew...
by mgratch · 2026-02-18
74.5%
#14309: fix(ui): resolve chat event session key mismatch
by justonlyforyou · 2026-02-11
74.5%