Skip to content

feat(relay): negotiate permessage-deflate for Responses WebSocket - #8487

Open
Ca11back wants to merge 1 commit into
QuantumNous:mainfrom
Ca11back:feat/responses-websocket-compression
Open

Ca11back wants to merge 1 commit into
QuantumNous:mainfrom
Ca11back:feat/responses-websocket-compression

Conversation

@Ca11back

@Ca11back Ca11back commented Nov 28, 2026 •

Copy link
Copy Markdown

Agent: Codex Desktop unknown · unknown · Linux x86_64 · 2026-11-28 UTC · AI-assisted

Closes #8486

Request summary

让 Responses WebSocket 在入口和回源独立协商消息压缩,无需新增配置项。

Summary

启用 permessage-deflate,并对解压后的消息执行现有大小限制。

  GET /v1/responses
+   入口 Upgrader 接受客户端的压缩提议
+   Responses 回源 Dialer 向上游提议压缩
+   两段读取消息时都检查解压后的大小

对端未协商压缩时,连接继续使用普通 WebSocket。

Evidence

  • Before: 在原版 rc.52 (04dfcbb71) 上运行同一个集成测试,入口未返回压缩扩展,测试上游也未收到压缩提议。
  • After: go test ./controller ./relay ./relay/channel 通过。集成测试覆盖两段压缩的四种组合、同一连接上的两轮续接,以及两段解压后超限的拒绝行为。
  • Production: 同一补丁部署在 rc.51 上。观察窗口内有 320 条 Responses WebSocket 记录,318 条完成,另外两条分别是客户端断开和上游要求 HTTP replay。应用日志未发现压缩解码或帧错误。

Merge Danger

Door: Two-way

Blast Radius: Relay

Summary by CodeRabbit

  • New Features
    • WebSocket connections used for Responses requests now support compression when both sides negotiate it, while other connection types retain their existing behavior.
  • Bug Fixes
    • Oversized WebSocket messages are now rejected with a “message too big” close response, whether they come from the client or the upstream service.
    • Compressed connections can handle sequential Responses requests and reuse the connection.

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Responses WebSocket connections now negotiate compression independently on the client and upstream sides. Client and upstream message reads use a bounded reader that closes connections when decoded messages exceed their configured limits.

Changes

Responses WebSocket compression and message limits

Layer / File(s) Summary
Compression negotiation
controller/responses_websocket.go, relay/channel/api_request.go, controller/responses_websocket_test.go
The Responses endpoint enables compression on a copy of the shared upgrader. The upstream dialer enables compression for the OpenAI Responses relay format. Tests cover both, either, or neither side negotiating compression, including sequential requests and upstream connection reuse.
Bounded decoded message reads
relay/responses_websocket.go, controller/responses_websocket_test.go
Client and upstream messages use a bounded reader. It returns websocket.ErrReadLimit and sends a message-too-big close frame when the decoded message exceeds the configured limit. Tests cover oversized messages from both directions.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant ResponsesClient
  participant ResponsesWebSocket
  participant DoWssRequest
  participant UpstreamWebSocket
  ResponsesClient->>ResponsesWebSocket: Sends upgrade with compression offer
  ResponsesWebSocket-->>ResponsesClient: Negotiates compression if accepted
  ResponsesWebSocket->>DoWssRequest: Opens upstream WebSocket
  DoWssRequest->>UpstreamWebSocket: Offers compression for Responses format
  UpstreamWebSocket-->>DoWssRequest: Negotiates compression if accepted
Loading

Suggested reviewers: kosukework, calcium-ion

Merge Risk: Minimal · up to 35c76

This change adds optional compression negotiation to the Responses WebSocket relay and enforces the message-size limit on decompressed messages. It falls back to regular WebSocket behavior when compression is not negotiated. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: the Responses WebSocket relay now negotiates permessage-deflate compression. The raw summary shows compression enabled on the upgrader copy, the upstream dialer, and t…
Linked Issues check Passed Issue #8486 requires three coding behaviors: (1) the client-facing leg of GET /v1/responses negotiates permessage-deflate, (2) the upstream leg proposes it independently, and (3) decompressed messages…
Out of Scope Changes check Passed All changed areas serve the objectives of #8486. The controller upgrader change and the DoWssRequest compression flag implement the two negotiation legs. The bounded reader in relay/responses_websocke…
Full details: Title check

Explanation

The title names the main change: the Responses WebSocket relay now negotiates permessage-deflate compression. The raw summary shows compression enabled on the upgrader copy, the upstream dialer, and the relay read path, matching the linked objectives. The title is specific and scoped to the primary change. The 65-character length is acceptable.

Full details: Linked Issues check

Explanation

Issue #8486 requires three coding behaviors: (1) the client-facing leg of GET /v1/responses negotiates permessage-deflate, (2) the upstream leg proposes it independently, and (3) decompressed messages stay under the existing size limit. The PR summary maps to each. controller/responses_websocket.go copies the shared upgrader and enables compression on the copy only, so the shared upgrader is unchanged. relay/channel/api_request.go enables compression in DoWssRequest when info.RelayFormat is types.RelayFormatOpenAIResponses. relay/responses_websocket.go adds a bounded message reader that caps decoded message bytes at the configured read limit and returns websocket.ErrReadLimit, which covers the decompressed-size requirement on both legs. Tests in controller/responses_websocket_test.go cover all four client/upstream combinations, two sequential requests on one connection, and one-byte-over-limit rejection from either side. Limits: the bounded reader body in relay/responses_websocket.go was only partly readable (output truncated at 16000 bytes), and the whole-PR diff was unavailable. The PASS rests on the PR summary plus the readable head file. The test results reported in the PR description were not independently run.

Full details: Out of Scope Changes check

Explanation

All changed areas serve the objectives of #8486. The controller upgrader change and the DoWssRequest compression flag implement the two negotiation legs. The bounded reader in relay/responses_websocket.go implements the decompressed-size requirement. The test changes in controller/responses_websocket_test.go verify these behaviors. The reported changes are limited to these four files and add no configuration option, which matches the issue's no-new-config requirement. No unrelated change was identified in the summary. The full diff could not be read, so this verdict relies on the change summary and the readable head file.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit taps the socket door,
Two links can compress their loads.
Large messages meet a measured gate,
Too-big frames receive a close.
Responses hop from client to stream,
While one upstream connection serves their flow.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 50c3ea82-f4a7-4202-9abb-218e2db4caa5
Commits

Reviewing files that changed from the base of the PR and between 04dfcbb and 35c763a.

Files selected for processing: 4

  • controller/responses_websocket.go
  • controller/responses_websocket_test.go
  • relay/channel/api_request.go
  • relay/responses_websocket.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

支持 Responses WebSocket 消息压缩

1 participant