Stop the UI freeze: coalesce snapshot storms and bound chat rendering
Busy agents emitted a snapshot-changed broadcast per tool turn; every event made the renderer reload the full snapshot while the main process re-read whole audit tables synchronously, and ChatTimeline re-rendered every message with per-row linear scans - quadratic work per keystroke of agent activity until clicks stopped responding. Root fixes at each layer: all broadcasts funnel through one 200ms-coalesced notifier (unit-tested), the renderer reloads at most every 800ms with a trailing load, audit/access snapshot reads use SQL limits instead of full-table scans, and the timeline renders the latest 150 messages via O(n) lookup maps with a real show-earlier control. cred.txt is now gitignored so the Composio key cannot leak.
This commit is contained in:
1 parent
538bf20057
commit
f13ef48a3e
8 files changed
+158
-25
No files matched your search
@@ -0,0 +1,49 @@
|
||||
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
||||
import { coalesce } from "../../src/main/app/coalesce";
|
||||
|
||||
describe("coalesce", () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
test("collapses a burst into one trailing call", () => {
|
||||
const calls: number[] = [];
|
||||
const notify = coalesce(() => calls.push(Date.now()), 200);
|
||||
notify();
|
||||
notify();
|
||||
notify();
|
||||
expect(calls).toHaveLength(0);
|
||||
vi.advanceTimersByTime(199);
|
||||
expect(calls).toHaveLength(0);
|
||||
vi.advanceTimersByTime(1);
|
||||
expect(calls).toHaveLength(1);
|
||||
});
|
||||
|
||||
test("fires again for events after the window closes", () => {
|
||||
let count = 0;
|
||||
const notify = coalesce(() => { count += 1; }, 200);
|
||||
notify();
|
||||
vi.advanceTimersByTime(200);
|
||||
expect(count).toBe(1);
|
||||
notify();
|
||||
notify();
|
||||
vi.advanceTimersByTime(200);
|
||||
expect(count).toBe(2);
|
||||
});
|
||||
|
||||
test("an event during the pending window is covered by the trailing call", () => {
|
||||
let count = 0;
|
||||
const notify = coalesce(() => { count += 1; }, 200);
|
||||
notify();
|
||||
vi.advanceTimersByTime(100);
|
||||
notify();
|
||||
vi.advanceTimersByTime(100);
|
||||
expect(count).toBe(1);
|
||||
vi.advanceTimersByTime(200);
|
||||
expect(count).toBe(1);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user