From a7a732e226c638ac5e02a4b64834b2dbd88ddf02 Mon Sep 17 00:00:00 2001 From: iliya Date: Sun, 31 May 2026 01:39:39 +0300 Subject: [PATCH] fix(team): guard runtime process row cache invalidation --- src/main/services/team/TeamProvisioningService.ts | 7 ++++++- test/main/services/team/TeamProvisioningService.test.ts | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/services/team/TeamProvisioningService.ts b/src/main/services/team/TeamProvisioningService.ts index 534dca9c..4e1e87b5 100644 --- a/src/main/services/team/TeamProvisioningService.ts +++ b/src/main/services/team/TeamProvisioningService.ts @@ -25932,7 +25932,12 @@ export class TeamProvisioningService { ): { rows: RuntimeTelemetryProcessTableRow[] | null } | null { const cached = this.runtimeProcessRowsForUsageSnapshotByTeam.get(teamName); const nowMs = Date.now(); - if (!cached || cached.expiresAtMs <= nowMs || cached.runId !== runId) { + if ( + !cached || + cached.expiresAtMs <= nowMs || + cached.runId !== runId || + cached.generation !== this.getRuntimeSnapshotCacheGeneration(teamName) + ) { return null; } diff --git a/test/main/services/team/TeamProvisioningService.test.ts b/test/main/services/team/TeamProvisioningService.test.ts index 610e8d67..f7b3981f 100644 --- a/test/main/services/team/TeamProvisioningService.test.ts +++ b/test/main/services/team/TeamProvisioningService.test.ts @@ -3514,7 +3514,7 @@ describe('TeamProvisioningService', () => { expect(listRuntimeProcessTableForCurrentPlatform).toHaveBeenCalledTimes(2); }); - it('keeps the short live runtime metadata cache for tracked runs', async () => { + it('reuses process rows through the short liveness cache for tracked runs', async () => { vi.useFakeTimers(); vi.setSystemTime(new Date('2026-05-03T12:00:00.000Z')); const svc = new TeamProvisioningService(); @@ -3533,6 +3533,11 @@ describe('TeamProvisioningService', () => { vi.setSystemTime(new Date('2026-05-03T12:00:03.000Z')); await (svc as any).getLiveTeamAgentRuntimeMetadata('runtime-team'); + expect(listRuntimeProcessTableForCurrentPlatform).toHaveBeenCalledTimes(1); + + vi.setSystemTime(new Date('2026-05-03T12:00:06.000Z')); + await (svc as any).getLiveTeamAgentRuntimeMetadata('runtime-team'); + expect(listRuntimeProcessTableForCurrentPlatform).toHaveBeenCalledTimes(2); });