Skip to content

feat: add opt-in Realtime reconnect and send queue - #681

Merged
jbeckwith-oai merged 2 commits into
mainfrom
codex/realtime-reconnect-send-queue
Sep 8, 2026
Merged

feat: add opt-in Realtime reconnect and send queue#681
jbeckwith-oai merged 2 commits into
mainfrom
codex/realtime-reconnect-send-queue

Conversation

@jbeckwith-oai

@jbeckwith-oai jbeckwith-oai commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Dropped Realtime connections currently require callers to build their own recovery loop. Add reconnect: true to the existing client.realtime.connect API, defaulting to false for compatibility. Recovery keeps one logical connection and runs the application block once, with finite transient-only retries, jittered backoff, refreshed authentication, and cancellation of outstanding socket work.

Optional byte-bounded retention holds outgoing events while recovering. Applications restore session state and call flush_pending explicitly; the SDK never automatically replays an uncertain write. Terminal errors distinguish never-attempted events from uncertain delivery without including payloads in their messages. Each sender receives only its own payload and delivery result, and successful writes are acknowledged atomically before clearing their in-flight identity.

The change is confined to maintained Realtime helpers, RBI/RBS, documentation, and focused tests. Transcription and existing-call sideband behavior are unchanged. Reopening a socket does not restore conversation, audio, or tool state.

Validation

  • Full non-Bedrock test suite against the pinned Steady mock: 1,872 tests, 15,764 assertions, zero failures/errors; one Linux-only procfs test skipped on macOS.
  • Realtime, Responses WebSocket, and client authentication on Ruby 3.3/3.4/4.0: 288 tests and 1,813 assertions per version.
  • Ten randomized reconnect runs: 350 tests and 2,020 assertions.
  • Bedrock: 44 tests, 390 assertions, zero failures/errors; one opt-in live AWS test skipped.
  • Full lint, formatting/directive checks, Sorbet and RBS validation, and gem build passed; packaged runtime and signatures verified.
  • Custom-code budget passed: 3,451 / 4,000 lines, with no budget or generation-ownership changes.
  • Two new consecutive clean adversarial-review rounds, with two independent fresh-context reviewers per round, on the unchanged diff. Transport/security review covers credential refresh, endpoint/TLS policy preservation, cancellation, retention accounting, and uncertain-write handling.

The caller-isolation regressions reproduced the original failure and the close/callback edge cases before the fix, then passed after correction. The repair passed three fresh-context adversarial-review rounds, ending with two consecutive clean rounds on the unchanged diff, plus the full test and lint checks above.

@jbeckwith-oai
jbeckwith-oai requested a review from a team as a code owner September 8, 2026 04:11
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 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-08T04:33:45.466312Z 6125c0e New commits
🔒 Security Review Completed 2026-09-08T04:37:13.829450Z 6125c0e 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.

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Castiron custom code

✅ No new custom-code files detected.

50 mixed files remain; 0 existing customizations changed.

Compared 345dabbb32466125c0e6ca86. Generated baselines verified.

50 existing customizations unchanged
  • lib/openai.rb
  • lib/openai/client.rb
  • lib/openai/models/audio/transcription_create_response.rb
  • lib/openai/models/chat/chat_completion_message.rb
  • lib/openai/models/chat/chat_completion_message_function_tool_call.rb
  • lib/openai/models/chat/completion_create_params.rb
  • lib/openai/models/response_format_json_schema.rb
  • lib/openai/models/responses/function_tool.rb
  • lib/openai/models/responses/response.rb
  • lib/openai/models/responses/response_create_params.rb
  • lib/openai/models/responses/response_format_text_config.rb
  • lib/openai/models/responses/response_format_text_json_schema_config.rb
  • lib/openai/models/responses/response_function_tool_call.rb
  • lib/openai/models/responses/response_function_web_search.rb
  • lib/openai/models/responses/response_output_text.rb
  • lib/openai/models/responses/tool.rb
  • lib/openai/resources/beta/threads.rb
  • lib/openai/resources/chat/completions.rb
  • lib/openai/resources/containers/files.rb
  • lib/openai/resources/files.rb
  • lib/openai/resources/responses.rb
  • lib/openai/resources/vector_stores/file_batches.rb
  • lib/openai/resources/vector_stores/files.rb
  • lib/openai/resources/webhooks.rb
  • rbi/openai/client.rbi
  • rbi/openai/models/chat/chat_completion_message.rbi
  • rbi/openai/models/chat/chat_completion_message_function_tool_call.rbi
  • rbi/openai/models/chat/completion_create_params.rbi
  • rbi/openai/models/response_format_json_schema.rbi
  • rbi/openai/models/responses/response.rbi
  • rbi/openai/models/responses/response_create_params.rbi
  • rbi/openai/models/responses/response_function_tool_call.rbi
  • rbi/openai/models/responses/response_function_web_search.rbi
  • rbi/openai/models/responses/response_output_text.rbi
  • rbi/openai/resources/chat/completions.rbi
  • rbi/openai/resources/files.rbi
  • rbi/openai/resources/responses.rbi
  • rbi/openai/resources/vector_stores/file_batches.rbi
  • rbi/openai/resources/vector_stores/files.rbi
  • scripts/castiron/README.md

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

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

git fetch --no-tags origin 345dabbb3246ce5fc389424d008e4937cf87395c 6125c0e6ca86e8352e9e4b08f72bfc9b052d11cc
python3 scripts/castiron/custom_code_report.py report \
  --base 345dabbb3246ce5fc389424d008e4937cf87395c \
  --head 6125c0e6ca86e8352e9e4b08f72bfc9b052d11cc --fetch --require-head-hash --public \
  --out /tmp/castiron-custom-code-6125c0e6ca86
cat /tmp/castiron-custom-code-6125c0e6ca86/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

@openai-sdks

openai-sdks Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

OkTest Summary

236/236 SDK tests passed in 6.457s for Ruby SDK PR #681.

Test results — 42 files
Test Result Time
tests/chat-completions-complex-body.test.ts ✅ Passed 111ms
tests/chat-completions-create.test.ts ✅ Passed 90ms
tests/chat-completions-stream.test.ts ✅ Passed 94ms
tests/files-content-binary.test.ts ✅ Passed 162ms
tests/files-create-multipart.test.ts ✅ Passed 166ms
tests/files-list-pagination.test.ts ✅ Passed 152ms
tests/initialize-config.test.ts ✅ Passed 63ms
tests/instance-isolation.test.ts ✅ Passed 105ms
tests/models-list.test.ts ✅ Passed 133ms
tests/responses-background-lifecycle.test.ts ✅ Passed 79ms
tests/responses-body-method-errors.test.ts ✅ Passed 438ms
tests/responses-cancel-timeout.test.ts ✅ Passed 171ms
tests/responses-cancel.test.ts ✅ Passed 149ms
tests/responses-compact-retries.test.ts ✅ Passed 150ms
tests/responses-compact.test.ts ✅ Passed 101ms
tests/responses-create-advanced-stream.test.ts ✅ Passed 98ms
tests/responses-create-advanced.test.ts ✅ Passed 112ms
tests/responses-create-disconnect.test.ts ✅ Passed 99ms
tests/responses-create-errors.test.ts ✅ Passed 268ms
tests/responses-create-malformed-api-responses.test.ts ✅ Passed 96ms
tests/responses-create-retries.test.ts ✅ Passed 124ms
tests/responses-create-stream-failures.test.ts ✅ Passed 95ms
tests/responses-create-stream-timeout.test.ts ✅ Passed 186ms
tests/responses-create-stream-wire.test.ts ✅ Passed 1.301s
tests/responses-create-stream.test.ts ✅ Passed 74ms
tests/responses-create-terminal-states.test.ts ✅ Passed 142ms
tests/responses-create-timeout.test.ts ✅ Passed 186ms
tests/responses-create.test.ts ✅ Passed 96ms
tests/responses-delete.test.ts ✅ Passed 97ms
tests/responses-input-items-errors.test.ts ✅ Passed 126ms
tests/responses-input-items-list.test.ts ✅ Passed 121ms
tests/responses-input-items-options.test.ts ✅ Passed 94ms
tests/responses-input-tokens-count-timeout.test.ts ✅ Passed 164ms
tests/responses-input-tokens-count.test.ts ✅ Passed 114ms
tests/responses-malformed-inputs.test.ts ✅ Passed 1.468s
tests/responses-not-found-errors.test.ts ✅ Passed 141ms
tests/responses-parse.test.ts ✅ Passed 66ms
tests/responses-retrieve-retries.test.ts ✅ Passed 103ms
tests/responses-retrieve.test.ts ✅ Passed 84ms
tests/responses-stored-method-errors.test.ts ✅ Passed 680ms
tests/retry-behavior.test.ts ✅ Passed 3.097s
tests/sdk-error-shape.test.ts ✅ Passed 342ms

View OkTest run #34187244586

SDK merge (c03a956266c5) · head (6125c0e6ca86) · base (345dabbb3246) · OkTest (08ec4299e769)

@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: 3f54cbbf78

ℹ️ 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 lib/openai/helpers/realtime/recovery.rb Outdated

@markstuart-oai markstuart-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 16 changed files at 6125c0e, including the maintained Realtime/WebSocket ownership paths, examples, and RBI/RBS contracts. No substantive correctness or structural findings. Recovery remains isolated in Realtime and reuses the canonical handshake/authentication and transport helpers; no changed file crosses 1,000 lines. Explicit restoration/flush and terminal handling of uncertain writes are preserved.

Independently reproduced the four caller-isolation/completion regressions using the pre-fix recovery implementation and verified they pass on this head. Fresh Ruby 4.0.6 validation: 35 reconnect tests / 202 assertions passed; the broader Realtime, Responses WebSocket, and client run completed 329 tests / 1,949 assertions with zero failures and two errors in unchanged proxy tests (also reproduced in isolation). Additional cancellation/queue-accounting probes passed. Sorbet and all 1,290 RBS files validated. I did not rerun the full mock-server suite, cross-version matrix, OkTest, or live API tests.

@jbeckwith-oai
jbeckwith-oai added this pull request to the merge queue Sep 8, 2026
Merged via the queue into main with commit 21b8a70 Sep 8, 2026
22 checks passed
@jbeckwith-oai
jbeckwith-oai deleted the codex/realtime-reconnect-send-queue branch September 8, 2026 04:54
@openai-sdks openai-sdks Bot mentioned this pull request Sep 8, 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