fix(orchestration): reuse carried worker-list counts only for the same Run scope

This commit is contained in:
Jinwoo-H
2026-11-11 18:52:03 -05:00
parent 2ba4815709
commit fa0b0e053f
2 changed files with 6 additions and 3 deletions
@@ -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<Record<WorkerTerminalListState, number>>
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<WorkerListInventory>
const { total, counts, runId, terminalState } = value as Partial<WorkerListInventory>
return (
(runId === undefined || typeof runId === 'string') &&
(terminalState === undefined || typeof terminalState === 'string') &&
Number.isSafeInteger(total) &&
Number(total) >= 0 &&
@@ -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)