fix(voice-call): keep replay caps production-owned

This commit is contained in:
Vincent Koc
2026-08-01 22:12:12 +08:00
parent c90983d59d
commit 02c8e76d7f
3 changed files with 12 additions and 9 deletions

View File

@@ -15,8 +15,9 @@ import type { AnswerCallInput, HangupCallInput, NormalizedEvent } from "../types
import type { CallManagerContext } from "./context.js";
import { processEvent } from "./events.js";
import { speakInitialMessage } from "./outbound.js";
import { MAX_CALL_REPLAY_KEYS, MAX_MANAGER_REPLAY_KEYS } from "./replay-keys.js";
import { MAX_CALL_REPLAY_KEYS } from "./replay-keys.js";
const MANAGER_REPLAY_KEY_LIMIT = 10_000;
const logSpy = vi.hoisted(() => {
const logEntries: string[] = [];
return {
@@ -775,7 +776,7 @@ describe("processEvent (functional)", () => {
it("bounds committed replay keys in both manager and persisted call owners", () => {
const now = Date.now();
const managerKeys = Array.from(
{ length: MAX_MANAGER_REPLAY_KEYS },
{ length: MANAGER_REPLAY_KEY_LIMIT },
(_, index) => `manager-${index}`,
);
const callKeys = Array.from({ length: MAX_CALL_REPLAY_KEYS }, (_, index) => `call-${index}`);
@@ -806,7 +807,7 @@ describe("processEvent (functional)", () => {
const call = ctx.activeCalls.get("call-bounded");
expect(result).toEqual({ kind: "processed" });
expect(ctx.processedEventIds.size).toBe(MAX_MANAGER_REPLAY_KEYS);
expect(ctx.processedEventIds.size).toBe(MANAGER_REPLAY_KEY_LIMIT);
expect(ctx.processedEventIds.has("manager-0")).toBe(false);
expect(ctx.processedEventIds.has("evt-bounded-new")).toBe(true);
expect(call?.processedEventIds).toHaveLength(MAX_CALL_REPLAY_KEYS);
@@ -827,7 +828,7 @@ describe("processEvent (functional)", () => {
it("bounds rejected provider calls while retaining hangup-once behavior", () => {
const rejectedProviderCallIds = new Map<string, symbol>(
Array.from(
{ length: MAX_MANAGER_REPLAY_KEYS },
{ length: MANAGER_REPLAY_KEY_LIMIT },
(_, index) => [`provider-${index}`, Symbol(`provider-${index}`)] as const,
),
);
@@ -851,7 +852,7 @@ describe("processEvent (functional)", () => {
}),
);
expect(ctx.rejectedProviderCallIds.size).toBe(MAX_MANAGER_REPLAY_KEYS);
expect(ctx.rejectedProviderCallIds.size).toBe(MANAGER_REPLAY_KEY_LIMIT);
expect(ctx.rejectedProviderCallIds.has("provider-0")).toBe(false);
expect(ctx.rejectedProviderCallIds.has("provider-new")).toBe(true);
expect(hangupCalls).toHaveLength(1);

View File

@@ -1,7 +1,7 @@
// Voice Call manager helpers own bounded webhook replay identity.
/** Match the existing voice-call webhook replay-cache cardinality. */
export const MAX_MANAGER_REPLAY_KEYS = 10_000;
const MAX_MANAGER_REPLAY_KEYS = 10_000;
/** Keep typical provider replay IDs near one raw persisted-record chunk. */
export const MAX_CALL_REPLAY_KEYS = 500;

View File

@@ -14,7 +14,7 @@ import {
} from "../manager.test-harness.js";
import { setVoiceCallStateRuntime } from "../runtime-state.js";
import { CallRecordSchema } from "../types.js";
import { MAX_CALL_REPLAY_KEYS, MAX_MANAGER_REPLAY_KEYS } from "./replay-keys.js";
import { MAX_CALL_REPLAY_KEYS } from "./replay-keys.js";
import {
findCallMatchesInStore,
getCallHistoryFromStore,
@@ -22,6 +22,8 @@ import {
persistCallRecord,
} from "./store.js";
const MANAGER_REPLAY_KEY_LIMIT = 10_000;
function installStateRuntime(): void {
setVoiceCallStateRuntime({
state: {
@@ -191,7 +193,7 @@ describe("voice-call call record store", () => {
);
for (
let callIndex = 0;
callIndex < MAX_MANAGER_REPLAY_KEYS / MAX_CALL_REPLAY_KEYS;
callIndex < MANAGER_REPLAY_KEY_LIMIT / MAX_CALL_REPLAY_KEYS;
callIndex++
) {
persistCallRecord(
@@ -221,7 +223,7 @@ describe("voice-call call record store", () => {
const restored = loadActiveCallsFromStore(storePath);
expect(restored.processedEventIds.size).toBe(MAX_MANAGER_REPLAY_KEYS);
expect(restored.processedEventIds.size).toBe(MANAGER_REPLAY_KEY_LIMIT);
expect(restored.processedEventIds.has("evt-latest-old")).toBe(true);
expect(restored.processedEventIds.has("evt-latest-new")).toBe(true);
expect(restored.processedEventIds.has("evt-fill-0-0")).toBe(false);