From 592ba6d503575f64a1945dce358e0bbefa6bca4f Mon Sep 17 00:00:00 2001 From: Neil Date: Wed, 11 Nov 2026 02:06:01 -0800 Subject: [PATCH] fix(cloud): a running Orca Cloud pane re-reads its agent account every ~30 s while visible, so a revoke shows the strip within ~30 s (no server push) --- .../cloud-running-agent-signout.test.ts | 14 ++++++++++ .../orca-cloud/cloud-running-agent-signout.ts | 27 ++++++++++++++----- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/renderer/src/lib/orca-cloud/cloud-running-agent-signout.test.ts b/src/renderer/src/lib/orca-cloud/cloud-running-agent-signout.test.ts index 7f000bf86e0..b1a735cc5bf 100644 --- a/src/renderer/src/lib/orca-cloud/cloud-running-agent-signout.test.ts +++ b/src/renderer/src/lib/orca-cloud/cloud-running-agent-signout.test.ts @@ -2,6 +2,8 @@ import { beforeEach, describe, expect, it } from 'vitest' import type { OrcaCloudAgentsStatus } from '../../../../shared/orca-cloud-agents/orca-cloud-agents-wire' import type { OrcaCloudAgentAccountsState } from './orca-cloud-agent-accounts-store' import { + CLOUD_RUNNING_LIVE_READ_MS, + cloudRunningLiveReadDue, clearCloudRunningSignout, cloudRunningStrip, resetCloudRunningSignoutForTest, @@ -157,3 +159,15 @@ describe('D13: only workspaces that run the agent on the person’s own account' ) }) }) + +describe('running-pane live read (RA-11f)', () => { + it('re-reads about every 30 s, so a revoke reaches the strip within ~30 s', () => { + expect(CLOUD_RUNNING_LIVE_READ_MS).toBe(30_000) + // A read from any caller within the last ~29 s counts; the poll skips. + expect(cloudRunningLiveReadDue(100_000, 110_000)).toBe(false) + expect(cloudRunningLiveReadDue(100_000, 128_999)).toBe(false) + // A poll old: the poll forces a fresh read (no 30 s cache skip at the boundary). + expect(cloudRunningLiveReadDue(100_000, 129_000)).toBe(true) + expect(cloudRunningLiveReadDue(100_000, 160_000)).toBe(true) + }) +}) diff --git a/src/renderer/src/lib/orca-cloud/cloud-running-agent-signout.ts b/src/renderer/src/lib/orca-cloud/cloud-running-agent-signout.ts index b9994498767..ba7274d7eaa 100644 --- a/src/renderer/src/lib/orca-cloud/cloud-running-agent-signout.ts +++ b/src/renderer/src/lib/orca-cloud/cloud-running-agent-signout.ts @@ -12,6 +12,8 @@ import { installWindowVisibilityInterval } from '@/lib/window-visibility-interva import { orcaCloudAgentCoverage } from './orca-cloud-agent-accounts-model' import { ensureFreshOrcaCloudAgentAccounts, + orcaCloudAgentAccountsLoadedAt, + reloadOrcaCloudAgentAccounts, type OrcaCloudAgentAccountsState } from './orca-cloud-agent-accounts-store' @@ -136,16 +138,29 @@ export function cloudRunningStrip(args: { let liveReaders = 0 let stopInterval: (() => void) | null = null -const LIVE_READ_MS = 60_000 +/** How soon a revoke shows on a running pane: the server pushes nothing, so the desktop re-reads. */ +export const CLOUD_RUNNING_LIVE_READ_MS = 30_000 + +/** The poll forces a read once the last one (from any caller) is about a poll old. */ +export function cloudRunningLiveReadDue(loadedAt: number, now: number): boolean { + return now - loadedAt >= CLOUD_RUNNING_LIVE_READ_MS - 1_000 +} function readNow(): void { void ensureFreshOrcaCloudAgentAccounts().catch(() => undefined) } +function pollNow(): void { + if (cloudRunningLiveReadDue(orcaCloudAgentAccountsLoadedAt(), Date.now())) { + void reloadOrcaCloudAgentAccounts().catch(() => undefined) + } +} + /** - * While any running Orca Cloud agent pane is mounted, keep the account read fresh: on window focus - * and at most once a minute while the window is visible (the read itself is cached for 30 s). The - * desktop gets no push for a revoke, so this read is how the strip learns. One timer per window. + * While any running Orca Cloud agent pane is mounted, keep the account read fresh: on window focus, + * and every ~30 s while the window is visible (paused while hidden, slower behind another app), so + * a revoke flips the strip within about 30 s. The desktop gets no push for a revoke, so this read is + * how the strip learns. One timer per window. */ export function useCloudRunningAccountReads(active: boolean): void { useEffect(() => { @@ -156,8 +171,8 @@ export function useCloudRunningAccountReads(active: boolean): void { if (liveReaders === 1) { window.addEventListener('focus', readNow) stopInterval = installWindowVisibilityInterval({ - run: readNow, - intervalMs: LIVE_READ_MS, + run: pollNow, + intervalMs: CLOUD_RUNNING_LIVE_READ_MS, slowWhileUnfocused: true }) readNow()