Skip to content

refactor: share WebSocket connection handling - #4084

Merged
markstuart-oai merged 1 commit into
mainfrom
castiron/promotions/pr-256
Oct 15, 2026
Merged

markstuart-oai merged 1 commit into
mainfrom
castiron/promotions/pr-256

Conversation

@markstuart-oai

Copy link
Copy Markdown
Contributor

Why

Responses, Realtime, and Live repeat the same WebSocket connection logic. Sharing that code makes fixes apply consistently while preserving each API's current behavior.

High-level description

Move existing send-queue flushing, reconnect, raw-send, and close logic into shared synchronous and asynchronous base classes. Keep public classes, method signatures, connection setup, event types, and API helpers unchanged. Preserve synchronous Responses' ability to interrupt a reconnect when closing.

Add a regression test for close during reconnect across six connection types. This change adds no automatic replay of commands whose delivery is uncertain.

Validation

  • All ten SDK CI jobs passed on the identical source patch, including Python 3.10 and 3.14, HTTPX2, lint, build, and type checks.
  • All 27 reconnect and queue tests passed on the current baseline. The production code also passed 255 focused recovery, queue, Live, and logging tests.
  • The six-connection close-during-reconnect probe passed before and after the refactor.
  • A separately installed wheel passed send and close checks across all six synchronous and asynchronous connection types.

Castiron-Internal-PR: openai/openai-python-internal#256
Castiron-Source-SHA: 46ea721b3232d5eec49eb7f22ec07a08e1e657b7
Castiron-Public-Base-SHA: 95dbee9
@markstuart-oai
markstuart-oai marked this pull request as ready for review October 15, 2026 03:38
@markstuart-oai
markstuart-oai requested a review from a team as a code owner October 15, 2026 03:38
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 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-15T03:41:45.315283Z 25e5587 Draft marked ready
🔒 Security Review ✅ Completed 2026-10-15T03:43:04.547437Z 25e5587 Draft marked ready
ℹ️ 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.

@openai-sdks

openai-sdks Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

OkTest Summary

✅ 236/236 SDK tests passed in 6.226s for Python SDK PR #4084.

Test results — 42 files
Test Result Time
tests/chat-completions-complex-body.test.ts ✅ Passed 117ms
tests/chat-completions-create.test.ts ✅ Passed 129ms
tests/chat-completions-stream.test.ts ✅ Passed 167ms
tests/files-content-binary.test.ts ✅ Passed 116ms
tests/files-create-multipart.test.ts ✅ Passed 71ms
tests/files-list-pagination.test.ts ✅ Passed 85ms
tests/initialize-config.test.ts ✅ Passed 92ms
tests/instance-isolation.test.ts ✅ Passed 122ms
tests/models-list.test.ts ✅ Passed 76ms
tests/responses-background-lifecycle.test.ts ✅ Passed 106ms
tests/responses-body-method-errors.test.ts ✅ Passed 169ms
tests/responses-cancel-timeout.test.ts ✅ Passed 196ms
tests/responses-cancel.test.ts ✅ Passed 155ms
tests/responses-compact-retries.test.ts ✅ Passed 238ms
tests/responses-compact.test.ts ✅ Passed 120ms
tests/responses-create-advanced-stream.test.ts ✅ Passed 190ms
tests/responses-create-advanced.test.ts ✅ Passed 146ms
tests/responses-create-disconnect.test.ts ✅ Passed 1.181s
tests/responses-create-errors.test.ts ✅ Passed 141ms
tests/responses-create-malformed-api-responses.test.ts ✅ Passed 95ms
tests/responses-create-retries.test.ts ✅ Passed 140ms
tests/responses-create-stream-failures.test.ts ✅ Passed 70ms
tests/responses-create-stream-timeout.test.ts ✅ Passed 187ms
tests/responses-create-stream-wire.test.ts ✅ Passed 1.284s
tests/responses-create-stream.test.ts ✅ Passed 76ms
tests/responses-create-terminal-states.test.ts ✅ Passed 186ms
tests/responses-create-timeout.test.ts ✅ Passed 187ms
tests/responses-create.test.ts ✅ Passed 351ms
tests/responses-delete.test.ts ✅ Passed 128ms
tests/responses-input-items-errors.test.ts ✅ Passed 227ms
tests/responses-input-items-list.test.ts ✅ Passed 181ms
tests/responses-input-items-options.test.ts ✅ Passed 142ms
tests/responses-input-tokens-count-timeout.test.ts ✅ Passed 184ms
tests/responses-input-tokens-count.test.ts ✅ Passed 150ms
tests/responses-malformed-inputs.test.ts ✅ Passed 630ms
tests/responses-not-found-errors.test.ts ✅ Passed 199ms
tests/responses-parse.test.ts ✅ Passed 136ms
tests/responses-retrieve-retries.test.ts ✅ Passed 128ms
tests/responses-retrieve.test.ts ✅ Passed 130ms
tests/responses-stored-method-errors.test.ts ✅ Passed 307ms
tests/retry-behavior.test.ts ✅ Passed 3.078s
tests/sdk-error-shape.test.ts ✅ Passed 141ms

View OkTest run #38677357189

SDK merge (1b080b238226) · head (25e558745740) · base (95dbee9ee406) · OkTest (63b471b22245)

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Castiron custom code

Evaluated main: 95dbee9ee406587053a0a21296eb82418073f2aa.

✅ No new custom-code files detected.

40 mixed files remain; 6 existing customizations changed.

Compared 95dbee9ee406 → 25e558745740. Generated baselines verified.

File Result Current custom patch
src/openai/resources/beta/responses/responses.py Existing customization changed +140 / −310
src/openai/resources/live/forks.py Existing customization changed +84 / −265
src/openai/resources/live/live.py Existing customization changed +80 / −253
src/openai/resources/live/sideband.py Existing customization changed +82 / −249
src/openai/resources/realtime/realtime.py Existing customization changed +150 / −271
src/openai/resources/responses/responses.py Existing customization changed +1009 / −332
34 existing customizations unchanged
  • api.md
  • scripts/castiron/custom_code_budget.py
  • scripts/castiron/test_custom_code_github.py
  • scripts/castiron/test_custom_code_publication.py
  • scripts/castiron/test_custom_code_report.py
  • src/openai/init.py
  • src/openai/_client.py
  • src/openai/resources/audio/transcriptions.py
  • src/openai/resources/audio/translations.py
  • src/openai/resources/beta/agents/environments/files.py
  • src/openai/resources/beta/agents/sessions/artifacts.py
  • src/openai/resources/beta/agents/sessions/sessions.py
  • src/openai/resources/beta/beta.py
  • src/openai/resources/beta/threads/runs/runs.py
  • src/openai/resources/beta/threads/threads.py
  • src/openai/resources/chat/completions/completions.py
  • src/openai/resources/embeddings.py
  • src/openai/resources/files.py
  • src/openai/resources/realtime/api.md
  • src/openai/resources/uploads/uploads.py
  • src/openai/resources/vector_stores/file_batches.py
  • src/openai/resources/vector_stores/files.py
  • src/openai/resources/videos.py
  • src/openai/resources/webhooks/init.py
  • src/openai/resources/webhooks/webhooks.py
  • src/openai/types/fine_tuning/fine_tuning_job_integration.py
  • src/openai/types/realtime/conversation_item_input_audio_transcription_delta_event.py
  • src/openai/types/realtime/realtime_error_event.py
  • src/openai/types/responses/tool.py
  • src/openai/types/responses/tool_param.py
  • src/openai/types/webhooks/init.py
  • src/openai/types/webhooks/live_call_incoming_webhook_event.py
  • src/openai/types/webhooks/unwrap_webhook_event.py
  • tests/api_resources/test_videos.py

A changed generated baseline means this report cannot reliably identify which handwritten lines changed.

Inspect the custom-code diff

Download the exact patch produced by this run (requires repository access):

gh run download 38677388174 --repo openai/openai-python \
  --name castiron-custom-code-38677388174-1 --dir /tmp/castiron-custom-code-38677388174-1
git apply --stat /tmp/castiron-custom-code-38677388174-1/custom-code.patch
cat /tmp/castiron-custom-code-38677388174-1/custom-code.patch

Or reproduce it from an SDK checkout containing the vendored reporter:

git fetch --no-tags origin 95dbee9ee406587053a0a21296eb82418073f2aa 25e5587457406a27e6fb2eb349f64566cc19294d
python3 scripts/castiron/custom_code_report.py report \
  --base 95dbee9ee406587053a0a21296eb82418073f2aa \
  --head 25e5587457406a27e6fb2eb349f64566cc19294d --fetch --require-head-hash --public \
  --out /tmp/castiron-custom-code-25e558745740
cat /tmp/castiron-custom-code-25e558745740/custom-code.patch

This is the current full custom patch for mixed files, not an attribution of only the handwritten lines changed by this PR.

Full report and patch

@markstuart-oai
markstuart-oai added this pull request to the merge queue Oct 15, 2026
Merged via the queue into main with commit 70d4738 Oct 15, 2026
33 checks passed
@markstuart-oai
markstuart-oai deleted the castiron/promotions/pr-256 branch October 15, 2026 04:00
@openai-sdks openai-sdks Bot mentioned this pull request Oct 15, 2026
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.

2 participants