ODS V3 Pre-Release: Public testing and refinement ahead of the official V3 launch. Turn your PC, Mac, or Linux box into a private AI server.
Python ai-agentsamdcomfyuidockerllama-cppllmlocal-ain8nnvidiaopen-webuiragself-hostedspeech-to-textstrix-halotext-to-speechworkflow-automation
fix(dashboard): confirm before unloading the model (#8175)
Mike Bradley3bc3adc66f04
diff --git a/ods/extensions/services/dashboard/src/pages/Models.jsx b/ods/extensions/services/dashboard/src/pages/Models.jsxindex df4e181a2..21a842b9b 100644--- a/ods/extensions/services/dashboard/src/pages/Models.jsx+++ b/ods/extensions/services/dashboard/src/pages/Models.jsx@@ -109,6 +109,7 @@ export default function Models({ compact = false }) {const [speedFilter, setSpeedFilter] = useState('any')const [contextFloor, setContextFloor] = useState(0)const [deleteConfirmModel, setDeleteConfirmModel] = useState(null)+ const [unloadConfirmOpen, setUnloadConfirmOpen] = useState(false)const [activationConfigModel, setActivationConfigModel] = useState(null)const [libraryScope, setLibraryScope] = useState('recommended')const libraryRef = useRef(null)@@ -257,6 +258,18 @@ export default function Models({ compact = false }) {}const pendingModelActions = actionLoadingModels ?? (actionLoading ? [actionLoading] : [])+ const runtimeControlsBusy = Boolean(runtimeActionLoading || activationLoading || modelLifecycle?.active || pendingModelActions.length || downloadProgress.isDownloading)+ // Unloading stops Portal and Hermes until Resume, so it asks first. The+ // question closes for good if the model stops or another operation starts.+ const unloadAvailable = Boolean(modelManagement?.managed === true && modelManagement.canUnload === true+ && modelManagement.running && !runtimeControlsBusy)+ useEffect(() => {+ if (!unloadAvailable) setUnloadConfirmOpen(false)+ }, [unloadAvailable])+ const handleConfirmUnload = async () => {+ setUnloadConfirmOpen(false)+ await stopRuntime()+ }const visibleDownloadProgress = downloadProgress.progress || (downloadProgress.statusError && {status: 'error',error: downloadProgress.statusError,@@ -373,8 +386,8 @@ export default function Models({ compact = false }) {<p role="status" className="mt-1 text-xs text-theme-text-secondary">{modelManagement.runtimeError}</p>)}</div>- <button type="button" onClick={modelManagement.running ? stopRuntime : startRuntime}- disabled={Boolean(runtimeActionLoading || activationLoading || modelLifecycle?.active || pendingModelActions.length || downloadProgress.isDownloading)}+ <button type="button" onClick={modelManagement.running ? () => setUnloadConfirmOpen(true) : startRuntime}+ disabled={runtimeControlsBusy}className="rounded-md border border-theme-border px-3 py-2 disabled:opacity-50">{runtimeActionLoading === 'stop' ? 'Unloading…' : runtimeActionLoading === 'start' ? (modelManagement.startRefusal ? 'Starting…' : 'Resuming…') : modelManagement.running ? 'Unload model' : modelManagement.startRefusal ? 'Start anyway' : 'Resume model'}</button>@@ -504,6 +517,12 @@ export default function Models({ compact = false }) {onConfirm={handleConfirmDelete}/>)}+ {unloadConfirmOpen && unloadAvailable && (+ <UnloadModelDialog+ onCancel={() => setUnloadConfirmOpen(false)}+ onConfirm={handleConfirmUnload}+ />+ )}{activationConfigModel && (<ModelActivationDialogmodel={activationConfigModel}@@ -1174,6 +1193,52 @@ function DeleteModelDialog({ model, onCancel, onConfirm }) {)}+function UnloadModelDialog({ onCancel, onConfirm }) {+ return (+ <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/70 px-4 py-6">+ <div+ role="dialog"+ aria-modal="true"+ aria-labelledby="unload-model-title"+ aria-describedby="unload-model-detail"+ className="w-full max-w-md rounded-xl border border-red-400/25 bg-theme-card p-5 shadow-[0_24px_80px_rgba(0,0,0,0.32)]"+ >+ <div className="flex items-start gap-3">+ <div className="flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-red-300/20 bg-red-500/10 text-red-300">+ <AlertCircle size={17} />+ </div>+ <div className="min-w-0">+ <h2 id="unload-model-title" className="text-sm font-semibold text-theme-text">+ Unload the model?+ </h2>+ <p id="unload-model-detail" className="mt-2 text-sm leading-5 text-theme-text-muted">+ Portal and Hermes stop answering until you choose Resume model. Loading it again can take a few minutes.+ </p>+ </div>+ </div>++ <div className="mt-5 flex justify-end gap-2">+ <button+ type="button"+ onClick={onCancel}+ autoFocus+ className="inline-flex h-9 items-center justify-center rounded-md border border-theme-border bg-theme-bg/45 px-3 text-xs font-semibold text-theme-text-secondary transition-colors hover:border-theme-accent/35 hover:text-theme-text"+ >+ Cancel+ </button>+ <button+ type="button"+ onClick={onConfirm}+ className="inline-flex h-9 items-center justify-center rounded-md border border-red-300/30 bg-red-500/15 px-3 text-xs font-semibold text-red-200 transition-colors hover:border-red-200/50 hover:bg-red-500/25"+ >+ Unload model+ </button>+ </div>+ </div>+ </div>+ )+}+function ModelActivationDialog({model,gpu,diff --git a/ods/extensions/services/dashboard/src/pages/Models.test.jsx b/ods/extensions/services/dashboard/src/pages/Models.test.jsxindex 5222fab8c..98b3be82e 100644--- a/ods/extensions/services/dashboard/src/pages/Models.test.jsx+++ b/ods/extensions/services/dashboard/src/pages/Models.test.jsx@@ -300,11 +300,50 @@ test.each([true, false])('only managed runtimes expose unload/resume and hide adrenderModels()const button = screen.getByRole('button', { name: running ? 'Unload model' : 'Resume model' })fireEvent.click(button)+ // Unloading asks first; Resume starts at once.+ if (running) fireEvent.click(within(screen.getByRole('dialog', { name: 'Unload the model?' })).getByRole('button', { name: 'Unload model' }))+ else expect(screen.queryByRole('dialog')).toBeNull()expect(running ? state.stopRuntime : state.startRuntime).toHaveBeenCalledOnce()expect(screen.queryByRole('button', { name: 'Adopt loaded model in ODS' })).toBeNull()if (!running) expect(screen.queryByText('Local model runtime unavailable')).toBeNull()})+test('an open unload question closes for good when the model stops or another operation starts', () => {+ const state = baseState({+ models: [model({ status: 'loaded' })],+ odsMode: 'local', configuredMode: 'local', llmBackend: 'llama-server', hostRuntime: true,+ modelManagement: { managed: true, canActivate: true, canUnload: true, running: true },+ stopRuntime: vi.fn(), startRuntime: vi.fn(),+ })+ useModelsMock.mockReturnValue(state)+ const view = renderModels()+ const show = (next, download = baseDownloadState()) => {+ useModelsMock.mockReturnValue(next)+ useDownloadProgressMock.mockReturnValue(download)+ view.rerender(createElement(MemoryRouter, null, createElement(Models)))+ }+ const ask = () => {+ fireEvent.click(within(screen.getByRole('region', { name: 'Model runtime controls' })).getByRole('button', { name: 'Unload model' }))+ expect(screen.getByRole('dialog', { name: 'Unload the model?' })).toBeVisible()+ }++ // The model stopped elsewhere: nothing is left to unload.+ ask()+ show({ ...state, modelManagement: { ...state.modelManagement, canActivate: false, running: false } })+ expect(screen.queryByRole('dialog')).toBeNull()+ show(state)+ expect(screen.queryByRole('dialog')).toBeNull()++ // A download started elsewhere: the runtime controls wait for it.+ ask()+ show(state, baseDownloadState({ isDownloading: true }))+ expect(screen.queryByRole('dialog')).toBeNull()+ expect(screen.getByRole('button', { name: 'Unload model' })).toBeDisabled()+ show(state)+ expect(screen.queryByRole('dialog')).toBeNull()+ expect(state.stopRuntime).not.toHaveBeenCalled()+})+test('a stopped runtime shows the launcher error, and a memory refusal turns Resume into Start anyway', () => {const refusal = 'The model was not started: Windows can lend it only 1.0 GiB right now (memory limit 30.5 GiB, 29.5 GiB in use) and it needs about 25.8 GiB.'const state = baseState({diff --git a/ods/extensions/services/dashboard/src/pages/Models.unload-confirm.test.jsx b/ods/extensions/services/dashboard/src/pages/Models.unload-confirm.test.jsxnew file mode 100644index 000000000..59852a3b1--- /dev/null+++ b/ods/extensions/services/dashboard/src/pages/Models.unload-confirm.test.jsx@@ -0,0 +1,85 @@+import { StrictMode, createElement } from 'react'+import { fireEvent, render, screen, within } from '@testing-library/react'+import { MemoryRouter } from 'react-router-dom'+import Models from './Models'++// The production model hook drives the page, so these tests see the requests+// the runtime controls actually send. Downloads are a separate transport.+vi.mock('../hooks/useDownloadProgress', () => ({+ useDownloadProgress: () => ({ isDownloading: false, refresh: vi.fn() }),+}))++const modelId = 'qwen3.5-9b-q4'+const json = (body, status = 200) => ({ ok: status < 400, status, json: async () => body })+const posts = () => fetch.mock.calls.filter(([, options]) => options?.method === 'POST')+let running++// A model on the Windows host that this ODS installation manages.+const catalog = () => ({+ models: [{+ id: modelId, name: 'Qwen 3.5 9B', status: running ? 'loaded' : 'downloaded',+ size: '5.6 GB', sizeGb: 5.6, vramRequired: 7, fitsVram: true,+ contextLength: 65536, maxContextLength: 65536, specialty: 'General',+ quantization: 'Q4_K_M', publisher: { name: 'Qwen' },+ }],+ currentModel: running ? modelId : null,+ gpu: { vramTotal: 16, vramFree: 8, vramUsed: 8 },+ odsMode: 'local', configuredMode: 'local', llmBackend: 'llama-server', hostRuntime: true,+ modelManagement: { managed: true, canActivate: running, canUnload: true, running },+})++beforeEach(() => {+ vi.stubGlobal('fetch', vi.fn(async (url, options) => {+ if (url === '/api/models') return json(catalog())+ if (options?.method === 'POST' && url === '/api/models/runtime/stop') {+ running = false+ return json({ status: 'stopped' })+ }+ if (options?.method === 'POST' && url === '/api/models/runtime/start') {+ running = true+ return json({ status: 'started' })+ }+ return json({}, 404)+ }))+})++afterEach(() => {+ vi.unstubAllGlobals()+})++async function openRuntimeControls() {+ render(createElement(StrictMode, null, createElement(MemoryRouter, null, createElement(Models))))+ return within(await screen.findByRole('region', { name: 'Model runtime controls' }))+}++test('Unload model asks first, Cancel sends nothing, and confirming stops the runtime once', async () => {+ running = true+ const controls = await openRuntimeControls()++ fireEvent.click(controls.getByRole('button', { name: 'Unload model' }))+ const dialog = screen.getByRole('dialog', { name: 'Unload the model?' })+ expect(dialog).toHaveAccessibleDescription('Portal and Hermes stop answering until you choose Resume model. Loading it again can take a few minutes.')+ expect(within(dialog).getByRole('button', { name: 'Cancel' })).toHaveFocus()+ expect(posts()).toEqual([])++ fireEvent.click(within(dialog).getByRole('button', { name: 'Cancel' }))+ expect(screen.queryByRole('dialog')).toBeNull()+ expect(controls.getByRole('button', { name: 'Unload model' })).toBeEnabled()+ expect(posts()).toEqual([])++ fireEvent.click(controls.getByRole('button', { name: 'Unload model' }))+ fireEvent.click(within(screen.getByRole('dialog', { name: 'Unload the model?' })).getByRole('button', { name: 'Unload model' }))+ expect(screen.queryByRole('dialog')).toBeNull()+ expect(await controls.findByRole('button', { name: 'Resume model' })).toBeEnabled()+ expect(posts().map(([url]) => url)).toEqual(['/api/models/runtime/stop'])+})++test('Resume model starts a stopped runtime without asking', async () => {+ running = false+ const controls = await openRuntimeControls()++ fireEvent.click(controls.getByRole('button', { name: 'Resume model' }))+ expect(screen.queryByRole('dialog')).toBeNull()+ expect(await controls.findByRole('button', { name: 'Unload model' })).toBeEnabled()+ expect(posts().map(([url]) => url)).toEqual(['/api/models/runtime/start'])+})