Skip to content

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

fix(live): check the joint between spoken lines whatever the new line's length

AdityaUmale48fdd664e28c
diff --git a/packages/phone-protocol/src/live-call.ts b/packages/phone-protocol/src/live-call.ts
index 93a0de8f3a..b7cd99ef2a 100644
--- a/packages/phone-protocol/src/live-call.ts
+++ b/packages/phone-protocol/src/live-call.ts
@@ -113,12 +113,15 @@ export class SpokenLines {
}
/** 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. */
+ * masks something in the last lines joined, they become one line. Looks back while the earlier lines it has
+ * joined are shorter than SPOKEN_JOIN_WINDOW, however long the newest line is, 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--) {
+ let earlier = 0;
+ for (let start = this.lines.length - 2; start >= 0 && earlier < SPOKEN_JOIN_WINDOW; start--) {
joined = this.lines[start]!.text + joined;
+ earlier += this.lines[start]!.text.length;
const scrubbed = this.scrub(joined);
if (scrubbed === joined) continue;
const merged = this.lines.splice(start);
diff --git a/server/live-call-controller.test.ts b/server/live-call-controller.test.ts
index af319beca9..493e7de158 100644
--- a/server/live-call-controller.test.ts
+++ b/server/live-call-controller.test.ts
@@ -1767,7 +1767,23 @@ describe("LiveCallController record", () => {
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/);
+ expect(record.spoken?.map((line) => line.text).join(" ")).not.toMatch(/73|19|42/);
+ });
+
+ it("masks a held code split at a pause when the line after it is long", 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: `1942${".".repeat(508)}`, start_ms: 3_000, end_ms: 3_500 });
+ } 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}${".".repeat(508)}` }]);
});
it("stores the call row with a held code masked after the code stops being held", async () => {