Skip to content

fix: realtime phone calls use the wrong audio format and stay open - #133018

Merged
steipete merged 3 commits into
mainfrom
codex/realtime-phone-lifecycle
Aug 30, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/realtime-phone-lifecycle

Conversation

@steipete

@steipete steipete commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Closes #132992

What Problem This Solves

Fixes an issue where realtime phone audio could be decoded with the wrong format when using GPT-Live, and where a provider ending its session could leave a silent carrier call open. A provider closing during bridge creation could also be connected again or replace a working predecessor.

Why This Change Was Made

The phone media owner now supplies its existing G.711 μ-law/8 kHz/mono contract explicitly. Normal WebSocket closure is distinguished from failure, and provider-ended calls use the existing carrier termination path. The handler records a terminal callback received during creation and rejects that candidate before connecting it or adopting its bridge and transcript state. Constructor failure and terminal creation share cleanup; transcript ownership is rolled back before disposing the rejected candidate, including when disposal emits final callbacks or throws.

User Impact

Twilio and Telnyx use the correct audio format. Finished provider sessions end their carrier call, including during startup. Failed replacements leave the working call and transcript intact. Local caller teardown, explicit end-call control, and stale transport callbacks retain their ownership rules. No configuration, schema, dependency, or wire-protocol change is required. Current native GPT-Live function-tool limitations are documented.

Evidence

  • Before-fix regressions captured missing carrier audioFormat, incorrect normal WebSocket closure, and carrier connections left open after provider completion.
  • The accepted startup review finding reproduced five failures before the final owner repair: missing carrier closure, reconnecting terminal candidates, replacing a live predecessor, and accepting post-close provisional transcripts.
  • All 65 phone handler, lifecycle, and runtime-routing tests pass, including both terminal reasons, first-call and replacement creation, disposal exceptions, late callbacks, explicit end-call, and caller disconnect grace. OpenAI bridge/session/delegation/routing suites also passed.
  • Extension type checking, type-aware lint, formatting, and diff checks passed. Fresh independent Codex review of the complete phone patch against its original base found no actionable P0–P2 defects.
  • Live GA backend audio and browser speech succeeded on Blacksmith Testbox tbx_01m185h6k7s0dnt939ehb0dtcg: https://github.com/openclaw/openclaw/actions/runs/33286432360 . These are GA sibling proofs, not GPT-Live or carrier-call claims.
  • GPT-Live live proof was attempted: the Platform account lacked model access and the hydrated subscription token was expired. No live carrier call was placed. The change reuses the existing codec conversion and WebSocket close contract; no external API payload shape changes.
  • Direct upstream inspection: OpenAI Codex 63d213884daea50e4f74efc192cdc44f549b67d5, codex-rs/codex-api/src/endpoint/realtime_websocket/protocol_frameless_bidi.rs:38 (PCM audio) and methods.rs:548 (normal versus abnormal close).
  • Production LOC: +45/-29, net +16; tests: +245/-163, net +82. Growth represents the explicit format contract and provisional terminal state with exception-safe disposal, while duplicated startup cleanup is consolidated.

CI follow-through: the first hosted run exposed an outdated routing expectation for provider completion and an assertion assuming client socket close implied server bridge disposal. Tests now verify distinct provider/caller end reasons in carrier calls and durable history, and wait for actual server disposal. ClawSweeper's synchronous-creation finding is addressed by the final admission repair and its failing/passing regressions.

Provenance: original failures reproduced at 9d8bf3525072487320da72b6718ecf9c69dc3f4e; exact introducing commit is not established. Shared core bridge reconnection semantics remain unchanged.

AI-assisted implementation and verification. Release-note context: correct realtime phone codecs, close carrier calls when their provider ends, and preserve live calls when a replacement fails during creation.

@steipete steipete self-assigned this Aug 30, 2026
@clawsweeper

clawsweeper Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: voice-call Channel integration: voice-call extensions: openai size: S maintainer Maintainer-authored PR labels Aug 30, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 30, 2026
@clawsweeper

clawsweeper Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 29, 2026, 11:01 PM ET / August 30, 2026, 03:01 UTC.

ClawSweeper review

What this changes

The PR passes carrier μ-law audio format into the GPT-Live bridge, treats a normal provider close as completion, and rejects a bridge that closes before it can be adopted.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep this current maintainer PR open: source review finds the earlier synchronous-creation blocker addressed and current main still has the pre-fix behavior, but exact-head CI is incomplete and the required upstream Codex protocol source was unavailable in this read-only environment.

Priority: P1
Reviewed head: 4dd71b41150bb6b106d454967359b4f1d01201d7

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The lifecycle patch is focused and covers the prior blocker, but upstream protocol inspection and live carrier evidence remain unavailable.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; its source-level carrier harnesses cover the changed owner boundary, while no live GPT-Live carrier proof is claimed.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; its source-level carrier harnesses cover the changed owner boundary, while no live GPT-Live carrier proof is claimed.
Evidence reviewed 5 items Carrier audio owner: The phone handler now supplies the existing μ-law, 8 kHz, mono SDK contract when creating its provider bridge; the GPT-Live bridge converts both inbound and outbound audio only when that contract is present.
Provider-close ownership: A normal WebSocket close is mapped to completion, and the adopted bridge callback closes the carrier socket and invokes manager-owned call termination.
Prior finding covered: The revised handler records a close before adoption, rolls transcript ownership back, disposes the candidate, and avoids ending an active predecessor; focused lifecycle tests cover both terminal reasons and replacement cleanup callbacks.
Findings None None.
Security None None.

How this fits together

Voice Call receives Twilio or Telnyx media and creates a realtime provider bridge; it owns the carrier socket, call termination, and call-history outcome. Provider callbacks must preserve an existing call during replacement while ending the carrier call when an adopted provider session finishes.

flowchart LR
  Carrier[Carrier media stream] --> Handler[Voice Call handler]
  Handler --> Format[Carrier audio contract]
  Format --> Bridge[Realtime provider bridge]
  Bridge --> Decision{Bridge lifecycle event}
  Decision --> Adopted[Adopted session ends]
  Decision --> Provisional[Candidate ends before adoption]
  Adopted --> CarrierEnd[End carrier call and record outcome]
  Provisional --> Preserve[Dispose candidate and preserve predecessor]
Loading

Before merge

  • Resolve merge risk (P1) - The runtime portion grows by 16 lines; the pre-adoption terminal state is warranted by a callback that can arrive before an owner exists, but it should remain confined to this lifecycle owner.
  • Resolve merge risk (P1) - A live GPT-Live carrier run and direct upstream Codex protocol inspection remain unavailable, so normal-close semantics have source and harness coverage but no independently verified provider trace.
Agent review details

Security

None.

PR surface

Source +16, Tests +82, Docs +11. Total +109 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 2 45 29 +16
Tests 4 245 163 +82
Docs 1 11 0 +11
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 301 192 +109

Review metrics

Metric Value Why it matters
Production versus test delta runtime +45/-29 (net +16); docs +11; tests +245/-163 (net +82) The runtime growth represents explicit carrier-format propagation and pre-adoption lifecycle state; the larger test change covers close ordering and replacement ownership.

Merge-risk options

Maintainer options:

  1. Finish lifecycle validation (recommended)
    Require exact-head CI and direct Codex protocol confirmation before merging the carrier-close behavior.

Technical review

Best possible solution:

Retain the owner-level provisional-admission state, then merge only after exact-head CI and a maintainer-capable upstream Codex contract check confirm the documented GPT-Live behavior.

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

Yes. The focused carrier WebSocket handler tests can inspect the bridge request and inject provider completion before or after bridge adoption; the code path is directly traceable, although this review did not execute tests.

Is this the best way to solve the issue?

Unclear. The owner-boundary repair and prior-finding coverage are coherent, but direct inspection of the cited Codex protocol contract was unavailable in this environment.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; its source-level carrier harnesses cover the changed owner boundary, while no live GPT-Live carrier proof is claimed.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: A provider completion can otherwise leave an active phone connection silent.
  • merge-risk: 🚨 message-delivery: The patch changes when provider lifecycle events terminate a carrier call and record its end reason.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; its source-level carrier harnesses cover the changed owner boundary, while no live GPT-Live carrier proof is claimed.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Complete exact-head CI.
  • Have a maintainer with the required Codex checkout confirm the cited normal-close and PCM protocol behavior.

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 (2 earlier review cycles)
  • reviewed 2026-08-30T02:30:31.454Z sha dcba7d1 :: found issues before merge. :: [P1] Handle provider closure during bridge creation
  • reviewed 2026-08-30T02:51:10.595Z sha 11ca45d :: found issues before merge. :: [P1] Preserve closure during bridge creation

@clawsweeper clawsweeper Bot added merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Aug 30, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Addressed the P1 synchronous-creation finding in 4dd71b4. The handler records early provider termination and rejects that candidate before connecting or adopting it. Creation exceptions and terminal candidates now share cleanup; transcript ownership rolls back before disposal, and a disposal exception cannot skip carrier cleanup or retire a working predecessor.

The new regressions failed in five cases before the repair. All 65 phone handler, lifecycle, and runtime-routing tests now pass, including completed/error startup, replacement preservation, disposal-time callbacks and exceptions, late transcripts, local disconnect grace, and explicit end-call. Type-aware lint and a fresh independent P0–P2 review of the complete phone PR also passed.

The protocol-review limitation is covered by direct maintainer inspection of the sibling public Codex checkout at 63d213884daea50e4f74efc192cdc44f549b67d5: PCM parsing and normal close handling. The live GPT-Live entitlement/credential limitation remains explicitly documented; no live carrier call is claimed. Final exact-head CI is still required before landing.

@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 30, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Final merge-gate follow-through for 4dd71b4: exact-head CI completed successfully; the PR rollup has 181 completed checks and no pending or failed checks.

The fresh review has no actionable code finding. Both rank-up moves are covered: CI is green, and I directly inspected the required sibling Codex checkout at 63d213884daea50e4f74efc192cdc44f549b67d5, including frameless audio parsing and normal-versus-abnormal closure. The +16 production-line delta stays in the phone lifecycle owner and OpenAI transport, with duplicate startup cleanup consolidated; shared core reconnection behavior is unchanged.

Live GPT-Live/carrier proof remains infeasible with the tested account entitlement and expired hydrated OAuth token, as disclosed in the PR. The observed GA sibling proof and failing-before/passing-after carrier harness regressions are not presented as a successful GPT-Live carrier call.

@steipete
steipete merged commit e30ef76 into main Aug 30, 2026
181 checks passed
@steipete
steipete deleted the codex/realtime-phone-lifecycle branch August 30, 2026 03:05
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 30, 2026
…penclaw#133018)

* fix: realtime phone calls use the wrong audio format and stay open

* test(voice-call): observe provider completion and server cleanup

* fix(voice-call): reject terminal bridges before call adoption
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: voice-call Channel integration: voice-call docs Improvements or additions to documentation extensions: openai maintainer Maintainer-authored PR merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M 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.

[Bug]: Realtime phone bridge receives no carrier audio format

1 participant