Skip to content

refactor: share existing WebSocket send and open handling - #2947

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

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

Conversation

@markstuart-oai

@markstuart-oai markstuart-oai commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Why

Responses and Live repeat the same socket-open checks, sends, and queue flushing. Sharing these operations reduces duplication while preserving each API's current behavior.

High-level description

Extract four internal functions and use them from stable/beta Responses and Live's main, fork, and sideband connections. Reuse the existing queue and transport types.

Keep credential refresh, reconnect timing, event parsing, errors, and public/protected interfaces unchanged. Preserve the different failed-send policies: Responses retains the queued item; Live removes an attempted item. Compatibility tests also cover socket replacement and reconnects triggered while reading the socket.

Generator ownership, further lifecycle consolidation, and intentional behavior changes remain separate follow-ups. Realtime and Translation are unchanged.

Validation

Public head: 62553b2d647c0ead0ed629e929bb4ecdc44f6782, based on 4ca7bd61c05effec8d2ace880a000047da37f1f3. Its complete source tree matches the locally tested commit.

  • 11,798 unit tests passed; one existing test skipped.
  • 1,509 focused WebSocket tests passed; one existing test skipped. New compatibility cases also passed against the original implementation.
  • Full lint, TypeScript checking, and CJS/ESM build passed.
  • Compared all 872 existing declaration files: public/protected interfaces are unchanged.
  • Packed-package checks passed, including browser bundling, TypeScript consumers, optional dependencies, and source maps.
  • Installed tarball passed 20 loopback cases across CJS/ESM on Node 22.0.0 and 24.21.0.

Hosted CI passed on this head. Local results above also cover package and compatibility checks; generated HTTP-resource tests were not rerun locally.

Castiron-Internal-PR: openai/openai-node-internal#306
Castiron-Source-SHA: 68a9ec540ee28500d40b6258020e04da6c6010ff
Castiron-Public-Base-SHA: 4ca7bd6
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Castiron custom code

Evaluated main: 4ca7bd61c05effec8d2ace880a000047da37f1f3.

✅ No new custom-code files detected.

51 mixed files remain; 5 existing customizations changed.

Compared 4ca7bd61c05e → 62553b2d647c. Generated baselines verified.

File Result Current custom patch
src/resources/beta/responses/ws-base.ts Existing customization changed +92 / −88
src/resources/live/forks/ws-base.ts Existing customization changed +24 / −77
src/resources/live/sideband/ws-base.ts Existing customization changed +24 / −77
src/resources/live/ws-base.ts Existing customization changed +24 / −77
src/resources/responses/ws-base.ts Existing customization changed +97 / −91
46 existing customizations unchanged
  • api.md
  • scripts/castiron/CUSTOM_CODE.md
  • scripts/castiron/custom_code_budget.py
  • scripts/castiron/custom_code_report.py
  • scripts/castiron/test_custom_code_budget.py
  • src/client.ts
  • src/resources/admin/organization/usage.ts
  • src/resources/audio/transcriptions.ts
  • src/resources/audio/translations.ts
  • src/resources/beta/agents/agents.ts
  • src/resources/beta/agents/environments/environments.ts
  • src/resources/beta/agents/environments/files.ts
  • src/resources/beta/agents/sessions/artifacts.ts
  • src/resources/beta/agents/sessions/sessions.ts
  • src/resources/beta/assistants.ts
  • src/resources/beta/beta.ts
  • src/resources/beta/index.ts
  • src/resources/beta/responses/internal-base.ts
  • src/resources/beta/responses/responses.ts
  • src/resources/beta/responses/ws.ts
  • src/resources/beta/threads/index.ts
  • src/resources/beta/threads/runs/index.ts
  • src/resources/beta/threads/runs/runs.ts
  • src/resources/beta/threads/threads.ts
  • src/resources/chat/completions/completions.ts
  • src/resources/chat/completions/index.ts
  • src/resources/conversations/index.ts
  • src/resources/embeddings.ts
  • src/resources/files.ts
  • src/resources/fine-tuning/checkpoints/permissions.ts
  • src/resources/images.ts
  • src/resources/live/forks/ws.ts
  • src/resources/live/sideband/ws.ts
  • src/resources/live/ws.ts
  • src/resources/responses/internal-base.ts
  • src/resources/responses/responses.ts
  • src/resources/responses/ws.ts
  • src/resources/skills/skills.ts
  • src/resources/skills/versions/versions.ts
  • src/resources/vector-stores/file-batches.ts

6 more in the full report.

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 38682391927 --repo openai/openai-node \
  --name castiron-custom-code-38682391927-1 --dir /tmp/castiron-custom-code-38682391927-1
git apply --stat /tmp/castiron-custom-code-38682391927-1/custom-code.patch
cat /tmp/castiron-custom-code-38682391927-1/custom-code.patch

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

git fetch --no-tags origin 4ca7bd61c05effec8d2ace880a000047da37f1f3 62553b2d647c0ead0ed629e929bb4ecdc44f6782
python3 scripts/castiron/custom_code_report.py report \
  --base 4ca7bd61c05effec8d2ace880a000047da37f1f3 \
  --head 62553b2d647c0ead0ed629e929bb4ecdc44f6782 --fetch --require-head-hash --public \
  --out /tmp/castiron-custom-code-62553b2d647c
cat /tmp/castiron-custom-code-62553b2d647c/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 marked this pull request as ready for review October 15, 2026 04:36
@markstuart-oai
markstuart-oai requested a review from a team as a code owner October 15, 2026 04:36
@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-15T04:38:08.712266Z 62553b2 Draft marked ready
🔒 Security Review ✅ Completed 2026-10-15T04:38:45.796060Z 62553b2 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 8.032s for Node SDK PR #2947.

Test results — 42 files
Test Result Time
tests/chat-completions-complex-body.test.ts ✅ Passed 159ms
tests/chat-completions-create.test.ts ✅ Passed 217ms
tests/chat-completions-stream.test.ts ✅ Passed 119ms
tests/files-content-binary.test.ts ✅ Passed 338ms
tests/files-create-multipart.test.ts ✅ Passed 169ms
tests/files-list-pagination.test.ts ✅ Passed 123ms
tests/initialize-config.test.ts ✅ Passed 393ms
tests/instance-isolation.test.ts ✅ Passed 263ms
tests/models-list.test.ts ✅ Passed 137ms
tests/responses-background-lifecycle.test.ts ✅ Passed 246ms
tests/responses-body-method-errors.test.ts ✅ Passed 213ms
tests/responses-cancel-timeout.test.ts ✅ Passed 231ms
tests/responses-cancel.test.ts ✅ Passed 149ms
tests/responses-compact-retries.test.ts ✅ Passed 239ms
tests/responses-compact.test.ts ✅ Passed 234ms
tests/responses-create-advanced-stream.test.ts ✅ Passed 310ms
tests/responses-create-advanced.test.ts ✅ Passed 127ms
tests/responses-create-disconnect.test.ts ✅ Passed 951ms
tests/responses-create-errors.test.ts ✅ Passed 116ms
tests/responses-create-malformed-api-responses.test.ts ✅ Passed 92ms
tests/responses-create-retries.test.ts ✅ Passed 207ms
tests/responses-create-stream-failures.test.ts ✅ Passed 98ms
tests/responses-create-stream-timeout.test.ts ✅ Passed 2.143s
tests/responses-create-stream-wire.test.ts ✅ Passed 1.17s
tests/responses-create-stream.test.ts ✅ Passed 100ms
tests/responses-create-terminal-states.test.ts ✅ Passed 187ms
tests/responses-create-timeout.test.ts ✅ Passed 193ms
tests/responses-create.test.ts ✅ Passed 233ms
tests/responses-delete.test.ts ✅ Passed 246ms
tests/responses-input-items-errors.test.ts ✅ Passed 128ms
tests/responses-input-items-list.test.ts ✅ Passed 132ms
tests/responses-input-items-options.test.ts ✅ Passed 130ms
tests/responses-input-tokens-count-timeout.test.ts ✅ Passed 217ms
tests/responses-input-tokens-count.test.ts ✅ Passed 230ms
tests/responses-malformed-inputs.test.ts ✅ Passed 692ms
tests/responses-not-found-errors.test.ts ✅ Passed 165ms
tests/responses-parse.test.ts ✅ Passed 132ms
tests/responses-retrieve-retries.test.ts ✅ Passed 231ms
tests/responses-retrieve.test.ts ✅ Passed 188ms
tests/responses-stored-method-errors.test.ts ✅ Passed 296ms
tests/retry-behavior.test.ts ✅ Passed 3.069s
tests/sdk-error-shape.test.ts ✅ Passed 354ms

View OkTest run #38682355289

SDK merge (34bb210e0f2e) · head (62553b2d647c) · base (4ca7bd61c05e) · OkTest (63b471b22245)

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all seven changed files at 62553b2d647c0ead0ed629e929bb4ecdc44f6782. No blocking findings.

The extraction preserves dynamic reads of the public socket, lazy reconnect-state checks, JSON/raw queue admission and error propagation, and the existing listener cleanup when waiting for open. The different failed-send policies are retained: Responses requeues the attempted item, while Live/forks/sideband discard that attempted item and retain never-attempted messages. The new compatibility tests cover reconnect-on-socket-read, socket replacement, and failed-write retention across all five variants. Public/protected signatures, authentication, reconnect policy, and package/runtime requirements are unchanged in this patch.

Validation: static source and surrounding-code review, plus git diff --check. I did not execute project code or run tests/builds locally. Exact-head hosted CI is green, including Node 22/24/26 tests, lint, builds, ecosystem tests, breaking-change detection, CodeQL, baseline consistency, and both trusted Castiron statuses.

@markstuart-oai
markstuart-oai added this pull request to the merge queue Oct 15, 2026
Merged via the queue into main with commit 5f218bf Oct 15, 2026
94 of 96 checks passed
@markstuart-oai
markstuart-oai deleted the castiron/promotions/pr-306 branch October 15, 2026 04:59
@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