fix(cloud): RA-11 retries a failed workspace Source read on the next account read (never caches a failure)

Real-app m4air: the first per-workspace Source read ran right after start, failed, and the cached
null hid state 1 for 10 minutes. Only a good answer is cached now; a failed read retries when the
account is read again (focus / the visible-window interval).
This commit is contained in:
Neil
2026-11-10 18:48:09 -08:00
parent f4bacdfa39
commit d422a64eea
2 changed files with 16 additions and 4 deletions
@@ -75,7 +75,12 @@ export function CloudRunningStripPortal({
accounts.load.status.credentials[agent].state !== 'active' &&
accounts.load.status.credentials[agent].state !== 'expiring' &&
accounts.load.status.credentials[agent].state !== 'none'
const usesAccount = useWorkspaceUsesAccount(running ? environmentId : null, agent, expired)
const usesAccount = useWorkspaceUsesAccount(
running ? environmentId : null,
agent,
expired,
orcaCloudAgentAccountsLoadedAt()
)
const hold = useCloudAgentHold(paneKey)
const gate = useAgentSignInGate(paneKey)
const held = hold !== null || gate !== null
@@ -187,7 +187,9 @@ export function workspaceUsesAccount(view: AgentSourcesView, agent: HostAgentSig
export function useWorkspaceUsesAccount(
runtimeEnvironmentId: string | null,
agent: HostAgentSignInAgent | null,
wanted: boolean
wanted: boolean,
/** Changes on every account read; a failed Source read retries then (never on its own). */
retryToken: number
): boolean | null {
const key = runtimeEnvironmentId && agent ? `${runtimeEnvironmentId}:${agent}` : null
useSyncExternalStore(
@@ -200,7 +202,12 @@ export function useWorkspaceUsesAccount(
return
}
const read = sourceReads.get(key)
if (read === 'pending' || (read && Date.now() - read.at < SOURCE_READ_MS)) {
// A good answer holds for 10 min; a failed one (e.g. right after start, before main knows the
// sandbox) is retried on the next account read.
if (
read === 'pending' ||
(read && read.usesAccount !== null && Date.now() - read.at < SOURCE_READ_MS)
) {
return
}
const api = window.api.orcaCloudAgents
@@ -216,7 +223,7 @@ export function useWorkspaceUsesAccount(
.workspaceSources({ runtimeEnvironmentId })
.then((result) => settle(result.ok ? workspaceUsesAccount(result.value, agent) : null))
.catch(() => settle(null))
}, [wanted, key, runtimeEnvironmentId, agent])
}, [wanted, key, runtimeEnvironmentId, agent, retryToken])
const read = key ? sourceReads.get(key) : undefined
return read && read !== 'pending' ? read.usesAccount : null
}