Skip to content

fix(codex): limit WebSocket connection churn - #88

Merged
raine merged 1 commit into
raine:mainfrom
ItsAlbertZhang:fix/issue-87-websocket-limits
Jul 31, 2026
Merged

fix(codex): limit WebSocket connection churn#88
raine merged 1 commit into
raine:mainfrom
ItsAlbertZhang:fix/issue-87-websocket-limits

Conversation

@ItsAlbertZhang

Copy link
Copy Markdown
Contributor

Summary

  • Prune the reusable Codex WebSocket pool to 40 least-recently-active idle connections when it grows beyond 50.
  • Enforce at least one second between fresh WebSocket connection attempts.
  • Retry an origin WebSocket upgrade 403 once after a three-second cooldown.
  • Keep explicit proxy CONNECT rejections terminal and preserve existing retry and fallback behavior.

Implementation notes

  • Track pool activity independently from the creation timestamp used for TTL expiry.
  • Skip leased connections during cleanup and release socket guards before returning reusable connections to the pool.
  • Keep origin-versus-proxy connection provenance private to the WebSocket connector.
  • Apply the connection timeout separately to each network attempt.

Testing

  • cargo test --lib providers::codex::websocket::tests:: — 37 passed
  • cargo test --test codex_websocket_proxy — 1 passed
  • cargo test --test codex_websocket — 9 passed
  • cargo test --test smoke_cutover smoke_codex_websocket_stream_returns_delta_before_terminal -- --exact — passed
  • cargo clippy --all-targets --all-features — passed with pre-existing warnings

Full cargo test reaches three pre-existing cursor_native mock-upstream HTTP 502 failures unrelated to this change.

Fixes #87

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
@raine

raine commented Jul 31, 2026

Copy link
Copy Markdown
Owner

Thanks for the thorough fix!

@raine
raine merged commit 529e1d6 into raine:main Jul 31, 2026
2 checks passed
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.

403: WebSocket upgrade rejected after Codex concurrent connections exceed a certain threshold

2 participants