Skip to content

Commit ad8ea56

Browse files
author
hclsys
committed
fix(voice-call): emit canonical agent-scoped session keys for per-phone and per-call scopes (#80064)
Before this fix, `resolveVoiceCallSessionKey` produced raw `voice:*` keys (`voice:<phone>`, `voice:call:<callId>`). Gateway startup migration canonicalizes those keys to `agent:<agentId>:voice:*` format, so after a restart the per-phone/per-call resolver and the session store used different keys — breaking caller continuity across restarts. Fix: include `agentId` in the Pick type and prefix every generated key with `agent:<agentId || "main">:voice:`. Explicit session keys pass through unchanged. All four call sites already supply full VoiceCallConfig objects, so no call-site changes are required.
1 parent 2694516 commit ad8ea56

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

extensions/voice-call/src/config.test.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,23 @@ describe("resolveVoiceCallConfig session routing", () => {
270270
callId: "call-123",
271271
phone: "+1 (555) 000-1111",
272272
}),
273-
).toBe("voice:15550001111");
273+
).toBe("agent:main:voice:15550001111");
274+
});
275+
276+
it("uses configured agentId in per-phone session key", () => {
277+
const config = resolveVoiceCallConfig({
278+
enabled: true,
279+
provider: "mock",
280+
agentId: "reception",
281+
});
282+
283+
expect(
284+
resolveVoiceCallSessionKey({
285+
config,
286+
callId: "call-123",
287+
phone: "+1 (555) 000-1111",
288+
}),
289+
).toBe("agent:reception:voice:15550001111");
274290
});
275291

276292
it("can scope voice sessions to each call", () => {
@@ -287,7 +303,7 @@ describe("resolveVoiceCallConfig session routing", () => {
287303
callId: "call-123",
288304
phone: "+1 (555) 000-1111",
289305
}),
290-
).toBe("voice:call:call-123");
306+
).toBe("agent:main:voice:call:call-123");
291307
});
292308

293309
it("preserves explicit voice session keys", () => {

extensions/voice-call/src/config.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ export function normalizeVoiceCallConfig(config: VoiceCallConfigInput): VoiceCal
717717
}
718718

719719
export function resolveVoiceCallSessionKey(params: {
720-
config: Pick<VoiceCallConfig, "sessionScope">;
720+
config: Pick<VoiceCallConfig, "sessionScope" | "agentId">;
721721
callId: string;
722722
phone?: string;
723723
explicitSessionKey?: string;
@@ -726,11 +726,14 @@ export function resolveVoiceCallSessionKey(params: {
726726
if (explicit) {
727727
return explicit;
728728
}
729+
const agentId = params.config.agentId ?? "main";
729730
if (params.config.sessionScope === "per-call") {
730-
return `voice:call:${params.callId}`;
731+
return `agent:${agentId}:voice:call:${params.callId}`;
731732
}
732733
const normalizedPhone = params.phone?.replace(/\D/g, "");
733-
return normalizedPhone ? `voice:${normalizedPhone}` : `voice:${params.callId}`;
734+
return normalizedPhone
735+
? `agent:${agentId}:voice:${normalizedPhone}`
736+
: `agent:${agentId}:voice:${params.callId}`;
734737
}
735738

736739
/**

0 commit comments

Comments
 (0)