From bf265267105cf2a37ce619954e9cd18c0e6f09a8 Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 10 Nov 2026 21:35:51 -0800 Subject: [PATCH] fix(cloud-sync): lint gates (no setInterval, no casts, scroll on the popover body) --- src/main/cloud-sync/cloud-sync-ipc.ts | 19 +++++-- src/main/cloud-sync/cloud-sync-plan.ts | 11 ++++ src/main/cloud-sync/cloud-sync-remote.ts | 16 +++--- .../cloud-sync/cloud-sync-service.test.ts | 7 +-- src/main/cloud-sync/cloud-sync-service.ts | 4 +- .../cloud-sync/cloud-sync-session.test.ts | 3 +- src/main/cloud-sync/cloud-sync-session.ts | 51 +++++++++---------- .../orca-cloud/CloudWorkspaceMark.tsx | 6 +-- .../orca-cloud/CloudWorkspaceSyncSection.tsx | 1 - 9 files changed, 68 insertions(+), 50 deletions(-) diff --git a/src/main/cloud-sync/cloud-sync-ipc.ts b/src/main/cloud-sync/cloud-sync-ipc.ts index ba378f0e723..8d7ddae07e4 100644 --- a/src/main/cloud-sync/cloud-sync-ipc.ts +++ b/src/main/cloud-sync/cloud-sync-ipc.ts @@ -161,12 +161,23 @@ export function installCloudSync(deps: { } } }) - const beat = setInterval(() => void sync.reconcile(), BEAT_MS) - beat.unref?.() - void sync.reconcile() + // One reconcile per beat, scheduled after the last one finished (never stacked). + let beat: ReturnType | null = null + let stopped = false + const scheduleBeat = (): void => { + if (stopped) { + return + } + beat = setTimeout(() => void sync.reconcile().finally(scheduleBeat), BEAT_MS) + beat.unref?.() + } + void sync.reconcile().finally(scheduleBeat) return () => { - clearInterval(beat) + stopped = true + if (beat) { + clearTimeout(beat) + } offRuntimes() offPower() for (const channel of [CH.getState, CH.setChoice, CH.openFolder, CH.retry, CH.removalPreview]) { diff --git a/src/main/cloud-sync/cloud-sync-plan.ts b/src/main/cloud-sync/cloud-sync-plan.ts index 03be8fd9a3e..1566af16d5d 100644 --- a/src/main/cloud-sync/cloud-sync-plan.ts +++ b/src/main/cloud-sync/cloud-sync-plan.ts @@ -160,3 +160,14 @@ export function planSync(input: { } return { download, remove, editedHere, skippedLarge, overLimit, totalBytes, totalFiles } } + +/** + * Safety net for anything the watch missed. The VM's watcher can miss a directory created along + * with its parent (`mkdir -p .context/shots`), so small folders are re-checked often (a few + * calls each) and large mirrors less often: 30 ms per file, between 30 s and 10 min, and never + * more than 5% of the time (a slow pass, e.g. on an image without files.statMany, waits longer). + */ +export const SAFETY_TICK_MS = 30_000 +export function safetyIntervalMs(files: number, lastPassMs = 0): number { + return Math.min(10 * 60_000, Math.max(SAFETY_TICK_MS, files * 30, lastPassMs * 20)) +} diff --git a/src/main/cloud-sync/cloud-sync-remote.ts b/src/main/cloud-sync/cloud-sync-remote.ts index dcf72032540..64d2392be05 100644 --- a/src/main/cloud-sync/cloud-sync-remote.ts +++ b/src/main/cloud-sync/cloud-sync-remote.ts @@ -30,6 +30,11 @@ export class SyncRemoteError extends Error { } } +function isNotFound(error: unknown): boolean { + const message = error instanceof Error ? error.message : String(error) + return /ENOENT|not.?found|no such/i.test(message) +} + /** Transport answers for a sandbox that is asleep, waking or unreachable right now. */ const WAITING_CODES = new Set([ 'runtime_environment_asleep', @@ -45,11 +50,8 @@ export function isWaitingError(error: unknown): boolean { } export function errorCode(error: unknown): string | null { - if (error && typeof error === 'object' && 'code' in error) { - const code = (error as { code: unknown }).code - return typeof code === 'string' ? code : null - } - return null + const code: unknown = error && typeof error === 'object' ? Reflect.get(error, 'code') : undefined + return typeof code === 'string' ? code : null } const WorktreeRows = z.looseObject({ @@ -125,7 +127,7 @@ async function listContext( ) } catch (error) { // No .context folder is the common case, not a failure. - if (depth === 0 && /ENOENT|not.?found|no such/i.test(String((error as Error)?.message))) { + if (depth === 0 && isNotFound(error)) { return } throw error @@ -292,7 +294,7 @@ async function statOneByOne( } } catch (error) { // Deleted between listing and stat: simply not in the manifest. - if (!/ENOENT|not.?found|no such/i.test(String((error as Error)?.message))) { + if (!isNotFound(error)) { throw error } } diff --git a/src/main/cloud-sync/cloud-sync-service.test.ts b/src/main/cloud-sync/cloud-sync-service.test.ts index b7298e28cd8..b4b32f432ce 100644 --- a/src/main/cloud-sync/cloud-sync-service.test.ts +++ b/src/main/cloud-sync/cloud-sync-service.test.ts @@ -4,7 +4,7 @@ import { join } from 'node:path' import { afterEach, describe, expect, it, vi } from 'vitest' import type { CloudSyncView } from '../../shared/cloud-sync/cloud-sync-contract' import type { EphemeralVmRuntimeRecord } from '../../shared/ephemeral-vm-runtimes' -import { createFakeVm, VM_ROOT } from './cloud-sync-fake-vm.test-support' +import { createFakeVm } from './cloud-sync-fake-vm.test-support' import { createCloudSyncService } from './cloud-sync-service' import { createCloudSyncStore } from './cloud-sync-store' @@ -25,10 +25,7 @@ function runtime(status: EphemeralVmRuntimeRecord['status']): EphemeralVmRuntime status, cleanupStatus: 'not_started', createdAt: 1, - updatedAt: 1, - recipeResult: { - connection: { type: 'orca-server', pairingCode: 'x', projectRoot: VM_ROOT } - } as unknown as EphemeralVmRuntimeRecord['recipeResult'] + updatedAt: 1 } } diff --git a/src/main/cloud-sync/cloud-sync-service.ts b/src/main/cloud-sync/cloud-sync-service.ts index 3b58b8927d0..50aadbc7878 100644 --- a/src/main/cloud-sync/cloud-sync-service.ts +++ b/src/main/cloud-sync/cloud-sync-service.ts @@ -201,7 +201,9 @@ export function createCloudSyncService(deps: CloudSyncServiceDeps) { do { again = false await reconcileOnce().catch((error: unknown) => - log(`[cloud-sync] reconcile failed: ${error instanceof Error ? error.message : error}`) + log( + `[cloud-sync] reconcile failed: ${error instanceof Error ? error.message : String(error)}` + ) ) } while (again && !disposed) } finally { diff --git a/src/main/cloud-sync/cloud-sync-session.test.ts b/src/main/cloud-sync/cloud-sync-session.test.ts index 16d152f6f8c..b0ccb436e98 100644 --- a/src/main/cloud-sync/cloud-sync-session.test.ts +++ b/src/main/cloud-sync/cloud-sync-session.test.ts @@ -4,7 +4,8 @@ import { join } from 'node:path' import { afterEach, describe, expect, it, vi } from 'vitest' import type { CloudSyncState } from '../../shared/cloud-sync/cloud-sync-contract' import { createFakeVm, VM_ROOT, type FakeVm } from './cloud-sync-fake-vm.test-support' -import { createCloudSyncSession, safetyIntervalMs } from './cloud-sync-session' +import { safetyIntervalMs } from './cloud-sync-plan' +import { createCloudSyncSession } from './cloud-sync-session' import { createCloudSyncStore, type CloudSyncChoice } from './cloud-sync-store' const dirs: string[] = [] diff --git a/src/main/cloud-sync/cloud-sync-session.ts b/src/main/cloud-sync/cloud-sync-session.ts index 6bfe8ed14bf..22cb63449e8 100644 --- a/src/main/cloud-sync/cloud-sync-session.ts +++ b/src/main/cloud-sync/cloud-sync-session.ts @@ -13,6 +13,8 @@ import { import { isContextPath, isSafeSyncPath } from './cloud-sync-paths' import { emptySyncState, + safetyIntervalMs, + SAFETY_TICK_MS, limitsFor, limitsInfo, planSync, @@ -38,16 +40,6 @@ import { export type { WatchSubscribe, WatchSubscription } -/** - * Safety net for anything the watch missed. The VM's watcher can miss a directory created along - * with its parent (`mkdir -p .context/shots`), so small folders are re-checked often (a few - * calls each) and large mirrors less often: 30 ms per file, between 30 s and 10 min, and never - * more than 5% of the time (a slow pass, e.g. on an image without files.statMany, waits longer). - */ -const SAFETY_TICK_MS = 30_000 -export function safetyIntervalMs(files: number, lastPassMs = 0): number { - return Math.min(10 * 60_000, Math.max(SAFETY_TICK_MS, files * 30, lastPassMs * 20)) -} const WATCH_RETRY_MIN_MS = 5_000 const WATCH_RETRY_MAX_MS = 5 * 60_000 @@ -76,7 +68,7 @@ export function createCloudSyncSession(deps: CloudSyncSessionDeps) { let watch: WatchSubscription | null = null let watchRetryMs = WATCH_RETRY_MIN_MS let watchRetryTimer: ReturnType | null = null - let safetyTimer: ReturnType | null = null + let safetyTimer: ReturnType | null = null let lastFullPassAt = 0 let lastFullPassMs = 0 const abort = new AbortController() @@ -274,6 +266,20 @@ export function createCloudSyncSession(deps: CloudSyncSessionDeps) { } } + /** One check per tick while running; stop() ends the chain. */ + function scheduleSafetyCheck(): void { + if (stopped) { + return + } + safetyTimer = setTimeout(() => { + if (now() - lastFullPassAt >= safetyIntervalMs(state.files, lastFullPassMs)) { + void requestFullPass() + } + scheduleSafetyCheck() + }, SAFETY_TICK_MS) + safetyTimer.unref?.() + } + function scheduleWatchRetry(): void { if (stopped || watchRetryTimer) { return @@ -295,18 +301,11 @@ export function createCloudSyncSession(deps: CloudSyncSessionDeps) { await loadIndex() await requestFullPass() await openWatch() - safetyTimer = setInterval(() => { - if (now() - lastFullPassAt >= safetyIntervalMs(state.files, lastFullPassMs)) { - void requestFullPass() - } - }, SAFETY_TICK_MS) - safetyTimer.unref?.() + scheduleSafetyCheck() }, /** This computer woke, or the connection came back: anything may have changed meanwhile. */ resync(): Promise { - if (!watch) { - void openWatch() - } + void openWatch() return requestFullPass() }, setChoice(next: CloudSyncChoice): Promise { @@ -321,14 +320,10 @@ export function createCloudSyncSession(deps: CloudSyncSessionDeps) { watch?.close() watch = null changes.dispose() - if (watchRetryTimer) { - clearTimeout(watchRetryTimer) - } - if (safetyTimer) { - clearInterval(safetyTimer) - } - watchRetryTimer = null - safetyTimer = null + // clearTimeout ignores null. + clearTimeout(watchRetryTimer ?? undefined) + clearTimeout(safetyTimer ?? undefined) + watchRetryTimer = safetyTimer = null return chain } } diff --git a/src/renderer/src/components/orca-cloud/CloudWorkspaceMark.tsx b/src/renderer/src/components/orca-cloud/CloudWorkspaceMark.tsx index 0e30dc19efc..0b3c4f76314 100644 --- a/src/renderer/src/components/orca-cloud/CloudWorkspaceMark.tsx +++ b/src/renderer/src/components/orca-cloud/CloudWorkspaceMark.tsx @@ -131,8 +131,7 @@ function CloudWorkspaceMarkInner({ align="start" sideOffset={10} focusRing - // Taller than a short window once the sync section is open: scroll instead of clipping. - className="scrollbar-sleek max-h-(--radix-popover-content-available-height) w-72 overflow-y-auto" + className="w-72" aria-label={label} tabIndex={-1} onPointerEnter={() => clearTimer()} @@ -147,7 +146,8 @@ function CloudWorkspaceMarkInner({ }} onClick={(event) => event.stopPropagation()} > -
+ {/* Taller than a short window once the sync section is open: scroll instead of clipping. */} +
{parts.map((part, i) => ( - // oxlint-disable-next-line react/no-array-index-key -- path segments can repeat; their order is the identity {part} {i < parts.length - 1 ? (