mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-02 06:41:37 +00:00
fix(voice-call): keep replay caps production-owned
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user