Skip to content

fix(proxy): align Codex WebSocket session header aliases - #1522

Closed
ROOOO wants to merge 3 commits into
ding113:devfrom
ROOOO:codex/ws-session-header-aliases
Closed

ROOOO wants to merge 3 commits into
ding113:devfrom
ROOOO:codex/ws-session-header-aliases

Conversation

@ROOOO

@ROOOO ROOOO commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Normal turns and raw compaction requests in the same trusted Codex WebSocket session can produce different outbound session headers. Complete a missing session_id or x-session-id alias from a valid companion; when both are absent, derive both from an existing valid prompt_cache_key. Preserve explicit values, including empty or invalid headers, and leave the request body unchanged without generating session identifiers.

Depends on #1516 and #1517. Merge order: #1516 -> #1517 -> this PR. All three target dev, so this branch includes its prerequisites until they merge.

Validation: This branch and its merge with upstream v0.9.8 both passed production build, Biome check and autofix, TypeScript checking, and the full Vitest suite (9,566 and 9,588 tests passed respectively; 13 skipped in each). The 72 session-header and continuation regression tests passed; added header-completion statements and branch arms have 100% coverage.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable issues were found.

Summary

Aligns Codex WebSocket session headers across normal turns and raw compaction requests.

  • Codex WebSocket requests send matching session headers when an alias is missing.
  • Local Responses continuations stay on the upstream WebSocket that created them.
  • The custom server routes Responses WebSocket upgrades separately from other paths.

No actionable issues were found. This review used code and test inspection; it did not independently run the reported checks.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Trusted Codex WebSocket turn] --> B[Complete missing session header aliases]
  B --> C{Local continuation?}
  C -->|Yes| D[Check bound provider and endpoint]
  D --> E[Check retained socket and matching headers]
  C -->|No| F[Choose upstream transport]
  E --> G[Forward response]
  F --> G
  G --> H[Wait for terminal delivery and HTTP completion]
  H --> I{Required local binding still available?}
  I -->|Yes| J[Accept next turn]
  I -->|No| K[Close client connection]
Loading

Reviews (1) · Last reviewed commit: "fix(proxy): align Codex WebSocket sessio..." · Reviewed by Greptile

ROOOO added 3 commits October 18, 2026 10:23
Symptoms:
Responses WebSocket connections can close immediately after a successful
101 handshake, causing clients to report "Connection reset without closing
handshake" and repeatedly reconnect. Different worker initialization orders
can produce alternating successful and failed connections.

Cause:
CCH and Next.js can both handle the same WebSocket upgrade event. After CCH
completes the handshake, the Next.js listener can close the accepted socket.

Solution:
Route /v1/responses upgrades exclusively to CCH before invoking ordinary
upgrade listeners. Preserve listener dispatch for other paths, the current
worker's private HTTP loopback target, payload limits, and cleanup behavior.
Symptoms:
Responses WebSocket continuations can fail with previous_response_not_found
while the client connection remains open. Remote Compaction v2 can also
be recorded as successful after a structured WebSocket error.

Cause:
Logical session affinity does not guarantee reuse of the same physical
upstream WebSocket. Connection, routing, or credential changes can lose
connection-local history while requests still carry previous_response_id.
Structured WebSocket failures can also bypass final error accounting.

Solution:
Bind protected continuations to the live upstream connection, provider,
endpoint, generation, and complete request-header fingerprint.
Recheck access and limits, preserve prior storage semantics, and reject
invalid bindings with a canonical 400 error requiring full-context replay.
Prevent alternate routing, retries, HTTP fallback, hedging, Replay, and
fake streaming for protected continuations. Confirm terminal delivery
before closing, discard queued continuations, and preserve attempt-local
error accounting with idempotent resource cleanup.
Complete missing outbound session header aliases for trusted Codex WebSocket
requests and derive both absent aliases from a valid prompt_cache_key.
Preserve explicit header values, request bodies, and complete connection
fingerprint checks without generating identifiers or using routing session IDs.
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

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: 6eb04984-ceee-4453-9866-09404350295b
Commits

Reviewing files that changed from the base of the PR and between 0c508ea and 17c4285.

Files selected for processing: 36
  • messages/en/errors.json
  • messages/ja/errors.json
  • messages/ru/errors.json
  • messages/zh-CN/errors.json
  • messages/zh-TW/errors.json
  • server.js
  • src/app/v1/_lib/proxy/error-handler.ts
  • src/app/v1/_lib/proxy/errors.ts
  • src/app/v1/_lib/proxy/fake-streaming/proxy-integration.ts
  • src/app/v1/_lib/proxy/forwarder.ts
  • src/app/v1/_lib/proxy/provider-selector.ts
  • src/app/v1/_lib/proxy/replay/replay-identity.ts
  • src/app/v1/_lib/proxy/response-handler.ts
  • src/app/v1/_lib/proxy/stream-finalization.ts
  • src/app/v1/_lib/responses-ws/__tests__/continuation.test.ts
  • src/app/v1/_lib/responses-ws/__tests__/server-helpers.test.ts
  • src/app/v1/_lib/responses-ws/__tests__/upstream-adapter.test.ts
  • src/app/v1/_lib/responses-ws/continuation.ts
  • src/app/v1/_lib/responses-ws/internal-secret.ts
  • src/app/v1/_lib/responses-ws/upstream-adapter.ts
  • src/lib/utils/error-messages.ts
  • tests/unit/proxy/error-handler-durable-persistence.test.ts
  • tests/unit/proxy/fake-streaming-ws-continuation.test.ts
  • tests/unit/proxy/memory-aware-disk-timeout.test.ts
  • tests/unit/proxy/provider-selector-affinity-ignore-session.test.ts
  • tests/unit/proxy/provider-selector-select-provider-by-type.test.ts
  • tests/unit/proxy/proxy-forwarder-raw-passthrough-regression.test.ts
  • tests/unit/proxy/proxy-forwarder-retry-limit.test.ts
  • tests/unit/proxy/proxy-forwarder.test.ts
  • tests/unit/proxy/replay-identity.test.ts
  • tests/unit/proxy/response-handler-endpoint-circuit-isolation.test.ts
  • tests/unit/proxy/response-handler-stream-terminal.test.ts
  • tests/unit/proxy/responses-ws-session-header-continuation.test.ts
  • tests/unit/server-ws-close-handshake.test.ts
  • tests/unit/server-ws-continuation.test.ts
  • tests/unit/server-ws-upgrade-routing.test.ts

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

Walkthrough

此变更为 Responses WebSocket 增加连接本地 continuation 绑定与校验,限制续传使用原供应商和上游连接,并处理前序响应不可用错误。服务端升级路由、代理转发、错误结算和相关测试也随之更新。

Changes: Responses WebSocket continuation

Layer / File(s) Summary
Continuation 绑定与上游 WebSocket 处理
src/app/v1/_lib/responses-ws/continuation.ts, src/app/v1/_lib/responses-ws/internal-secret.ts, src/app/v1/_lib/responses-ws/upstream-adapter.ts, src/app/v1/_lib/responses-ws/__tests__/*, tests/unit/proxy/responses-ws-session-header-continuation.test.ts
新增可信请求识别、会话绑定和响应 outcome 状态。上游适配器校验 continuation 绑定,并在连接有效时复用该 WebSocket。
WebSocket 服务端续传与升级路由
server.js, src/app/v1/_lib/responses-ws/__tests__/server-helpers.test.ts, tests/unit/server-ws-*
服务端依据响应终态和实时绑定设置 prior-local 标记。升级路由将 /v1/responses 交给 WebSocket handler,并委派其他路径。
供应商固定与代理转发约束
src/app/v1/_lib/proxy/provider-selector.ts, src/app/v1/_lib/proxy/forwarder.ts, src/app/v1/_lib/proxy/fake-streaming/*, src/app/v1/_lib/proxy/replay/replay-identity.ts, tests/unit/proxy/*
Continuation 固定到绑定供应商和端点,并跳过重试、切换及 HTTP 回退。代理过滤内部标记、保留 outcome,并为 Codex WebSocket 请求补齐会话标识。测试覆盖绑定、转发限制及会话标识处理。
Continuation 错误与响应结算
messages/*/errors.json, src/lib/utils/error-messages.ts, src/app/v1/_lib/proxy/errors.ts, src/app/v1/_lib/proxy/error-handler.ts, src/app/v1/_lib/proxy/response-handler.ts, src/app/v1/_lib/proxy/stream-finalization.ts, tests/unit/proxy/error-handler-durable-persistence.test.ts, tests/unit/proxy/response-handler-*
新增规范的不可重试客户端错误响应。延迟流结算记录 continuation 错误状态,并避免将其归类为流故障或熔断失败。新增多语言错误消息及相应测试。

Priority: Normal

Estimated code review effort: 4 (Complex) | ~60 minutes

Suggested reviewers: ding113, tesgth032

Merge Risk: Minimal · up to 17c42

This change pins Responses WebSocket continuations to their original provider and upstream connection, and fills in missing session header aliases for trusted Codex WebSocket requests. No concrete merge-blocking defect was identified. Merge it in the stated order after #1516 and #1517.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surv… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed 标题准确概括了本次变更的主要目标:对齐 Codex WebSocket 会话标头别名。
Description check Passed 描述与变更内容直接相关,说明了会话标头补全规则、保留显式值、请求体不变及验证结果。
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 39 functions across 31 files. (5 skipped: 5 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
🧪 Generate unit tests (beta)
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • 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

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-27T14:30:02.104342Z
We couldn’t complete this review. Comment @codex review to try again.
17c4285 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added bug Something isn't working area:core area:session labels Oct 27, 2026
@github-actions github-actions Bot added the size/XL Extra Large PR (> 1000 lines) label Oct 27, 2026
@ROOOO ROOOO closed this Oct 27, 2026
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Claude Code Hub Roadmap Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core area:session bug Something isn't working size/XL Extra Large PR (> 1000 lines)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant