#13679: feat(gateway): make WebSocket maxPayload configurable
gateway
stale
## Summary
Makes the WebSocket `maxPayload` configurable via the `gateway.wsMaxPayload` config option, fixing Error 1009 when webchat users upload images.
## Changes
- **Config schema**: Added `gateway.wsMaxPayload` field (optional, integer, minimum: 1)
- **Type definition**: Added `wsMaxPayload?: number` to `GatewayConfig` type
- **Server constants**:
- Replaced hardcoded `MAX_PAYLOAD_BYTES = 512 * 1024` with configurable getter/setter pattern
- New default: 10MB (was 512KB)
- Exported `getMaxPayloadBytes()` and `setMaxPayloadBytes(value?: number)`
- **Runtime initialization**: Applied config value during gateway startup in `server.impl.ts`
- **WebSocket servers**: Updated both main and extension relay WS server creation to use `getMaxPayloadBytes()`
## Why
The hardcoded 512KB limit caused Error 1009 when webchat users uploaded images, as base64-encoded images easily exceed this size.
## Default behavior
- Default is now 10MB (20x increase from 512KB)
- Users can override via config: `gateway.wsMaxPayload: <bytes>`
- Validates positive integers only
Fixes #10243
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR makes the WebSocket `maxPayload` configurable to fix Error 1009 when webchat users upload images. Previously hardcoded at 512KB, the limit is now configurable via `gateway.wsMaxPayload` with a new default of 10MB.
**Key changes:**
- Added `gateway.wsMaxPayload` config field with validation (positive integer)
- Replaced hardcoded `MAX_PAYLOAD_BYTES` constant with getter/setter pattern
- Applied config value during gateway startup in `server.impl.ts:226`
- Updated both main gateway and message handler WebSocket servers to use `getMaxPayloadBytes()`
- Increased default from 512KB to 10MB (20x increase)
**Implementation is sound:**
- Config changes to `gateway.*` trigger gateway restart (verified in `config-reload.ts:83`), ensuring the new value is picked up
- Validation ensures only positive integers are accepted
- Setter safely handles undefined values by keeping the default
- All main WebSocket server instances updated to use the new getter
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The implementation is straightforward and follows established patterns in the codebase. All WebSocket servers that handle user content are properly updated. The validation is appropriate, the default value increase is reasonable for the use case, and config hot-reload will correctly restart the gateway when this value changes. No breaking changes or security issues identified.
- No files require special attention
<!-- 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
#20381: feat(gateway): make chat history byte limit configurable via `gatew...
by mgratch · 2026-02-18
85.4%
#6805: fix: increase WebSocket MAX_PAYLOAD_BYTES to 6MB for attachments
by cortexuvula · 2026-02-02
84.8%
#20394: feat(gateway): make chat history byte limit configurable via gatewa...
by mgratch · 2026-02-18
78.3%
#23420: Gateway: tighten WS connect schema bounds and validation
by bmendonca3 · 2026-02-22
75.1%
#23714: Gateway: add websocket ingress limits for DoS hardening
by bmendonca3 · 2026-02-22
74.7%
#10441: webchat: switch file uploads to HTTP /uploads
by supernewbilityxht1 · 2026-02-06
74.3%
#16006: fix(gateway): reduce chat.history byte cap from 6 MB to 2 MB
by fagemx · 2026-02-14
73.9%
#15603: fix(gateway): correct malformed HTTP 429 response on WebSocket upgrade
by AI-Reviewer-QS · 2026-02-13
73.0%
#19255: feat(gateway): add WebSocket connection metrics monitoring
by Wike-CHI · 2026-02-17
72.2%
#16777: feat(gateway): add multimodal image support to /v1/chat/completions
by dzianisv · 2026-02-15
71.9%