fix(cloud): REG-12 Orca Cloud refuses before touching anything, so "nothing was deleted" is true; design-squad's copy (Couldn't delete {{name}}, three bodies, Try again)

This commit is contained in:
Neil
2026-11-11 23:26:36 -08:00
parent 6ef36198c5
commit d5ee74e7e9
6 changed files with 136 additions and 43 deletions
@@ -280,14 +280,17 @@ describe('Orca Cloud: Delete destroys the sandbox or fails visibly, never "kept"
const cloud: Partial<EphemeralVmRuntimeRecord> = {
recipe: { id: 'cloud', name: 'Orca Cloud', create: 'orca-cloud create', provider: 'orca-cloud' }
}
const removedCheckout = (ports: ReturnType<typeof makePorts>) =>
ports.call.mock.calls.some(([, method]) => method === 'worktree.rm')
it('the worktree list fails: an error, and no sandbox delete was sent', async () => {
it('the worktree list fails: an error, and nothing was deleted (no checkout removal, no destroy)', async () => {
seed('orca-worktree', cloud)
const ports = makePorts({ 'worktree.list': failed('runtime_unavailable') })
await expect(removeRecipeWorkspace(root, params, ports)).rejects.toMatchObject({
code: CLOUD_DELETE_NOT_SENT,
message: CLOUD_DELETE_NOT_SENT_UNCHECKED
})
expect(removedCheckout(ports)).toBe(false)
expect(ports.cleanup).not.toHaveBeenCalled()
})
@@ -297,10 +300,11 @@ describe('Orca Cloud: Delete destroys the sandbox or fails visibly, never "kept"
await expect(removeRecipeWorkspace(root, params, ports)).rejects.toMatchObject({
message: CLOUD_DELETE_NOT_SENT_UNCHECKED
})
expect(removedCheckout(ports)).toBe(false)
expect(ports.cleanup).not.toHaveBeenCalled()
})
it('other workspaces still on the sandbox: an error naming that, nothing destroyed', async () => {
it('other workspaces still on the sandbox: an error naming that, nothing deleted', async () => {
seed('orca-worktree', cloud)
const ports = makePorts({
'worktree.list': ok({
@@ -310,10 +314,21 @@ describe('Orca Cloud: Delete destroys the sandbox or fails visibly, never "kept"
await expect(removeRecipeWorkspace(root, params, ports)).rejects.toMatchObject({
message: CLOUD_DELETE_NOT_SENT_IN_USE
})
expect(removedCheckout(ports)).toBe(false)
expect(ports.cleanup).not.toHaveBeenCalled()
})
it('a "cleaned" record without a destroy is not a delete', async () => {
it('a sandbox nothing would destroy: refused up front, nothing deleted', async () => {
seed('orca-worktree', { ...cloud, cleanupStatus: 'disabled' })
const ports = makePorts()
await expect(removeRecipeWorkspace(root, params, ports)).rejects.toMatchObject({
message: CLOUD_DELETE_NOT_SENT_NO_DESTROY
})
expect(ports.call).not.toHaveBeenCalled()
expect(ports.cleanup).not.toHaveBeenCalled()
})
it('a "cleaned" record without a destroy still never reads as deleted (guard)', async () => {
seed('orca-worktree', cloud)
const ports = makePorts({}, 'disabled')
await expect(removeRecipeWorkspace(root, params, ports)).rejects.toMatchObject({
@@ -321,13 +336,14 @@ describe('Orca Cloud: Delete destroys the sandbox or fails visibly, never "kept"
})
})
it('an empty sandbox is destroyed, and only then reports success', async () => {
it('a sandbox that is this workspace’s alone is destroyed, and only then reports success', async () => {
seed('orca-worktree', cloud)
const ports = makePorts()
await expect(removeRecipeWorkspace(root, params, ports)).resolves.toMatchObject({
removed: true,
host: { state: 'destroyed' }
})
expect(removedCheckout(ports)).toBe(true)
expect(ports.cleanup).toHaveBeenCalledWith('vm-a')
})
+38 -23
View File
@@ -172,6 +172,12 @@ export async function removeRecipeWorkspace(
}
const environmentId = runtime.runtimeEnvironmentId
const isOrcaCloud = runtime.recipe?.provider === 'orca-cloud'
if (isOrcaCloud && (runtime.recipe?.destroyDisabled || runtime.cleanupStatus === 'disabled')) {
// REG-12: nothing would destroy the sandbox, so refuse before touching anything.
throw new RecipeWorkspaceRemovalError(CLOUD_DELETE_NOT_SENT, CLOUD_DELETE_NOT_SENT_NO_DESTROY, {
runtimeId: runtime.id
})
}
const { destroyHost: _destroyHost, ...forwarded } = params
let checkoutResult: Record<string, unknown> = {}
// A provisioned root is the VM's primary checkout, protected from ordinary Git deletion.
@@ -182,6 +188,31 @@ export async function removeRecipeWorkspace(
"This workspace's environment is asleep. Open the workspace to wake it, then delete it again."
)
}
// Other workspaces on the same environment keep it alive; no answer is not proof it's empty.
const otherWorkspaces = async (): Promise<unknown[] | undefined> => {
const listed = await ports.call(environmentId, 'worktree.list', {})
const parsedList = listed.ok ? Worktrees.safeParse(listed.result).data : undefined
return parsedList && parsedList.truncated !== true
? parsedList.worktrees.filter(
(worktree) =>
worktree.isMainWorktree !== true &&
worktree.removing !== true &&
worktree.id !== params.worktree.slice(3)
)
: undefined
}
// REG-12: deleting an Orca Cloud workspace means deleting its sandbox, so prove the sandbox is
// its alone before touching anything. A refusal then really deleted nothing (Try again is safe).
if (isOrcaCloud) {
const others = await otherWorkspaces()
if (!others || others.length > 0) {
throw new RecipeWorkspaceRemovalError(
CLOUD_DELETE_NOT_SENT,
others ? CLOUD_DELETE_NOT_SENT_IN_USE : CLOUD_DELETE_NOT_SENT_UNCHECKED,
{ runtimeId: runtime.id }
)
}
}
const response = await ports.call(environmentId, 'worktree.rm', {
...forwarded,
hostId: 'local',
@@ -207,29 +238,13 @@ export async function removeRecipeWorkspace(
}
checkoutResult = { ...removed, removed: true }
}
// Other workspaces on the same environment keep it alive; no answer is not proof it's empty.
const listed = await ports.call(environmentId, 'worktree.list', {})
const parsedList = listed.ok ? Worktrees.safeParse(listed.result).data : undefined
const remaining =
parsedList && parsedList.truncated !== true
? parsedList.worktrees.filter(
(worktree) =>
worktree.isMainWorktree !== true &&
worktree.removing !== true &&
worktree.id !== params.worktree.slice(3)
)
: undefined
if (!remaining || remaining.length > 0) {
// REG-12: deleting an Orca Cloud workspace means deleting its sandbox. Keeping the sandbox
// must never read as "Deleted": fail visibly (nothing destroyed, so Try again is safe).
if (isOrcaCloud) {
throw new RecipeWorkspaceRemovalError(
CLOUD_DELETE_NOT_SENT,
remaining ? CLOUD_DELETE_NOT_SENT_IN_USE : CLOUD_DELETE_NOT_SENT_UNCHECKED,
{ runtimeId: runtime.id }
)
// A recipe VM shared by several workspaces stays while others live on it. (Orca Cloud proved
// its sandbox was this workspace's alone above, so its delete always goes on to destroy.)
if (!isOrcaCloud) {
const remaining = await otherWorkspaces()
if (!remaining || remaining.length > 0) {
return { ...checkoutResult, removed: true, host: { runtimeId: runtime.id, state: 'kept' } }
}
return { ...checkoutResult, removed: true, host: { runtimeId: runtime.id, state: 'kept' } }
}
}
const cleaned = await orderDestroy(() => ports.cleanup(runtime.id))
@@ -241,7 +256,7 @@ export async function removeRecipeWorkspace(
)
}
if (isOrcaCloud && cleaned.cleanupStatus === 'disabled') {
// Orca Cloud always destroys; a "cleaned" record without a destroy is not a delete.
// Guard only (checked up front): a "cleaned" record without a destroy is never "Deleted".
throw new RecipeWorkspaceRemovalError(CLOUD_DELETE_NOT_SENT, CLOUD_DELETE_NOT_SENT_NO_DESTROY, {
runtimeId: runtime.id
})
@@ -3,14 +3,20 @@
import type React from 'react'
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { CLOUD_DELETE_NOT_SENT_UNCHECKED } from '../../../../../../shared/recipe-host-removal'
import {
CLOUD_DELETE_NOT_SENT_IN_USE,
CLOUD_DELETE_NOT_SENT_NO_DESTROY,
CLOUD_DELETE_NOT_SENT_UNCHECKED
} from '../../../../../../shared/recipe-host-removal'
const shown = vi.hoisted((): { description: React.ReactNode; duration: number } => ({
const shown = vi.hoisted((): { title: string; description: React.ReactNode; duration: number } => ({
title: '',
description: null,
duration: 0
}))
vi.mock('sonner', () => {
const show = (_title: string, options: { description: React.ReactNode; duration: number }) => {
const show = (title: string, options: { description: React.ReactNode; duration: number }) => {
shown.title = title
shown.description = options.description
shown.duration = options.duration
}
@@ -41,14 +47,30 @@ function showFor(error: string, onRetry = vi.fn()) {
describe('delete failure toast: Try again', () => {
it('offers Try again when no sandbox delete was sent, and it re-runs the delete', () => {
const onRetry = showFor(CLOUD_DELETE_NOT_SENT_UNCHECKED)
expect(screen.getByText(CLOUD_DELETE_NOT_SENT_UNCHECKED)).toBeTruthy()
const onRetry = showFor(`Error: ${CLOUD_DELETE_NOT_SENT_UNCHECKED}`)
expect(shown.title).toBe("Couldn't delete ik-actions")
expect(
screen.getByText("Orca couldn't check the sandbox, so nothing was deleted.")
).toBeTruthy()
// It stays until the user acts: deleting must not silently time out.
expect(shown.duration).toBe(Infinity)
fireEvent.click(screen.getByRole('button', { name: 'Try again' }))
expect(onRetry).toHaveBeenCalledOnce()
})
it('names the case: others still on the sandbox, or no delete went through', () => {
showFor(CLOUD_DELETE_NOT_SENT_IN_USE)
expect(
screen.getByText(
'Other workspaces still run in this sandbox, so nothing was deleted. Delete them first.'
)
).toBeTruthy()
expect(screen.getByRole('button', { name: 'Try again' })).toBeTruthy()
cleanup()
showFor(CLOUD_DELETE_NOT_SENT_NO_DESTROY)
expect(screen.getByText("The delete didn't go through, so nothing was deleted.")).toBeTruthy()
})
it('does not offer it for other failures (a retry could repeat a partial destroy)', () => {
showFor('Environment destroy failed. The environment may still be running.')
expect(screen.queryByRole('button', { name: 'Try again' })).toBeNull()
@@ -5,7 +5,12 @@ import { useTranslate } from '@/i18n/use-translate'
import { DeleteNestedWorktreesDialog } from './DeleteNestedWorktreesDialog'
import { WorktreeForceDeleteButton } from './WorktreeForceDeleteButton'
import { isNestedWorktreeRemovalError } from '../../../../../../shared/worktree/nested-removal'
import { isCloudDeleteNotSentError } from '../../../../../../shared/recipe-host-removal'
import {
CLOUD_DELETE_NOT_SENT_IN_USE,
CLOUD_DELETE_NOT_SENT_NO_DESTROY,
isCloudDeleteNotSentError
} from '../../../../../../shared/recipe-host-removal'
import { translate } from '@/i18n/i18n'
import { composeWorktreeHostIdentity } from '../../../../../../shared/worktree/host-qualified-identity'
import type { ExecutionHostId } from '../../../../../../shared/execution-host'
import {
@@ -130,6 +135,38 @@ function DeleteWorktreeFailureToastBody({
)
}
/** REG-12: an Orca Cloud delete refused before anything was deleted, in design-squad's copy. */
function cloudDeleteNotSentCopy(
worktreeName: string,
error: string
): { title: string; description: string; isDestructive: boolean } {
const description = error.includes(CLOUD_DELETE_NOT_SENT_IN_USE)
? translate(
'auto.components.sidebar.delete.worktree.failure.cloudInUse',
'Other workspaces still run in this sandbox, so nothing was deleted. Delete them first.'
)
: error.includes(CLOUD_DELETE_NOT_SENT_NO_DESTROY)
? translate(
'auto.components.sidebar.delete.worktree.failure.cloudNoDestroy',
"The delete didn't go through, so nothing was deleted."
)
: translate(
'auto.components.sidebar.delete.worktree.failure.cloudUnchecked',
"Orca couldn't check the sandbox, so nothing was deleted."
)
return {
title: translate(
'auto.components.sidebar.delete.worktree.failure.cloudTitle',
"Couldn't delete {{name}}",
{
name: worktreeName
}
),
description,
isDestructive: true
}
}
export function showDeleteWorktreeFailureToast({
error,
canForceDelete,
@@ -148,12 +185,9 @@ export function showDeleteWorktreeFailureToast({
nestedRemovalTarget,
onNestedDeleted
}: DeleteWorktreeFailureToastOptions): void {
const toastCopy = getDeleteWorktreeToastCopy(
worktreeName,
forceDeleteReason,
error,
lockReason ?? null
)
const toastCopy = isCloudDeleteNotSentError(error)
? cloudDeleteNotSentCopy(worktreeName, error)
: getDeleteWorktreeToastCopy(worktreeName, forceDeleteReason, error, lockReason ?? null)
const showToast = toastCopy.isDestructive ? toast.error : toast.info
const id = deleteWorktreeFailureToastId({
id: worktreeId,
+5 -1
View File
@@ -7455,7 +7455,11 @@
"archive": {
"waiver": "Delete Anyway"
},
"tryAgain": "Try again"
"tryAgain": "Try again",
"cloudInUse": "Other workspaces still run in this sandbox, so nothing was deleted. Delete them first.",
"cloudNoDestroy": "The delete didn't go through, so nothing was deleted.",
"cloudUnchecked": "Orca couldn't check the sandbox, so nothing was deleted.",
"cloudTitle": "Couldn't delete {{name}}"
}
}
},
+5 -3
View File
@@ -35,11 +35,13 @@ export class RecipeWorkspaceRemovalError extends Error {
* reports success while the sandbox is kept (another workspace on it, or no proof it is empty).
*/
export const CLOUD_DELETE_NOT_SENT = 'cloud_delete_not_sent'
// Main sends these as the error message; the toast shows the translated copy for each (design-squad).
export const CLOUD_DELETE_NOT_SENT_UNCHECKED =
"Orca Cloud couldn't check this sandbox, so it wasn't deleted. Try again."
"Orca couldn't check the sandbox, so nothing was deleted."
export const CLOUD_DELETE_NOT_SENT_IN_USE =
"Other workspaces still run in this sandbox, so it wasn't deleted. Delete them first, then try again."
export const CLOUD_DELETE_NOT_SENT_NO_DESTROY = "Orca Cloud didn't delete this sandbox. Try again."
'Other workspaces still run in this sandbox, so nothing was deleted. Delete them first.'
export const CLOUD_DELETE_NOT_SENT_NO_DESTROY =
"The delete didn't go through, so nothing was deleted."
/** The removal failed before any sandbox delete was sent: retrying is safe and may succeed. */
export function isCloudDeleteNotSentError(message: string): boolean {