Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(inspector): retain equal-time events across refreshes
agooll11e097709f04
diff --git a/src/components/InspectorPanel.tsx b/src/components/InspectorPanel.tsxindex 6ccb4ceb43..2f5e49a2f6 100644--- a/src/components/InspectorPanel.tsx+++ b/src/components/InspectorPanel.tsx@@ -18,9 +18,7 @@ const tabLabel = (key: LocaleKey) => (activeLocale() === "en" ? t(key) : capitaltype Lens = "run" | "events" | "raw";/**- * Displays one thread's Inspector snapshot and live event window.- * Snapshot requests share the live subscription's buffering lifecycle, including- * the initial request, because disk persistence can lag behind live delivery.+ * Disk persistence can lag behind live delivery, even for equal-time events.* Native expansion resets on a loaded snapshot: its positional keys are not identities.*/export function InspectorPanel({ bot }: { bot: Bot }) {diff --git a/src/components/live-panels.test.ts b/src/components/live-panels.test.tsindex 7e8cc09032..622cce693a 100644--- a/src/components/live-panels.test.ts+++ b/src/components/live-panels.test.ts@@ -70,6 +70,27 @@ afterEach(() => {});describe("Inspector on the app's live stream", () => {+ it("retains a distinct equal-time live event received before a later refresh", async () => {+ await mount(InspectorPanel);+ const events = [...document.querySelectorAll<HTMLButtonElement>('[role="tab"]')].find((tab) => tab.textContent === "events")!;+ flushSync(() => events.click());+ frame(runtime("before-equal", { type: "item.started", itemType: "tool", title: "pre-refresh equal tail" }));+ await vi.waitFor(() => expect(document.body.textContent).toContain("pre-refresh equal tail"));+ vi.stubGlobal("fetch", () => Promise.resolve(new Response(JSON.stringify({+ entries: [{ kind: "runtime", at: "2026-10-04T09:00:00.000Z", data: runtime("disk-equal", { type: "item.started", itemType: "tool", title: "equal disk snapshot" }) }],+ total: { runtime: 1, native: 0 },+ }))));+ missed();+ await vi.waitFor(() => expect(document.body.textContent).toContain("equal disk snapshot"));+ expect(document.body.textContent).toContain("pre-refresh equal tail");+ expect(document.querySelectorAll('button .tabular-nums')).toHaveLength(2);+ expect(document.body.textContent).toContain("2 entries");+ missed();+ await settle();+ expect(document.querySelectorAll('button .tabular-nums')).toHaveLength(2);+ expect(document.body.textContent).toContain("2 entries");+ });+it("buffers distinct equal-time live events during the initial snapshot load", async () => {let finish!: (response: Response) => void;vi.stubGlobal("fetch", () => new Promise<Response>((resolve) => { finish = resolve; }));diff --git a/src/lib/inspector-window.test.ts b/src/lib/inspector-window.test.tsindex 9f59f01776..4b01503cea 100644--- a/src/lib/inspector-window.test.ts+++ b/src/lib/inspector-window.test.ts@@ -9,6 +9,18 @@ const event = (i: number): RuntimeEvent => ({const entry = (i: number): InspectorEntry => ({ kind: "runtime", at: String(i), data: event(i) });describe("Inspector's recent event window", () => {+ it("preserves distinct equal-time records without an overlap and counts the union once", () => {+ const first = { ...event(1), createdAt: "same" };+ const second = { ...event(2), createdAt: "same" };+ const previous: InspectorPage = { entries: [{ kind: "runtime", at: "same", data: second }], total: { runtime: 1, native: 0 } };+ const snapshot: InspectorPage = { entries: [{ kind: "runtime", at: "same", data: first }], total: { runtime: 1, native: 0 } };+ const merged = mergeInspectorSnapshot(previous, snapshot);+ expect(merged.entries).toEqual([...snapshot.entries, ...previous.entries]);+ expect(merged.total.runtime).toBe(2);+ expect(mergeInspectorSnapshot(merged, snapshot)).toEqual(merged);+ expect(mergeInspectorSnapshot(merged, merged)).toEqual(merged);+ });+it("retains a live tail across stale snapshots and counts it once when disk catches up", () => {const previous: InspectorPage = { entries: [entry(1), entry(2), entry(3)], total: { runtime: 53, native: 12 } };const snapshot: InspectorPage = { entries: [entry(1), entry(2)], total: { runtime: 52, native: 10 } };diff --git a/src/lib/inspector-window.ts b/src/lib/inspector-window.tsindex 1bbb1744d6..ef6e5abb4a 100644--- a/src/lib/inspector-window.ts+++ b/src/lib/inspector-window.ts@@ -44,7 +44,8 @@ export function appendInspectorRuntime(page: InspectorPage | null, events: Runti/*** Reconciles a disk snapshot with the retained runtime tail when persistence lags.* A shared event ID anchors publication order even for equal timestamps; without- * an overlap, only a later timestamp establishes that a retained event is newer.+ * an overlap, equal-time records remain ambiguous and distinct IDs are retained+ * alongside later records rather than risking the loss of a live event.* Events arriving during the request must be buffered separately by the caller* and appended afterward, including distinct events with equal timestamps.* Native records come from the snapshot, while the runtime total never decreases.@@ -57,7 +58,7 @@ export function mergeInspectorSnapshot(previous: InspectorPage | null, snapshot:const ids = new Set(snapshotRuntime.map((entry) => entry.data.eventId));const overlap = runtime.findLastIndex((event) => ids.has(event.eventId));const latest = snapshotRuntime.at(-1)?.at;- const tail = overlap >= 0 ? runtime.slice(overlap + 1) : runtime.filter((event) => latest === undefined || event.createdAt > latest);+ const tail = overlap >= 0 ? runtime.slice(overlap + 1) : runtime.filter((event) => latest === undefined || event.createdAt >= latest);const merged = appendInspectorRuntime(next, tail)!;return { ...merged, total: { ...merged.total, runtime: Math.max(previous.total.runtime, merged.total.runtime) } };}