Repository navigation
fix(openai): GPT-Live relay calls answer the callee before the opening line - #165147
jayzhou2309 wants to merge 5 commits into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: passed. What this changesThis PR holds WebRTC caller audio until session startup and the readiness callback complete, and times out sessions that never start. Example: An inbound gpt-live-1-codex call captures speech while connecting.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Partial Merge readiness✅ Ready for maintainer review Keep this PR: it repairs a current relay startup defect with a focused change. No blocking code defect was found, but the required CI gate remains unsatisfied. Reviewed head: Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe OpenAI Gateway relay bridges phone, Talk, and Discord audio to GPT-Live, combining WebRTC media with WebSocket session control. flowchart LR
A[Phone Talk or Discord] --> B[Gateway relay bridge]
C[GPT Live sideband] --> B
B --> D[Readiness callback]
D --> E[Release buffered audio]
E --> F[Audio worker]
F --> G[GPT Live WebRTC peer]
Technical reviewBest possible solution: Land the focused relay repair after required CI passes and keep the broader phone-call greeting report open. Do we have a high-confidence way to reproduce the issue? I did not execute target code; current main visibly releases capture before readiness, and the contributor supplies contrasting current-head and main transport traces. Is this the best way to solve the issue? The repair belongs in the shared relay owner and reuses its bounded buffer and deadline without adding configuration or another lifecycle owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4384da1230e1. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +9, Tests +61. Total +70 across 4 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall readiness starts with the lower of the proof and patch scores. It is capped at 3/6 if the fix is partial, the change offers little benefit, a product decision is still open, or the PR reverses an earlier decision without saying why. ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (6 earlier review cycles)
Reviewed November 30, 2026, 9:29 AM ET / 14:29 UTC (Revision 7). |
e56c565 to
472f455
Compare
472f455 to
415871a
Compare
415871a to
99956a4
Compare
0c6503e to
7e9c1cb
Compare
The audio pipeline test expected the bridge to hand its retained caller audio to the WebRTC peer as soon as the peer existed. The bridge now holds that audio until the Live sideband reports session.started, so the opening context reaches the model first. Emit session.started in the test and check the bridge still owns the buffer before it.
The relay now holds WebRTC caller audio until session.started, but the WebRTC connect resolves without waiting for that event. When the sideband never reports session.started, connect() resolves and the caller stays muted until close or the session TTL. Expect connect() to time out instead and release the held audio.
The relay holds WebRTC caller audio until session.started so the opening context reaches the model first. WebRTC connect did not wait for that event, so when it never arrived connect() still resolved and the caller stayed muted until close or the session TTL. Wait for session.started inside the connect deadline, as the direct transport already does. A missing start now rejects connect() with a TimeoutError and releases the held audio. Both transports now observe readiness before connect completes, so onReady fires and held audio is released in one place, and the session.started handler no longer calls onReady itself. Tests that resolved a WebRTC connect without session.started now start the session during connect, the way the provider does.
7e9c1cb to
f93c78c
Compare
|
Updated: rebased onto main c24097e, new head f93c78c. Two main changes conflicted. #190466 (60c2748) changed Fixed in f93c78c. The missed-start path was real, because WebRTC connect never waited for
@clawsweeper re-review 🤖 Written and posted by an AI agent (Claude Code) on behalf of @jayzhou2309. |
|
🦞👀 Re-review progress:
|
|
Updated: the PR body's "Real behavior proof" section now holds a current-head run through the voice-call phone-call controller and the bridge's worker-thread audio facade, with the same harness run against main's bridge for contrast.
@clawsweeper re-review 🤖 Written and posted by an AI agent (Claude Code) on behalf of @jayzhou2309. |
|
🦞👀 Re-review progress:
|
Related: #164979
What Problem This Solves
On GPT-Live calls through the Gateway relay (the WebRTC transport used with ChatGPT sign-in), caller audio captured while the call connects reaches GPT-Live before the session has started. On an inbound phone call, where voice-call sends the greeting once the session is ready, the caller's first words reach the model before the greeting, so the assistant can answer them before it greets. If GPT-Live never reports that the session started, the call stays up with no greeting while the caller's audio goes into a session that never started.
User Impact
On GPT-Live relay calls over WebRTC, caller audio now reaches GPT-Live only after the session has started and after any greeting sent when the session is ready. Audio captured while the call connects is held (newest 5 s), not dropped. On inbound phone calls the greeting now goes out before the caller's first words. On outbound phone calls the opening line has been in the session instructions since #165715, and the callee's first words now arrive after the session starts instead of before. If the session never starts, connect now fails at its 30 s deadline, as the direct transport already does, and voice-call ends the call with an error instead of keeping a silent call open. The direct transport and other realtime providers are unchanged.
Why This Change Was Made
A greeting sent on ready goes out as speakable session context from
onReady, which runs once the sideband reportssession.started. On WebRTC,OpenAIQuicksilverGatewayBridge.connectWebRtchanded the pre-ready caller audio to the media peer as soon as the peer existed, andsendAudioforwarded every later frame straight to the peer. Both happened beforesession.started, so the model heard the caller first.The bridge now keeps WebRTC caller audio in its existing bounded buffer (newest 5 s) until the session starts. Because the audio is held until then, WebRTC connect also waits for
session.startedinside the connect deadline, as the direct transport already does. A session that never starts failsconnect()with aTimeoutErrorand releases the held audio, instead of resolving and holding the caller's audio until the 30-minute session TTL. When connect completes, the bridge callsonReadyfirst, so any greeting context goes out, then hands the buffer to the peer. This is direction (b) from the issue. It does not change where voice-call puts the opening line (#165715 moved outbound openings into the session instructions), add a listen-first mode (#164980), or touch greeting playback protection (#159144).Evidence
sends the greeting context before releasing caller audio to the modeltoextensions/openai/realtime-quicksilver-gateway-bridge.test.ts. It records the order of sideband sends and peer audio. Since f93c78c the session starts while the WebRTC answer is still being applied, and caller audio arrives in that window. With the bridge file from upstream/main c24097e it fails, becauseaudio:0102andaudio:0304reach the peer beforesession.context.append. On this head it passes with the ordersession.context.append, then the held audio, then live audio.fails the connection and drops held caller audio when the session never starts. On 3223ec6 it fails (1 failed, 14 passed), becauseconnect()resolves although the session never started. Commit f93c78c makes WebRTC connect wait forsession.started, and the test passes.connect()rejects withTimeoutError,onReadynever fires, the peer is closed, and the bridge neither holds nor sends caller audio.sendAudioonreadyinstead ofconnectedfails the ordering test (1 failed, 14 passed). The test covers the window wheresession.startedhas arrived but connect has not finished.session.started, and they now start the session during connect, the way the provider does. Three are inrealtime-quicksilver-gateway-bridge.test.ts, one is the webrtc case ofrealtime-quicksilver-gateway-audio.test.ts, and one is the retained-audio test inrealtime-quicksilver-media.runtime.test.ts. Each still checks what it checked before.extensions/openai/realtime-*.test.tsfiles (450 tests). It also passes voice-callrealtime-handlerandrealtime-handler.lifecycle,src/talk/session-runtime,src/gateway/talk/relay/index, and Discordrealtime-speaker-sessions(5 files, 220 tests).tsgo -p tsconfig.extensions.json,tsgo -p test/tsconfig/tsconfig.extensions.test.json,oxfmt --check,oxlinton the four changed files, andgit diff --checkare clean.onReady, abort before start, and the direct transport, and found no correctness issue.node scripts/check-changed.mjs --base upstream/mainpassed on 472f4550db4, with its extension-test typecheck step rerun alone after a local time limit. It was not rerun on this head.Real behavior proof
This run used head f93c78c. It ran again with only
extensions/openai/realtime-quicksilver-gateway-bridge.tsreplaced by the copy from upstream/main fac490e. Main has no other product change on these paths since this PR's base. Each call enters through the voice-call phone-call controller, as a Twilio media stream does, and that controller decides when to send the greeting.Real in this run:
RealtimeCallHandler, with a realCallManagerand SQLite call store. The stream URL comes frombuildTwiMLPayloadand the stream connects throughhandleWebSocketUpgrade. The provider is resolved the wayruntime.tsdoes it. The controller's own greeting policy decides the greeting: on ready for inbound calls, and in the session instructions for outbound calls.OpenAIQuicksilverGatewayBridge, with modelgpt-live-1-codexand ChatGPT auth resolution, so the bridge uses WebRTC.realtime-quicksilver-peer.runtime.ts. Opus, DTLS and SRTP run in the audio worker. Each timeline logs the peer class and its worker thread id.Faked:
session.started600 ms after the WebRTC connection comes up, or never. The bridge reaches both through itsfetchImplandwebSocketFactoryoptions, which rewrite only the host.connected,start, thenmediaevery 20 ms, thenstop). The caller speaks a 440 Hz tone for the first second, then sends silence.FakeProviderstands in for Twilio's REST API.A speech packet is an RTP payload of 10 bytes or more. The peer's silence frames are 3 bytes, and no other payload sizes appeared. Times are in ms from the carrier's
startmessage.session.startedconnect()resolved at 232 ms. The call was still open at 40 s.connect()rejected withTimeoutErrorat 30.1 s. voice-call ended the call witherrorand closed the stream with 1011Failed to connect.On outbound calls the callee's speech claims the opening, so the controller's 3 s fallback greeting never fires, in either build. The difference there is only when the callee's first words reach GPT-Live: before the session starts on main, and 18-22 ms after
session.startedon this branch.Inbound, first run on each build (some lines omitted):
Session never starts, this PR (some lines omitted):
What this does not show:
session.startedis a choice, not a measured GPT-Live latency.Harness (temporary test file, not committed)
Copy it to
extensions/logbook/zz-proof-165147.test.ts, a database-worker test root, so the realCallManagergets the main-thread SQLite broker. Then runPROOF_LABEL=after PROOF_OUT=after.jsonl node scripts/run-vitest.mjs run extensions/logbook/zz-proof-165147.test.ts. For the main run, check outextensions/openai/realtime-quicksilver-gateway-bridge.tsfrom upstream/main first. Each output line is one call, with a summary and its timeline.Test cost
realtime-quicksilver-gateway-bridge.test.tsnow has 15 tests. In a local three-file run, the missed-start case took 109 ms, most of it the real 100 ms connect deadline the test sets, and the reworked ordering case took 76 ms. The newstartSessionhelper polls withvi.waitForuntil the sideband socket exists. The retained-audio case inrealtime-quicksilver-media.runtime.test.tstook 283 ms. The--maxWorkers=1wall times were not remeasured on this head.Not verified: a live call with a real carrier and GPT-Live. See "What this does not show" above.
Rebased 2026-11-30 onto main c24097e (head f93c78c). Main's #190466 (60c2748) defers
onReadyuntil the WebRTC answer is accepted, and it conflicted with this PR's change toonSessionStarted. Main's #189029 (c6ad0a9) changed the captured-length check inrealtime-quicksilver-gateway-audio.test.ts, and it conflicted with this PR's edit to that test. The resolution keeps both of main's changes and releases held audio right afteronReadyon each path that calls it. The connect fix then makes WebRTC observesession.startedbefore connect completes, soonReadyhas one call site again.AI disclosure: an AI agent (Claude Code) reproduced the ordering defect, traced the root cause, wrote the tests and the fixes, rebased the branch onto main and resolved the conflicts, and wrote and ran the proof harness above on f93c78c and against main's bridge. It ran
node scripts/run-vitest.mjs runon each test file named above and on the harness,tsgofor the extension and extension-test configs,oxfmt --check,oxlint, andgit diff --check. A second model reviewed the original diff.🤖 Written and posted by an AI agent (Claude Code) on behalf of @jayzhou2309.