Skip to content

Commit 02c8e76

Browse files
committed
fix(voice-call): keep replay caps production-owned
1 parent c90983d commit 02c8e76

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ import type { AnswerCallInput, HangupCallInput, NormalizedEvent } from "../types
1515
import type { CallManagerContext } from "./context.js";
1616
import { processEvent } from "./events.js";
1717
import { speakInitialMessage } from "./outbound.js";
18-
import { MAX_CALL_REPLAY_KEYS, MAX_MANAGER_REPLAY_KEYS } from "./replay-keys.js";
18+
import { MAX_CALL_REPLAY_KEYS } from "./replay-keys.js";
1919

20+
const MANAGER_REPLAY_KEY_LIMIT = 10_000;
2021
const logSpy = vi.hoisted(() => {
2122
const logEntries: string[] = [];
2223
return {
@@ -775,7 +776,7 @@ describe("processEvent (functional)", () => {
775776
it("bounds committed replay keys in both manager and persisted call owners", () => {
776777
const now = Date.now();
777778
const managerKeys = Array.from(
778-
{ length: MAX_MANAGER_REPLAY_KEYS },
779+
{ length: MANAGER_REPLAY_KEY_LIMIT },
779780
(_, index) => `manager-${index}`,
780781
);
781782
const callKeys = Array.from({ length: MAX_CALL_REPLAY_KEYS }, (_, index) => `call-${index}`);
@@ -806,7 +807,7 @@ describe("processEvent (functional)", () => {
806807

807808
const call = ctx.activeCalls.get("call-bounded");
808809
expect(result).toEqual({ kind: "processed" });
809-
expect(ctx.processedEventIds.size).toBe(MAX_MANAGER_REPLAY_KEYS);
810+
expect(ctx.processedEventIds.size).toBe(MANAGER_REPLAY_KEY_LIMIT);
810811
expect(ctx.processedEventIds.has("manager-0")).toBe(false);
811812
expect(ctx.processedEventIds.has("evt-bounded-new")).toBe(true);
812813
expect(call?.processedEventIds).toHaveLength(MAX_CALL_REPLAY_KEYS);
@@ -827,7 +828,7 @@ describe("processEvent (functional)", () => {
827828
it("bounds rejected provider calls while retaining hangup-once behavior", () => {
828829
const rejectedProviderCallIds = new Map<string, symbol>(
829830
Array.from(
830-
{ length: MAX_MANAGER_REPLAY_KEYS },
831+
{ length: MANAGER_REPLAY_KEY_LIMIT },
831832
(_, index) => [`provider-${index}`, Symbol(`provider-${index}`)] as const,
832833
),
833834
);
@@ -851,7 +852,7 @@ describe("processEvent (functional)", () => {
851852
}),
852853
);
853854

854-
expect(ctx.rejectedProviderCallIds.size).toBe(MAX_MANAGER_REPLAY_KEYS);
855+
expect(ctx.rejectedProviderCallIds.size).toBe(MANAGER_REPLAY_KEY_LIMIT);
855856
expect(ctx.rejectedProviderCallIds.has("provider-0")).toBe(false);
856857
expect(ctx.rejectedProviderCallIds.has("provider-new")).toBe(true);
857858
expect(hangupCalls).toHaveLength(1);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Voice Call manager helpers own bounded webhook replay identity.
22

33
/** Match the existing voice-call webhook replay-cache cardinality. */
4-
export const MAX_MANAGER_REPLAY_KEYS = 10_000;
4+
const MAX_MANAGER_REPLAY_KEYS = 10_000;
55
/** Keep typical provider replay IDs near one raw persisted-record chunk. */
66
export const MAX_CALL_REPLAY_KEYS = 500;
77

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ import {
1414
} from "../manager.test-harness.js";
1515
import { setVoiceCallStateRuntime } from "../runtime-state.js";
1616
import { CallRecordSchema } from "../types.js";
17-
import { MAX_CALL_REPLAY_KEYS, MAX_MANAGER_REPLAY_KEYS } from "./replay-keys.js";
17+
import { MAX_CALL_REPLAY_KEYS } from "./replay-keys.js";
1818
import {
1919
findCallMatchesInStore,
2020
getCallHistoryFromStore,
2121
loadActiveCallsFromStore,
2222
persistCallRecord,
2323
} from "./store.js";
2424

25+
const MANAGER_REPLAY_KEY_LIMIT = 10_000;
26+
2527
function installStateRuntime(): void {
2628
setVoiceCallStateRuntime({
2729
state: {
@@ -191,7 +193,7 @@ describe("voice-call call record store", () => {
191193
);
192194
for (
193195
let callIndex = 0;
194-
callIndex < MAX_MANAGER_REPLAY_KEYS / MAX_CALL_REPLAY_KEYS;
196+
callIndex < MANAGER_REPLAY_KEY_LIMIT / MAX_CALL_REPLAY_KEYS;
195197
callIndex++
196198
) {
197199
persistCallRecord(
@@ -221,7 +223,7 @@ describe("voice-call call record store", () => {
221223

222224
const restored = loadActiveCallsFromStore(storePath);
223225

224-
expect(restored.processedEventIds.size).toBe(MAX_MANAGER_REPLAY_KEYS);
226+
expect(restored.processedEventIds.size).toBe(MANAGER_REPLAY_KEY_LIMIT);
225227
expect(restored.processedEventIds.has("evt-latest-old")).toBe(true);
226228
expect(restored.processedEventIds.has("evt-latest-new")).toBe(true);
227229
expect(restored.processedEventIds.has("evt-fill-0-0")).toBe(false);

0 commit comments

Comments
 (0)