From d773dd13a8643fb379bb4d1cab4eb505b994ab84 Mon Sep 17 00:00:00 2001 From: Joe Thel Date: Mon, 14 Sep 2026 17:27:51 -0700 Subject: [PATCH 01/10] Support canceling imports This constitutes two closely-related workflows: 1. Finalizing a disk from `import_ready` to `detached`. You can get yourself stuck in `import_ready` by starting and immediately abandoning an image upload (which creates a temp disk). 2. Canceling a bulk write and _then_ finalizing a disk, moving from `importing_from_bulk_writes` to `detached`. Same activity, but you get to that stuck state by abandoning an image upload after the actual upload starts. While we won't pretend the states are same when viewing them, "doing something about it" is basically the same thing in both cases, even if the API actions are slightly different. --- app/pages/project/disks/DisksPage.tsx | 70 +++++++++++++++++++++------ mock-api/disk.ts | 28 +++++++++++ test/e2e/disks.e2e.ts | 46 +++++++++++++++++- 3 files changed, 127 insertions(+), 17 deletions(-) diff --git a/app/pages/project/disks/DisksPage.tsx b/app/pages/project/disks/DisksPage.tsx index 956c29182e..4ed67f04c2 100644 --- a/app/pages/project/disks/DisksPage.tsx +++ b/app/pages/project/disks/DisksPage.tsx @@ -9,6 +9,7 @@ import { useQuery } from '@tanstack/react-query' import { createColumnHelper } from '@tanstack/react-table' import { useCallback, useMemo } from 'react' import { Outlet, type LoaderFunctionArgs } from 'react-router' +import { match } from 'ts-pattern' import { api, @@ -28,6 +29,7 @@ import { DiskStateBadge, DiskTypeBadge, ReadOnlyBadge } from '~/components/State import { makeCrumb } from '~/hooks/use-crumbs' import { getProjectSelector, useProjectSelector } from '~/hooks/use-params' import { useQuickActions } from '~/hooks/use-quick-actions' +import { confirmAction } from '~/stores/confirm-action' import { confirmDelete } from '~/stores/confirm-delete' import { addToast } from '~/stores/toast' import { DiskSourceName } from '~/table/cells/DiskSourceCell' @@ -113,6 +115,9 @@ export default function DisksPage() { }, }) + const { mutateAsync: finalize } = useApiMutation(api.diskFinalizeImport) + const { mutateAsync: stopBulkWriteImport } = useApiMutation(api.diskBulkWriteImportStop) + const makeActions = useCallback( (disk: Disk): MenuAction[] => [ { @@ -131,23 +136,56 @@ export default function DisksPage() { }, disabled: snapshotDisabledReason(disk), }, - { - label: 'Delete', - onActivate: confirmDelete({ - doDelete: () => deleteDisk({ path: { disk: disk.name }, query: { project } }), - label: disk.name, - resourceKind: 'disk', - }), - disabled: - !diskCan.delete(disk) && - (disk.state.state === 'attached' ? ( - 'Disk must be detached before it can be deleted' - ) : ( - <>Only disks in state {fancifyStates(diskCan.delete.states)} can be deleted - )), - }, + match(disk.state.state) + .with('import_ready', 'importing_from_bulk_writes', () => ({ + label: 'Cancel import', + onActivate() { + confirmAction({ + doAction: async () => { + if (disk.state.state === 'importing_from_bulk_writes') { + await stopBulkWriteImport({ + path: { disk: disk.name }, + query: { project }, + }) + } + + await finalize({ + path: { disk: disk.name }, + query: { project }, + body: {}, + }) + + queryClient.invalidateEndpoint('diskList') + addToast( + <> + Import canceled for {disk.name} + + ) + }, + modalTitle: 'Cancel import', + modalContent: `Are you sure you want to cancel import for ${disk.name}?`, + errorTitle: 'Failed to cancel import', + actionType: 'danger', + }) + }, + })) + .otherwise(() => ({ + label: 'Delete', + onActivate: confirmDelete({ + doDelete: () => deleteDisk({ path: { disk: disk.name }, query: { project } }), + label: disk.name, + resourceKind: 'disk', + }), + disabled: + !diskCan.delete(disk) && + (disk.state.state === 'attached' ? ( + 'Disk must be detached before it can be deleted' + ) : ( + <>Only disks in state {fancifyStates(diskCan.delete.states)} can be deleted + )), + })), ], - [createSnapshot, deleteDisk, project] + [createSnapshot, deleteDisk, stopBulkWriteImport, finalize, project] ) const columns = useColsWithActions( diff --git a/mock-api/disk.ts b/mock-api/disk.ts index 577cbddce6..2a8621c6a9 100644 --- a/mock-api/disk.ts +++ b/mock-api/disk.ts @@ -239,6 +239,34 @@ export const disks: Json[] = [ disk_type: 'distributed', read_only: false, }, + { + id: '7b898827-35a1-4459-a4e3-34db90640b74', + name: 'tmp-for-image-29884739', + description: 'stuck in import_ready after bailling on an image upload early', + project_id: project.id, + time_created: new Date().toISOString(), + time_modified: new Date().toISOString(), + state: { state: 'import_ready' }, + device_path: '/import', + size: 8 * GiB, + block_size: 2048, + disk_type: 'distributed', + read_only: false, + }, + { + id: 'f874c0b9-72ad-4eac-8e55-e6090e10366a', + name: 'tmp-for-image-59986861', + description: 'stuck in bulk-write after bailling on an image upload early', + project_id: project.id, + time_created: new Date().toISOString(), + time_modified: new Date().toISOString(), + state: { state: 'importing_from_bulk_writes' }, + device_path: '/import', + size: 8 * GiB, + block_size: 2048, + disk_type: 'distributed', + read_only: false, + }, { id: '3f23c80f-c523-4d86-8292-2ca3f807bb12', name: 'disk-snapshot-error', diff --git a/test/e2e/disks.e2e.ts b/test/e2e/disks.e2e.ts index 0b9724df13..0ce5d3eafa 100644 --- a/test/e2e/disks.e2e.ts +++ b/test/e2e/disks.e2e.ts @@ -7,6 +7,7 @@ */ import { clickRowAction, + clickRowActions, expect, expectNoToast, expectRowVisible, @@ -93,7 +94,7 @@ test('List disks and snapshot', async ({ page }) => { await page.goto('/projects/mock-project/disks') const table = page.getByRole('table') - await expect(table.getByRole('row')).toHaveCount(16) // 15 + header + await expect(table.getByRole('row')).toHaveCount(18) // 17 + header // check one attached and one not attached await expectRowVisible(table, { @@ -166,6 +167,49 @@ test('Read-only disk snapshot disabled', async ({ page }) => { ) }) +test('Cancel import from import_ready', async ({ page }) => { + const diskImportReadyName = 'tmp-for-image-29884739' + await page.goto('/projects/mock-project/disks') + const table = page.getByRole('table') + await expectRowVisible(table, { name: diskImportReadyName, state: 'import ready' }) + + await clickRowActions(page, diskImportReadyName) + await expect(page.getByRole('menuitem', { name: 'Delete' })).toBeHidden() + await page.getByRole('menuitem', { name: 'Cancel import' }).click() + + const modal = page.getByRole('dialog', { name: 'Cancel import' }) + await expect(modal).toBeVisible() + await modal.getByRole('button', { name: 'Confirm' }).click() + + await expectToast(page, `Import canceled for ${diskImportReadyName}`) + await expectRowVisible(table, { name: diskImportReadyName, state: 'detached' }) + await clickRowActions(page, diskImportReadyName) + await expect(page.getByRole('menuitem', { name: 'Delete' })).toBeVisible() +}) + +test('Cancel import from importing_from_bulk_writes', async ({ page }) => { + const diskImportingName = 'tmp-for-image-59986861' + await page.goto('/projects/mock-project/disks') + const table = page.getByRole('table') + await expectRowVisible(table, { + name: diskImportingName, + state: 'importing from bulk writes', + }) + + await clickRowActions(page, diskImportingName) + await expect(page.getByRole('menuitem', { name: 'Delete' })).toBeHidden() + await page.getByRole('menuitem', { name: 'Cancel import' }).click() + + const modal = page.getByRole('dialog', { name: 'Cancel import' }) + await expect(modal).toBeVisible() + await modal.getByRole('button', { name: 'Confirm' }).click() + + await expectToast(page, `Import canceled for ${diskImportingName}`) + await expectRowVisible(table, { name: diskImportingName, state: 'detached' }) + await clickRowActions(page, diskImportingName) + await expect(page.getByRole('menuitem', { name: 'Delete' })).toBeVisible() +}) + test.describe('Disk create', () => { test.beforeEach(async ({ page }) => { await page.goto('/projects/mock-project/disks-new') From e0dd917b201347a5edb97fd61fe72a3fa81305df Mon Sep 17 00:00:00 2001 From: Joe Thel Date: Mon, 14 Sep 2026 17:51:24 -0700 Subject: [PATCH 02/10] Eagerly refresh disk state while canceling Kind of a middle ground between "show two toasts for this action" and "pretend we aren't making two api calls". --- app/pages/project/disks/DisksPage.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/pages/project/disks/DisksPage.tsx b/app/pages/project/disks/DisksPage.tsx index 4ed67f04c2..bb6d4d0c69 100644 --- a/app/pages/project/disks/DisksPage.tsx +++ b/app/pages/project/disks/DisksPage.tsx @@ -115,8 +115,16 @@ export default function DisksPage() { }, }) - const { mutateAsync: finalize } = useApiMutation(api.diskFinalizeImport) - const { mutateAsync: stopBulkWriteImport } = useApiMutation(api.diskBulkWriteImportStop) + const { mutateAsync: finalize } = useApiMutation(api.diskFinalizeImport, { + onSuccess() { + queryClient.invalidateEndpoint('diskList') + }, + }) + const { mutateAsync: stopBulkWriteImport } = useApiMutation(api.diskBulkWriteImportStop, { + onSuccess() { + queryClient.invalidateEndpoint('diskList') + }, + }) const makeActions = useCallback( (disk: Disk): MenuAction[] => [ @@ -155,7 +163,6 @@ export default function DisksPage() { body: {}, }) - queryClient.invalidateEndpoint('diskList') addToast( <> Import canceled for {disk.name} From 2bb465f5e58f074937a52344c8183fdae9817a9b Mon Sep 17 00:00:00 2001 From: Joe Thel Date: Mon, 14 Sep 2026 18:14:12 -0700 Subject: [PATCH 03/10] Use deterministic temp disk name for upload tests --- app/forms/image-upload.tsx | 1 + mock-api/disk.ts | 4 ++-- test/e2e/image-upload.e2e.ts | 6 ++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/forms/image-upload.tsx b/app/forms/image-upload.tsx index bade806847..3945c5604f 100644 --- a/app/forms/image-upload.tsx +++ b/app/forms/image-upload.tsx @@ -153,6 +153,7 @@ function getTmpDiskName(imageName: string) { 'import-start-500', 'import-stop-500', 'disk-finalize-500', + 'cancel-upload', ]) if (specialNames.has(imageName)) return imageName } diff --git a/mock-api/disk.ts b/mock-api/disk.ts index 2a8621c6a9..757f6bbbf6 100644 --- a/mock-api/disk.ts +++ b/mock-api/disk.ts @@ -242,7 +242,7 @@ export const disks: Json[] = [ { id: '7b898827-35a1-4459-a4e3-34db90640b74', name: 'tmp-for-image-29884739', - description: 'stuck in import_ready after bailling on an image upload early', + description: 'stuck in import_ready after bailing on an image upload early', project_id: project.id, time_created: new Date().toISOString(), time_modified: new Date().toISOString(), @@ -256,7 +256,7 @@ export const disks: Json[] = [ { id: 'f874c0b9-72ad-4eac-8e55-e6090e10366a', name: 'tmp-for-image-59986861', - description: 'stuck in bulk-write after bailling on an image upload early', + description: 'stuck in bulk-write after bailing on an image upload early', project_id: project.id, time_created: new Date().toISOString(), time_modified: new Date().toISOString(), diff --git a/test/e2e/image-upload.e2e.ts b/test/e2e/image-upload.e2e.ts index 34df277991..314e6acb13 100644 --- a/test/e2e/image-upload.e2e.ts +++ b/test/e2e/image-upload.e2e.ts @@ -192,7 +192,7 @@ test.describe('Image upload', () => { for (const state of cancelStates) { test(`cancel in state '${state}'`, async ({ page }) => { - await fillForm(page, 'new-image') + await fillForm(page, 'cancel-upload') await page.getByRole('button', { name: 'Upload image' }).click() @@ -219,7 +219,9 @@ test.describe('Image upload', () => { await page.getByRole('button', { name: 'Cancel' }).click() await page.getByRole('link', { name: 'Disks' }).click() await expect(page.getByRole('cell', { name: 'disk-1', exact: true })).toBeVisible() - await expect(page.getByRole('cell', { name: 'tmp' })).toBeHidden() + await expect( + page.getByRole('cell', { name: 'cancel-upload', exact: true }) + ).toBeHidden() }) } From d0ce6d9dde4d44175d09342fcac9bf574e837f54 Mon Sep 17 00:00:00 2001 From: Joe Thel Date: Mon, 14 Sep 2026 19:06:51 -0700 Subject: [PATCH 04/10] Add test for partial success in cancellation --- mock-api/disk.ts | 15 +++++++++++++++ mock-api/msw/handlers.ts | 4 +++- test/e2e/disks.e2e.ts | 21 ++++++++++++++++++++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/mock-api/disk.ts b/mock-api/disk.ts index 757f6bbbf6..23a3887fba 100644 --- a/mock-api/disk.ts +++ b/mock-api/disk.ts @@ -267,6 +267,21 @@ export const disks: Json[] = [ disk_type: 'distributed', read_only: false, }, + { + id: '0f60c28e-ead0-48f0-aab9-e74b917dc8e4', + name: 'disk-finalize-fail', + description: + "stuck in bulk-write after bailing on an image upload early, but can't be finalized", + project_id: project.id, + time_created: new Date().toISOString(), + time_modified: new Date().toISOString(), + state: { state: 'importing_from_bulk_writes' }, + device_path: '/import', + size: 8 * GiB, + block_size: 2048, + disk_type: 'distributed', + read_only: false, + }, { id: '3f23c80f-c523-4d86-8292-2ca3f807bb12', name: 'disk-snapshot-error', diff --git a/mock-api/msw/handlers.ts b/mock-api/msw/handlers.ts index d0ce152a1f..7ead447933 100644 --- a/mock-api/msw/handlers.ts +++ b/mock-api/msw/handlers.ts @@ -284,7 +284,9 @@ export const handlers = makeHandlers({ diskFinalizeImport: ({ path, query, body }) => { const disk = lookup.disk({ ...path, ...query }) - if (disk.name === 'disk-finalize-500') throw internalError('disk finalize failed') + if (disk.name === 'disk-finalize-500' || disk.name === 'disk-finalize-fail') { + throw internalError('disk finalize failed') + } if (disk.state.state !== 'import_ready') { throw `Cannot finalize disk in state ${disk.state.state}. Must be import_ready.` diff --git a/test/e2e/disks.e2e.ts b/test/e2e/disks.e2e.ts index 0ce5d3eafa..8115c822a6 100644 --- a/test/e2e/disks.e2e.ts +++ b/test/e2e/disks.e2e.ts @@ -94,7 +94,7 @@ test('List disks and snapshot', async ({ page }) => { await page.goto('/projects/mock-project/disks') const table = page.getByRole('table') - await expect(table.getByRole('row')).toHaveCount(18) // 17 + header + await expect(table.getByRole('row')).toHaveCount(19) // 18 + header // check one attached and one not attached await expectRowVisible(table, { @@ -210,6 +210,25 @@ test('Cancel import from importing_from_bulk_writes', async ({ page }) => { await expect(page.getByRole('menuitem', { name: 'Delete' })).toBeVisible() }) +test('Cancel import from importing_from_bulk_writes shows error and refreshes state when finalize fails', async ({ + page, +}) => { + const diskName = 'disk-finalize-fail' + await page.goto('/projects/mock-project/disks') + const table = page.getByRole('table') + await expectRowVisible(table, { name: diskName, state: 'importing from bulk writes' }) + + await clickRowActions(page, diskName) + await page.getByRole('menuitem', { name: 'Cancel import' }).click() + await page + .getByRole('dialog', { name: 'Cancel import' }) + .getByRole('button', { name: 'Confirm' }) + .click() + + await expectToast(page, 'Failed to cancel import') + await expectRowVisible(table, { name: diskName, state: 'import ready' }) +}) + test.describe('Disk create', () => { test.beforeEach(async ({ page }) => { await page.goto('/projects/mock-project/disks-new') From f3ad9b016578c791079410e9e1547ae399692693 Mon Sep 17 00:00:00 2001 From: Joe Thel Date: Tue, 22 Sep 2026 15:55:25 -0700 Subject: [PATCH 05/10] Make showing the disk delete action unconditional --- app/pages/project/disks/DisksPage.tsx | 88 ++++++++++++++------------- test/e2e/disks.e2e.ts | 4 +- 2 files changed, 48 insertions(+), 44 deletions(-) diff --git a/app/pages/project/disks/DisksPage.tsx b/app/pages/project/disks/DisksPage.tsx index bb6d4d0c69..c13c297c6b 100644 --- a/app/pages/project/disks/DisksPage.tsx +++ b/app/pages/project/disks/DisksPage.tsx @@ -144,53 +144,57 @@ export default function DisksPage() { }, disabled: snapshotDisabledReason(disk), }, - match(disk.state.state) - .with('import_ready', 'importing_from_bulk_writes', () => ({ - label: 'Cancel import', - onActivate() { - confirmAction({ - doAction: async () => { - if (disk.state.state === 'importing_from_bulk_writes') { - await stopBulkWriteImport({ + ...match(disk.state.state) + .returnType() + .with('import_ready', 'importing_from_bulk_writes', () => [ + { + label: 'Cancel import', + onActivate() { + confirmAction({ + doAction: async () => { + if (disk.state.state === 'importing_from_bulk_writes') { + await stopBulkWriteImport({ + path: { disk: disk.name }, + query: { project }, + }) + } + + await finalize({ path: { disk: disk.name }, query: { project }, + body: {}, }) - } - await finalize({ - path: { disk: disk.name }, - query: { project }, - body: {}, - }) - - addToast( - <> - Import canceled for {disk.name} - - ) - }, - modalTitle: 'Cancel import', - modalContent: `Are you sure you want to cancel import for ${disk.name}?`, - errorTitle: 'Failed to cancel import', - actionType: 'danger', - }) + addToast( + <> + Import canceled for {disk.name} + + ) + }, + modalTitle: 'Cancel import', + modalContent: `Are you sure you want to cancel import for ${disk.name}?`, + errorTitle: 'Failed to cancel import', + actionType: 'danger', + }) + }, }, - })) - .otherwise(() => ({ - label: 'Delete', - onActivate: confirmDelete({ - doDelete: () => deleteDisk({ path: { disk: disk.name }, query: { project } }), - label: disk.name, - resourceKind: 'disk', - }), - disabled: - !diskCan.delete(disk) && - (disk.state.state === 'attached' ? ( - 'Disk must be detached before it can be deleted' - ) : ( - <>Only disks in state {fancifyStates(diskCan.delete.states)} can be deleted - )), - })), + ]) + .otherwise(() => []), + { + label: 'Delete', + onActivate: confirmDelete({ + doDelete: () => deleteDisk({ path: { disk: disk.name }, query: { project } }), + label: disk.name, + resourceKind: 'disk', + }), + disabled: + !diskCan.delete(disk) && + (disk.state.state === 'attached' ? ( + 'Disk must be detached before it can be deleted' + ) : ( + <>Only disks in state {fancifyStates(diskCan.delete.states)} can be deleted + )), + }, ], [createSnapshot, deleteDisk, stopBulkWriteImport, finalize, project] ) diff --git a/test/e2e/disks.e2e.ts b/test/e2e/disks.e2e.ts index 8115c822a6..03562cb6d4 100644 --- a/test/e2e/disks.e2e.ts +++ b/test/e2e/disks.e2e.ts @@ -174,7 +174,7 @@ test('Cancel import from import_ready', async ({ page }) => { await expectRowVisible(table, { name: diskImportReadyName, state: 'import ready' }) await clickRowActions(page, diskImportReadyName) - await expect(page.getByRole('menuitem', { name: 'Delete' })).toBeHidden() + await expect(page.getByRole('menuitem', { name: 'Delete' })).toBeDisabled() await page.getByRole('menuitem', { name: 'Cancel import' }).click() const modal = page.getByRole('dialog', { name: 'Cancel import' }) @@ -197,7 +197,7 @@ test('Cancel import from importing_from_bulk_writes', async ({ page }) => { }) await clickRowActions(page, diskImportingName) - await expect(page.getByRole('menuitem', { name: 'Delete' })).toBeHidden() + await expect(page.getByRole('menuitem', { name: 'Delete' })).toBeDisabled() await page.getByRole('menuitem', { name: 'Cancel import' }).click() const modal = page.getByRole('dialog', { name: 'Cancel import' }) From 4e5b9ad6b1d6f885172a783d0eb1f941aae4d65c Mon Sep 17 00:00:00 2001 From: David Crespo Date: Mon, 2 Nov 2026 15:53:22 -0600 Subject: [PATCH 06/10] Highlight disk name in cancel import modal --- AGENTS.md | 1 + app/pages/project/disks/DisksPage.tsx | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/AGENTS.md b/AGENTS.md index e4a89ab47e..cd941e463d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -60,6 +60,7 @@ # Mutations & UI flow - Wrap writes in `useApiMutation` and surface results with `addToast` (`app/stores/toast.ts`). Guard destructive flows with the zustand confirm helpers `confirmDelete`/`confirmAction` (`app/stores/confirm-delete.tsx`, `app/stores/confirm-action.ts`), passing a `mutateAsync` lambda so the modal can catch failures and toast them. +- In toasts and confirm modal content, wrap resource names in `` (e.g., `

Are you sure you want to detach {disk.name}?

`). - When a form's `onSuccess` always navigates away, pass `loading={mutation.isPending || mutation.isSuccess}` to the form shell. `isPending` alone flips false before the navigation unmounts the modal, so the button's spinner animates back out right before close. Skip `isSuccess` if the form can stay open and be reused after success, or if the mutation lives in a component that survives the modal (e.g., a tab page with `{open && }`) — there success closes the modal synchronously so `isPending` alone is glitch-free, and a sticky `isSuccess` would strand a spinner on next open. - Mutation error display depends on context. In forms, errors display inline via `submitError={mutation.error}` — do not add `onError` with a toast to the `useApiMutation` call. In `confirmAction`/`confirmDelete` flows, the confirm modal catches the error and shows a toast using `errorTitle` — do not also add `onError` on the mutation, or the user will see two toasts. For standalone actions (fire-and-forget `mutate` calls not wrapped in a confirm modal or form), use `onError` on the mutation to show an error toast. - Keep page scaffolding consistent: `PageHeader`, `PageTitle`, `DocsPopover`, `RefreshButton`, `PropertiesTable`, and `CardBlock` provide the expected layout for new system pages. diff --git a/app/pages/project/disks/DisksPage.tsx b/app/pages/project/disks/DisksPage.tsx index c13c297c6b..5d30c6346d 100644 --- a/app/pages/project/disks/DisksPage.tsx +++ b/app/pages/project/disks/DisksPage.tsx @@ -172,7 +172,11 @@ export default function DisksPage() { ) }, modalTitle: 'Cancel import', - modalContent: `Are you sure you want to cancel import for ${disk.name}?`, + modalContent: ( +

+ Are you sure you want to cancel import for {disk.name}? +

+ ), errorTitle: 'Failed to cancel import', actionType: 'danger', }) From 09ad97c80bafcfa3d363f4b317b09f1505c85f4b Mon Sep 17 00:00:00 2001 From: Joe Thel Date: Mon, 2 Nov 2026 14:51:28 -0800 Subject: [PATCH 07/10] bits and bobs --- app/api/util.ts | 4 ++ app/pages/project/disks/DisksPage.tsx | 80 +++++++++++++-------------- test/e2e/disks.e2e.ts | 4 +- 3 files changed, 45 insertions(+), 43 deletions(-) diff --git a/app/api/util.ts b/app/api/util.ts index 6eb4739a91..3cc457a288 100644 --- a/app/api/util.ts +++ b/app/api/util.ts @@ -299,6 +299,10 @@ const diskStateActions = { detach: ['attached'], // https://github.com/oxidecomputer/omicron/blob/3093818/nexus/db-queries/src/db/datastore/instance.rs#L1077-L1081 setAsBootDisk: ['attached'], + // https://github.com/oxidecomputer/omicron/blob/9971869/nexus/src/app/sagas/finalize_disk.rs#L155-L186 + finalizeImport: ['import_ready'], + // https://github.com/oxidecomputer/omicron/blob/9971869/nexus/src/app/disk.rs#L684-L697 + stopImport: ['importing_from_bulk_writes'], } satisfies Record // snapshot has a type check in addition to state check diff --git a/app/pages/project/disks/DisksPage.tsx b/app/pages/project/disks/DisksPage.tsx index aa5cb19edf..a6b708cf54 100644 --- a/app/pages/project/disks/DisksPage.tsx +++ b/app/pages/project/disks/DisksPage.tsx @@ -10,7 +10,6 @@ import { useQuery } from '@tanstack/react-query' import { createColumnHelper } from '@tanstack/react-table' import { useCallback, useMemo } from 'react' import { Outlet } from 'react-router' -import { match } from 'ts-pattern' import { api, @@ -130,6 +129,45 @@ export default function DisksPage() { const makeActions = useCallback( (disk: Disk): MenuAction[] => [ + ...(diskCan.finalizeImport(disk) || diskCan.stopImport(disk) + ? [ + { + label: 'Cancel import', + onActivate() { + confirmAction({ + doAction: async () => { + if (diskCan.stopImport(disk)) { + await stopBulkWriteImport({ + path: { disk: disk.name }, + query: { project }, + }) + } + + await finalize({ + path: { disk: disk.name }, + query: { project }, + body: {}, + }) + + addToast( + <> + Import canceled for {disk.name} + + ) + }, + modalTitle: 'Cancel import', + modalContent: ( +

+ Are you sure you want to cancel import for {disk.name}? +

+ ), + errorTitle: 'Failed to cancel import', + actionType: 'danger', + }) + }, + }, + ] + : []), { label: 'Snapshot', onActivate() { @@ -146,46 +184,6 @@ export default function DisksPage() { }, disabled: snapshotDisabledReason(disk), }, - ...match(disk.state.state) - .returnType() - .with('import_ready', 'importing_from_bulk_writes', () => [ - { - label: 'Cancel import', - onActivate() { - confirmAction({ - doAction: async () => { - if (disk.state.state === 'importing_from_bulk_writes') { - await stopBulkWriteImport({ - path: { disk: disk.name }, - query: { project }, - }) - } - - await finalize({ - path: { disk: disk.name }, - query: { project }, - body: {}, - }) - - addToast( - <> - Import canceled for {disk.name} - - ) - }, - modalTitle: 'Cancel import', - modalContent: ( -

- Are you sure you want to cancel import for {disk.name}? -

- ), - errorTitle: 'Failed to cancel import', - actionType: 'danger', - }) - }, - }, - ]) - .otherwise(() => []), { label: 'Delete', onActivate: confirmDelete({ diff --git a/test/e2e/disks.e2e.ts b/test/e2e/disks.e2e.ts index 6f59c18163..edfdc9ef53 100644 --- a/test/e2e/disks.e2e.ts +++ b/test/e2e/disks.e2e.ts @@ -184,7 +184,7 @@ test('Cancel import from import_ready', async ({ page }) => { await expectToast(page, `Import canceled for ${diskImportReadyName}`) await expectRowVisible(table, { name: diskImportReadyName, state: 'detached' }) await clickRowActions(page, diskImportReadyName) - await expect(page.getByRole('menuitem', { name: 'Delete' })).toBeVisible() + await expect(page.getByRole('menuitem', { name: 'Delete' })).toBeEnabled() }) test('Cancel import from importing_from_bulk_writes', async ({ page }) => { @@ -207,7 +207,7 @@ test('Cancel import from importing_from_bulk_writes', async ({ page }) => { await expectToast(page, `Import canceled for ${diskImportingName}`) await expectRowVisible(table, { name: diskImportingName, state: 'detached' }) await clickRowActions(page, diskImportingName) - await expect(page.getByRole('menuitem', { name: 'Delete' })).toBeVisible() + await expect(page.getByRole('menuitem', { name: 'Delete' })).toBeEnabled() }) test('Cancel import from importing_from_bulk_writes shows error and refreshes state when finalize fails', async ({ From d47bd1e1e9aa30881b33b641a2f1450e958a19bf Mon Sep 17 00:00:00 2001 From: Joe Thel Date: Mon, 2 Nov 2026 15:05:56 -0800 Subject: [PATCH 08/10] Invalidate disk list (and view) when import cancellation fails --- app/pages/project/disks/DisksPage.tsx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/pages/project/disks/DisksPage.tsx b/app/pages/project/disks/DisksPage.tsx index a6b708cf54..1b1e2e1afe 100644 --- a/app/pages/project/disks/DisksPage.tsx +++ b/app/pages/project/disks/DisksPage.tsx @@ -88,6 +88,11 @@ export async function clientLoader({ params }: Route.ClientLoaderArgs) { const colHelper = createColumnHelper() +const invalidateDiskListAndView = () => { + queryClient.invalidateEndpoint('diskList') + queryClient.invalidateEndpoint('diskView') +} + export default function DisksPage() { const { project } = useProjectSelector() @@ -116,15 +121,16 @@ export default function DisksPage() { }, }) + // the states that allow these actions are both temporary, so a failure is + // most likely to be due to a state change from afar. for that reason it's + // worth invalidating on failures as well as successes const { mutateAsync: finalize } = useApiMutation(api.diskFinalizeImport, { - onSuccess() { - queryClient.invalidateEndpoint('diskList') - }, + onSuccess: invalidateDiskListAndView, + onError: invalidateDiskListAndView, }) const { mutateAsync: stopBulkWriteImport } = useApiMutation(api.diskBulkWriteImportStop, { - onSuccess() { - queryClient.invalidateEndpoint('diskList') - }, + onSuccess: invalidateDiskListAndView, + onError: invalidateDiskListAndView, }) const makeActions = useCallback( From 0425caa72dd69ac92b934ab919832b780824843b Mon Sep 17 00:00:00 2001 From: Joe Thel Date: Mon, 2 Nov 2026 16:38:13 -0800 Subject: [PATCH 09/10] Add a little more clarity to copy --- app/pages/project/disks/DisksPage.tsx | 139 ++++++++++++++------------ 1 file changed, 73 insertions(+), 66 deletions(-) diff --git a/app/pages/project/disks/DisksPage.tsx b/app/pages/project/disks/DisksPage.tsx index 1b1e2e1afe..67fe437823 100644 --- a/app/pages/project/disks/DisksPage.tsx +++ b/app/pages/project/disks/DisksPage.tsx @@ -134,78 +134,85 @@ export default function DisksPage() { }) const makeActions = useCallback( - (disk: Disk): MenuAction[] => [ - ...(diskCan.finalizeImport(disk) || diskCan.stopImport(disk) - ? [ - { - label: 'Cancel import', - onActivate() { - confirmAction({ - doAction: async () => { - if (diskCan.stopImport(disk)) { - await stopBulkWriteImport({ + (disk: Disk): MenuAction[] => { + const canCancelImport = diskCan.finalizeImport(disk) || diskCan.stopImport(disk) + + return [ + ...(canCancelImport + ? [ + { + label: 'Cancel import', + onActivate() { + confirmAction({ + doAction: async () => { + if (diskCan.stopImport(disk)) { + await stopBulkWriteImport({ + path: { disk: disk.name }, + query: { project }, + }) + } + + await finalize({ path: { disk: disk.name }, query: { project }, + body: {}, }) - } - - await finalize({ - path: { disk: disk.name }, - query: { project }, - body: {}, - }) - addToast( - <> - Import canceled for {disk.name} - - ) - }, - modalTitle: 'Cancel import', - modalContent: ( -

- Are you sure you want to cancel import for {disk.name}? -

- ), - errorTitle: 'Failed to cancel import', - actionType: 'danger', - }) + addToast( + <> + Import canceled for {disk.name} + + ) + }, + modalTitle: 'Cancel import', + modalContent: ( +

+ Are you sure you want to cancel import for {disk.name}? + This will leave it in the detached state. +

+ ), + errorTitle: 'Failed to cancel import', + actionType: 'danger', + }) + }, }, - }, - ] - : []), - { - label: 'Snapshot', - onActivate() { - // prettier-ignore - addToast(<>Creating snapshot of disk {disk.name}) - createSnapshot({ - query: { project }, - body: { - name: genName(disk.name), - disk: disk.name, - description: '', - }, - }) + ] + : []), + { + label: 'Snapshot', + onActivate() { + // prettier-ignore + addToast(<>Creating snapshot of disk {disk.name}) + createSnapshot({ + query: { project }, + body: { + name: genName(disk.name), + disk: disk.name, + description: '', + }, + }) + }, + disabled: snapshotDisabledReason(disk), }, - disabled: snapshotDisabledReason(disk), - }, - { - label: 'Delete', - onActivate: confirmDelete({ - doDelete: () => deleteDisk({ path: { disk: disk.name }, query: { project } }), - label: disk.name, - resourceKind: 'disk', - }), - disabled: - !diskCan.delete(disk) && - (disk.state.state === 'attached' ? ( - 'Disk must be detached before it can be deleted' - ) : ( - <>Only disks in state {fancifyStates(diskCan.delete.states)} can be deleted - )), - }, - ], + { + label: 'Delete', + onActivate: confirmDelete({ + doDelete: () => deleteDisk({ path: { disk: disk.name }, query: { project } }), + label: disk.name, + resourceKind: 'disk', + }), + disabled: + !diskCan.delete(disk) && + (disk.state.state === 'attached' ? ( + 'Disk must be detached before it can be deleted' + ) : canCancelImport ? ( + 'Import must be canceled before the disk can be deleted' + ) : ( + <>Only disks in state {fancifyStates(diskCan.delete.states)} can be deleted + )), + }, + ] + }, [createSnapshot, deleteDisk, stopBulkWriteImport, finalize, project] ) From e4125dd39d5384576d2111439a13eb1c70b79068 Mon Sep 17 00:00:00 2001 From: Joe Thel Date: Wed, 18 Nov 2026 11:20:28 -0800 Subject: [PATCH 10/10] Refer to this process as "stop imports" instead of cancel --- app/api/util.ts | 2 +- app/pages/project/disks/DisksPage.tsx | 22 +++++++++++----------- test/e2e/disks.e2e.ts | 24 ++++++++++++------------ 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/app/api/util.ts b/app/api/util.ts index 3cc457a288..23228b0e00 100644 --- a/app/api/util.ts +++ b/app/api/util.ts @@ -302,7 +302,7 @@ const diskStateActions = { // https://github.com/oxidecomputer/omicron/blob/9971869/nexus/src/app/sagas/finalize_disk.rs#L155-L186 finalizeImport: ['import_ready'], // https://github.com/oxidecomputer/omicron/blob/9971869/nexus/src/app/disk.rs#L684-L697 - stopImport: ['importing_from_bulk_writes'], + cancelBulkWrites: ['importing_from_bulk_writes'], } satisfies Record // snapshot has a type check in addition to state check diff --git a/app/pages/project/disks/DisksPage.tsx b/app/pages/project/disks/DisksPage.tsx index 67fe437823..581f5df0df 100644 --- a/app/pages/project/disks/DisksPage.tsx +++ b/app/pages/project/disks/DisksPage.tsx @@ -135,17 +135,17 @@ export default function DisksPage() { const makeActions = useCallback( (disk: Disk): MenuAction[] => { - const canCancelImport = diskCan.finalizeImport(disk) || diskCan.stopImport(disk) + const canStopImport = diskCan.finalizeImport(disk) || diskCan.cancelBulkWrites(disk) return [ - ...(canCancelImport + ...(canStopImport ? [ { - label: 'Cancel import', + label: 'Stop import', onActivate() { confirmAction({ doAction: async () => { - if (diskCan.stopImport(disk)) { + if (diskCan.cancelBulkWrites(disk)) { await stopBulkWriteImport({ path: { disk: disk.name }, query: { project }, @@ -160,18 +160,18 @@ export default function DisksPage() { addToast( <> - Import canceled for {disk.name} + Import stopped for {disk.name} ) }, - modalTitle: 'Cancel import', + modalTitle: 'Stop import', modalContent: (

- Are you sure you want to cancel import for {disk.name}? - This will leave it in the detached state. + Are you sure you want to stop import for {disk.name}? This + will leave it in the detached state.

), - errorTitle: 'Failed to cancel import', + errorTitle: 'Failed to stop import', actionType: 'danger', }) }, @@ -205,8 +205,8 @@ export default function DisksPage() { !diskCan.delete(disk) && (disk.state.state === 'attached' ? ( 'Disk must be detached before it can be deleted' - ) : canCancelImport ? ( - 'Import must be canceled before the disk can be deleted' + ) : canStopImport ? ( + 'Import must be stopped before the disk can be deleted' ) : ( <>Only disks in state {fancifyStates(diskCan.delete.states)} can be deleted )), diff --git a/test/e2e/disks.e2e.ts b/test/e2e/disks.e2e.ts index edfdc9ef53..ed8203f73a 100644 --- a/test/e2e/disks.e2e.ts +++ b/test/e2e/disks.e2e.ts @@ -167,7 +167,7 @@ test('Read-only disk snapshot disabled', async ({ page }) => { ) }) -test('Cancel import from import_ready', async ({ page }) => { +test('Stop import from import_ready', async ({ page }) => { const diskImportReadyName = 'tmp-for-image-29884739' await page.goto('/projects/mock-project/disks') const table = page.getByRole('table') @@ -175,19 +175,19 @@ test('Cancel import from import_ready', async ({ page }) => { await clickRowActions(page, diskImportReadyName) await expect(page.getByRole('menuitem', { name: 'Delete' })).toBeDisabled() - await page.getByRole('menuitem', { name: 'Cancel import' }).click() + await page.getByRole('menuitem', { name: 'Stop import' }).click() - const modal = page.getByRole('dialog', { name: 'Cancel import' }) + const modal = page.getByRole('dialog', { name: 'Stop import' }) await expect(modal).toBeVisible() await modal.getByRole('button', { name: 'Confirm' }).click() - await expectToast(page, `Import canceled for ${diskImportReadyName}`) + await expectToast(page, `Import stopped for ${diskImportReadyName}`) await expectRowVisible(table, { name: diskImportReadyName, state: 'detached' }) await clickRowActions(page, diskImportReadyName) await expect(page.getByRole('menuitem', { name: 'Delete' })).toBeEnabled() }) -test('Cancel import from importing_from_bulk_writes', async ({ page }) => { +test('Stop import from importing_from_bulk_writes', async ({ page }) => { const diskImportingName = 'tmp-for-image-59986861' await page.goto('/projects/mock-project/disks') const table = page.getByRole('table') @@ -198,19 +198,19 @@ test('Cancel import from importing_from_bulk_writes', async ({ page }) => { await clickRowActions(page, diskImportingName) await expect(page.getByRole('menuitem', { name: 'Delete' })).toBeDisabled() - await page.getByRole('menuitem', { name: 'Cancel import' }).click() + await page.getByRole('menuitem', { name: 'Stop import' }).click() - const modal = page.getByRole('dialog', { name: 'Cancel import' }) + const modal = page.getByRole('dialog', { name: 'Stop import' }) await expect(modal).toBeVisible() await modal.getByRole('button', { name: 'Confirm' }).click() - await expectToast(page, `Import canceled for ${diskImportingName}`) + await expectToast(page, `Import stopped for ${diskImportingName}`) await expectRowVisible(table, { name: diskImportingName, state: 'detached' }) await clickRowActions(page, diskImportingName) await expect(page.getByRole('menuitem', { name: 'Delete' })).toBeEnabled() }) -test('Cancel import from importing_from_bulk_writes shows error and refreshes state when finalize fails', async ({ +test('Stop import from importing_from_bulk_writes shows error and refreshes state when finalize fails', async ({ page, }) => { const diskName = 'disk-finalize-fail' @@ -219,13 +219,13 @@ test('Cancel import from importing_from_bulk_writes shows error and refreshes st await expectRowVisible(table, { name: diskName, state: 'importing from bulk writes' }) await clickRowActions(page, diskName) - await page.getByRole('menuitem', { name: 'Cancel import' }).click() + await page.getByRole('menuitem', { name: 'Stop import' }).click() await page - .getByRole('dialog', { name: 'Cancel import' }) + .getByRole('dialog', { name: 'Stop import' }) .getByRole('button', { name: 'Confirm' }) .click() - await expectToast(page, 'Failed to cancel import') + await expectToast(page, 'Failed to stop import') await expectRowVisible(table, { name: diskName, state: 'import ready' }) })