Skip to content

fix(openai): close preconnect realtime sessions - #116735

Merged
vincentkoc merged 6 commits into
mainfrom
fix/openai-preconnect-lifecycle
Jul 31, 2026
Merged

vincentkoc merged 6 commits into
mainfrom
fix/openai-preconnect-lifecycle

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Jul 31, 2026 •

Copy link
Copy Markdown
Member

Related: #116201

What Problem This Solves

Fixes an issue where closing an OpenAI Realtime voice bridge before its first connection could retain queued audio and allow that cancelled generation's work to reach a later explicit connection.

Why This Change Was Made

The existing named OpenAI Realtime lifecycle now owns the preconnection terminal state. GA and GPT-Live adapters delegate close to it, discard queued bridge state once, ignore late post-close input, and require an explicit fresh connection generation. Connected-session behavior, retry policy, provider selection, config, and environment surfaces remain unchanged.

The current head uses a signed two-parent merge from main; the lifecycle commit series remains intact.

User Impact

Cancellation and close are idempotent before and after connection. Closing before connect no longer leaks stale audio into a later session, and an explicit reconnect starts cleanly.

Evidence

  • Exact head: b218adb7a7d931927aa7fd577f40b31ecc113c3b
  • Focused lifecycle, GA provider, and GPT-Live coverage: 109/109 passed.
  • Live GA gpt-realtime-2.1: cancelled generation produced no ready/audio/close event; explicit reconnect became ready once, sent no stale audio, returned 19,200 audio bytes, and repeated close emitted one callback.
  • Structured autoreview on the identical six-file lifecycle diff: clean, 0.95 confidence.
  • ClawSweeper on the lifecycle diff: no findings, proof sufficient.
  • Exact sibling Codex contract check:
    • codex-rs/core/src/realtime_conversation.rs:286-299 replaces and stops prior active state before start.
    • codex-rs/core/src/realtime_conversation.rs:425-443 terminalizes only the matching active generation.
    • codex-rs/core/src/realtime_conversation.rs:643-669 removes active state and aborts its input task on shutdown.
  • The earlier native-i18n CI failure was baseline locale drift repaired on main by fe408e109f6; this exact head includes that repair.

The available ChatGPT OAuth account is not entitled to GPT-Live. GPT-Live is therefore covered by focused adapter tests, while the live GA path exercises the same shared lifecycle.

AI-assisted: yes. The implementation and proof were reviewed against source, live behavior, current main, and sibling Codex ownership semantics.

@vincentkoc vincentkoc self-assigned this Jul 31, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 High-priority user-facing bug, regression, or broken workflow. labels Jul 31, 2026
@clawsweeper

clawsweeper Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 31, 2026, 8:10 AM ET / 12:10 UTC.

ClawSweeper review

What this changes

The PR makes OpenAI Realtime bridge cancellation terminal before the first socket connection, clears queued audio in both GA and QuickSilver adapters, and requires an explicit fresh connection.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep this PR open for normal maintainer merge review. It is maintainer-authored and carries the protected maintainer label; the supplied evidence describes a focused fix for stale preconnect audio crossing into a later OpenAI Realtime session, with no remaining line-level defect established in this review.

Priority: P1
Reviewed head: b218adb7a7d931927aa7fd577f40b31ecc113c3b

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is focused, regression-covered, and supported by concrete live provider evidence; the remaining gate is ordinary maintainer review of the shared generation boundary.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body provides after-fix live GA output describing no events from the cancelled generation, no stale audio after explicit reconnect, normal returned audio, and idempotent close behavior.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body provides after-fix live GA output describing no events from the cancelled generation, no stale audio after explicit reconnect, normal returned audio, and idempotent close behavior.
Evidence reviewed 5 items Changed lifecycle contract: The branch introduces an explicit idle state and makes cancellation terminal before a connection exists; an explicit later connect creates a new generation. The accompanying lifecycle test covers terminal preconnect cancellation followed by a clean connection.
Both adapter paths clear state: The GA provider bridge and QuickSilver bridge now call lifecycle cancellation before checking for an established connection, reset terminal bridge state, and only send transport close when a connection exists.
Focused regression coverage: The branch adds provider and QuickSilver tests asserting that audio queued before preconnect close is not sent after a later explicit reconnect, while the later connected close emits one completed callback.
Findings None None.
Security None None.

How this fits together

The OpenAI extension’s Realtime voice bridges accept audio before a provider socket is ready, then hand it to a shared lifecycle object that owns connection generations and terminal state. That lifecycle determines whether buffered audio may reach the provider and whether close callbacks belong to the active generation.

flowchart LR
  A[Voice input] --> B[GA or QuickSilver bridge]
  B --> C[Shared realtime lifecycle]
  C --> D{Active generation?}
  D -->|No: terminal| E[Discard queued audio]
  D -->|Yes| F[Provider socket]
  F --> G[Audio and close callbacks]
Loading

Before merge

  • Resolve merge risk (P1) - The change alters the terminal generation boundary shared by GA and QuickSilver bridges. A missed late-callback or reconnect caller path could still associate old buffered state with a new connection, so maintainer review should confirm the complete callback contract on the current merge result.
  • Complete next step (P2) - This is an open, maintainer-authored PR with the protected maintainer label; the next action is a human merge decision, not an automated repair or cleanup lane.
Agent review details

Security

None.

PR surface

Source +29, Tests +73. Total +102 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 41 12 +29
Tests 3 73 0 +73
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 114 12 +102

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: extensions/openai/realtime-voice-provider.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Confirm generation isolation before merge (recommended)
    Review the current merge result’s GA and QuickSilver callers and callbacks to confirm that preconnect cancellation cannot deliver stale audio or duplicate a close callback after reconnect.
  2. Accept the focused lifecycle repair
    Merge with the documented live GA proof and focused adapter tests if maintainers judge the shared lifecycle contract complete.

Technical review

Best possible solution:

Preserve one shared terminal-generation invariant in the lifecycle, retain the paired GA and QuickSilver regression coverage, and merge only after confirming late callbacks cannot revive or drain a cancelled generation.

Do we have a high-confidence way to reproduce the issue?

Yes, from source and supplied regression coverage: queue audio, close before the first connection, then explicitly reconnect and verify no old audio is sent. The PR also supplies a reported live GA after-fix run for the same observable boundary.

Is this the best way to solve the issue?

Yes, based on the supplied diff: placing preconnect terminalization in the shared lifecycle avoids two adapter-specific definitions of cancellation while each bridge clears its own queued transport state.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 7af2bb62622e.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides after-fix live GA output describing no events from the cancelled generation, no stale audio after explicit reconnect, normal returned audio, and idempotent close behavior.

Label justifications:

  • P1: Cancelled realtime voice work could otherwise carry queued audio into a later user-requested connection.
  • merge-risk: 🚨 session-state: The diff changes lifecycle terminal state, queued bridge state, and close-callback ownership across connection generations.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body provides after-fix live GA output describing no events from the cancelled generation, no stale audio after explicit reconnect, normal returned audio, and idempotent close behavior.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides after-fix live GA output describing no events from the cancelled generation, no stale audio after explicit reconnect, normal returned audio, and idempotent close behavior.

Evidence

What I checked:

  • Changed lifecycle contract: The branch introduces an explicit idle state and makes cancellation terminal before a connection exists; an explicit later connect creates a new generation. The accompanying lifecycle test covers terminal preconnect cancellation followed by a clean connection. (extensions/openai/realtime-voice-lifecycle.ts:12, b218adb7a7d9)
  • Both adapter paths clear state: The GA provider bridge and QuickSilver bridge now call lifecycle cancellation before checking for an established connection, reset terminal bridge state, and only send transport close when a connection exists. (extensions/openai/realtime-voice-provider.ts:734, b218adb7a7d9)
  • Focused regression coverage: The branch adds provider and QuickSilver tests asserting that audio queued before preconnect close is not sent after a later explicit reconnect, while the later connected close emits one completed callback. (extensions/openai/realtime-voice-provider.test.ts:1549, b218adb7a7d9)
  • Real behavior evidence: The PR body reports a live GA gpt-realtime-2.1 run in which a cancelled preconnect generation emitted no ready/audio/close event, then a fresh reconnect sent no stale audio and returned audio normally. (b218adb7a7d9)
  • Related root-cause scope: The linked open issue explicitly includes terminal close clearing retained state and rejecting post-close input; this PR is a focused candidate fix for that Realtime voice slice.

Likely related people:

  • vincentkoc: The supplied context identifies this repository member as author of the related Realtime voice resource-boundary report and of the lifecycle commit series in this PR; current-main ownership provenance was not available through the read-only inspection backend. (role: related issue author and current lifecycle contributor; confidence: medium; commits: 42f1e8dd4177, 337a2b3fc7ef, 07a352ac9568; files: extensions/openai/realtime-voice-lifecycle.ts, extensions/openai/realtime-voice-provider.ts, extensions/openai/realtime-quicksilver-bridge.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Confirm the GA and QuickSilver late-callback paths against the current merge result before merging.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (4 earlier review cycles)
  • reviewed 2026-07-31T09:37:28.098Z sha 07a352a :: found issues before merge. :: [P3] Remove the release-owned changelog entry
  • reviewed 2026-07-31T10:40:39.261Z sha bfbba67 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-31T11:06:41.507Z sha b218adb :: needs maintainer review before merge. :: none
  • reviewed 2026-07-31T11:12:03.137Z sha b218adb :: needs maintainer review before merge. :: none

* origin/main: (38 commits)
  fix(agents): compact session status change text (#116742)
  fix(llama-cpp): recover plaintext tool calls (#116736)
  fix(telegram): validate native queue arguments before fallback (#116726)
  chore(skills): add autonomous issue sweep workflow
  docs(auto-qa): require clean root-cause refactors
  fix(ollama): models advertise tools when /api/show fails (#109971)
  fix(ollama): use CJK-aware char estimate for usage fallback (#110073)
  fix(ollama): release failed setup response bodies before returning (#111802)
  feat(plugins): externalize Synthetic provider (#116720)
  fix(agents): unblock channel turns after restart recovery (#116728)
  fix(telegram): keep typing alive during active steered tasks (#116721)
  fix(gateway): admit standalone MCP app work (#116727)
  fix(googlechat): record canonical receipt thread (#116717)
  test(ui): cover the Talk relay start-stop race
  fix(ui): close superseded Talk allocations
  fix(agents): resume interrupted turns past progress commentary (#116725)
  fix(gateway): sign device proofs with challenge time (#116679)
  test(google): cover expired CLI OAuth compatibility
  fix(testing): load relay smoke through UI Vite config
  test(testing): guard realtime relay smoke module path
  ...
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jul 31, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

Maintainer Codex contract check completed against sibling openai/codex head 414782450952.

  • codex-rs/core/src/realtime_conversation.rs:286-299: starting a realtime conversation takes and stops any prior active state before installing the replacement.
  • codex-rs/core/src/realtime_conversation.rs:425-443: terminal completion mutates state only when the active Arc still matches the completing conversation.
  • codex-rs/core/src/realtime_conversation.rs:643-669: shutdown takes the active state and aborts its input task; audio input without active state returns conversation is not running.

That matches this PR's invariant: cancellation owns the current generation, late work cannot revive it, and only an explicit fresh connection becomes eligible for audio. The ClawSweeper rank-up move is satisfied.

* origin/main: (23 commits)
  fix(agents): preserve resumed turns after stale terminal events (#116777)
  fix(browser): preserve tab-bound browser authorization (#116778)
  fix(doctor): correct SQLite-backed automation warnings (#116769)
  fix(release): skip unavailable Buzz QA runner (#116753)
  feat(plugins): externalize DuckDuckGo search (#116740)
  refactor(reply): simplify task-owned typing refresh (#116770)
  fix(chat): explain chat-only model limits
  feat(models): expose tool support to clients
  docs(skill): require independent proof before issue closure
  fix(skills): allow autonomous sweep sync (#116755)
  fix(irc): recognize punctuation in nickname mentions (#116758)
  fix(plugins): require explicit source external startup (#116759)
  fix(whatsapp): keep sends running when typing presence fails (#116739)
  fix(cli): reject dangling config path escapes (#116738)
  fix(qa): authenticate summaries and bound native scenario commands (#116748)
  fix(bedrock): reject truncated streams and preserve audio results (#116743)
  docs(skill): isolate autonomous issue sweep worktrees
  fix(ci): retire Kova runtime deps coverage (#116760)
  chore(i18n): refresh native locales (#116640)
  fix(ollama): resolve web search secret refs (#104829)
  ...
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. labels Jul 31, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review July 31, 2026 12:06
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jul 31, 2026
@vincentkoc
vincentkoc merged commit d8f229f into main Jul 31, 2026
294 of 296 checks passed
@vincentkoc
vincentkoc deleted the fix/openai-preconnect-lifecycle branch July 31, 2026 12:19
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 1, 2026
…ect-lifecycle

* commit '67eace4ae77b63cfc98703626b30512d1e18d03a':
  chore(openai): drop release-owned changelog entry
  fix(openai): narrow idle lifecycle cancellation
  fix(openai): discard preconnect audio on close
  fix(openai): terminalize preconnect lifecycle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: openai maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant