From a669ba7df10019c5a7b300420168d43f20c15d3d Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 25 Apr 2026 03:50:24 +0100 Subject: [PATCH] fix(voice-call): reap stale pre-answer calls --- CHANGELOG.md | 2 +- extensions/voice-call/src/config.test.ts | 8 ++++++++ extensions/voice-call/src/config.ts | 7 +++---- extensions/voice-call/src/webhook.test.ts | 16 +++++++++++++++- .../voice-call/src/webhook/stale-call-reaper.ts | 5 +++++ 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46d76b061e6..88617bc80ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,7 +73,7 @@ Docs: https://docs.openclaw.ai - Config/doctor: reject legacy `secretref-env:` marker strings on SecretRef credential paths and migrate valid markers to structured env SecretRefs with `openclaw doctor --fix`. Fixes #51794. Thanks @halointellicore. - Providers/OpenAI: separate API-key and Codex sign-in onboarding groups, and avoid replaying stale OpenAI Responses reasoning blocks after a model route switch. - Providers/ElevenLabs: omit the MP3-only `Accept` header for PCM telephony synthesis, so Voice Call requests for `pcm_22050` no longer receive MP3 audio. Fixes #67340. Thanks @marcchabot. -- Plugins/Voice Call: honor configured TTS timeouts for Twilio media-stream playback and fail empty telephony audio instead of completing as silence. Fixes #42071; supersedes #60957. Thanks @Ryce and @sliekens. +- Plugins/Voice Call: reap stale pre-answer calls by default, honor configured TTS timeouts for Twilio media-stream playback, and fail empty telephony audio instead of completing as silence. Fixes #42071; supersedes #60957. Thanks @Ryce and @sliekens. - Skills: honor legacy `metadata.clawdbot` requirements and installer hints when `metadata.openclaw` is absent, so older skills no longer appear ready when required binaries are missing. Fixes #71323. Thanks @chen-zhang-cs-code. - Browser/config: expand `~` in `browser.executablePath` before Chromium launch, so home-relative custom browser paths no longer fail with `ENOENT`. Fixes #67264. Thanks @Quratulain-bilal. - Telegram/streaming: hide tool-progress status updates by default while keeping explicit `streaming.preview.toolProgress` opt-in support for edited preview messages. Fixes #71320. Thanks @neeravmakwana. diff --git a/extensions/voice-call/src/config.test.ts b/extensions/voice-call/src/config.test.ts index 60f8d9c4e46..eff9d73479c 100644 --- a/extensions/voice-call/src/config.test.ts +++ b/extensions/voice-call/src/config.test.ts @@ -226,6 +226,14 @@ describe("validateProviderConfig", () => { }); }); +describe("resolveVoiceCallConfig", () => { + it("enables the pre-answer stale call reaper by default", () => { + const config = resolveVoiceCallConfig({ enabled: true, provider: "mock" }); + + expect(config.staleCallReaperSeconds).toBe(120); + }); +}); + describe("normalizeVoiceCallConfig", () => { it("fills nested runtime defaults from a partial config boundary", () => { const normalized = normalizeVoiceCallConfig({ diff --git a/extensions/voice-call/src/config.ts b/extensions/voice-call/src/config.ts index 565bd8e2112..f87187e3ed2 100644 --- a/extensions/voice-call/src/config.ts +++ b/extensions/voice-call/src/config.ts @@ -331,11 +331,10 @@ export const VoiceCallConfigSchema = z /** * Maximum age of a call in seconds before it is automatically reaped. - * Catches calls stuck in unexpected states (e.g., notify-mode calls that - * never receive a terminal webhook). Set to 0 to disable. - * Default: 0 (disabled). Recommended: 120-300 for production. + * Catches calls stuck before answer (for example, local mock calls that + * never receive provider webhooks). Set to 0 to disable. */ - staleCallReaperSeconds: z.number().int().nonnegative().default(0), + staleCallReaperSeconds: z.number().int().nonnegative().default(120), /** Silence timeout for end-of-speech detection (ms) */ silenceTimeoutMs: z.number().int().positive().default(800), diff --git a/extensions/voice-call/src/webhook.test.ts b/extensions/voice-call/src/webhook.test.ts index 3db46c92925..8d5e321a303 100644 --- a/extensions/voice-call/src/webhook.test.ts +++ b/extensions/voice-call/src/webhook.test.ts @@ -353,11 +353,12 @@ async function runStaleCallReaperCase(params: { callAgeMs: number; staleCallReaperSeconds: number; advanceMs: number; + callOverrides?: Partial; }) { const now = new Date("2026-02-16T00:00:00Z"); vi.setSystemTime(now); - const call = createCall(now.getTime() - params.callAgeMs); + const call = { ...createCall(now.getTime() - params.callAgeMs), ...params.callOverrides }; const { manager, endCall } = createManager([call]); const config = createConfig({ staleCallReaperSeconds: params.staleCallReaperSeconds }); const server = new VoiceCallWebhookServer(config, manager, provider); @@ -485,6 +486,19 @@ describe("VoiceCallWebhookServer stale call reaper", () => { await server.stop(); } }); + + it("does not reap calls that reached the answered state", async () => { + const { endCall } = await runStaleCallReaperCase({ + callAgeMs: 120_000, + staleCallReaperSeconds: 60, + advanceMs: 30_000, + callOverrides: { + state: "answered", + answeredAt: new Date("2026-02-15T23:58:30Z").getTime(), + }, + }); + expect(endCall).not.toHaveBeenCalled(); + }); }); describe("VoiceCallWebhookServer path matching", () => { diff --git a/extensions/voice-call/src/webhook/stale-call-reaper.ts b/extensions/voice-call/src/webhook/stale-call-reaper.ts index 4c9661153d5..6283ffa03f2 100644 --- a/extensions/voice-call/src/webhook/stale-call-reaper.ts +++ b/extensions/voice-call/src/webhook/stale-call-reaper.ts @@ -1,4 +1,5 @@ import type { CallManager } from "../manager.js"; +import { TerminalStates } from "../types.js"; const CHECK_INTERVAL_MS = 30_000; @@ -15,6 +16,10 @@ export function startStaleCallReaper(params: { const interval = setInterval(() => { const now = Date.now(); for (const call of params.manager.getActiveCalls()) { + if (call.answeredAt || TerminalStates.has(call.state)) { + continue; + } + const age = now - call.startedAt; if (age > maxAgeMs) { console.log(