From fa0b0e053fef0edd9bf159b100259add54e2d679 Mon Sep 17 00:00:00 2001 From: Jinwoo-H Date: Wed, 11 Nov 2026 18:52:03 -0500 Subject: [PATCH] fix(orchestration): reuse carried worker-list counts only for the same Run scope --- .../rpc/methods/orchestration/worker/worker-list-cursor.ts | 6 ++++-- .../rpc/methods/orchestration/worker/worker-list-method.ts | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/runtime/rpc/methods/orchestration/worker/worker-list-cursor.ts b/src/main/runtime/rpc/methods/orchestration/worker/worker-list-cursor.ts index 04c69dabffa..74d0d23180c 100644 --- a/src/main/runtime/rpc/methods/orchestration/worker/worker-list-cursor.ts +++ b/src/main/runtime/rpc/methods/orchestration/worker/worker-list-cursor.ts @@ -3,10 +3,11 @@ import type { WorkerTerminalListState } from '../../../../orchestration/terminal /** Order by databaseId; keep createdAt/dispatchId so older peers can decode new cursors. */ type WorkerListCursorAfter = { createdAt: string; dispatchId: string; databaseId?: number } -/** The first page's count of the pinned snapshot; later pages with the same filter repeat it instead of rescanning. */ +/** The first page's count of the pinned snapshot; later pages with the same scope repeat it instead of rescanning. */ export type WorkerListInventory = { total: number counts: Partial> + runId?: string terminalState?: WorkerTerminalListState } @@ -95,8 +96,9 @@ function isWorkerListInventory(value: unknown): value is WorkerListInventory { return false } // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: every field is checked below before the value is trusted. - const { total, counts, terminalState } = value as Partial + const { total, counts, runId, terminalState } = value as Partial return ( + (runId === undefined || typeof runId === 'string') && (terminalState === undefined || typeof terminalState === 'string') && Number.isSafeInteger(total) && Number(total) >= 0 && diff --git a/src/main/runtime/rpc/methods/orchestration/worker/worker-list-method.ts b/src/main/runtime/rpc/methods/orchestration/worker/worker-list-method.ts index 7892843c67b..7ee074feebc 100644 --- a/src/main/runtime/rpc/methods/orchestration/worker/worker-list-method.ts +++ b/src/main/runtime/rpc/methods/orchestration/worker/worker-list-method.ts @@ -214,7 +214,7 @@ async function projectWorkerListPageWithFilteredSnapshot( const inventory: WorkerListInventory = pinnedCount !== undefined && params.terminalState ? { total: pinnedCount, counts: { [params.terminalState]: pinnedCount } } - : carried && carried.terminalState === params.terminalState + : carried && carried.runId === params.run && carried.terminalState === params.terminalState ? carried : { ...db.countWorkerTerminalInventory({ @@ -222,6 +222,7 @@ async function projectWorkerListPageWithFilteredSnapshot( terminalState: params.terminalState, snapshot: args.snapshot }), + ...(params.run ? { runId: params.run } : {}), ...(params.terminalState ? { terminalState: params.terminalState } : {}) } const nextRow = pageRows.at(-1)