Skip to content

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

Chat: keep a turn's silence start across mode switches

Krishna Dobhaldb27b413c524
diff --git a/src/components/TurnPresence.tsx b/src/components/TurnPresence.tsx
index c8d2f2046b..4c4a9477fe 100644
--- a/src/components/TurnPresence.tsx
+++ b/src/components/TurnPresence.tsx
@@ -4,7 +4,7 @@ import { cn } from "@/lib/cn";
import { WorkingTimer } from "@/components/WorkingIndicator";
import { phraseAt, phraseHoldMs } from "@/lib/live-activity";
import { quietText, silenceText } from "@/lib/now-steps";
-import { lastFrameAt } from "@/state/turn-status";
+import { silentSince } from "@/state/turn-status";
import { t } from "@/lib/i18n";
import { formatElapsed } from "@/lib/working-time";
import type { StepQuiet } from "../../shared/turn-progress";
@@ -72,13 +72,12 @@ function QuietPart({ quiet }: { quiet: StepQuiet }) {
/** "nothing new for 5 min" when the whole turn has gone silent, counted from the last frame this window saw. */
function SilencePart({ threadId }: { threadId: string }) {
- const [watchedFrom] = useState(() => Date.now());
const [now, setNow] = useState(() => Date.now());
useEffect(() => {
const timer = setInterval(() => setNow(Date.now()), 15_000);
return () => clearInterval(timer);
}, []);
- const text = silenceText(lastFrameAt(threadId) ?? watchedFrom, now);
+ const text = silenceText(silentSince(threadId), now);
return text ? <><Dot /><span data-turn-silent="" className="text-[12px] text-ink-tertiary">{text}</span></> : null;
}
diff --git a/src/state/turn-status.test.ts b/src/state/turn-status.test.ts
index d65960ba34..e240fdbae4 100644
--- a/src/state/turn-status.test.ts
+++ b/src/state/turn-status.test.ts
@@ -1,25 +1,34 @@
-import { afterEach, describe, expect, it } from "vitest";
+import { afterEach, describe, expect, it, vi } from "vitest";
import type { RuntimeEvent } from "../../shared/runtime-events";
-import { lastFrameAt, noteTurnEvent, resetTurnLive, turnLive } from "./turn-status";
+import { noteTurnEvent, resetTurnLive, silentSince, turnLive } from "./turn-status";
let seq = 0;
const note = (event: Partial<RuntimeEvent>, threadId = "t") =>
noteTurnEvent({ eventId: `e${++seq}`, provider: "claudeAgent", threadId, createdAt: "2026-10-23T12:00:00.000Z", turnId: "turn-1", ...event } as RuntimeEvent);
-afterEach(() => resetTurnLive());
+afterEach(() => {
+ resetTurnLive();
+ vi.restoreAllMocks();
+});
-describe("a thread's last frame", () => {
- it("stamps every frame, even one that changes nothing on the line", () => {
- expect(lastFrameAt("t")).toBeUndefined();
+describe("a thread's silence", () => {
+ it("restarts at every frame, even one that changes nothing on the line", () => {
+ const clock = vi.spyOn(Date, "now").mockReturnValue(1_000);
note({ type: "content.delta", streamKind: "assistant_text", delta: "a" } as Partial<RuntimeEvent>);
- const first = lastFrameAt("t")!;
- expect(first).toBeGreaterThan(0);
const status = turnLive("t");
+ clock.mockReturnValue(5_000);
note({ type: "content.delta", streamKind: "assistant_text", delta: "b" } as Partial<RuntimeEvent>);
- expect(lastFrameAt("t")).toBeGreaterThanOrEqual(first);
+ expect(silentSince("t")).toBe(5_000);
expect(turnLive("t"), "the line's state is untouched, so nothing re-renders").toBe(status);
});
+
+ it("before any frame, counts from when the window first asked, however often it asks", () => {
+ const clock = vi.spyOn(Date, "now").mockReturnValue(1_000);
+ expect(silentSince("t")).toBe(1_000);
+ clock.mockReturnValue(90_000);
+ expect(silentSince("t")).toBe(1_000);
+ });
});
describe("a thread's live turn", () => {
diff --git a/src/state/turn-status.ts b/src/state/turn-status.ts
index 7960c70891..6882bfe82d 100644
--- a/src/state/turn-status.ts
+++ b/src/state/turn-status.ts
@@ -79,9 +79,14 @@ export function turnLive(threadId: string | null | undefined): TurnLive {
return (threadId && threads.get(threadId)) || UNKNOWN;
}
-/** When this thread last sent any live frame. Read on a clock rather than subscribed, so streamed text never re-renders. */
-export function lastFrameAt(threadId: string | null | undefined): number | undefined {
- return threadId ? lastFrames.get(threadId) : undefined;
+/** When this thread last sent any live frame, or, before its first one, when this window first asked. Read on a clock
+ * rather than subscribed, so streamed text never re-renders. */
+export function silentSince(threadId: string): number {
+ const at = lastFrames.get(threadId);
+ if (at !== undefined) return at;
+ const now = Date.now();
+ lastFrames.set(threadId, now);
+ return now;
}
function subscribe(threadId: string | null | undefined, listener: () => void): () => void {