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.
This commit is contained in:
Neil
2026-11-10 23:18:50 -08:00
parent cf9847771a
commit 1c7a5bcc2c
2 changed files with 49 additions and 11 deletions
@@ -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()
)
})
})
@@ -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<typeof useAppStore.getState>) => {
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<typeof useAppStore.getState>): 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<typeof useAppStore.getState>) =>
Object.values(state.pendingWorktreeCreations ?? {}).find(
(creation) => creation.request.name === workspaceName
)
let sandboxUp = false
let sawCreation = false
const settle = (state: ReturnType<typeof useAppStore.getState>): '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: {