Skip to content

fix(responses): bound closing handshakes for non-reused upstream WebSockets (carry #7681) - #7743

Merged
lidge-jun merged 1 commit into
devfrom
fix/carry-7681-ws-close-grace
Oct 26, 2026
Merged

lidge-jun merged 1 commit into
devfrom
fix/carry-7681-ws-close-grace

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

Carries #7681 by @luvs01 onto current dev (the original is a 23-behind author draft). When a Codex Responses WebSocket that will not be reused is disposed, the proxy now asks for a graceful close and, if the peer never answers the closing handshake, terminates that native socket after one second. Before this, Bun 1.4.4 could leave a private upstream socket waiting indefinitely on an unresponsive peer.

Retained-pool disposal keeps its immediate close-and-terminate, and a successful pooled release stays reusable. The close timer and listener are cleaned up on early close, timeout and exceptions; a socket without native terminate() only receives a close attempt. The owning wire contract in structure/transports/responses-wire-shapes.md describes the behavior, and tests/responses/codex-ws-handshake-validation.test.ts adds native loopback stalled-peer, receipt, cancellation and ownership regressions.

The source change is byte-identical to #7681's dev-relative diff (3 files); only the base moved.

Verification

Run on Windows with pinned Bun 1.4.4 on this exact tree (944fdbb31e, parent origin/dev c2f3d8b42be):

  • bun test over all 19 tests/responses/*ws* files: 575 pass, 1 existing conditional skip, 0 fail.
  • bun x tsc --noEmit: exit 0.
  • bun run structure:check: passed. tests/ci-workflows/file-size-ratchet.test.ts: 9 pass.

Full local suite NOT RUN (shared-host resource exception; hosted Ubuntu shards and a lane=all dispatch on this head cover the rest). #7681's description records an older broad test:changed run on Bun 1.4.3 with failures that were never classified; the hosted shards on this head are the current evidence for that.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Supersedes #7681.

Co-authored-by: luvs01 27862058+luvs01@users.noreply.github.com

Summary by CodeRabbit

  • Bug Fixes
    • Improved WebSocket session cleanup: connections are given time to close gracefully, then force-closed if they remain open. Cleanup also handles close errors and peers that do not respond, reducing lingering connections.

…ockets

Carry of #7681 onto current dev. A private (non-retained) Codex WebSocket
now gets a one-second graceful close window, after which the native socket
is terminated; retained-pool disposal stays immediate and successful pooled
release stays reusable.

Co-authored-by: luvs01 <27862058+luvs01@users.noreply.github.com>
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner October 26, 2026 05:35
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 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 ✅ Completed 2026-10-26T05:36:21.260331Z 944fdbb 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.

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between c2f3d8b and 944fdbb.

Files selected for processing: 3
  • src/server/responses/codex-ws-session.ts
  • structure/transports/responses-wire-shapes.md
  • tests/responses/codex-ws-handshake-validation.test.ts

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

Walkthrough

Codex WebSocket session disposal now uses a shared teardown helper. Private sockets receive a one-second grace period before forced termination; retained sockets close and terminate immediately on disposal. Tests cover stalled peers, timer cleanup, and socket behavior when optional methods are unavailable.

Changes: Codex WebSocket teardown

Layer / File(s) Summary
Socket teardown behavior
src/server/responses/codex-ws-session.ts, structure/transports/responses-wire-shapes.md
dispose delegates socket cleanup to closeSessionSocket. Private sockets use a one-second grace period before termination; retained sockets close and terminate immediately on disposal. The documentation describes socket reuse conditions and disposal behavior.
Teardown validation
tests/responses/codex-ws-handshake-validation.test.ts
Tests cover timer scheduling and cleanup, socket and owner errors, retained-session reuse, and a real peer that withholds its close reply.

Priority: Low

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix

Possibly related PRs

  • lidge-jun/opencodex#7635: Applies a similar graceful-close timeout and forced termination pattern to live-sideband teardown.

Suggested labels: bug

Suggested reviewers: luvs01

Merge Risk: Minimal · up to 944fd

Private sockets receive the intended close window, and retained sockets dispose immediately. No actionable merge-blocking risk was established.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the main change: adding a bounded graceful-close window for non-reused upstream Codex WebSockets. The carry reference is additional context and does not reduce clarity.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 …
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 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 unsupported.)

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • 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.

@github-actions github-actions Bot added the bug Something isn't working label Oct 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@lidge-jun

Copy link
Copy Markdown
Owner Author

Maintainer integration decision for v2.93.0 (lane L-D1): merging into dev by squash.

  • Exact head 944fdbb31e394c666d45f205764bab7ddbf8c686. PR CI 40275016630 passed: ci, all four test shards, gates and docker smoke. Cross-platform lane=all 40275071825 on the same head also passed, including the Windows and macOS shards.
  • Independent review (round 1): PASS with zero blocking findings for this change. It also flagged a separate, pre-existing ownership gap in sideband join cancellation that this PR does not introduce; that is tracked outside this PR.
  • Merged with current dev 415078c34 locally on Bun 1.4.4: tsc --noEmit exit 0, and 98 WebSocket handshake, reuse, contention, liveness, layout and ratchet tests passed with 0 failures.
  • scripts/ci/assert-mergeable-review.sh --maintainer-integration 7743 returned OK for this head.

This carries #7681 by @luvs01; the squash keeps the Co-authored-by trailer.

@lidge-jun
lidge-jun merged commit 852bf9d into dev Oct 26, 2026
65 of 69 checks passed
@lidge-jun
lidge-jun deleted the fix/carry-7681-ws-close-grace branch October 26, 2026 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant