Skip to content

fix(responses): refresh credentials on WebSocket reconnects - #2849

Closed
markstuart-oai wants to merge 3 commits into
mainfrom
castiron/promotions/pr-212
Closed

markstuart-oai wants to merge 3 commits into
mainfrom
castiron/promotions/pr-212

Conversation

@markstuart-oai

Copy link
Copy Markdown
Contributor

Responses WebSockets now refresh callable API keys on each reconnect attempt that needs one, preserving caller-supplied Authorization, Basic auth and custom credentials on initial and subsequent handshakes. Client and socket headers are captured before an asynchronous refresh.

Closing during credential refresh ends the connection promptly without replaying an in-flight create. The synchronous constructor still requires an already-resolved key or an explicit caller credential.

Validation: real upgrade and TLS reconnect tests pass on stable and beta APIs, along with packed-package consumer, build and lint checks.

@markstuart-oai
markstuart-oai requested a review from a team as a code owner September 30, 2026 21:45
@openai-sdks

openai-sdks Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

OkTest Summary

✅ 236/236 SDK tests passed in 9.414s for Node SDK PR #2849.

Test results — 42 files
Test Result Time
tests/chat-completions-complex-body.test.ts ✅ Passed 162ms
tests/chat-completions-create.test.ts ✅ Passed 145ms
tests/chat-completions-stream.test.ts ✅ Passed 112ms
tests/files-content-binary.test.ts ✅ Passed 185ms
tests/files-create-multipart.test.ts ✅ Passed 239ms
tests/files-list-pagination.test.ts ✅ Passed 142ms
tests/initialize-config.test.ts ✅ Passed 104ms
tests/instance-isolation.test.ts ✅ Passed 113ms
tests/models-list.test.ts ✅ Passed 123ms
tests/responses-background-lifecycle.test.ts ✅ Passed 127ms
tests/responses-body-method-errors.test.ts ✅ Passed 321ms
tests/responses-cancel-timeout.test.ts ✅ Passed 172ms
tests/responses-cancel.test.ts ✅ Passed 168ms
tests/responses-compact-retries.test.ts ✅ Passed 161ms
tests/responses-compact.test.ts ✅ Passed 171ms
tests/responses-create-advanced-stream.test.ts ✅ Passed 152ms
tests/responses-create-advanced.test.ts ✅ Passed 125ms
tests/responses-create-disconnect.test.ts ✅ Passed 1.115s
tests/responses-create-errors.test.ts ✅ Passed 166ms
tests/responses-create-malformed-api-responses.test.ts ✅ Passed 87ms
tests/responses-create-retries.test.ts ✅ Passed 189ms
tests/responses-create-stream-failures.test.ts ✅ Passed 110ms
tests/responses-create-stream-timeout.test.ts ✅ Passed 2.141s
tests/responses-create-stream-wire.test.ts ✅ Passed 2.26s
tests/responses-create-stream.test.ts ✅ Passed 78ms
tests/responses-create-terminal-states.test.ts ✅ Passed 209ms
tests/responses-create-timeout.test.ts ✅ Passed 170ms
tests/responses-create.test.ts ✅ Passed 185ms
tests/responses-delete.test.ts ✅ Passed 173ms
tests/responses-input-items-errors.test.ts ✅ Passed 137ms
tests/responses-input-items-list.test.ts ✅ Passed 161ms
tests/responses-input-items-options.test.ts ✅ Passed 182ms
tests/responses-input-tokens-count-timeout.test.ts ✅ Passed 195ms
tests/responses-input-tokens-count.test.ts ✅ Passed 154ms
tests/responses-malformed-inputs.test.ts ✅ Passed 1.809s
tests/responses-not-found-errors.test.ts ✅ Passed 260ms
tests/responses-parse.test.ts ✅ Passed 168ms
tests/responses-retrieve-retries.test.ts ✅ Passed 222ms
tests/responses-retrieve.test.ts ✅ Passed 221ms
tests/responses-stored-method-errors.test.ts ✅ Passed 483ms
tests/retry-behavior.test.ts ✅ Passed 3.076s
tests/sdk-error-shape.test.ts ✅ Passed 271ms

View OkTest run #36895191433

SDK merge (d9b5805d9c51) · head (5f6f94b73bee) · base (95b197b6b35c) · OkTest (e7cf6535e0ca)

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 30, 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-09-30T23:30:10.232142Z b3a0d59 New commits
🔒 Security Review ✅ Completed 2026-09-30T23:28:55.203230Z b3a0d59 New commits
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: df3c37a0ac

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/resources/responses/ws.ts Outdated

@dpiet-oai dpiet-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.

Requesting changes for the current-head credential-handling findings documented inline.

Comment thread src/client.ts
Comment thread src/internal/realtime-credentials.ts Outdated
Comment thread src/resources/responses/ws.ts Outdated
@markstuart-oai
markstuart-oai force-pushed the castiron/promotions/pr-212 branch from c5a1325 to 87028e2 Compare September 30, 2026 22:16

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 87028e26d1

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/resources/responses/ws.ts Outdated
Comment thread src/client.ts Outdated
@markstuart-oai
markstuart-oai force-pushed the castiron/promotions/pr-212 branch from 87028e2 to c1f2db7 Compare September 30, 2026 22:28

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c1f2db736e

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/resources/responses/ws.ts Outdated

@dpiet-oai dpiet-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.

Requesting changes for the current-head credential transformation regression documented inline.

Comment thread src/internal/realtime-credentials.ts Outdated
@markstuart-oai
markstuart-oai force-pushed the castiron/promotions/pr-212 branch 2 times, most recently from 0e65622 to 7cf2846 Compare September 30, 2026 22:46

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7cf2846911

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/internal/realtime-credentials.ts Outdated
Comment thread src/internal/ws-adapter-node.ts
@markstuart-oai
markstuart-oai force-pushed the castiron/promotions/pr-212 branch from 7cf2846 to c683ff5 Compare September 30, 2026 23:01

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c683ff5cbe

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/resources/responses/ws.ts Outdated
Comment thread src/client.ts
@markstuart-oai
markstuart-oai force-pushed the castiron/promotions/pr-212 branch from c683ff5 to 2d4ab82 Compare September 30, 2026 23:14

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2d4ab824aa

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/internal/ws.ts Outdated
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Castiron custom code

✅ No new custom-code files detected.

47 mixed files remain; 5 existing customizations changed.

Compared 95b197b6b35c → 5f6f94b73bee. Generated baselines verified.

File Result Current custom patch
src/client.ts Existing customization changed +950 / −109
src/resources/beta/responses/ws-base.ts Existing customization changed +111 / −21
src/resources/beta/responses/ws.ts Existing customization changed +29 / −15
src/resources/responses/ws-base.ts Existing customization changed +116 / −24
src/resources/responses/ws.ts Existing customization changed +29 / −15
42 existing customizations unchanged
  • api.md
  • scripts/castiron/README.md
  • scripts/castiron/custom_code_report.py
  • scripts/castiron/test_custom_code_report.py
  • src/resources/audio/transcriptions.ts
  • src/resources/audio/translations.ts
  • src/resources/beta/agents/agents.ts
  • src/resources/beta/agents/environments/files.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/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-base.ts
  • src/resources/live/forks/ws.ts
  • src/resources/live/sideband/ws-base.ts
  • src/resources/live/sideband/ws.ts
  • src/resources/live/ws-base.ts
  • src/resources/live/ws.ts
  • src/resources/responses/internal-base.ts
  • src/resources/responses/responses.ts
  • src/resources/skills/skills.ts
  • src/resources/skills/versions/versions.ts
  • src/resources/vector-stores/file-batches.ts
  • src/resources/vector-stores/files.ts
  • src/resources/webhooks/index.ts
  • src/resources/webhooks/webhooks.ts
  • tests/api-resources/beta/agents/environments/files.test.ts

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

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

git fetch --no-tags origin 95b197b6b35c84bb7da322c3e5eb9adf1d1f79e7 5f6f94b73bee507c55a16eeee363941834b03408
python3 scripts/castiron/custom_code_report.py report \
  --base 95b197b6b35c84bb7da322c3e5eb9adf1d1f79e7 \
  --head 5f6f94b73bee507c55a16eeee363941834b03408 --fetch --require-head-hash --public \
  --out /tmp/castiron-custom-code-5f6f94b73bee
cat /tmp/castiron-custom-code-5f6f94b73bee/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

@dpiet-oai dpiet-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.

Requesting changes for the current-head reconnect compatibility regressions documented inline.

Comment thread src/resources/responses/ws.ts Outdated
Comment thread src/resources/responses/ws.ts Outdated
@markstuart-oai
markstuart-oai force-pushed the castiron/promotions/pr-212 branch from b3a0d59 to f9106a5 Compare October 1, 2026 16:18

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f9106a51b4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/internal/ws.ts Outdated
@markstuart-oai
markstuart-oai force-pushed the castiron/promotions/pr-212 branch from f9106a5 to d77e798 Compare October 1, 2026 16:24
Castiron-Internal-PR: openai/openai-node-internal#212
Castiron-Source-SHA: 55ae639a6df5ca90c61cea0285d9468fc0ff5a54
Castiron-Public-Base-SHA: 95b197b
@markstuart-oai
markstuart-oai force-pushed the castiron/promotions/pr-212 branch from d77e798 to 2ff1948 Compare October 1, 2026 16:31

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5f6f94b73b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +80 to +85
const hookKey =
current.providerKey !== undefined && apiKey !== undefined && apiKey !== current.providerKey
? validateCapturedAPIKey(client, apiKey)
: undefined;
const cached = current.commit();
return hookKey === undefined ? validateCapturedAPIKey(client, cached) : hookKey;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve post-super wrapper credentials during deferred refresh

When a client subclass uses the existing wrapper pattern await super._callApiKey() followed by capture?.(this.apiKey) (or derives its capture from that property), a reconnect runs super in deferred-cache mode and leaves client.apiKey at the old value until current.commit(). The wrapper therefore captures stale key A; this branch prefers it over providerKey B and sends A on the new handshake, even though it then caches B. Preserve the provider result for these post-super wrappers rather than treating that stale capture as a credential transform.

AGENTS.md reference: AGENTS.md:L52-L57

Useful? React with 👍 / 👎.

gh-actions-shared Bot pushed a commit to xf-qubit/openai-node that referenced this pull request Oct 1, 2026
)

Responses WebSockets now refresh callable API keys on every reconnect
attempt that uses SDK credentials. Initial and subsequent handshakes
preserve caller Authorization, Basic auth, custom credentials, and TLS
settings. Closing during a slow refresh cancels promptly without
replaying a command whose delivery is uncertain.

Validation: real stable and beta upgrade, redirect and TLS reconnect
tests; focused 583/583, lint, CJS/ESM build, and actual packed-package
browser and TypeScript consumer checks. At the same commit, Node
22/24/26, Windows build, and the required Castiron custom-code budget
passed in openai#2849.

Supersedes openai#2849 at the same tested commit to obtain a fresh review.
Previous review discussion remains at openai#2849; prior approvals are not
assumed.

---------

Co-authored-by: markstuart-oai <323302876+markstuart-oai@users.noreply.github.com>
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