Skip to content

Commit 4e82cac

Browse files
committed
fix(voice-call): summarize restored call verification logs
1 parent ab0f8a7 commit 4e82cac

3 files changed

Lines changed: 182 additions & 16 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ Docs: https://docs.openclaw.ai
290290
- QA Lab: stop gateway children when the suite parent disappears, so interrupted local QA runs cannot leave hot orphaned gateways behind.
291291
- Codex/app-server: tolerate a second connection close during startup recovery and include retry counts plus stringified errors in the restart warning, so concurrent lanes do not fail after one shared-client race.
292292
- Plugins/CLI: cache plugin CLI registration entries per command program so completion state generation does not repeat the full plugin sweep in one invocation. Thanks @ScientificProgrammer.
293+
- Voice Call: summarize restored-call verification logs during startup while preserving expired-call cleanup, reducing duplicate per-call skip messages. Thanks @jckm14.
293294
- Plugins: reuse gateway-bindable plugin loader cache entries for later default-mode loads without serving default-built registries to gateway-bound requests, reducing repeated plugin registration during dispatch. Refs #61756. Thanks @DmitryPogodaev.
294295
- Gateway/secrets: include the caught error message in `secrets.reload` and `secrets.resolve` warning logs while keeping RPC errors generic, so operators can diagnose reload and permission failures. Thanks @davidangularme.
295296
- Providers/OpenRouter: fill DeepSeek V4 `reasoning_content` replay placeholders for `openrouter/deepseek/deepseek-v4-flash` and `openrouter/deepseek/deepseek-v4-pro`, so thinking/tool follow-up turns do not fail with DeepSeek's replay-shape error. Fixes #76018. Thanks @cloph-dsp.

‎extensions/voice-call/src/manager.restore.test.ts‎

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function requireSingleActiveCall(manager: CallManager) {
2222
describe("CallManager verification on restore", () => {
2323
afterEach(() => {
2424
vi.useRealTimers();
25+
vi.restoreAllMocks();
2526
});
2627

2728
async function initializeManager(params?: {
@@ -121,6 +122,129 @@ describe("CallManager verification on restore", () => {
121122
expect(activeCall.state).toBe(call.state);
122123
});
123124

125+
it("summarizes repeated restored-call verification outcomes", async () => {
126+
const now = Date.now();
127+
const storePath = createTestStorePath();
128+
const calls = [
129+
makePersistedCall({
130+
callId: "missing-provider-a",
131+
providerCallId: undefined,
132+
state: "initiated",
133+
startedAt: now - 10_000,
134+
answeredAt: undefined,
135+
}),
136+
makePersistedCall({
137+
callId: "missing-provider-b",
138+
providerCallId: undefined,
139+
state: "initiated",
140+
startedAt: now - 10_000,
141+
answeredAt: undefined,
142+
}),
143+
makePersistedCall({
144+
callId: "expired-a",
145+
providerCallId: "expired-provider-a",
146+
state: "initiated",
147+
startedAt: now - 600_000,
148+
answeredAt: undefined,
149+
}),
150+
makePersistedCall({
151+
callId: "terminal-a",
152+
providerCallId: "terminal-provider-a",
153+
state: "initiated",
154+
startedAt: now - 20_000,
155+
answeredAt: undefined,
156+
}),
157+
makePersistedCall({
158+
callId: "terminal-b",
159+
providerCallId: "terminal-provider-b",
160+
state: "initiated",
161+
startedAt: now - 20_000,
162+
answeredAt: undefined,
163+
}),
164+
makePersistedCall({
165+
callId: "unknown-a",
166+
providerCallId: "unknown-provider-a",
167+
state: "initiated",
168+
startedAt: now - 20_000,
169+
answeredAt: undefined,
170+
}),
171+
makePersistedCall({
172+
callId: "active-a",
173+
providerCallId: "active-provider-a",
174+
state: "initiated",
175+
startedAt: now - 20_000,
176+
answeredAt: undefined,
177+
}),
178+
makePersistedCall({
179+
callId: "failure-a",
180+
providerCallId: "failure-provider-a",
181+
state: "initiated",
182+
startedAt: now - 20_000,
183+
answeredAt: undefined,
184+
}),
185+
];
186+
writeCallsToStore(storePath, calls);
187+
188+
const provider = new FakeProvider();
189+
provider.getCallStatus = async ({ providerCallId }) => {
190+
if (providerCallId.startsWith("terminal-provider")) {
191+
return { status: "completed", isTerminal: true };
192+
}
193+
if (providerCallId.startsWith("unknown-provider")) {
194+
return { status: "unknown", isTerminal: false, isUnknown: true };
195+
}
196+
if (providerCallId.startsWith("active-provider")) {
197+
return { status: "in-progress", isTerminal: false };
198+
}
199+
throw new Error("network failure");
200+
};
201+
const config = VoiceCallConfigSchema.parse({
202+
enabled: true,
203+
provider: "plivo",
204+
fromNumber: "+15550000000",
205+
maxDurationSeconds: 300,
206+
});
207+
const logSpy = vi.spyOn(console, "log").mockImplementation(() => {});
208+
const manager = new CallManager(config, storePath);
209+
210+
await manager.initialize(provider, "https://example.com/voice/webhook");
211+
212+
expect(
213+
manager
214+
.getActiveCalls()
215+
.map((call) => call.callId)
216+
.toSorted(),
217+
).toEqual(["active-a", "failure-a", "unknown-a"]);
218+
expect(provider.hangupCalls).toEqual([
219+
expect.objectContaining({
220+
callId: "expired-a",
221+
providerCallId: "expired-provider-a",
222+
reason: "timeout",
223+
}),
224+
]);
225+
expect(logSpy).toHaveBeenCalledWith(
226+
"[voice-call] Skipped 2 restored call(s) with no providerCallId",
227+
);
228+
expect(logSpy).toHaveBeenCalledWith(
229+
"[voice-call] Skipped 1 restored call(s) older than maxDurationSeconds",
230+
);
231+
expect(logSpy).toHaveBeenCalledWith(
232+
"[voice-call] Skipped 2 restored call(s) with provider status: completed",
233+
);
234+
expect(logSpy).toHaveBeenCalledWith(
235+
"[voice-call] Kept 1 restored call(s) confirmed active by provider",
236+
);
237+
expect(logSpy).toHaveBeenCalledWith(
238+
"[voice-call] Kept 1 restored call(s) with unknown provider status (relying on timer)",
239+
);
240+
expect(logSpy).toHaveBeenCalledWith(
241+
"[voice-call] Kept 1 restored call(s) after verification failure (relying on timer)",
242+
);
243+
expect(logSpy.mock.calls.map((call) => String(call[0])).join("\n")).not.toContain("terminal-a");
244+
245+
logSpy.mockRestore();
246+
});
247+
124248
it("uses only remaining max duration for restored answered calls", async () => {
125249
vi.useFakeTimers();
126250
const now = new Date("2026-03-17T03:07:00Z");

‎extensions/voice-call/src/manager.ts‎

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ function markRestoredCallSkipped(call: CallRecord, endReason: "completed" | "tim
3737
call.state = endReason;
3838
}
3939

40+
function incrementRestoreStatusCount(
41+
counts: Map<string, number>,
42+
status: string | undefined,
43+
): void {
44+
const key = normalizeOptionalString(status) ?? "terminal";
45+
counts.set(key, (counts.get(key) ?? 0) + 1);
46+
}
47+
4048
function resolveDefaultStoreBase(config: VoiceCallConfig, storePath?: string): string {
4149
const rawOverride = storePath?.trim() || config.store?.trim();
4250
if (rawOverride) {
@@ -110,6 +118,7 @@ export class CallManager {
110118
}
111119

112120
// Restart max-duration timers for restored calls that are past the answered state
121+
let skippedAlreadyElapsedTimers = 0;
113122
for (const [callId, call] of verified) {
114123
if (call.answeredAt && !TerminalStates.has(call.state)) {
115124
const elapsed = Date.now() - call.answeredAt;
@@ -120,9 +129,7 @@ export class CallManager {
120129
if (call.providerCallId) {
121130
this.providerCallIdMap.delete(call.providerCallId);
122131
}
123-
console.log(
124-
`[voice-call] Skipping restored call ${callId} (max duration already elapsed)`,
125-
);
132+
skippedAlreadyElapsedTimers += 1;
126133
continue;
127134
}
128135
startMaxDurationTimer({
@@ -136,6 +143,11 @@ export class CallManager {
136143
console.log(`[voice-call] Restarted max-duration timer for restored call ${callId}`);
137144
}
138145
}
146+
if (skippedAlreadyElapsedTimers > 0) {
147+
console.log(
148+
`[voice-call] Skipped ${skippedAlreadyElapsedTimers} restored call(s) whose max-duration timer already elapsed`,
149+
);
150+
}
139151

140152
if (verified.size > 0) {
141153
console.log(`[voice-call] Restored ${verified.size} active call(s) from store`);
@@ -159,19 +171,23 @@ export class CallManager {
159171
const now = Date.now();
160172
const verified = new Map<CallId, CallRecord>();
161173
const verifyTasks: Array<{ callId: CallId; call: CallRecord; promise: Promise<void> }> = [];
174+
let skippedNoProviderCallId = 0;
175+
let skippedOlderThanMaxDuration = 0;
176+
const skippedTerminalStatuses = new Map<string, number>();
177+
let keptVerifiedActive = 0;
178+
let keptUnknownProviderStatus = 0;
179+
let keptVerificationFailures = 0;
162180

163181
for (const [callId, call] of candidates) {
164182
// Skip calls without a provider ID — can't verify
165183
if (!call.providerCallId) {
166-
console.log(`[voice-call] Skipping restored call ${callId} (no providerCallId)`);
184+
skippedNoProviderCallId += 1;
167185
continue;
168186
}
169187

170188
// Skip calls older than maxDurationSeconds (time-based fallback)
171189
if (now - call.startedAt > maxAgeMs) {
172-
console.log(
173-
`[voice-call] Skipping restored call ${callId} (older than maxDurationSeconds)`,
174-
);
190+
skippedOlderThanMaxDuration += 1;
175191
markRestoredCallSkipped(call, "timeout");
176192
persistCallRecord(this.storePath, call);
177193
await provider
@@ -196,32 +212,57 @@ export class CallManager {
196212
.getCallStatus({ providerCallId: call.providerCallId })
197213
.then((result) => {
198214
if (result.isTerminal) {
199-
console.log(
200-
`[voice-call] Skipping restored call ${callId} (provider status: ${result.status})`,
201-
);
215+
incrementRestoreStatusCount(skippedTerminalStatuses, result.status);
202216
markRestoredCallSkipped(call, "completed");
203217
persistCallRecord(this.storePath, call);
204218
} else if (result.isUnknown) {
205-
console.log(
206-
`[voice-call] Keeping restored call ${callId} (provider status unknown, relying on timer)`,
207-
);
219+
keptUnknownProviderStatus += 1;
208220
verified.set(callId, call);
209221
} else {
222+
keptVerifiedActive += 1;
210223
verified.set(callId, call);
211224
}
212225
})
213226
.catch(() => {
214227
// Verification failed entirely — keep the call, rely on timer
215-
console.log(
216-
`[voice-call] Keeping restored call ${callId} (verification failed, relying on timer)`,
217-
);
228+
keptVerificationFailures += 1;
218229
verified.set(callId, call);
219230
}),
220231
};
221232
verifyTasks.push(task);
222233
}
223234

224235
await Promise.allSettled(verifyTasks.map((t) => t.promise));
236+
if (skippedNoProviderCallId > 0) {
237+
console.log(
238+
`[voice-call] Skipped ${skippedNoProviderCallId} restored call(s) with no providerCallId`,
239+
);
240+
}
241+
if (skippedOlderThanMaxDuration > 0) {
242+
console.log(
243+
`[voice-call] Skipped ${skippedOlderThanMaxDuration} restored call(s) older than maxDurationSeconds`,
244+
);
245+
}
246+
for (const [status, count] of [...skippedTerminalStatuses].toSorted(([a], [b]) =>
247+
a.localeCompare(b),
248+
)) {
249+
console.log(`[voice-call] Skipped ${count} restored call(s) with provider status: ${status}`);
250+
}
251+
if (keptVerifiedActive > 0) {
252+
console.log(
253+
`[voice-call] Kept ${keptVerifiedActive} restored call(s) confirmed active by provider`,
254+
);
255+
}
256+
if (keptUnknownProviderStatus > 0) {
257+
console.log(
258+
`[voice-call] Kept ${keptUnknownProviderStatus} restored call(s) with unknown provider status (relying on timer)`,
259+
);
260+
}
261+
if (keptVerificationFailures > 0) {
262+
console.log(
263+
`[voice-call] Kept ${keptVerificationFailures} restored call(s) after verification failure (relying on timer)`,
264+
);
265+
}
225266
return verified;
226267
}
227268

0 commit comments

Comments
 (0)