Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(live): mask a held code said across several pauses and pin the stored call row

AdityaUmale2f9da6a271ba
diff --git a/packages/phone-protocol/src/live-call.ts b/packages/phone-protocol/src/live-call.ts
index a0048a4f21..93a0de8f3a 100644
--- a/packages/phone-protocol/src/live-call.ts
+++ b/packages/phone-protocol/src/live-call.ts
@@ -80,6 +80,8 @@ export class LiveTranscript {
/** A pause on the session timeline longer than this starts a new spoken line. */
const SPOKEN_LINE_GAP_MS = 1_000;
const MAX_SPOKEN_LINES = 2_000;
+/** Held values said across pauses are looked for over this many characters of the latest lines. */
+const SPOKEN_JOIN_WINDOW = 512;
type SpokenLineState = { at: number; text: string; endMs: number };
@@ -107,20 +109,22 @@ export class SpokenLines {
if (this.lines.length >= MAX_SPOKEN_LINES) return;
this.lines.push({ at, text: this.scrub(text), endMs: timed ? endMs : Number.NEGATIVE_INFINITY });
}
- this.joinAcrossPause();
+ this.joinAcrossPauses();
}
- /** A value said across a pause is split over two lines, neither of which holds all of it: when the scrub
- * masks something in the two joined, they become one line. */
- private joinAcrossPause(): void {
- while (this.lines.length >= 2) {
- const [previous, last] = this.lines.slice(-2) as [SpokenLineState, SpokenLineState];
- const joined = previous.text + last.text;
+ /** A value said across pauses is split over several lines, none of which holds all of it: when the scrub
+ * masks something in the last lines joined, they become one line. Looks back while the text after the line
+ * it adds is shorter than SPOKEN_JOIN_WINDOW, so any held value up to that length is caught. */
+ private joinAcrossPauses(): void {
+ let joined = this.lines.at(-1)?.text ?? "";
+ for (let start = this.lines.length - 2; start >= 0 && joined.length < SPOKEN_JOIN_WINDOW; start--) {
+ joined = this.lines[start]!.text + joined;
const scrubbed = this.scrub(joined);
- if (scrubbed === joined) return;
- previous.text = scrubbed;
- previous.endMs = Math.max(previous.endMs, last.endMs);
- this.lines.pop();
+ if (scrubbed === joined) continue;
+ const merged = this.lines.splice(start);
+ this.lines.push({ at: merged[0]!.at, text: scrubbed, endMs: Math.max(...merged.map((line) => line.endMs)) });
+ this.joinAcrossPauses();
+ return;
}
}
diff --git a/server/live-call-controller.test.ts b/server/live-call-controller.test.ts
index e42d311f25..af319beca9 100644
--- a/server/live-call-controller.test.ts
+++ b/server/live-call-controller.test.ts
@@ -4,14 +4,18 @@ import {
ATTACH_TIMEOUT_MS, CLOSE_TIMEOUT_MS, CONSENT_SETTLE_MS, DELEGATION_SETTLE_MS, FISH_ATTACH_TIMEOUT_MS, GOODBYE_MS, IDLE_CHECK_MS, PROGRESS_INTERVAL_MS,
LIVE_FISH_NEEDS_APP, LIVE_ELEVENLABS_NEEDS_APP, LIVE_GEMINI_NEEDS_APP, LiveCallBusyError, LiveCallController, LiveCallSignedOutError, type LiveActivity, type LiveCallDeps, type LiveSocket,
} from "./live-call-controller.ts";
+import { rmSync } from "node:fs";
import { LIVE_COPY } from "../shared/live-approval.ts";
+import { DATA_DIR } from "./config.ts";
+import { recordLiveCall } from "./live-call-record.ts";
+import { flushLaterSaves } from "./save-batch.ts";
import { LIVE_CUSTOM_REFUSAL } from "./live-access.ts";
import { LIVE_NEEDS_AZURE, LIVE_NEEDS_KEY, LiveSessionError, type LiveEndpoint } from "./live-call.ts";
import { FishRelays, FISH_AGENT_VOICE } from "./live-fish.ts";
import type { LiveElevenLabsSession, LiveFishSessionToken, LiveGeminiSession } from "../shared/wire.ts";
import { addHeldSecretScrubber, HELD_SECRET_MASK, redactSecretsInText } from "./redact.ts";
import type { RequestAuth } from "./request-auth.ts";
-import type { Message, StoreChange } from "./store.ts";
+import { Store, type Message, type StoreChange } from "./store.ts";
class FakeSocket implements LiveSocket {
readyState = 0;
@@ -1748,6 +1752,45 @@ describe("LiveCallController record", () => {
expect(JSON.stringify(record)).not.toContain("Q7XK");
});
+ it("masks a held code said across two pauses, which splits it over three lines", async () => {
+ const code = "731942";
+ const forget = addHeldSecretScrubber((text) => text.replaceAll(code, HELD_SECRET_MASK));
+ const t = setup({ recordCall: vi.fn() });
+ try {
+ await t.start();
+ t.socket().receive({ type: "session.output_transcript.delta", delta: "Your code is 73", start_ms: 1_000, end_ms: 1_500 });
+ t.socket().receive({ type: "session.output_transcript.delta", delta: "19", start_ms: 3_000, end_ms: 3_200 });
+ t.socket().receive({ type: "session.output_transcript.delta", delta: "42.", start_ms: 5_000, end_ms: 5_300 });
+ } finally {
+ forget();
+ }
+ t.socket().drop();
+ const record = recorded(t)[0]!.record;
+ expect(record.spoken).toEqual([{ at: expect.any(Number), text: `Your code is ${HELD_SECRET_MASK}.` }]);
+ expect(JSON.stringify(record.spoken)).not.toMatch(/73|19|42/);
+ });
+
+ it("stores the call row with a held code masked after the code stops being held", async () => {
+ rmSync(DATA_DIR, { recursive: true, force: true });
+ const selection = () => ({ instanceId: "claude", model: "claude-sonnet-5" });
+ const store = new Store(selection);
+ const bot = store.createBot({}, { seedMessages: false });
+ const t = setup({ recordCall: (input) => recordLiveCall({ chatExists: () => true, appendMessage: (_threadId, message) => store.appendMessage(bot.threadId, message) }, input) });
+ const forget = addHeldSecretScrubber((text) => text.replaceAll("731942", HELD_SECRET_MASK));
+ try {
+ await t.start();
+ t.socket().receive({ type: "session.output_transcript.delta", delta: "Your code is 7319", start_ms: 1_000, end_ms: 1_500 });
+ t.socket().receive({ type: "session.output_transcript.delta", delta: "42.", start_ms: 3_000, end_ms: 3_300 });
+ } finally {
+ forget();
+ }
+ t.socket().drop();
+ flushLaterSaves();
+ const row = new Store(selection).messagesFor(bot.threadId).find((message) => message.kind === "call");
+ expect(row?.call?.spoken).toEqual([{ at: expect.any(Number), text: `Your code is ${HELD_SECRET_MASK}.` }]);
+ expect(JSON.stringify(row?.call?.spoken)).not.toContain("7319");
+ });
+
it("leaves a credential shape whole until the record is redacted, so a key split across deltas is masked in full", async () => {
const t = setup({ recordCall: vi.fn() });
await t.start();