Skip to content

Voice Call: enforce spoken-output contract and fix stream TTS silence regression - #51500

Merged
joshavant merged 12 commits into
openclaw:mainfrom
joshavant:fix/voice-call-plugin
Mar 21, 2026
Merged

joshavant merged 12 commits into
openclaw:mainfrom
joshavant:fix/voice-call-plugin

Conversation

@joshavant

@joshavant joshavant commented Mar 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This PR hardens voice-call response generation and Twilio streaming behavior to remove reasoning leakage, prevent silent playback failures, and close stream lifecycle edge cases.

Problem

Two issues were reproduced in voice-call flows:

  • Spoken replies could include reasoning/meta text.
  • Twilio streaming flows could go silent due to playback delivery failures, first-message lifecycle races, or stream reconnect/disconnect edge cases.

What Changed

1) Deterministic spoken output extraction

In extensions/voice-call/src/response-generator.ts:

  • Enforced a strict spoken-output contract ({"spoken":"..."}).
  • Added robust extraction for direct JSON, fenced JSON, and inline fallback.
  • Suppressed reasoning/meta/error payloads from spoken output.
  • Added sanitization/fallback behavior for malformed or mixed responses.

2) Initial-message and barge handling hardening

In extensions/voice-call/src/manager.ts, extensions/voice-call/src/manager/outbound.ts, and extensions/voice-call/src/webhook.ts:

  • Initial message is no longer cleared before successful playback.
  • Failed playback now resets state back to listening.
  • Added in-flight guard for initial-message replay to prevent concurrent double plays.
  • Barge suppression now ignores barge transcripts during initial greeting (and suppresses reply generation for those suppressed transcripts).
  • Conversation-mode answered-time deferral now waits for stream-connect only when Twilio stream-connect is actually available; otherwise it speaks on answered.

3) Twilio stream playback contract + reliability

In extensions/voice-call/src/providers/twilio.ts:

  • Active-stream contract is explicit:
    • If a stream is active, playback must use stream TTS.
    • If telephony TTS is unavailable while stream is active, playback fails (no TwiML fallback).
  • TwiML <Say> fallback remains only for calls without an active stream.
  • Stream playback fails when delivery is effectively zero (dropped chunks / unsent completion mark).

4) Stream reconnect/disconnect correctness

In extensions/voice-call/src/providers/twilio.ts and extensions/voice-call/src/webhook.ts:

  • unregisterCallStream now supports stream-SID-aware unregisters.
  • Stale disconnects no longer remove mappings for newer replacement streams.
  • Disconnect grace hangup now respects replacement streams correctly.

5) Media stream security hardening

In extensions/voice-call/src/media-stream.ts:

  • Added explicit WebSocket send backpressure ceiling using bufferedAmount.
  • When buffer exceeds threshold, sends fail and socket is closed with backpressure reason.
  • Sanitized and length-capped WebSocket close reasons before logging (control-char stripping).

Testing

Automated:

  • pnpm test -- extensions/voice-call/src/response-generator.test.ts
  • pnpm test -- extensions/voice-call/src/manager.notify.test.ts
  • pnpm test -- extensions/voice-call/src/providers/twilio.test.ts
  • pnpm test -- extensions/voice-call/src/media-stream.test.ts
  • pnpm test -- extensions/voice-call/src/webhook.test.ts
  • pnpm test -- extensions/voice-call/src/manager.notify.test.ts extensions/voice-call/src/providers/twilio.test.ts extensions/voice-call/src/media-stream.test.ts extensions/voice-call/src/webhook.test.ts

Repository checks were also run via scripts/committer for committed changes.

Notes

  • This PR no longer references getTtsDiagnostics(); final implementation uses explicit send-result semantics + delivery checks and does not expose that method.
  • Scope remains within extensions/voice-call behavior and tests.

@aisle-research-bot

aisle-research-bot Bot commented Mar 21, 2026 •

Copy link
Copy Markdown

🔒 Aisle Security Analysis

We found 1 potential security issue(s) in this PR:

# Severity Title
1 🟠 High Unbounded CPU consumption in windowed-sinc resampler (telephony-audio) enabling call-triggered DoS

1. 🟠 Unbounded CPU consumption in windowed-sinc resampler (telephony-audio) enabling call-triggered DoS

Property Value
Severity High
CWE CWE-400
Location extensions/voice-call/src/telephony-audio.ts:57-79

Description

The new resamplePcmTo8k() implementation uses a windowed-sinc FIR filter (RESAMPLE_FILTER_TAPS = 31) and performs expensive trigonometric operations per output sample.

  • Work per output sample is O(taps) and each tap computes sin()/cos() and performs a Buffer.readInt16LE().
  • The function processes the entire PCM buffer returned by TTS (convertPcmToMulaw8k() → resamplePcmTo8k()), and there are no hard caps on:
    • generated spoken text length (auto-response text is passed directly to TTS), or
    • maximum PCM duration/bytes resampled.
  • In Node.js this CPU-bound loop blocks the event loop; even the newly added TTS synthesis timeout in the Twilio streaming path cannot reliably preempt CPU-bound work.

Impact: A caller who can trigger long TTS outputs (e.g., via inbound transcripts influencing auto-responses) can cause high CPU usage and event-loop stalls, degrading or denying service.

Vulnerable code (hot loop + bandlimited sampling):

const outputSamples = Math.floor(inputSamples / ratio);
const output = Buffer.alloc(outputSamples * 2);

for (let i = 0; i < outputSamples; i++) {
  const srcPos = i * ratio;
  const sample = Math.round(
    sampleBandlimited(input, inputSamples, srcPos, cutoffCyclesPerSample),
  );
  output.writeInt16LE(clamp16(sample), i * 2);
}

Recommendation

Add hard limits to prevent unbounded resampling work, and fail fast when exceeded.

  1. Cap caller-facing text length before TTS (defense-in-depth):
const MAX_SPOKEN_CHARS = 800; // tune for your use-case
const spoken = result.text?.slice(0, MAX_SPOKEN_CHARS) ?? null;
  1. Cap PCM duration/bytes in convertPcmToMulaw8k() / resamplePcmTo8k():
const MAX_TTS_SECONDS = 30;
if (!Number.isFinite(inputSampleRate) || inputSampleRate <= 0) {
  throw new Error(`Invalid inputSampleRate: ${inputSampleRate}`);
}
const inputSamples = Math.floor(input.length / 2);
const maxSamples = Math.floor(inputSampleRate * MAX_TTS_SECONDS);
if (inputSamples > maxSamples) {
  throw new Error(`PCM too long (${inputSamples} samples)`);
}
  1. Consider optimizing the resampler to reduce per-sample trig (e.g., precompute the Hann window, avoid recomputing constants, or use a dedicated DSP/resampling library/native addon).

These controls prevent an attacker from turning long TTS outputs into CPU/memory exhaustion.


Analyzed PR: #51500 at commit b917125

Last updated on: 2026-03-21T09:43:55Z

@openclaw-barnacle openclaw-barnacle Bot added channel: voice-call Channel integration: voice-call size: XL maintainer Maintainer-authored PR labels Mar 21, 2026
@greptile-apps

greptile-apps Bot commented Mar 21, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR hardens voice-call reply generation and fixes a silence regression in Twilio streaming calls. The changes span five areas: (1) a JSON spoken-output contract injected into the system prompt with multi-strategy extraction and reasoning/meta-text filtering; (2) state-aware barge-in suppression (tied to call.state === "speaking" rather than metadata presence alone); (3) playback-failure recovery — transcript is only recorded after successful playTts and the call transitions back to listening on failure so it is never stuck; (4) a 2-second grace window on stream disconnect before auto-hangup to survive brief reconnects; and (5) drift-corrected chunk pacing, a keep-alive silence loop during synthesis, and a synthesis timeout in playTtsViaStream.

Key findings:

  • Bug (response-generator.ts): tryParseSpokenJson conflates "successfully parsed the contract but spoken is empty" with "could not parse any JSON contract at all" — both paths return null. When the model follows the contract and returns {"spoken":""} (explicitly instructed for "nothing to say"), extractSpokenTextFromPayloads treats the null as "not a contract" and falls through to sanitizePlainSpokenText, which processes the raw JSON string as conversational text and returns '{"spoken":""} to be spoken aloud to the caller. The fix is to use a distinct empty-string sentinel so that a valid but empty contract response short-circuits the plain-text fallback. There is also no test covering this {"spoken":""} case.
  • manager/outbound.ts: transcript entry moved to after successful playback and failure now correctly transitions state to listening — both are straightforward correctness improvements.
  • webhook.ts: the stream-disconnect grace window is well-guarded; clearPendingDisconnectHangup is called in onConnect before registerCallStream, which is the correct ordering. The hasRegisteredStream guard inside the deferred timer is redundant given that onConnect always cancels the timer first, but it is harmless defensive code.
  • telephony-audio.ts: the upgrade from linear interpolation to a windowed sinc low-pass kernel is a genuine audio quality improvement and is well-tested.

Confidence Score: 3/5

  • Safe to merge after fixing the empty-spoken-output fallthrough bug in response-generator.ts; all other changes are well-reasoned and well-tested.
  • One concrete P1 logic bug exists: the {"spoken":""} contract response is supposed to produce silence but instead falls through to plain-text processing and speaks the raw JSON string to the caller. The contract explicitly instructs the model to return this payload, making the bug reproducible in normal usage. All other changes (state machine fixes, grace-period hangup, keep-alive TTS, sinc resampling) are correct and backed by new tests. A targeted one-line sentinel fix in tryParseSpokenJson resolves the issue.
  • extensions/voice-call/src/response-generator.ts — the empty spoken-output fallthrough bug.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: extensions/voice-call/src/response-generator.ts
Line: 77-84

Comment:
**Empty `{"spoken":""}` contract response falls through to plain-text, speaking the raw JSON**

When the model correctly follows the contract and returns `{"spoken":""}` (which the contract explicitly instructs for "nothing to say"), `tryParseSpokenJson` parses the JSON successfully and calls `normalizeSpokenText("")`, which returns `null`. Since `null` is returned, `extractSpokenTextFromPayloads` at line 155–161 treats this as "couldn't parse the JSON contract" and falls through to `sanitizePlainSpokenText(rawText)`.

`sanitizePlainSpokenText` then processes the raw string `{"spoken":""}` as plain conversational text, which passes all filters (it's a single paragraph, not meta-reasoning), and ultimately returns `"{"spoken":""}"` — causing that literal JSON string to be spoken to the caller.

The problem is that `tryParseSpokenJson` conflates two distinct outcomes with a single `null` return:
- **"Successfully parsed the contract but `spoken` is empty"** → caller should hear nothing.
- **"Could not find/parse any JSON contract at all"** → should fall back to plain-text extraction.

Only the second case should trigger the plain-text fallback. A targeted fix is to use a sentinel for "successfully parsed but empty":

```typescript
// In tryParseSpokenJson, before returning normalizeSpokenText(parsed.spoken):
const normalized = normalizeSpokenText(parsed.spoken);
return normalized ?? "";   // "" = "parsed OK, nothing to say"; null = "not a contract"
```

Then in `extractSpokenTextFromPayloads`:

```typescript
const structured = tryParseSpokenJson(rawText);
if (structured !== null) {       // null means "not a contract"
  if (structured.length > 0) {   // "" means "contract says nothing"
    spokenSegments.push(structured);
  }
  continue;                      // Either way, don't fall through to plain-text
}
// ... plain-text path unchanged
```

The same fix should be applied to the inline-fallback path (line 83–93): `!inlineSpokenMatch?.[1]` currently returns `null` for both "no match" and "matched but group is empty string". For an empty-string match the function should also return `""` rather than `null` so the plain-text fallback is not triggered.

How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: "voice-call: fix sile..."

Comment on lines +77 to +84
return normalizeSpokenText(parsed.spoken);
} catch {
// Continue trying other candidates.
}
}

const inlineSpokenMatch = trimmed.match(/"spoken"\s*:\s*"((?:[^"\\]|\\.)*)"/i);
if (!inlineSpokenMatch?.[1]) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Empty {"spoken":""} contract response falls through to plain-text, speaking the raw JSON

When the model correctly follows the contract and returns {"spoken":""} (which the contract explicitly instructs for "nothing to say"), tryParseSpokenJson parses the JSON successfully and calls normalizeSpokenText(""), which returns null. Since null is returned, extractSpokenTextFromPayloads at line 155–161 treats this as "couldn't parse the JSON contract" and falls through to sanitizePlainSpokenText(rawText).

sanitizePlainSpokenText then processes the raw string {"spoken":""} as plain conversational text, which passes all filters (it's a single paragraph, not meta-reasoning), and ultimately returns "{"spoken":""}" — causing that literal JSON string to be spoken to the caller.

The problem is that tryParseSpokenJson conflates two distinct outcomes with a single null return:

  • "Successfully parsed the contract but spoken is empty" → caller should hear nothing.
  • "Could not find/parse any JSON contract at all" → should fall back to plain-text extraction.

Only the second case should trigger the plain-text fallback. A targeted fix is to use a sentinel for "successfully parsed but empty":

// In tryParseSpokenJson, before returning normalizeSpokenText(parsed.spoken):
const normalized = normalizeSpokenText(parsed.spoken);
return normalized ?? "";   // "" = "parsed OK, nothing to say"; null = "not a contract"

Then in extractSpokenTextFromPayloads:

const structured = tryParseSpokenJson(rawText);
if (structured !== null) {       // null means "not a contract"
  if (structured.length > 0) {   // "" means "contract says nothing"
    spokenSegments.push(structured);
  }
  continue;                      // Either way, don't fall through to plain-text
}
// ... plain-text path unchanged

The same fix should be applied to the inline-fallback path (line 83–93): !inlineSpokenMatch?.[1] currently returns null for both "no match" and "matched but group is empty string". For an empty-string match the function should also return "" rather than null so the plain-text fallback is not triggered.

Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/voice-call/src/response-generator.ts
Line: 77-84

Comment:
**Empty `{"spoken":""}` contract response falls through to plain-text, speaking the raw JSON**

When the model correctly follows the contract and returns `{"spoken":""}` (which the contract explicitly instructs for "nothing to say"), `tryParseSpokenJson` parses the JSON successfully and calls `normalizeSpokenText("")`, which returns `null`. Since `null` is returned, `extractSpokenTextFromPayloads` at line 155–161 treats this as "couldn't parse the JSON contract" and falls through to `sanitizePlainSpokenText(rawText)`.

`sanitizePlainSpokenText` then processes the raw string `{"spoken":""}` as plain conversational text, which passes all filters (it's a single paragraph, not meta-reasoning), and ultimately returns `"{"spoken":""}"` — causing that literal JSON string to be spoken to the caller.

The problem is that `tryParseSpokenJson` conflates two distinct outcomes with a single `null` return:
- **"Successfully parsed the contract but `spoken` is empty"** → caller should hear nothing.
- **"Could not find/parse any JSON contract at all"** → should fall back to plain-text extraction.

Only the second case should trigger the plain-text fallback. A targeted fix is to use a sentinel for "successfully parsed but empty":

```typescript
// In tryParseSpokenJson, before returning normalizeSpokenText(parsed.spoken):
const normalized = normalizeSpokenText(parsed.spoken);
return normalized ?? "";   // "" = "parsed OK, nothing to say"; null = "not a contract"
```

Then in `extractSpokenTextFromPayloads`:

```typescript
const structured = tryParseSpokenJson(rawText);
if (structured !== null) {       // null means "not a contract"
  if (structured.length > 0) {   // "" means "contract says nothing"
    spokenSegments.push(structured);
  }
  continue;                      // Either way, don't fall through to plain-text
}
// ... plain-text path unchanged
```

The same fix should be applied to the inline-fallback path (line 83–93): `!inlineSpokenMatch?.[1]` currently returns `null` for both "no match" and "matched but group is empty string". For an empty-string match the function should also return `""` rather than `null` so the plain-text fallback is not triggered.

How can I resolve this? If you propose a fix, please make it concise.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ded14c6f26

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +664 to +665
throw new Error(
"Cannot use TwiML fallback while media stream is active; telephony TTS is unavailable",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restore audio fallback for streaming calls without telephony TTS

extensions/voice-call/src/runtime.ts:216-236 still treats “Twilio streaming enabled, but no textToSpeechTelephony runtime” as a supported configuration and only logs that streaming TTS is disabled. After this change, once a stream is registered, playTts() throws here instead of using the existing TwiML <Say> fallback, so every response on those deployments becomes silent whenever telephony TTS is unavailable or fails to initialize.

Useful? React with 👍 / 👎.

Comment on lines +262 to +264
// Clear only after successful playback so transient provider failures can retry.
if (call.metadata) {
delete call.metadata.initialMessage;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Guard initial greeting against overlapping replay triggers

Clearing metadata.initialMessage only after await speak(...) makes speakInitialMessage() re-entrant. extensions/voice-call/src/webhook.ts calls this on every Twilio stream connect, so if the stream reconnects or a duplicate answered/connect event arrives while the first greeting is still playing, the second invocation still sees initialMessage and queues the same greeting again. Before this change the field was cleared up front, so the duplicate trigger was a no-op.

Useful? React with 👍 / 👎.

@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Mar 21, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d5a77fe0af

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +284 to +288
if (mode === "conversation") {
const shouldWaitForStreamConnect =
this.provider?.name === "twilio" && this.config.streaming.enabled;
if (shouldWaitForStreamConnect) {
return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Fall back to answered-time greeting when streaming is unavailable

This now suppresses the outbound conversation greeting whenever provider.name === "twilio" && config.streaming.enabled, but that flag does not guarantee a stream will ever connect. In this same codepath initializeMediaStreaming() can bail out when no OpenAI key is present, and TwilioProvider only emits <Connect><Stream> when it has a public URL; in either case onConnect never fires. Those deployments used to speak the initial message on call.answered, but after this change the callee just gets silence because we wait for a stream that cannot exist.

Useful? React with 👍 / 👎.

Comment thread extensions/voice-call/src/webhook.ts Outdated
Comment on lines +194 to +198
if (suppressBargeIn) {
console.log(
`[voice-call] Skipping auto-response while initial message is still playing (${providerCallId})`,
);
return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Drop suppressed transcripts before they reach the call manager

When suppressBargeIn is true, this early return happens only after manager.processEvent(event) has already run above. processManagerEvent() treats that final call.speech as real user input: it appends the transcript and flips the call to listening. The result is that an outbound caller who speaks once during the greeting gets no reply at all—their utterance is consumed and recorded, but handleInboundResponse() is skipped here, so nothing ever answers it.

Useful? React with 👍 / 👎.

Comment on lines +234 to +236
if (this.provider.name === "twilio") {
(this.provider as TwilioProvider).unregisterCallStream(callId);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep reconnect grace keyed to the disconnected stream

This unregisters the call's stream by callId before starting the grace timer, but TwilioProvider stores only one callId -> streamSid mapping. If Twilio reconnects by opening a replacement stream before the old socket's disconnect callback arrives, that stale disconnect will delete the new mapping here; two seconds later hasRegisteredStream(callId) is false and we auto-end a call whose replacement stream is already active. The grace logic needs to distinguish the old streamSid from the current one.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b6b93e03ec

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

markSent = sendPlaybackMark(`tts-${Date.now()}`).sent;
}

if (!signal.aborted && chunkAttempts > 0 && (chunkDelivered === 0 || !markSent)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Don't fail the turn when only the completion mark drops

If Twilio drops the terminal mark frame after the media chunks were already accepted, playTtsViaStream() still throws here because !markSent is treated the same as chunkDelivered === 0. In that case the caller may already have heard the full prompt, but speak() reports failure, so extensions/voice-call/src/manager/outbound.ts skips the bot transcript and leaves metadata.initialMessage intact. A duplicate answered/stream-connect callback will then replay audio that was already played.

Useful? React with 👍 / 👎.

Comment on lines +135 to +136
while (paragraphs.length > 1 && isLikelyMetaReasoningParagraph(paragraphs[0])) {
paragraphs.shift();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Strip one-paragraph reasoning lead-ins before speaking

The new reasoning scrubber only removes meta text when it is in a separate paragraph. If the model returns something like Reasoning: ... Sure, what time works for you? or The user ... I should ... as a single paragraph, the paragraphs.length > 1 guard leaves the whole string intact, so callers still hear the planning text this change is meant to suppress.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 47a9f8f671

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines 211 to 215
transitionState(call, "speaking");
persistCallRecord(ctx.storePath, call);

addTranscriptEntry(call, "bot", text);

const voice = provider.name === "twilio" ? ctx.config.tts?.openai?.voice : undefined;
await provider.playTts({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Delay greeting suppression until playback really starts

On Twilio streaming calls, speak() flips the call to speaking before provider.playTts() has synthesized or queued any real greeting audio. VoiceCallWebhookServer.shouldSuppressBargeInForInitialMessage() then drops transcripts for any outbound conversation call that is speaking and still has metadata.initialMessage, and this patch now keeps that metadata until playback succeeds. In practice, if telephony TTS is slow or cold-starting, a callee who says something immediately after answering can be ignored for several seconds even though the greeting has not actually started yet.

Useful? React with 👍 / 👎.

Comment on lines +687 to +691
const synthPromise = ttsProvider.synthesizeForTelephony(text);
const timeoutPromise = new Promise<Buffer>((_, reject) => {
synthTimeout = setTimeout(() => {
reject(
new Error(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Cancel timed-out telephony synthesis requests

This 8-second guard only races synthesizeForTelephony() against a timer; it never aborts the underlying synthesis request. The shared TTS runtime still uses its own longer network timeout (30s by default), so every stream reply that hits this path leaves an orphaned OpenAI/ElevenLabs request running in the background even though the call path has already failed. Under a slow or wedged TTS backend, repeated calls can pile up these stray requests and waste capacity/cost for tens of seconds after each timeout.

Useful? React with 👍 / 👎.

Signed-off-by: joshavant <[email protected]>
@joshavant
joshavant merged commit 3f7f2c8 into openclaw:main Mar 21, 2026
7 checks passed
@joshavant
joshavant deleted the fix/voice-call-plugin branch March 21, 2026 09:17
frankekn pushed a commit to artwalker/openclaw that referenced this pull request Mar 23, 2026
… regression (openclaw#51500)

* voice-call: harden streaming startup and fallback behavior

* voice-call: suppress barge-in during intro

* voice-call: skip first-turn auto-response while greeting plays

* Voice-call: improve telephony audio fidelity and pacing

* voice-call: enforce spoken JSON and first-message barge skip

* voice-call: fix silent stream TTS regression

* voice-call: remove TTS timing diagnostics and document stream behavior

* voice-call: fail stream playback when stream sends are dropped

* voice-call: harden spoken contract and initial stream replay

* voice-call: suppress barge transcripts during initial greeting

* voice-call: harden stream fallback and media safety
furaul pushed a commit to furaul/openclaw that referenced this pull request Mar 24, 2026
… regression (openclaw#51500)

* voice-call: harden streaming startup and fallback behavior

* voice-call: suppress barge-in during intro

* voice-call: skip first-turn auto-response while greeting plays

* Voice-call: improve telephony audio fidelity and pacing

* voice-call: enforce spoken JSON and first-message barge skip

* voice-call: fix silent stream TTS regression

* voice-call: remove TTS timing diagnostics and document stream behavior

* voice-call: fail stream playback when stream sends are dropped

* voice-call: harden spoken contract and initial stream replay

* voice-call: suppress barge transcripts during initial greeting

* voice-call: harden stream fallback and media safety
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
… regression (openclaw#51500)

* voice-call: harden streaming startup and fallback behavior

* voice-call: suppress barge-in during intro

* voice-call: skip first-turn auto-response while greeting plays

* Voice-call: improve telephony audio fidelity and pacing

* voice-call: enforce spoken JSON and first-message barge skip

* voice-call: fix silent stream TTS regression

* voice-call: remove TTS timing diagnostics and document stream behavior

* voice-call: fail stream playback when stream sends are dropped

* voice-call: harden spoken contract and initial stream replay

* voice-call: suppress barge transcripts during initial greeting

* voice-call: harden stream fallback and media safety
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
… regression (openclaw#51500)

* voice-call: harden streaming startup and fallback behavior

* voice-call: suppress barge-in during intro

* voice-call: skip first-turn auto-response while greeting plays

* Voice-call: improve telephony audio fidelity and pacing

* voice-call: enforce spoken JSON and first-message barge skip

* voice-call: fix silent stream TTS regression

* voice-call: remove TTS timing diagnostics and document stream behavior

* voice-call: fail stream playback when stream sends are dropped

* voice-call: harden spoken contract and initial stream replay

* voice-call: suppress barge transcripts during initial greeting

* voice-call: harden stream fallback and media safety
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
… regression (openclaw#51500)

* voice-call: harden streaming startup and fallback behavior

* voice-call: suppress barge-in during intro

* voice-call: skip first-turn auto-response while greeting plays

* Voice-call: improve telephony audio fidelity and pacing

* voice-call: enforce spoken JSON and first-message barge skip

* voice-call: fix silent stream TTS regression

* voice-call: remove TTS timing diagnostics and document stream behavior

* voice-call: fail stream playback when stream sends are dropped

* voice-call: harden spoken contract and initial stream replay

* voice-call: suppress barge transcripts during initial greeting

* voice-call: harden stream fallback and media safety
Nachx639 pushed a commit to Nachx639/clawdbot that referenced this pull request Jun 17, 2026
… regression (openclaw#51500)

* voice-call: harden streaming startup and fallback behavior

* voice-call: suppress barge-in during intro

* voice-call: skip first-turn auto-response while greeting plays

* Voice-call: improve telephony audio fidelity and pacing

* voice-call: enforce spoken JSON and first-message barge skip

* voice-call: fix silent stream TTS regression

* voice-call: remove TTS timing diagnostics and document stream behavior

* voice-call: fail stream playback when stream sends are dropped

* voice-call: harden spoken contract and initial stream replay

* voice-call: suppress barge transcripts during initial greeting

* voice-call: harden stream fallback and media safety
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
… regression (openclaw#51500)

* voice-call: harden streaming startup and fallback behavior

* voice-call: suppress barge-in during intro

* voice-call: skip first-turn auto-response while greeting plays

* Voice-call: improve telephony audio fidelity and pacing

* voice-call: enforce spoken JSON and first-message barge skip

* voice-call: fix silent stream TTS regression

* voice-call: remove TTS timing diagnostics and document stream behavior

* voice-call: fail stream playback when stream sends are dropped

* voice-call: harden spoken contract and initial stream replay

* voice-call: suppress barge transcripts during initial greeting

* voice-call: harden stream fallback and media safety
globalcaos pushed a commit to globalcaos/tinkerclaw that referenced this pull request Sep 29, 2026
… regression (openclaw#51500)

* voice-call: harden streaming startup and fallback behavior

* voice-call: suppress barge-in during intro

* voice-call: skip first-turn auto-response while greeting plays

* Voice-call: improve telephony audio fidelity and pacing

* voice-call: enforce spoken JSON and first-message barge skip

* voice-call: fix silent stream TTS regression

* voice-call: remove TTS timing diagnostics and document stream behavior

* voice-call: fail stream playback when stream sends are dropped

* voice-call: harden spoken contract and initial stream replay

* voice-call: suppress barge transcripts during initial greeting

* voice-call: harden stream fallback and media safety
lhfer pushed a commit to lhfer/openclaw that referenced this pull request Oct 11, 2026
… regression (openclaw#51500)

* voice-call: harden streaming startup and fallback behavior

* voice-call: suppress barge-in during intro

* voice-call: skip first-turn auto-response while greeting plays

* Voice-call: improve telephony audio fidelity and pacing

* voice-call: enforce spoken JSON and first-message barge skip

* voice-call: fix silent stream TTS regression

* voice-call: remove TTS timing diagnostics and document stream behavior

* voice-call: fail stream playback when stream sends are dropped

* voice-call: harden spoken contract and initial stream replay

* voice-call: suppress barge transcripts during initial greeting

* voice-call: harden stream fallback and media safety
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 maintainer Maintainer-authored PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant