Skip to content

fix(openai): prevent realtime barge-in truncation errors - #125502

Merged
steipete merged 2 commits into
mainfrom
steipete/silly-mayer-a52eec
Aug 18, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/silly-mayer-a52eec

Conversation

@steipete

@steipete steipete commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users interrupting OpenAI Realtime voice playback could hit a provider rejection instead of cleanly truncating the assistant response. A live clawstudio observation on 2026-08-17 showed OpenAI reject conversation.item.truncate with Audio content of 3700ms is already shorter than 3760ms.

The voice-call transport forwards Twilio's inbound media.timestamp, which is a stream-relative presentation clock. The OpenAI bridge had used elapsed clock time directly as audio_end_ms: 29,600 decoded G.711 µ-law bytes represented 3,700 ms of audio while the transport clock had advanced to 3,760 ms. OpenAI requires audio_end_ms not to exceed the item's actual audio duration.

Why This Change Was Made

The OpenAI provider now owns and tracks decoded audio bytes per assistant item, then clamps the transport-clock estimate to the duration actually produced for negotiated G.711 µ-law and PCM16 audio. The GA browser sideband also passes its negotiated 24 kHz PCM16 format into the bridge so the same owner-boundary accounting applies there. Current transport marks establish outstanding playback but do not carry byte-position duration, so widening voice-call would duplicate provider-specific state.

Voice-call transport and disconnect-grace behavior are unchanged. xAI behavior and files are explicitly out of scope.

Production LOC: +35/-27 (net +8). Tests: +86/-27 (net +59). The production growth records the provider-owned duration fact and propagates the already-negotiated PCM16 format required by the external truncation contract.

Provenance: the elapsed-clock approach originated in direct commit a23ab9b906dc6a4f6b24bb3f681f395eb792dbcd on 2026-04-04 by Peter Steinberger (no associated PR found), and was carried forward by Peter Steinberger's PR #122414, merged by Peter Steinberger on 2026-08-12. This PR is authored by steipete.

External contracts:

AI-assisted: yes. The code and behavior were reviewed and verified by the maintainer.

User Impact

Interrupting an OpenAI Realtime voice response now sends a truncation position that cannot run past the audio OpenAI actually produced, preventing the provider error and allowing barge-in to complete normally for G.711 µ-law and PCM16 sessions.

Evidence

  • Live observation before the fix (clawstudio, 2026-08-17): OpenAI rejected conversation.item.truncate because 3,700 ms of decoded audio was paired with a 3,760 ms transport-clock timestamp.
  • Pre-fix regression proof: with only the production files reversed, node scripts/run-vitest.mjs extensions/openai/realtime-voice-bridge-events.test.ts failed exactly 2 cases (received 3760 vs expected 3700); 15 passed.
  • Post-fix focused proof: 30 OpenAI tests passed across extensions/openai/realtime-voice-bridge-events.test.ts and extensions/openai/realtime-voice-response-control.test.ts.
  • ClawSweeper sideband regression: before the one-line PCM16 format propagation, the browser sideband factory test received 3760 instead of 3700 while 17 other tests passed. The fixture produces 177,600 PCM16 bytes (3,700 ms) with a 3,760 ms playback clock.
  • Sideband correction proof: 48 OpenAI connection, events, and response-control tests passed across three files after the format propagation.
  • Sibling transport proof: 54 voice-call handler, adapter, and pacer tests passed across three files.
  • Changed-surface gates: the full changed-path extension gate passed across all six PR files, including all selected extensions and extensionTests gates.
  • Patch hygiene: git diff --check passed before commit and again after rebasing onto current origin/main.
  • Live provider acceptance: a temporary authenticated OpenAI Realtime probe generated real µ-law output, advanced the transport clock 60 ms beyond decoded duration, sent barge-in, and received conversation.item.truncated; 1 live test passed. The temporary probe was deleted and no secret was printed.
  • Source-blind repeatability: the focused event test passed 17/17 twice. Payload-level assertions were hidden by the reporter; the real OpenAI live probe supplied provider acceptance proof.
  • Fresh Codex-backed autoreview in uncommitted mode completed cleanly with no accepted/actionable findings. A second fresh review of the uncommitted sideband correction was also clean.
  • Rebase sanity on the original reviewed head: both focused OpenAI files passed, 30/30 tests.
  • All actionable items and rank-up moves from ClawSweeper's review were applied: propagate the negotiated PCM16 format, add the sideband factory regression, and refresh the PR evidence. The review is under 12 hours old and its only finding was addressed exactly, so no re-review request is needed.

Clamp OpenAI Realtime barge-in truncation to the audio duration produced for each assistant item. This prevents interruption failures observed live when 3,700 ms of decoded audio was paired with a 3,760 ms transport-clock timestamp.
@clawsweeper

clawsweeper Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 18, 2026 01:49
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 18, 2026
@clawsweeper

clawsweeper Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 17, 2026, 10:17 PM ET / August 18, 2026, 02:17 UTC.

ClawSweeper review

What this changes

The PR tracks decoded assistant audio per OpenAI Realtime item, clamps barge-in truncation to that duration, and passes the browser sideband’s negotiated PCM16 format into the bridge.

Regression provenance

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

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

No blocking correctness findings. This maintainer-owned PR repairs a current-main OpenAI Realtime truncation defect and addresses the prior sideband PCM finding; it should remain open for maintainer approval after exact-head checks complete.

Priority: P1
Reviewed head: eca3a7c46fb62444d9e4e37ba71586de2d60f5e4
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused owner-boundary repair with direct regression coverage and reported live provider acceptance.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body provides after-fix live OpenAI Realtime output showing a successful truncation after a deliberate playback-clock overrun.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body provides after-fix live OpenAI Realtime output showing a successful truncation after a deliberate playback-clock overrun.
Evidence reviewed 8 items Current-main defect: Current main derives truncation only from the playback clock minus the response start time, so a transport clock ahead of decoded output can exceed the provider item duration.
Provider-owned repair: The PR records decoded bytes for the active assistant item and bounds the clock-derived endpoint by format-aware produced duration before sending the truncation event.
Browser sideband coverage: The browser session already negotiates 24 kHz PCM16 and this head passes that same format to its bridge, preventing duration accounting from falling back to 8 kHz µ-law.
Findings None None.
Security None None.

How this fits together

OpenAI Realtime voice bridges receive decoded provider audio while call and browser transports report playback time. On barge-in, the bridge cancels output and sends OpenAI a truncation boundary that must not exceed produced audio.

flowchart LR
A[OpenAI audio deltas] --> B[OpenAI voice bridge]
C[Playback timestamp] --> B
D[Negotiated audio format] --> B
B --> E[Produced audio duration]
E --> F[Barge-in handling]
F --> G[OpenAI truncation event]
Loading

Decision needed

Question Recommendation
Should this maintainer-owned OpenAI Realtime repair be approved once the remaining exact-head checks finish green? Approve after exact-head CI: Accept the provider-owned byte-duration boundary after the in-progress required checks complete successfully.

Why: The patch is technically sound and has reported live provider proof, but the protected maintainer workflow requires a human merge decision.

Before merge

  • Resolve merge risk (P1) - The bug fix has a net +8 production LOC delta; the added state is limited to the provider-owned audio-duration fact and format propagation, but it is deliberate growth in a bug fix.
Agent review details

Security

None.

PR surface

Source +8, Tests +59. Total +67 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 35 27 +8
Tests 3 86 27 +59
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 121 54 +67

Review metrics

Metric Value Why it matters
Production versus test LOC production +35/-27 (net +8); tests +86/-27 (net +59) The production increase records provider-owned decoded-duration state and the test increase covers µ-law, PCM16, and browser-sideband paths.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Merge the format-aware, provider-owned duration boundary after exact-head CI is green; no smaller downstream transport change can know the decoded OpenAI item duration.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Merge the format-aware, provider-owned duration boundary after exact-head CI is green; no smaller downstream transport change can know the decoded OpenAI item duration.

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

Yes—the current-main clock-only calculation and the focused overrun cases give a high-confidence reproduction path; the PR also reports a successful live provider probe.

Is this the best way to solve the issue?

Yes—the provider bridge owns both decoded item bytes and negotiated format, while transport timestamps alone cannot establish the safe OpenAI truncation limit.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: The fix prevents a provider rejection during normal OpenAI Realtime voice barge-in.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • 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 OpenAI Realtime output showing a successful truncation after a deliberate playback-clock overrun.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides after-fix live OpenAI Realtime output showing a successful truncation after a deliberate playback-clock overrun.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Current-main history attributes the Realtime voice layering module and this focused repair to this OpenAI provider area. (role: feature owner and recent area contributor; confidence: high; commits: dac940bf3a52, eca3a7c46fb6; files: extensions/openai/realtime-voice-protocol.ts, extensions/openai/realtime-voice-events.ts, extensions/openai/realtime-voice-provider.ts)

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 (1 earlier review cycle)
  • reviewed 2026-08-18T01:55:26.241Z sha 8e8a9e1 :: found issues before merge. :: [P1] Propagate the sideband PCM format to the truncation counter

The browser sideband negotiated PCM16, but its bridge defaulted to G.711 for duration accounting. Propagate the negotiated format so truncation uses the actual PCM duration and closes ClawSweeper's in-scope finding.
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 18, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready verification for exact head eca3a7c46fb62444d9e4e37ba71586de2d60f5e4:

  • Root cause reproduced: Twilio's inbound stream clock advanced 3,760 ms while OpenAI had produced 29,600 G.711 µ-law bytes (3,700 ms), so the old bridge sent an invalid truncation endpoint.
  • Original regression proof: reversing only the production repair made the focused event suite fail two cases with received 3760 vs expected 3700.
  • ClawSweeper P1 addressed: the GA browser sideband now passes its negotiated PCM16 24 kHz format into the bridge. Before that one-line propagation, the factory regression failed with received 3760 vs expected 3700; after it, the three focused OpenAI files passed 48/48 tests.
  • Additional focused proof: 54/54 voice-call handler, adapter, and pacer tests passed.
  • node scripts/check-changed.mjs -- <six PR files> passed all selected extension and extension-test gates, including formatting, production/test types, lint, boundaries, dead exports, and import cycles.
  • Authenticated provider proof: a temporary OpenAI Realtime probe generated real µ-law output, advanced the transport clock by 60 ms beyond decoded duration, and received conversation.item.truncated. The probe was removed and no secret was printed.
  • Exact-head CI is green: https://github.com/openclaw/openclaw/actions/runs/32090914975
  • Final integrated Codex-backed autoreview is clean with no accepted/actionable findings.
  • Latest ClawSweeper review is 5/6 with no correctness findings; every prior actionable item and rank-up move was applied.

Production LOC is +35/-27 (net +8); tests are +86/-27 (net +59). I accept the small production increase because the OpenAI provider must retain one canonical per-item decoded-duration fact, and the browser sideband must pass its already-negotiated format into that owner. Transport timestamps or marks alone cannot establish the provider-safe upper bound.

Known proof gap: the exact patched commit was not redeployed for another full clawstudio-to-Twilio phone call. The changed provider contract was exercised against the live OpenAI Realtime service, while Twilio timestamp/mark handling and the browser PCM factory path have focused deterministic coverage.

@steipete
steipete merged commit 41c0818 into main Aug 18, 2026
108 checks passed
@steipete
steipete deleted the steipete/silly-mayer-a52eec branch August 18, 2026 02:29
@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 18, 2026
…5502)

* fix(openai): clamp realtime barge-in truncation

Clamp OpenAI Realtime barge-in truncation to the audio duration produced for each assistant item. This prevents interruption failures observed live when 3,700 ms of decoded audio was paired with a 3,760 ms transport-clock timestamp.

* fix(openai): propagate PCM sideband audio format

The browser sideband negotiated PCM16, but its bridge defaulted to G.711 for duration accounting. Propagate the negotiated format so truncation uses the actual PCM duration and closes ClawSweeper's in-scope finding.
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 P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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