Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

perf: avoid nested session lookup in pane header refreshes (#1719)

Joshua France05067740d8f8
diff --git a/plugins/web-ui/src/split.ts b/plugins/web-ui/src/split.ts
index d3e22e5b7..7a5e09b81 100644
--- a/plugins/web-ui/src/split.ts
+++ b/plugins/web-ui/src/split.ts
@@ -805,10 +805,13 @@ export function drawCanvas(): void {
function computeHeaderSignature(): string {
return (dockApi?.panels ?? [])
- .map(
- (p) =>
- `${p.id}|${paneSession(p)?.id ?? ""}|${paneCrumb(p) ?? ""}|${paneTitle(p)}|${JSON.stringify(paneSession(p)?.status ?? null)}|${paneIsWorking(p)}|${paneAwaitsInput(p)}|${paneBackground(p)?.label ?? ""}|${paneKindBadge(p)}|${paneSession(p)?.parentSessionId ?? ""}|${sessionsState.list.find((row) => row.id === paneSession(p)?.parentSessionId)?.title ?? ""}`,
- )
+ .map((p) => {
+ const session = paneSession(p);
+ const parent = session?.parentSessionId
+ ? sessionsState.list.find((row) => row.id === session.parentSessionId)
+ : undefined;
+ return `${p.id}|${session?.id ?? ""}|${paneCrumb(p) ?? ""}|${paneTitle(p)}|${JSON.stringify(session?.status ?? null)}|${paneIsWorking(p)}|${paneAwaitsInput(p)}|${paneBackground(p)?.label ?? ""}|${paneKindBadge(p)}|${session?.parentSessionId ?? ""}|${parent?.title ?? ""}`;
+ })
.join("~");
}
diff --git a/plugins/web-ui/test/single-view-navigation.test.ts b/plugins/web-ui/test/single-view-navigation.test.ts
index b4002e280..a49daea57 100644
--- a/plugins/web-ui/test/single-view-navigation.test.ts
+++ b/plugins/web-ui/test/single-view-navigation.test.ts
@@ -19,6 +19,41 @@ const compile = (source: string): string =>
compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.None },
}).outputText;
+test("pane header updates scan session metadata linearly and retain parent-title invalidation", () => {
+ let reads = 0;
+ const list = Array.from({ length: 128 }, (_, index) => ({
+ get id() {
+ reads++;
+ return `session-${index}`;
+ },
+ title: `Title ${index}`,
+ parentSessionId: index === 126 ? "session-0" : undefined,
+ }));
+ const panels = [126, 127].map((index) => ({ id: `pane-${index}`, params: { sessionId: `session-${index}` } }));
+ const signature = runInNewContext(
+ compile(
+ `${functionSource(split, "paneSession")}\n${functionSource(split, "computeHeaderSignature")}\ncomputeHeaderSignature;`,
+ ),
+ {
+ sessionsState: { list },
+ dockApi: { panels },
+ panelParams: (panel: { params: object }) => panel.params,
+ paneCrumb: () => null,
+ paneTitle: () => "Conversation",
+ paneIsWorking: () => false,
+ paneAwaitsInput: () => false,
+ paneBackground: () => null,
+ paneKindBadge: () => 0,
+ },
+ ) as () => string;
+ const before = signature();
+ assert.match(before, /session-0\|Title 0/);
+ assert.ok(reads <= list.length * panels.length * 8, `Header update visited ${reads} session IDs`);
+ list[0]!.title = "Renamed parent";
+ assert.notEqual(signature(), before);
+ assert.match(signature(), /session-0\|Renamed parent/);
+});
+
test("single-pane navigation follows the pane identity without depending on the session list", () => {
const dockApi = { panels: [] as { params: { sessionId?: string; appId?: string } }[] };
const splitState = { active: true };