From 1c7a5bcc2cd07563b80aba79ff4363e6df98f41d Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 10 Nov 2026 23:18:50 -0800 Subject: [PATCH] fix(cloud): DS-p follows its own create even when the name is generated later The real-app check found the prompt never showed for an empty name field: the gate matched the create by the composer's name text, but the create named the workspace itself ("chinook"). Match by that name or else the newest create started around the call, then follow it by id and show its real name. --- .../cloud-agent-not-started-toast.test.ts | 23 +++++++++++- .../cloud-agent-not-started-toast.ts | 37 ++++++++++++++----- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/src/renderer/src/lib/orca-cloud/cloud-agent-not-started-toast.test.ts b/src/renderer/src/lib/orca-cloud/cloud-agent-not-started-toast.test.ts index cfed9335510..70a0f0fa708 100644 --- a/src/renderer/src/lib/orca-cloud/cloud-agent-not-started-toast.test.ts +++ b/src/renderer/src/lib/orca-cloud/cloud-agent-not-started-toast.test.ts @@ -43,8 +43,8 @@ function accounts( function creation(name: string, phase: string, status = 'creating'): void { useAppStore.setState({ pendingWorktreeCreations: { - // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the toast reads only status, phase and request.name - c1: { status, phase, request: { name } } as never + // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the toast reads only these fields + c1: { creationId: 'c1', startedAt: Date.now(), status, phase, request: { name } } as never } }) } @@ -160,4 +160,23 @@ describe('cloud agent not-started toast', () => { useAppStore.setState({ pendingWorktreeCreations: {} }) expect(toastMock.message).not.toHaveBeenCalled() }) + + it('follows the create it was asked for even when its name is generated later (DS-p)', () => { + // An empty name field: the create names the workspace itself ("chinook"). + showCloudAgentNotStartedToast('claude', '') + creation('chinook', 'provisioning-vm') + expect(toastMock.message).not.toHaveBeenCalled() + useAppStore.setState({ pendingWorktreeCreations: {} }) + expect(toastMock.message).toHaveBeenLastCalledWith( + 'Claude isn’t set up for Orca Cloud, so it didn’t start.', + expect.anything() + ) + // Away from it, the toast names the real workspace, not the empty field. + useAppStore.setState({ activeWorktreeId: 'chinook-id' }) + useAppStore.setState({ activeWorktreeId: 'other' }) + expect(toastMock.message).toHaveBeenLastCalledWith( + 'Claude isn’t set up for Orca Cloud, so it didn’t start in chinook.', + expect.anything() + ) + }) }) diff --git a/src/renderer/src/lib/orca-cloud/cloud-agent-not-started-toast.ts b/src/renderer/src/lib/orca-cloud/cloud-agent-not-started-toast.ts index 6c936cc71a5..ac2929e3880 100644 --- a/src/renderer/src/lib/orca-cloud/cloud-agent-not-started-toast.ts +++ b/src/renderer/src/lib/orca-cloud/cloud-agent-not-started-toast.ts @@ -160,9 +160,12 @@ export function cloudAgentSignInView( } } +/** A create counts as this toast's when it started at most this long before the toast was asked for. */ +const CREATION_MATCH_SLACK_MS = 5_000 + export function showCloudAgentNotStartedToast( agent: OrcaCloudAccountAgent, - workspaceName: string, + requestedName: string, { onlyWhenAway = false }: { @@ -175,18 +178,34 @@ export function showCloudAgentNotStartedToast( ): void { teardown?.() const name = agentName(agent, translate) + const askedAt = Date.now() + // The create this prompt is about: the one with the requested name, else the newest create started + // around this call (the name is often generated later, e.g. an empty name becomes "chinook"). + // Once found it is followed by id, and its real name is the one the toast shows. + let creationId: string | null = null + let workspaceName = requestedName.trim() + const creationFor = (state: ReturnType) => { + const creations = Object.values(state.pendingWorktreeCreations ?? {}) + if (creationId) { + return creations.find((creation) => creation.creationId === creationId) + } + const found = + creations.find((creation) => workspaceName && creation.request.name === workspaceName) ?? + creations + .filter((creation) => creation.startedAt >= askedAt - CREATION_MATCH_SLACK_MS) + .sort((a, b) => b.startedAt - a.startedAt)[0] + if (found) { + creationId = found.creationId + workspaceName = found.request.name.trim() || workspaceName + } + return found + } // The workspace this prompt is about is still being created (its sandbox is starting). const isStarting = (state: ReturnType): boolean => - Object.values(state.pendingWorktreeCreations ?? {}).some( - (creation) => creation.status === 'creating' && creation.request.name === workspaceName - ) + creationFor(state)?.status === 'creating' // DS-p: the prompt is about a workspace that exists. It waits until the sandbox is up (the create // moved past provisioning, or finished); a refused create (e.g. the team's running limit) never // shows it, only its own error. - const creationFor = (state: ReturnType) => - Object.values(state.pendingWorktreeCreations ?? {}).find( - (creation) => creation.request.name === workspaceName - ) let sandboxUp = false let sawCreation = false const settle = (state: ReturnType): 'up' | 'refused' | 'waiting' => { @@ -207,7 +226,7 @@ export function showCloudAgentNotStartedToast( const view: ToastView = signIn ?? { message: cloudAgentNotStartedMessage( name, - switchedAway && workspaceName.trim() ? workspaceName : null, + switchedAway && workspaceName ? workspaceName : null, { starting: isStarting(useAppStore.getState()) } ), action: {