From b5bdab0a63ff059aebbb703a2b721d227570dfcb Mon Sep 17 00:00:00 2001 From: Mr0Bread <55754540+Mr0Bread@users.noreply.github.com> Date: Wed, 18 Nov 2026 05:55:57 +0200 Subject: [PATCH] fix(agents): release closed and deleted tasks' conversations (#4037) The agents store never released a task's conversation: deleting, archiving, closing its tab or switching the docked task kept its entries, subagent conversations and changes in memory for the whole session, and the Web Content process kept growing in long sessions. A deleted task, or an archived one that isn't shown, is now dropped at once; closed or un-docked tasks stay in a cache of the 5 most recent and fetch their conversation and changes again when reopened. Change fetches that finish after a task's cache was dropped are discarded. The symbol lookup, file-existence and GitHub item caches are bounded, and a large symbol lookup answers every name of the request. Co-authored-by: Mr0Bread <55754540+Mr0Bread@users.noreply.github.com> --- src/features/agents/ReferenceChip.tsx | 15 ++- src/features/agents/SessionAssets.tsx | 8 +- src/features/agents/index.ts | 5 + src/features/agents/sessionState.test.tsx | 64 ++++++++++ src/features/agents/store.ts | 139 +++++++++++++++++++++- src/features/agents/symbolLinks.test.ts | 11 ++ src/features/agents/symbolLinks.ts | 26 ++-- src/features/agents/unread.test.tsx | 84 ++++++++++++- 8 files changed, 334 insertions(+), 18 deletions(-) diff --git a/src/features/agents/ReferenceChip.tsx b/src/features/agents/ReferenceChip.tsx index 6655eecf5..07453dfe4 100644 --- a/src/features/agents/ReferenceChip.tsx +++ b/src/features/agents/ReferenceChip.tsx @@ -28,17 +28,22 @@ import styles from "./ReferenceChip.module.css"; export { styles as chipStyles }; +const MAX_EXISTING = 4000; /** Whether a path names an existing file or folder, per path (the same files come up again and again). */ const existing = new Map>(); export function fileExists(path: string): Promise { let known = existing.get(path); - if (!known) { - known = call(commands.fsProbe(path)).then( - () => true, - () => false, - ); + if (known) { + existing.delete(path); existing.set(path, known); + return known; } + known = call(commands.fsProbe(path)).then( + () => true, + () => false, + ); + if (existing.size >= MAX_EXISTING) existing.delete(existing.keys().next().value!); + existing.set(path, known); return known; } diff --git a/src/features/agents/SessionAssets.tsx b/src/features/agents/SessionAssets.tsx index 87e8fdb64..58f8dd607 100644 --- a/src/features/agents/SessionAssets.tsx +++ b/src/features/agents/SessionAssets.tsx @@ -51,6 +51,7 @@ interface PopupSection { items: PopupItem[]; } +const MAX_GH_META = 500; /** Shared per-process cache so repeated renders/tabs never re-query `gh api` for the same PR or issue. */ const ghMetaCache = new Map>(); const ghResolvedMeta = new Map(); @@ -117,9 +118,14 @@ function fetchGithubMeta( .then((text) => parseGhItemResponse(text, kind)) .catch(() => null) .then((meta) => { - ghResolvedMeta.set(cacheKey, meta); + if (ghMetaCache.get(cacheKey) === req) ghResolvedMeta.set(cacheKey, meta); return meta; }); + if (ghMetaCache.size >= MAX_GH_META) { + const oldest = ghMetaCache.keys().next().value!; + ghMetaCache.delete(oldest); + ghResolvedMeta.delete(oldest); + } ghMetaCache.set(cacheKey, req); return req; } diff --git a/src/features/agents/index.ts b/src/features/agents/index.ts index b0844ca1e..0d2a00456 100644 --- a/src/features/agents/index.ts +++ b/src/features/agents/index.ts @@ -47,6 +47,7 @@ import { openHome, refreshModels, refreshProviders, + releaseClosedTaskCache, useAgents, } from "./store"; import { TaskStatusMark } from "./TaskStatusMark"; @@ -174,6 +175,10 @@ export function activate(): () => void { // Tabs of tasks deleted meanwhile are closed when the tasks load (`connect`). restorable: true, onTabClose: (tabId) => clearAgentTabFontZoom(tabId), + onClose: (input) => { + const task = (input.data as { task?: string } | undefined)?.task; + if (task) releaseClosedTaskCache(task); + }, // Rebuilding a long conversation on every switch back is slow. keepAlive: true, }), diff --git a/src/features/agents/sessionState.test.tsx b/src/features/agents/sessionState.test.tsx index c7899a637..b01e49264 100644 --- a/src/features/agents/sessionState.test.tsx +++ b/src/features/agents/sessionState.test.tsx @@ -15,6 +15,7 @@ import { hideImportSessions, importExternalSessions, refreshExternalSessions, + releaseClosedTaskCache, showImportSessions, useAgents, } from "./store"; @@ -2115,6 +2116,69 @@ describe("session state across tasks and hosts", () => { act(() => disconnect()); expect(useAgents.getState().scrollPositions.size).toBe(0); }); + + it("bounds retained entries for closed tabs (including busy and subagent entries) and refreshes MRU order", () => { + const entries = new Map(); + const entryLoads = new Map(); + const changes = new Map(); + const scrollPositions = new Map(); + const tasks = new Map(); + const baseTask = useAgents.getState().tasks.get("A")!; + for (let i = 1; i <= 7; i++) { + const id = `T${i}`; + tasks.set(id, { ...baseTask, id, title: id, status: i === 2 ? "running" : "ready" }); + entries.set(id, [{ type: "agent", text: `Reply ${id}` }]); + entries.set(`${id}/sub`, [{ type: "agent", text: `Sub ${id}` }]); + entryLoads.set(id, { error: "err" }); + changes.set(id, [{ path: "a.ts", relPath: "a.ts", oldPath: null, kind: "modified", added: 1, removed: 0 }]); + scrollPositions.set(id, { top: 10, stick: false }); + } + entries.set("gone", [{ type: "agent", text: "Deleted reply" }]); + useAgents.setState({ tasks, entries, entryLoads, changes, scrollPositions }); + for (let i = 1; i <= 5; i++) releaseClosedTaskCache(`T${i}`); + // A deleted task's tab closing drops its data without taking one of the cached slots. + releaseClosedTaskCache("gone"); + expect(useAgents.getState().entries.has("gone")).toBe(false); + expect(useAgents.getState().entries.has("T1")).toBe(true); + // Re-closing T1 refreshes it so T2 (even though running) becomes the oldest and is evicted next. + releaseClosedTaskCache("T1"); + releaseClosedTaskCache("T6"); + releaseClosedTaskCache("T7"); + const state = useAgents.getState(); + expect(state.entries.has("T1")).toBe(true); + expect(state.entries.has("T2")).toBe(false); + expect(state.entries.has("T2/sub")).toBe(false); + expect(state.entryLoads.has("T2")).toBe(false); + expect(state.changes.has("T2")).toBe(false); + expect(state.scrollPositions.has("T2")).toBe(false); + expect(state.entries.has("T3")).toBe(false); + expect(state.entries.has("T7")).toBe(true); + }); + + it("loads an archived task's conversation and changes again when it reopens after its cache was dropped", async () => { + backend.changes = [ + { + path: "/project/kept-change.ts", + relPath: "kept-change.ts", + kind: "modified", + added: 1, + removed: 0, + oldPath: null, + }, + ]; + localStorage.setItem("openidea.agents.changesOpen.v1", JSON.stringify({ A: true })); + useAgents.setState((s) => ({ + tasks: new Map(s.tasks).set("A", { ...s.tasks.get("A")!, status: "archived" }), + })); + releaseClosedTaskCache("A"); + expect(useAgents.getState().entries.has("A")).toBe(false); + backend.fetched = []; + render(); + expect(await screen.findByText("Answer A")).toBeInTheDocument(); + const panel = await screen.findByRole("complementary", { name: "Changes" }); + expect(await within(panel).findByText("kept-change.ts")).toBeInTheDocument(); + expect(backend.fetched).toEqual(["A"]); + }); }); describe("meters in the task header", () => { diff --git a/src/features/agents/store.ts b/src/features/agents/store.ts index 231135a59..b7267aeac 100644 --- a/src/features/agents/store.ts +++ b/src/features/agents/store.ts @@ -546,11 +546,117 @@ function onEntryEvent(s: AgentsState, e: EntryEvent) { else if (next !== current) useAgents.setState({ entries: new Map(s.entries).set(key, next) }); } +const CACHED_CLOSED_TASKS = 5; + +/** Recent closed-task ids kept in memory so reopening a just-closed tab avoids refetching. */ +const closedTaskMru: string[] = []; +/** Bumped when a task's cache is dropped, so a fetch started before that doesn't refill it. */ +const cacheDrops = new Map(); + +function isTaskKey(key: string, taskId: string): boolean { + return key === taskId || key.startsWith(`${taskId}/`); +} + +function forgetClosed(taskId: string) { + const idx = closedTaskMru.indexOf(taskId); + if (idx >= 0) closedTaskMru.splice(idx, 1); +} + +function clearTaskMaps(taskId: string, clearStreaming = false) { + forgetClosed(taskId); + for (const key of [...arrivedWhileLoading.keys()]) { + if (isTaskKey(key, taskId)) arrivedWhileLoading.delete(key); + } + // Mounted streams write into this map directly, so it is pruned in place rather than replaced. + const positions = useAgents.getState().scrollPositions; + for (const key of [...positions.keys()]) { + if (isTaskKey(key, taskId)) positions.delete(key); + } + if (clearStreaming) streamingReply.delete(taskId); + const timer = pendingChanges.get(taskId); + if (timer !== undefined) { + clearTimeout(timer); + pendingChanges.delete(taskId); + } +} + +function withoutTaskCache(s: AgentsState, taskId: string): Partial | null { + let entries: Map | undefined; + for (const key of s.entries.keys()) { + if (isTaskKey(key, taskId)) (entries ??= new Map(s.entries)).delete(key); + } + let entryLoads: Map | undefined; + for (const key of s.entryLoads.keys()) { + if (isTaskKey(key, taskId)) (entryLoads ??= new Map(s.entryLoads)).delete(key); + } + let changes: Map | undefined; + if (s.changes.has(taskId)) { + changes = new Map(s.changes); + changes.delete(taskId); + } + let groupedChanges: Map | undefined; + if (s.groupedChanges.has(taskId)) { + groupedChanges = new Map(s.groupedChanges); + groupedChanges.delete(taskId); + } + if (!entries && !entryLoads && !changes && !groupedChanges) return null; + return { + ...(entries ? { entries } : {}), + ...(entryLoads ? { entryLoads } : {}), + ...(changes ? { changes } : {}), + ...(groupedChanges ? { groupedChanges } : {}), + }; +} + +function dropTaskCache(taskId: string) { + clearTaskMaps(taskId); + // A deleted task needs no marker: fetches already discard results for tasks that are gone. + if (useAgents.getState().tasks.has(taskId)) cacheDrops.set(taskId, (cacheDrops.get(taskId) ?? 0) + 1); + useAgents.setState((s) => withoutTaskCache(s, taskId) ?? s); +} + +function isTaskOpenInUi(taskId: string): boolean { + if (useAgents.getState().docked === taskId) return true; + return (editorService().openTabs?.() ?? []).some( + (t) => t.input.kind === SESSION_KIND && (t.input.data as { task?: string } | undefined)?.task === taskId, + ); +} + +/** Whether a background trigger should reload a task's changes: only while they are shown or still cached. */ +function wantsChanges(taskId: string): boolean { + const s = useAgents.getState(); + return s.changes.has(taskId) || s.groupedChanges.has(taskId) || isTaskOpenInUi(taskId); +} + +/** + * Releases cached conversation data for a closed or un-docked session once more than + * `CACHED_CLOSED_TASKS` closed tasks have been retained. Archived and deleted tasks are + * dropped immediately; other tasks stay in a small MRU cache so reopening is instant. + */ +export function releaseClosedTaskCache(taskId: string) { + if (!taskId || isTaskOpenInUi(taskId)) return; + const task = useAgents.getState().tasks.get(taskId); + if (!task || task.status === "archived") { + dropTaskCache(taskId); + return; + } + forgetClosed(taskId); + closedTaskMru.push(taskId); + while (closedTaskMru.length > CACHED_CLOSED_TASKS) { + const oldest = closedTaskMru.shift()!; + if (!isTaskOpenInUi(oldest)) dropTaskCache(oldest); + } +} + export function disconnect() { generation++; arrivedWhileLoading.clear(); streamingReply.clear(); modelFlights.clear(); + closedTaskMru.length = 0; + cacheDrops.clear(); + for (const timer of pendingChanges.values()) clearTimeout(timer); + pendingChanges.clear(); resetAllAgentFontZoom(); useAgents.setState({ loaded: false, @@ -584,9 +690,12 @@ function onEvent(e: AgentEvent) { const prev = s.tasks.get(e.task.id); useAgents.setState({ tasks: new Map(s.tasks).set(e.task.id, e.task) }); if (prev && (prev.title !== e.task.title || prev.status !== e.task.status)) notifyTabTitlesChanged(); - if (e.task.status === "archived") setUnread(e.task.id, false); - if (prev?.status !== e.task.status && !isBusy(e.task.status)) { - void refreshChanges(e.task.id); + if (e.task.status === "archived") { + setUnread(e.task.id, false); + if (prev?.status !== "archived" && !isTaskOpenInUi(e.task.id)) dropTaskCache(e.task.id); + } + if (prev?.status !== e.task.status && !isBusy(e.task.status) && e.task.status !== "archived") { + if (wantsChanges(e.task.id)) void refreshChanges(e.task.id); void refreshProviders(); } break; @@ -597,6 +706,8 @@ function onEvent(e: AgentEvent) { break; } case "removed": { + clearTaskMaps(e.id, true); + cacheDrops.delete(e.id); const tasks = new Map(s.tasks); tasks.delete(e.id); const composers = new Map(s.composers); @@ -610,6 +721,7 @@ function onEvent(e: AgentEvent) { tasks, composers, unread, + ...withoutTaskCache(s, e.id), organize, ...(s.docked === e.id ? { docked: null } : {}), }); @@ -734,16 +846,23 @@ export async function loadEntries(task: string, subagent: string | null = null): } export async function refreshChanges(task: string): Promise { + const gen = generation; + const drops = cacheDrops.get(task); + // Discard a result that arrives after a project switch, the task's deletion, or its cache being dropped. + const stillWanted = () => + gen === generation && useAgents.getState().tasks.has(task) && cacheDrops.get(task) === drops; // Local tasks have no commits of their own to group: the flat list is their only view. const grouped = useChangesOptions.getState().groupByCommit && useAgents.getState().tasks.get(task)?.isolation === "worktree"; if (grouped) { try { const review = await call(commands.agentGroupedChanges(task)); + if (!stillWanted()) return; useAgents.setState((s) => ({ groupedChanges: new Map(s.groupedChanges).set(task, review), })); } catch { + if (!stillWanted()) return; // The worktree is gone or not a repository: nothing to list. useAgents.setState((s) => ({ groupedChanges: new Map(s.groupedChanges).set(task, { uncommitted: [], commits: [] }), @@ -753,10 +872,12 @@ export async function refreshChanges(task: string): Promise { } try { const changes = await call(commands.agentChanges(task)); + if (!stillWanted()) return; useAgents.setState((s) => ({ changes: new Map(s.changes).set(task, changes), })); } catch { + if (!stillWanted()) return; // The worktree is gone or not a repository: nothing to list. useAgents.setState((s) => ({ changes: new Map(s.changes).set(task, []) })); } @@ -792,7 +913,7 @@ export function scheduleChanges(task: string) { task, setTimeout(() => { pendingChanges.delete(task); - void refreshChanges(task); + if (wantsChanges(task)) void refreshChanges(task); }, 500), ); } @@ -850,6 +971,7 @@ export function useAgentCommands( } export function openTask(task: string) { + forgetClosed(task); if (useAgents.getState().sessionLocation === "toolWindow") { showDockedTask(task); return; @@ -865,12 +987,14 @@ function openTaskInEditor(task: string) { } function showDockedTask(task: string) { + const previousDocked = useAgents.getState().docked; useAgents.setState({ docked: task, lastTask: task, homeOpen: false, lastComposer: task, }); + if (previousDocked && previousDocked !== task) releaseClosedTaskCache(previousDocked); toolWindowService().show(TOOL_WINDOW, true); void editorService().closeInput?.(sessionKey(task)); } @@ -899,8 +1023,11 @@ export function setSessionLocation(location: SessionLocation) { [...s.tasks.values()] .filter((t) => t.status !== "archived") .sort((a, b) => (b.updatedMs ?? b.createdMs ?? 0) - (a.updatedMs ?? a.createdMs ?? 0))[0]?.id; + const previousDocked = s.docked; saveSessionLocation(location); useAgents.setState({ docked: null, homeOpen: false }); + // The docked task itself reopens in the new location unless the New Task page takes its place. + if (previousDocked && (home || previousDocked !== task)) releaseClosedTaskCache(previousDocked); if (home) { openHome(); } else if (task) { @@ -922,8 +1049,10 @@ export function undockTask() { /** An explicit editor drop also updates where subsequent sessions open. */ export function openTaskInEditorLocation(task: string) { + const previousDocked = useAgents.getState().docked; saveSessionLocation("editor"); useAgents.setState({ docked: null, homeOpen: false }); + if (previousDocked && previousDocked !== task) releaseClosedTaskCache(previousDocked); openTask(task); } @@ -957,7 +1086,9 @@ export function openHome(prompt?: string) { } if (prompt !== undefined) updateComposer(HOME, { text: prompt }); if (useAgents.getState().sessionLocation === "toolWindow") { + const previousDocked = useAgents.getState().docked; useAgents.setState({ docked: null, homeOpen: true }); + if (previousDocked) releaseClosedTaskCache(previousDocked); toolWindowService().show(TOOL_WINDOW, true); void editorService().closeInput?.(HOME_KEY); return; diff --git a/src/features/agents/symbolLinks.test.ts b/src/features/agents/symbolLinks.test.ts index 6b1d45a04..3cf707d1b 100644 --- a/src/features/agents/symbolLinks.test.ts +++ b/src/features/agents/symbolLinks.test.ts @@ -78,4 +78,15 @@ describe("lookupSymbols", () => { await lookupSymbols("/elsewhere", ["load"]).get("load"); expect(asked).toEqual([["FooView", "load"], ["BarView"], ["load"]]); }); + + it("answers every name of one request even when it exceeds the per-folder limit", async () => { + mockIPC((cmd, args) => { + if (cmd !== "find_symbols_named") return null; + const { names } = args as { names: string[] }; + return names.map((name) => symbol(name, `/repo/${name}.ts`)); + }); + const requested = Array.from({ length: 2001 }, (_, i) => `Name${i}`); + const found = lookupSymbols("/large", requested); + expect((await found.get("Name0"))!.map((match) => match.name)).toEqual(["Name0"]); + }); }); diff --git a/src/features/agents/symbolLinks.ts b/src/features/agents/symbolLinks.ts index e6559e13d..124673f07 100644 --- a/src/features/agents/symbolLinks.ts +++ b/src/features/agents/symbolLinks.ts @@ -8,24 +8,36 @@ import type { SymbolRef } from "./conversation"; /** Index answers by the folder they were asked in, then by name. */ const answers = new Map>>(); const NAMES_PER_FOLDER = 2000; +const MAX_FOLDERS = 16; /** The index's symbols named exactly each of `names` inside `within`; one request for the names not asked before. */ export function lookupSymbols(within: string, names: Iterable): Map> { - const known = answers.get(within) ?? new Map>(); + let known = answers.get(within); + if (known) { + answers.delete(within); + } else { + if (answers.size >= MAX_FOLDERS) answers.delete(answers.keys().next().value!); + known = new Map>(); + } answers.set(within, known); const wanted = new Set(names); - const missing = [...wanted].filter((name) => !known.has(name)); + const result = new Map>(); + const missing: string[] = []; + for (const name of wanted) { + const hit = known.get(name); + if (hit) result.set(name, hit); + else missing.push(name); + } if (missing.length) { const found = call(commands.findSymbolsNamed(missing, within)).catch(() => []); for (const name of missing) { + const promise = found.then((symbols) => symbols.filter((symbol) => symbol.name === name)); + result.set(name, promise); if (known.size >= NAMES_PER_FOLDER) known.delete(known.keys().next().value!); - known.set( - name, - found.then((symbols) => symbols.filter((symbol) => symbol.name === name)), - ); + known.set(name, promise); } } - return new Map([...wanted].map((name) => [name, known.get(name)!])); + return result; } /** Narrows `symbols` by each preference in turn, skipping one that would leave nothing. */ diff --git a/src/features/agents/unread.test.tsx b/src/features/agents/unread.test.tsx index eb3e945e6..1e0d65e90 100644 --- a/src/features/agents/unread.test.tsx +++ b/src/features/agents/unread.test.tsx @@ -13,7 +13,7 @@ import { AgentsStatus } from "./AgentsStatus"; import { activate } from "./index"; import { openChangeDiff } from "./session/ChangesPane"; import * as actions from "@/platform/actions"; -import { TASK_DRAG } from "./model"; +import { SESSION_KIND, sessionKey, TASK_DRAG } from "./model"; import { connect, disconnect, @@ -265,6 +265,88 @@ describe("agent unread activity", () => { expect(useAgents.getState().unread.size).toBe(0); expect([...useAgents.getState().tasks.keys()]).toEqual(["other"]); }); + + it("evicts entries, subagent entries, changes, and scroll positions when a task is removed or archived", () => { + backend.tabs = [ + { + input: { kind: SESSION_KIND, key: sessionKey("open"), data: { task: "open" } }, + title: "open", + icon: "toolwindow-agents", + lastActive: 1, + }, + ]; + useAgents.setState((s) => ({ + tasks: new Map(s.tasks).set("two", task("two", "ready")).set("open", task("open", "ready")), + entries: new Map(s.entries) + .set("one", [{ type: "agent", text: "Answer one" }]) + .set("one/child", [{ type: "agent", text: "Child one" }]) + .set("one1", [{ type: "agent", text: "Answer one1" }]) + .set("two", [{ type: "agent", text: "Answer two" }]) + .set("open", [{ type: "agent", text: "Answer open" }]), + changes: new Map(s.changes) + .set("one", [{ path: "a.ts", relPath: "a.ts", oldPath: null, kind: "modified", added: 1, removed: 0 }]) + .set("two", [{ path: "b.ts", relPath: "b.ts", oldPath: null, kind: "modified", added: 1, removed: 0 }]), + groupedChanges: new Map(s.groupedChanges) + .set("one", { uncommitted: [], commits: [] }) + .set("two", { uncommitted: [], commits: [] }), + scrollPositions: new Map(s.scrollPositions) + .set("one", { top: 100, stick: false }) + .set("one/child", { top: 50, stick: false }), + })); + emit({ type: "removed", id: "one" }); + const afterRemoved = useAgents.getState(); + expect(afterRemoved.entries.has("one")).toBe(false); + expect(afterRemoved.entries.has("one/child")).toBe(false); + expect(afterRemoved.changes.has("one")).toBe(false); + expect(afterRemoved.groupedChanges.has("one")).toBe(false); + expect(afterRemoved.scrollPositions.has("one")).toBe(false); + expect(afterRemoved.scrollPositions.has("one/child")).toBe(false); + expect(afterRemoved.entries.has("one1")).toBe(true); + expect(afterRemoved.entries.has("two")).toBe(true); + + emit({ type: "task", task: task("two", "archived") }); + const afterArchived = useAgents.getState(); + expect(afterArchived.entries.has("two")).toBe(false); + expect(afterArchived.changes.has("two")).toBe(false); + expect(afterArchived.groupedChanges.has("two")).toBe(false); + + // An archived task that is still open in a tab keeps its entries until closed. + emit({ type: "task", task: task("open", "archived") }); + expect(useAgents.getState().entries.has("open")).toBe(true); + backend.tabs = []; + const dispose = activate(); + try { + const sessionKind = useContributions.getState().editorKinds.get(SESSION_KIND); + sessionKind?.onClose?.({ kind: SESSION_KIND, key: sessionKey("open"), data: { task: "open" } }); + expect(useAgents.getState().entries.has("open")).toBe(false); + } finally { + dispose(); + } + }); + + it.each([false, true])( + "releases the previously docked task when another task or New Task replaces it (via New Task: %s)", + (viaHome) => { + setSessionLocation("toolWindow"); + const tasks = new Map(); + const entries = new Map(); + for (let i = 1; i <= 7; i++) { + const id = `D${i}`; + tasks.set(id, task(id, "ready")); + entries.set(id, [{ type: "agent", text: `Reply ${id}` }]); + } + useAgents.setState({ tasks, entries }); + for (let i = 1; i <= 7; i++) { + if (viaHome) openHome(); + openTask(`D${i}`); + } + const state = useAgents.getState(); + expect(state.docked).toBe("D7"); + expect(state.entries.has("D1")).toBe(false); + expect(state.entries.has("D7")).toBe(true); + expect(state.entries.size).toBe(6); // D7 docked + 5 most recently un-docked (D2..D6) + }, + ); }); describe("agent unread indicators", () => {