Skip to content

fix(voice-call): stop assistant echo from being taken as caller speech - #159145

Closed
mnowrot wants to merge 8 commits into
openclaw:mainfrom
mnowrot:fix/voice-call-echo-barge-in-guard
Closed

mnowrot wants to merge 8 commits into
openclaw:mainfrom
mnowrot:fix/voice-call-echo-barge-in-guard

Conversation

@mnowrot

@mnowrot mnowrot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Refs #159140 — this PR fixes the plugin-side echo barge-in. The provider-side (Google VAD) echo interruption and the provider-committed echo transcript remain open in the linked issue. The current-head real-call observation is below; the ownership decision is in the decision comment on this PR.

What problem this solves

The realtime handler's local RMS gate counted any inbound energy as caller speech. Assistant audio that leaks back through the line (echo) therefore armed the gate, which cancelled the agent's own turn mid-sentence and could store caller lines the caller never said. Reported in #159140.

What this change does

RealtimeAudioPacer.getPlayoutEndsAt() projects the paced stream clock onto Date.now(), so the handler knows when the assistant's audio has actually reached the line. While paced audio is queued, or within a 400 ms tail after the last outbound chunk (ASSISTANT_SPEECH_TAIL_MS), the local RMS gate is fed rms 0, so it cannot arm handleBargeIn. Inbound audio is still forwarded to the realtime provider, so provider-owned barge-in is untouched. Once the window closes, the gate behaves exactly as it does on the merge base.

Scope — what this change does not do

  • It cannot stop the realtime provider from raising its own interruption from line echo. On the observed head, Google's server-side VAD (provider defaults) interrupted the greeting 9–10 times per call on echo alone.
  • It cannot stop the provider from committing a transcription of that echo as a user: turn, so the phantom caller transcript persists. Both remain open in [Bug]: realtime voice call treats the agent's own leaked audio as caller speech #159140 — this PR does not close it.
  • On a bridge with no provider-owned barge-in, a genuine caller who speaks over the assistant is not interrupted by the local gate until the paced queue and the 400 ms tail finish. That is a deliberate, measured trade-off, put to the maintainers in the decision comment on this PR.

Evidence

The current-head real-call observation (below) measured the local gate going from 12 echo-driven detections at −12 dB on the merge base to 0 on this head, with genuine caller turns still delivered and the post-window fallback intact. The redacted per-frame traces, the harness and the per-scenario numbers are in the observation section below.


Revision 5: reduced to the change the observation supports

Head: 9b0e825a4bc37ce6c08a361e499737e43906fb8a fix(voice-call): mask local barge-in while assistant audio plays out. It is one commit on top of a6ec34f7, pushed as a fast-forward.

Why

The real-call observation on 2181c268 showed two things:

  • The learned echo floor only delayed the false local barge-in, by 170–800 ms into each playback segment.
  • The phantom-transcript guard never fired, because the provider delivers the final inputTranscription after the line has gone quiet.

Only b918ba3c had zero echo barge-ins at −12 dB, and that commit fully masked the local gate while assistant audio was active. This revision keeps that masking and drops everything else.

What remains

  • RealtimeAudioPacer.getPlayoutEndsAt() projects the paced stream clock onto Date.now() and is clamped on clear or close. Together with ASSISTANT_SPEECH_TAIL_MS = 400, it defines the window: assistant audio is active while hasPendingAudio() || now < playoutEndsAt + 400 ms.
  • While the window is open, the local RMS gate is fed rms 0, so it cannot fire handleBargeIn. Inbound audio is still forwarded to the provider, so provider-side barge-in is untouched.
  • Once the window closes, the gate behaves as it does on the merge base.
  • Transcript emission is back to the merge-base form. A code comment explains why the host must not drop provider-committed turns.

What was removed and why

These were removed:

  • the constants ECHO_OVERLAP_MARGIN, ECHO_AMBIGUITY_MARGIN, ECHO_BASELINE_SMOOTHING, ECHO_FLOOR_MIN_SAMPLES and PHANTOM_GUARD_MIN_RMS
  • the state echoBaselineRms/Samples, maxEchoInputRms, maxRecentInputRms and callerAudioSinceTranscript
  • the helper resetInputAccounting
  • the per-segment floor reset
  • the realtime phantom transcript suppressed branch
  • the ambiguous-overlap logic

The floor did not stop echo barge-in; it only postponed it. The phantom guard never fired on a real call. Both added complexity with no observed benefit.

The phantom-transcript symptom is not fixed by this PR. The provider drives it: the provider commits the final input transcription after playout has ended. It remains open as a follow-up.

Diff vs merge base 7ff7042d: 4 files, +261/−46. Production code accounts for +33/−1 of that (realtime-handler.ts +16/−1, realtime-audio-pacer.ts +17); the rest is tests. For comparison, the diff was +469/−36 at a6ec34f7. Diff vs a6ec34f7: 3 files, +182/−400.

Test-contract change (pending Voice Call owner approval)

Three existing realtime-handler.test.ts cases asserted that the local gate barges in on loud input while assistant audio is still playing out, or within 400 ms of playout ending. Issue #159140 reports exactly that behaviour as the bug: echo of the agent's own audio arms the local barge-in gate and cancels the agent's turn. The level gate cannot tell echo from the caller, so those assertions encoded the defect. Each test keeps its intent under the new contract:

Test (old name → new name) Intent kept Change
keeps local barge-in fallback for providers without speech-started events → masks local barge-in during playout and keeps the fallback for providers without speech-started events For providers without speech-started events, the local gate owns barge-in Loud frames during playout now assert no handleBargeIn and no clear. After the window, a second burst asserts the original cancelled turn, clear, handleBargeIn({ audioPlaybackActive: true }), and output.audio.done on the cancelled turn.
lets a session bridge override provider-level barge-in capabilities → ... once playout ends A bridge with handlesInputAudioBargeIn: false hands barge-in to the local gate A loud frame during playout does not barge in. After the window, the override still produces the cancelled turn, clear, and handleBargeIn({ audioPlaybackActive: true }).
clears remote playback after local pacing and output state have finished → clears remote playback after paced playout and output state have finished After response.done and playout, the local gate clears remote playback The caller frames are now delivered 1 s later on the wall clock, past playout and the 400 ms tail. The assertions are unchanged: handleBargeIn({ audioPlaybackActive: false }), exactly one extra clear, and no turn.cancelled.

Only Date is faked (vi.useFakeTimers({ toFake: ["Date"] })), so no real sleeps are added. The socket, the pacer timers and vi.waitFor all stay on real timers.

Trade-off

While a provider's local gate owns barge-in (no speech-started events, or a bridge override), a caller can no longer interrupt through the local gate during assistant playout or its 400 ms tail. The provider still receives every inbound frame. Barge-in by providers that own it (speech-started events) is unaffected. We accept this because a false barge-in on echo cancels the agent's own turn. That is the reported and observed failure, and it happens far more often than a genuine interruption during playout.

Lanes (on 9b0e825a, run via node --import ./scripts/tsx.mjs scripts/run-vitest.mjs run …)

Lane Result
realtime-handler.test.ts + realtime-handler.persistence.test.ts 2 files, 84/84 pass
All 12 extensions/voice-call/src/webhook/*.test.ts files (explicit list) 12 files, 175/175 pass
realtime-handler.echo-guard.test.ts 4/4 pass
npx oxlint --tsconfig extensions/tsconfig.json extensions/voice-call/src/webhook exit 0
npx oxfmt --check (4 touched files) clean
git diff --check clean

Not run: pnpm tsgo:extensions:test (it runs out of memory on the 7.7 GB host) and scripts/run-oxlint.mjs (it refuses the external dependency links). No real-call proof was captured on this head.

Negative control (current tests, merge-base handler 7ff7042d)

  • realtime-handler.echo-guard.test.ts: 4 of 4 fail. Each failure is handleBargeIn called once, which means echo barge-in fires.
  • Updated realtime-handler.test.ts cases: both masking cases fail. The clears remote playback case passes, as expected, because it exercises post-window behaviour that the merge base shares.
  • The handler source was restored byte-identical afterwards.

Real-call observation on head 9b0e825a (Revision 6)

What this is: This is a real Google Live provider session with real speech audio, running through the real
RealtimeCallHandler and a real carrier WebSocket. The line echo is simulated at the media-frame level. It is not
a PSTN/telephony call.

Setup:

  • Head: 9b0e825a, realtime-handler.ts blob 6894b015. Contrast: merge base 7ff7042d, blob a8bdb29d.
  • Transport: gemini-2.5-flash-native-audio-preview-12-2025 over wss://generativelanguage.googleapis.com (TLSv1.3,
    authorized=true, server setupComplete), with no mocks. Raw inputTranscription wire frames matched the provider
    callbacks 1:1.
  • Local barge-in armed: supportsBargeIn: true, handlesInputAudioBargeIn: false.
  • Caller audio: Google TTS → ffmpeg … -f mulaw → 20 ms frames.
  • Echo: outbound audio at −12 or −18 dB with a 40 ms delay.
  • Each row is one live call.
Scenario Local speech detections / clears Google VAD interrupts (→ clears) turn.cancelled Caller turn
A echo-only −12 dB, merge base 12 / 12 9 (8) 20 — (echo committed as user:)
A echo-only −12 dB, head 0 / 0 10 (10) 10 — (echo committed as user:)
A echo-only −18 dB, head 0 / 0 9 (9) 9 — (echo committed as user:)
B caller overlaps playout, head 0 / 0 during 2023 ms of overlap 2 (2), first 2033 ms after caller onset 2 delivered and answered
C caller after playout + 400 ms tail, head 1 / 1, 292 ms after caller onset 2 (1) 1 delivered

What this shows:

  • The local echo barge-in is fixed. It went from 12 to 0 at −12 dB, and was 0 at −18 dB.
  • Echo still cancels turns in this setup. Google's server-side VAD, left at the provider defaults, interrupts on
    the echo 9–10 times per greeting. Google's transcription of the echo is still committed as a user: turn while
    the caller is silent. The mask removes only the host's barge-ins on echo.
  • Genuine caller turns are delivered. In B and C, the question was committed and answered. Echo words
    ("Hello.", "the capital.") were merged into the delivered turn.
  • Measured cost (the P1). In B, the caller was about 12 dB louder than the echo (voiced RMS 0.169 vs 0.043). They
    spoke over the assistant for 2023 ms, and the local gate never fired. Only Google's VAD stopped playback, 2.03 s
    after caller onset. A bridge without provider barge-in would have kept playing until the queue and the 400 ms tail
    finished. While assistant audio plays, the local gate does not interrupt. Interruption is deferred until playout
    ends; it is not removed (C: the gate fired 292 ms after onset once the window closed).

Not exercised: a PSTN or acoustic echo path, a bridge with no provider VAD (the B conclusion for such bridges is
inferred), other providers or models, and repeat runs.

Assistant audio leaks back through the phone line, and the local RMS gate treated
that echo as caller speech: it fired spurious barge-ins that cancelled the bot's
own turn, and at end-of-turn it produced "phantom" user transcripts (including
whole sentences the caller never said) that were stored as caller speech.

Split input accounting by an assistant-audio window: while the paced telephony
queue still holds audio, or within ASSISTANT_SPEECH_TAIL_MS of the last outbound
chunk, input energy is recorded as echo and cannot arm the barge-in gate or
count as caller speech. Only sustained speech heard on a quiet line sets
lastLocalAudioAt and triggers barge-in.

Also guard the final-transcript path: a transcript is dropped as phantom only
when no caller audio was seen for PHANTOM_GUARD_MAX_AGE_MS and the loudest input
since the last transcript was below PHANTOM_GUARD_MIN_RMS - a loud caller is
never discarded.
@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added channel: voice-call Channel integration: voice-call size: S labels Sep 26, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 4, 2026, 6:01 PM ET / 22:01 UTC (Revision 11).

ClawSweeper review

What this changes

The Voice Call plugin tracks carrier playout duration and suppresses local speech-triggered interruption during assistant playback and a 400 ms tail.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 4 items remain

This PR remains useful and is not implemented on current main. The carrier-backlog blocker is fixed, but the previously reported fallback-interruption regression still lacks explicit Voice Call owner acceptance.

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

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong, candid production-boundary evidence supports the partial repair, but the existing interruption contract remains unresolved.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The recorded run exercised the real handler and carrier WebSocket against Google Live with injected media-frame echo, showing local detections fall from 12 to zero and caller turns remain delivered. That proof covers the retained masking mechanism at the tested revision; the latest backlog correction has source and regression coverage rather than new live measurements. PSTN echo and provider-side symptoms were explicitly outside the proven result. No stored-data contract changes.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The recorded run exercised the real handler and carrier WebSocket against Google Live with injected media-frame echo, showing local detections fall from 12 to zero and caller turns remain delivered. That proof covers the retained masking mechanism at the tested revision; the latest backlog correction has source and regression coverage rather than new live measurements. PSTN echo and provider-side symptoms were explicitly outside the proven result. No stored-data contract changes.
Evidence reviewed 10 items Verified introduced change: The pinned merge-base-to-head diff adds playout accounting and replaces incoming RMS with zero throughout assistant playback. It also changes the existing bridge-override test from interruption during playback to interruption after playback.
Current main still needs the local echo repair: Current main directly feeds incoming mu-law RMS into the speech gate and invokes local interruption when the bridge does not handle input-audio barge-in. The corresponding current-main test still expects loud caller input to interrupt during assistant playback.
Latest release preserves fallback interruption: The supplied latest-release commit also directly feeds RMS into the local gate. Thus the PR changes an existing shipped fallback behavior; this is not an implemented-on-main cleanup.
Findings 1 actionable finding [P1] Preserve fallback interruption or obtain explicit owner acceptance
Security None None.

How this fits together

Voice Call relays caller audio from a carrier WebSocket to a realtime voice provider and paces assistant audio back to the carrier. Its local speech gate supplies interruption when the provider bridge does not own that behavior.

flowchart TD
  A[Caller audio] --> B[Carrier WebSocket]
  B --> C[Local speech gate]
  B --> D[Realtime voice provider]
  D --> E[Assistant audio pacer]
  E --> F[Carrier playback]
  E --> G[Playback window]
  G --> C
  C --> H[Fallback interruption]
Loading

Decision needed

Question Recommendation
Should Voice Call accept suppressing fallback caller interruption throughout assistant playout and its 400 ms tail? Accept and document deferred fallback interruption: Explicitly approve the measured tradeoff and document that fallback bridges cannot interrupt during assistant playout.

Why: The patch measurably removes local echo interruptions but changes shipped caller-interruption behavior; choosing that tradeoff requires owner intent.

Before merge

  • Preserve fallback interruption or obtain explicit owner acceptance (P1) - When handlesInputAudioBargeIn is false, this gate supplies caller interruption. Feeding zero throughout assistant playout also prevents genuine callers from stopping playback; callers whose utterance ends inside the window may never trigger it. Current main and the latest release preserve that interruption, and the live observation measured 2023 ms of overlap without a local detection. This previously reported blocker remains unresolved: preserve an echo-safe overlap path or obtain explicit Voice Call owner acceptance and document the changed contract.
  • Resolve merge risk (P2) - Existing bridges that rely on local interruption will no longer stop assistant playback when a caller speaks during playout or its 400 ms tail; a short interruption that ends inside that window may never trigger the fallback. Explicit owner acceptance and documentation, or an echo-safe overlap path, remain required.
  • Complete next step (P2) - Obtain explicit Voice Call owner acceptance and document suppressed fallback interruption during playout, or preserve an echo-safe overlap path before merge.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

  • [P1] Preserve fallback interruption or obtain explicit owner acceptance — extensions/voice-call/src/webhook/realtime-handler.ts:1356-1357
Agent review details

Security

None.

PR surface

Source +33, Tests +182. Total +215 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 34 1 +33
Tests 3 202 20 +182
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 236 21 +215

Review metrics

Metric Value Why it matters
Production versus test growth production +34/-1; tests +202/-20 Production growth supplies playout accounting and masking; the tests cover carrier backlog and the changed interruption contract.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #159140
Summary: This PR is a partial candidate fix for the canonical echo report, leaving provider interruption and phantom transcripts unresolved.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Approve the measured tradeoff (recommended)
    Obtain explicit Voice Call owner acceptance and document the loss of interruption during fallback playback before merging.
  2. Keep overlap interruption
    Preserve a bounded echo-safe interruption path for bridges without provider-owned barge-in.

Technical review

Best possible solution:

Retain the measured local echo repair under an explicitly approved and documented fallback-interruption contract, while keeping provider echo and phantom transcripts tracked separately.

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

Yes: source establishes the fallback regression when a bridge does not own barge-in and caller speech arrives during assistant playout. The contributor's real Google Live observation corroborates the masking effect; this review did not execute a call.

Is this the best way to solve the issue?

Unclear: masking is a small, measured fix for local echo, but it also masks genuine callers and does not solve provider-side echo or phantom transcripts. It needs explicit acceptance of that narrower contract or an echo-safe overlap alternative.

Full review comments:

  • [P1] Preserve fallback interruption or obtain explicit owner acceptance — extensions/voice-call/src/webhook/realtime-handler.ts:1356-1357
    When handlesInputAudioBargeIn is false, this gate supplies caller interruption. Feeding zero throughout assistant playout also prevents genuine callers from stopping playback; callers whose utterance ends inside the window may never trigger it. Current main and the latest release preserve that interruption, and the live observation measured 2023 ms of overlap without a local detection. This previously reported blocker remains unresolved: preserve an echo-safe overlap path or obtain explicit Voice Call owner acceptance and document the changed contract.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against a58fe52a98b5.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The change addresses cancelled spoken replies in live calls while introducing a blocking change to genuine caller interruption.
  • merge-risk: 🚨 compatibility: Merging changes existing fallback bridges from interruptible playback to suppression throughout playout and a 400 ms tail without owner acceptance.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The recorded run exercised the real handler and carrier WebSocket against Google Live with injected media-frame echo, showing local detections fall from 12 to zero and caller turns remain delivered. That proof covers the retained masking mechanism at the tested revision; the latest backlog correction has source and regression coverage rather than new live measurements. PSTN echo and provider-side symptoms were explicitly outside the proven result. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The recorded run exercised the real handler and carrier WebSocket against Google Live with injected media-frame echo, showing local detections fall from 12 to zero and caller turns remain delivered. That proof covers the retained masking mechanism at the tested revision; the latest backlog correction has source and regression coverage rather than new live measurements. PSTN echo and provider-side symptoms were explicitly outside the proven result. No stored-data contract changes.

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)
  • moellenbeck: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • LiuwqGit: 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.

  • Obtain explicit Voice Call owner acceptance and document deferred fallback interruption, or preserve an echo-safe overlap path.

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 (10 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-27T21:38:27.949Z sha 4eb648d :: needs real behavior proof before merge. :: [P1] Reset or adapt the echo floor when playback level changes | [P2] Wait for delivered frames instead of sleeping in the regression test
  • reviewed 2026-09-27T21:57:06.010Z sha 2181c26 :: needs real behavior proof before merge. :: [P1] Base the echo tail on audio reaching the carrier | [P1] Preserve recognized callers below the echo margin
  • reviewed 2026-09-28T03:57:43.850Z sha a6ec34f :: needs real behavior proof before merge. :: [P1] Reset the echo floor when playback is cleared | [P1] Keep recognized callers below the ambiguity margin
  • reviewed 2026-09-28T04:36:22.841Z sha 9b0e825 :: needs real behavior proof before merge. :: [P1] Preserve interruption for bridges without provider barge-in
  • reviewed 2026-09-28T05:03:51.400Z sha 9b0e825 :: blocked before merge. :: [P1] Preserve or explicitly approve interruption on fallback bridges
  • reviewed 2026-09-28T05:17:06.989Z sha 9b0e825 :: blocked before merge. :: [P1] Preserve fallback interruption or obtain owner acceptance
  • reviewed 2026-10-04T21:05:49.846Z sha 8ad1dd5 :: blocked before merge. :: [P1] [P1] Preserve fallback interruption or obtain explicit owner acceptance | [P2] [P2] Retain carrier backlog when calculating the playout deadline
  • reviewed 2026-10-04T21:44:39.600Z sha 13386d2 :: blocked before merge. :: [P1] Preserve fallback interruption or obtain explicit owner acceptance

The phantom-transcript guard suppressed a final caller turn whenever no
quiet-line caller audio had been seen and the loudest input was weak. A
caller who talks over the assistant never produces quiet-line audio, so
their turn could be dropped as a phantom.

Learn the leaked-playback floor from assistant-active input frames and only
treat overlap energy that clearly exceeds it (2.5x) as caller speech. The
floor is compared against the samples learned before the current frame, so a
loud frame cannot raise the threshold it is being judged against. Also decide
suppression before emitting transcript.done/input.audio.committed, so a
suppressed phantom never reaches the observer as committed caller input.
@mnowrot

mnowrot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The findings from the last review have been addressed on the current head; the PR body now carries a "Review response" section with the reworked behaviour and the after-fix regression tests (names + exact command + observed result). passes on the branch.

@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

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 merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Sep 26, 2026
…ence

The phantom-transcript guard treated missing local caller evidence as echo:
lastLocalAudioAt === 0 counted as "stale", so any provider-committed final
user transcript without qualifying local RMS energy was dropped. That
discarded genuine caller turns (provider-side VAD, no inbound media, quiet
callers) and broke 24 realtime-handler tests.

- Drop a committed final user transcript only when assistant audio is on the
  line now, echo was heard under it this turn, no input rose above the
  learned leak floor or the speech gate, and no quiet-line input was as loud
  as the echo. Per-turn caller evidence replaces the 15 s age window.
- Gate local barge-in on the learned echo floor instead of ignoring all
  overlap: caller frames clearly above the floor still barge in, echo does
  not. Learn the floor only from echo-attributed frames so a sustained
  interruption cannot raise its own threshold; before a floor exists, assume
  echo may reach the speech-gate threshold.
- Restore transcript.delta (with role) for user partials, which the guard
  refactor had re-labelled output.text.delta.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Sep 27, 2026
mnowrot and others added 2 commits September 27, 2026 23:48
The echo floor that separates leaked assistant audio from caller speech was
call-long and learned only from echo-attributed frames. After a quiet playback
segment set a low floor, a louder later segment's bleed cleared floor x 2.5,
was classified as caller audio, and armed the false local barge-in this guard
exists to prevent. The mirror case also held: a floor learned under loud
playback hid a caller talking over later, quieter playback.

- Reset the floor whenever assistant audio resumes after the line went quiet
  (no pending paced audio and past the playback tail), so each segment is
  judged against its own leak level. The segment's first frames fall back to
  the existing cold-start assumption (echo may reach the speech gate), and only
  echo-attributed frames still teach the floor.
- Echo-guard tests wait for the bridge to receive each carrier frame, which the
  handler does only after its input accounting runs, instead of sleeping 80 ms.
- Cover a louder echo-only segment after a quiet one with a silent caller: no
  barge-in and no committed caller turn.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ambiguous caller turns

The echo tail started when the provider handed audio to the pacer, not when
that audio finished playing. For a chunk the pacer needed longer than the
400 ms tail to send, the tail expired while playout continued, so once the
queue drained the remaining playback and its echo counted as caller speech
and armed the false barge-in this guard exists to prevent. The per-segment
echo-floor reset used the same signal and could fire mid-playout.

- The pacer projects its paced stream clock onto the wall clock each time
  it sends a frame (getPlayoutEndsAt) and clamps it when playback is
  cleared. Assistant audio counts as on the line while audio is queued or
  until that playout end plus the tail.

The phantom-transcript guard dropped a committed caller turn whenever no
overlap frame cleared the 2.5x barge-in margin, so a caller answering over
playback at a moderate level lost a correctly finalized turn.

- Overlap input more than 1.25x above the learned segment floor is too weak
  to barge in but marks the turn ambiguous; the provider's transcript is
  kept. Suppression now needs echo that never rose above its own floor.

Tests: a 4 s chunk paced past the tail yields no barge-in and no echoed
turn; a caller at ~1.4x the echo floor over playback keeps their turn.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mnowrot

mnowrot commented Sep 28, 2026

Copy link
Copy Markdown
Contributor Author

Live after-fix observation — negative result (real Google Live session, simulated line echo)

I ran the real-call observation ClawSweeper has been asking for. It ran, the transport is real, and the result is negative: on a real provider session the current handler does not stop assistant echo from being taken as caller speech. I'm posting it because the negative result is the evidence, and it drives the change I'm making next (see the note at the end).

Head tested: 2181c268, extensions/voice-call/src/webhook/realtime-handler.ts blob 1c987a40. This is the head the observation was built against. The current PR head a6ec34f7 changes the echo-window signal (getPlayoutEndsAt()) and adds ambiguity handling, so I have not re-run this against a6ec34f7; the core mechanism below (a per-segment floor learned from quiet onset frames) is unchanged by it, but I'm not claiming a number for a head I didn't run.

Scope: a real Google Live provider session with real speech audio, through the real RealtimeCallHandler and a real carrier WebSocket (Twilio media-stream protocol), with a real SQLite call store read back with findCallInStore. The line echo is simulated at the media-frame level: every outbound assistant media frame is attenuated −12 dB or −18 dB, delayed 40 ms, and mixed into the inbound stream. This is not a PSTN/telephony call.

Setup:

  • Model gemini-2.5-flash-native-audio-preview-12-2025 over TLS to generativelanguage.googleapis.com, server setupComplete, no mocks (no vi.mock/nock/msw).
  • Assistant speaks a queued greeting. Caller speech (scenario B) is real Google TTS, transcoded with ffmpeg -f s16le -ar 24000 -ac 1 -i caller.pcm24k -ar 8000 -ac 1 -f mulaw caller.ulaw to 20 ms frames.
  • The local barge-in gate is armed (handlesInputAudioBargeIn: false), the configuration where the handler's own RMS gate owns barge-in.
  • One live call per row.
Run Handler Echo Local barge-ins on echo Phantom suppressed Phantom caller turn stored
A echo-only after 1c987a40 −12 dB 2 (446, 765 ms) 0 yes — "Hello, the firm your dentist approach."
A echo-only after 1c987a40 −18 dB 4 (168–658 ms) 0 yes
A echo-only merge base 7ff7042, blob a8bdb29d −12 dB 2 (~100 ms) n/a yes
A echo-only b918ba3c, blob 93f347bb −12 dB 0 0 yes
B overlap after 1c987a40 −12 dB 1 caller-driven + 1 echo-driven 0 caller turn delivered

What this shows

  1. Echo still triggers local barge-in after the fix. Each playback segment learns its floor from the quiet onset frames (RMS 0.0001–0.03). The next voiced echo syllable (0.04–0.10) then clears floor × 2.5 and the 0.035 speech gate. Example (−12 dB, segment age 446 ms): echo:0.0067 0.0025 0.0016 0.0017 0.0015 0.0040 0.0553 0.0612 → realtime local speech detected. Compared with the merge base the fix delays echo barge-in (~100 ms → 170–800 ms into a segment) but does not prevent it. The unit tests pass because their synthetic ECHO_MULAW frames are constant-level and have no onset dynamics — a hypothesis for the gap, not a verified cause.
  2. The phantom guard never fired. In every run Google delivered the caller's final inputTranscription only when the session closed, by which point the line had been quiet for 6 s, so isAssistantAudioActive() was false and the guard's first condition could not hold. In the after-fix runs the false local detections had also already set callerAudioSinceTranscript. Recognized echo was committed as a caller turn in every echo run — including on b918ba3c, which had zero echo barge-ins.
  3. Genuine overlap works. Scenario B: caller voiced RMS 0.169 (max 0.374) vs echo 0.043 (max 0.104), ~12 dB above the echo; 80 frames of true overlap. The caller turn "What is the capital of France?" was delivered and answered ("The capital of France is Paris."). That answer was then cut by an echo-only local barge-in 324 ms into its playback (frames 0.0736, 0.1043).
  4. b918ba3c (an earlier commit of this PR) fully masked the local gate during playback and had zero echo barge-ins at −12 dB. The later revisions reintroduced them.

What this does not cover: a phone network or acoustic/hybrid echo path (the echo here is a clean scaled+delayed copy, no line noise or carrier re-encode); the default Google deployment where the provider owns barge-in (handlesInputAudioBargeIn: true); OpenAI Realtime or other models; repeat runs for statistics.

Redacted per-frame traces, handler log lines, raw inputTranscription wire frames, and the stored transcripts are in the artifact set (key, call IDs, numbers, and endpoint path/query redacted).

Next: this result is why I'm replacing the approach rather than adding another revision. I'm cutting the diff down to what the observation actually supports — hold the echo window through paced playout and keep the local barge-in gate closed while assistant audio is draining, dropping the learned-floor and phantom-transcript machinery — and will post a fresh observation against the new head. The phantom-transcript half of the issue is provider-driven (the provider emits the transcription; we cannot reliably separate it at the media frame) and will be stated as such rather than patched at this layer.

The local RMS gate cannot tell echo of our own paced playout from the caller,
so it hears silence while assistant audio is on the line (paced playout plus a
400 ms tail). Inbound audio is still forwarded to the provider throughout.
Drop the per-segment echo floor and the phantom-transcript guard: the provider
owns barge-in and transcription during playout.

The three realtime-handler tests that asserted local barge-in during playout
now assert the masking and the local fallback once the window has closed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. label Sep 28, 2026
@mnowrot

mnowrot commented Sep 28, 2026

Copy link
Copy Markdown
Contributor Author

Decision needed: accept the altered interruption contract, or hold — with the current-head real-call proof

This PR changes a documented behaviour: while assistant audio is playing out (plus a 400 ms tail), the plugin's own RMS gate no longer interrupts. On bridges that do not handle input-audio barge-in, that gate is the only interruption path. @clawsweeper asks for an explicit ownership decision before merge, and that is the honest ask. Below is the current-head evidence and our position.

Position: accept the contract change. The interruption this removes is the reported bug. Issue #159140 is about the agent's own leaked audio being taken as caller speech and cancelling the agent's turn. The level gate cannot tell echo from a caller — the observation below measures that directly. Removing it during playout is the fix; the cost is that a genuine caller who overlaps playout is not interrupted by the plugin until playout ends.

Proof: real Google Live session on the current head

Head: 9b0e825a4bc37ce6c08a361e499737e43906fb8a, extensions/voice-call/src/webhook/realtime-handler.ts blob 6894b015. Contrast: merge base 7ff7042d, blob a8bdb29d.

Real RealtimeCallHandler, real carrier WebSocket (Twilio media-stream protocol), real SQLite store read back with findCallInStore, real Google Live session (gemini-2.5-flash-native-audio-preview-12-2025 over wss://generativelanguage.googleapis.com, TLSv1.3, server setupComplete), no mocks. Caller audio is real speech (Google TTS → ffmpeg → mu-law, 20 ms frames). Local barge-in armed (supportsBargeIn: true, handlesInputAudioBargeIn: false). Echo is the outbound assistant frames attenuated −12 / −18 dB and delayed 40 ms, mixed into the inbound stream. One live call per row.

Run Handler Local speech detections / clears Google VAD interrupts (→ clears) turn.cancelled Stored caller turn
Echo-only −12 dB merge base a8bdb29d 12 / 12 (80–1860 ms into a segment) 9 (8) 20 echo text (caller silent)
Echo-only −12 dB head 6894b015 0 / 0 10 (10) 10 echo text (caller silent)
Echo-only −18 dB head 0 / 0 9 (9) 9 echo text (caller silent)
Caller overlaps playout head 0 / 0 across 2023 ms of overlap 2 (2), first 2033 ms after caller onset 2 delivered, answered
Caller after playout + tail head 1 / 1, 292 ms after caller onset 2 (1) 1 delivered, answered

Caller in the overlap run was ~12 dB above the echo (voiced RMS 0.169 vs 0.043; 99 mixed frames). Per-frame traces, raw inputTranscription wire frames, handler lines and stored transcripts are in the artifact set (key, call ids, numbers and endpoint path/query redacted).

What this shows, and what it does not

  1. The plugin-side echo barge-in is fixed. 12 → 0 at −12 dB, and 0 at −18 dB, on the merge base vs this head. The masking works for what the plugin controls.
  2. Echo still cancels turns end to end in the default Google setup — because Google's own server-side VAD, at provider defaults, still hears the echo and raises its own interruption (9–10 per greeting). The plugin cannot veto that; it is decided provider-side before the plugin sees it. Google's transcription of the echo is still committed as a user: turn while the caller is silent.
  3. Genuine caller turns are delivered, and echo words are still merged into them ("Hello.", "the capital.").
  4. The measured cost (the P1). A caller ~12 dB above the echo spoke over the assistant for 2023 ms and the local gate never fired. A bridge with no provider VAD would have kept playing until the queue and the 400 ms tail drained. Interruption is deferred, not removed — once the window closed the gate fired 292 ms after caller onset (last row).
  5. Not exercised: a PSTN/telephony or acoustic/hybrid echo path (the echo here is a clean scaled+delayed copy), a bridge with no provider VAD (the deferral conclusion for such bridges is inferred, not observed), other models/providers, repeat runs. Each row is one call.

Two consequences

  • This does not fully close [Bug]: realtime voice call treats the agent's own leaked audio as caller speech #159140. It removes the plugin-side false barge-in; it cannot remove the provider-side one, nor the provider-committed echo transcript. The PR body is updated from Closes #159140 to Refs #159140, and the phantom-transcript half stays open as a provider-driven follow-up.
  • The three existing realtime-handler.test.ts cases that asserted local barge-in during playout now assert the new contract (no barge-in during playout; fallback intact after the window). Rationale is in the PR body.

Maintainers: accept the altered contract (recommended — the removed behaviour is the reported bug), or hold for a bounded overlap path. We do not have a media-frame signal that reliably separates echo from genuine overlap; that is the measured finding, not an assumption.

@clawsweeper re-review

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 28, 2026
@mnowrot

mnowrot commented Sep 28, 2026

Copy link
Copy Markdown
Contributor Author

@steipete — flagging this for the Voice Call owner decision, since it changes a documented behaviour in extensions/voice-call/src/webhook/realtime-handler.ts.

What changed: while paced assistant audio is playing out (plus the 400 ms tail), the plugin's local RMS gate no longer interrupts. That removes the echo-triggered self-cancellation this PR was opened for, but it also defers genuine caller interruption on bridges that rely on the local gate (no provider-owned barge-in).

What the current-head real-call evidence shows: local echo detections fall from 12 on the merge base to 0 on this head, genuine caller turns are still delivered, and the post-window gate still fires. The measured cost is 2023 ms of genuine overlap without a local detection. Provider-side (Google VAD) echo interruption and the provider-committed echo transcript remain — both stay open in #159140; this PR is Refs, not Closes.

ClawSweeper's current review (Rev 8) recommends accepting the deferred-interruption contract and documenting it. The blocker is that acceptance, not a further code change.

Could you confirm whether Voice Call accepts deferred local interruption on fallback bridges, or wants a bounded interruption path before merge? The full trace and trade-off are in the decision comment above.

…arge-in-guard

Resolve the realtime-handler.test.ts conflict on main's test scaffold
(bargeInHarness, sendMedia, expectFrame, talkEvents):

- Re-express the playout-masking contract on the two barge-in tests main
  kept: the session-bridge override test now asserts no local barge-in
  while assistant audio plays out and the fallback once the window closes;
  the late local barge-in test advances past the playout tail first.
- Take main's removal of the continuity-reset mark test and of the
  provider-without-speech-started fallback test (openclaw#162202). The masking and
  post-window fallback for that provider shape stay covered by
  realtime-handler.echo-guard.test.ts; its output.audio.done turn
  assertion moves into the override test.
- Drop the echo-guard test's own teardown: main's connectCarrierStream
  now registers socket, handler, and server cleanup, so closing again
  failed with ERR_SERVER_NOT_RUNNING.
roboclaw-bot added a commit that referenced this pull request Nov 2, 2026
…91537)

Ignore unconfirmed caller transcripts during carrier playback and its 400 ms echo tail at the existing audio controller. Preserve local RMS and provider barge-in, and keep admitted caller partials eligible through their final transcript. Carrier playout accounting survives a drained local queue.

Supersedes #159145, thanks @mnowrot. Provider-owned echo interruptions and late transcripts remain tracked in #159140; the Deepgram UtteranceEnd fix is untouched.

Proof: fake carrier media and echoed STT words reproduce call.speech on main 77fadc0; green after the repair. Focused handler/pacer/controller tests passed 53/53, and expanded handler/lifecycle/call-control tests passed 75/75. Touched-file lint/format and independent Codex autoreview P0-P3 passed. PR CI supplies broad proof.

The 43-line regression allocation covers playback echo, tail expiry, both interruption owners and renewed playback without additional test scaffolding.

Co-authored-by: mnowrot <[email protected]>
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Thanks @mnowrot for the investigation and carrier playout-accounting work. The credited replacement landed in #191537 (2bbce75), with a playback/tail transcript gate that preserves caller interruption and a regression that fails on main and passes with the fix. Provider-owned echo behavior remains tracked in #159140.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 3, 2026
…enclaw#191537)

Ignore unconfirmed caller transcripts during carrier playback and its 400 ms echo tail at the existing audio controller. Preserve local RMS and provider barge-in, and keep admitted caller partials eligible through their final transcript. Carrier playout accounting survives a drained local queue.

Supersedes openclaw#159145, thanks @mnowrot. Provider-owned echo interruptions and late transcripts remain tracked in openclaw#159140; the Deepgram UtteranceEnd fix is untouched.

Proof: fake carrier media and echoed STT words reproduce call.speech on main 30e2969; green after the repair. Focused handler/pacer/controller tests passed 53/53, and expanded handler/lifecycle/call-control tests passed 75/75. Touched-file lint/format and independent Codex autoreview P0-P3 passed. PR CI supplies broad proof.

The 43-line regression allocation covers playback echo, tail expiry, both interruption owners and renewed playback without additional test scaffolding.

Co-authored-by: mnowrot <[email protected]>
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 23, 2026
…enclaw#191537)

Ignore unconfirmed caller transcripts during carrier playback and its 400 ms echo tail at the existing audio controller. Preserve local RMS and provider barge-in, and keep admitted caller partials eligible through their final transcript. Carrier playout accounting survives a drained local queue.

Supersedes openclaw#159145, thanks @mnowrot. Provider-owned echo interruptions and late transcripts remain tracked in openclaw#159140; the Deepgram UtteranceEnd fix is untouched.

Proof: fake carrier media and echoed STT words reproduce call.speech on main 77fadc0; green after the repair. Focused handler/pacer/controller tests passed 53/53, and expanded handler/lifecycle/call-control tests passed 75/75. Touched-file lint/format and independent Codex autoreview P0-P3 passed. PR CI supplies broad proof.

The 43-line regression allocation covers playback echo, tail expiry, both interruption owners and renewed playback without additional test scaffolding.

Co-authored-by: mnowrot <[email protected]>
(cherry picked from commit 2bbce75)

Release adaptation: Bounded echo suppression at existing audio controller; preserves local and provider barge-in and caller finals. Later greeting-audibility and late-transcript work remains separate.

Co-authored-by: RomneyDa <[email protected]>
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 merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants