Repository navigation
fix(desktop): hide models and controls for stopped engines #189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { useCallback, useMemo, useState } from 'react' | ||
| import { useCallback, useEffect, useMemo, useState } from 'react' | ||
| import { Button, Flex, Stack, Text } from '@nvidia/foundations-react-core' | ||
| import type { BackendInfo } from '@/ui/types/engine-info' | ||
| import { EngineCapabilities } from '@/ui/constants/engine-capabilities' | ||
|
|
@@ -23,6 +23,16 @@ import type { ModelEntry } from '@/ui/types/model-hub' | |
| export function ModelManager({ backend, nodeId }: { backend: BackendInfo; nodeId: string }) { | ||
| const [openModelHubModal, setOpenModelHubModal] = useState(false) | ||
| const [modelPendingDelete, setModelPendingDelete] = useState<string | null>(null) | ||
| const isRunning = backend.processStatus === 'running' | ||
|
|
||
| // A lifecycle transition ends the interaction that opened either dialog. | ||
| // Forget it so restarting cannot reopen a stale download or delete prompt. | ||
| useEffect(() => { | ||
| if (!isRunning) { | ||
| setOpenModelHubModal(false) | ||
| setModelPendingDelete(null) | ||
| } | ||
| }, [isRunning]) | ||
| const models = (backend.models ?? []).sort((a, b) => | ||
| formatModelDisplayName(a.name, backend.type).localeCompare( | ||
| formatModelDisplayName(b.name, backend.type) | ||
|
|
@@ -115,6 +125,7 @@ export function ModelManager({ backend, nodeId }: { backend: BackendInfo; nodeId | |
|
|
||
| const handleAction = useCallback( | ||
| (modelName: string, action: string) => { | ||
| if (!isRunning) return | ||
| switch (action) { | ||
| case 'load': | ||
| window.pairApi.engines.loadModel(backendType, nodeId, modelName) | ||
|
|
@@ -131,24 +142,25 @@ export function ModelManager({ backend, nodeId }: { backend: BackendInfo; nodeId | |
| break | ||
| } | ||
| }, | ||
| [backendType, confirmBeforeDelete, nodeId] | ||
| [backendType, confirmBeforeDelete, isRunning, nodeId] | ||
| ) | ||
|
|
||
| // `ConfirmModal` closes (`onOpenChange(false)`) before it calls `onConfirm`, | ||
| // which clears `modelPendingDelete`. This still reads the right model: the | ||
| // callback closes over the value from the render that showed the modal, and | ||
| // React's state update does not mutate that binding. | ||
| const handleConfirmDelete = useCallback(() => { | ||
| if (modelPendingDelete) { | ||
| if (isRunning && modelPendingDelete) { | ||
| window.pairApi.engines.deleteModel(backendType, nodeId, modelPendingDelete) | ||
| } | ||
| }, [backendType, modelPendingDelete, nodeId]) | ||
| }, [backendType, isRunning, modelPendingDelete, nodeId]) | ||
|
|
||
| const handleExpiryChange = useCallback( | ||
| (modelName: string, value: ModelExpiry) => { | ||
| if (!isRunning) return | ||
| window.pairApi.engines.setModelExpiry(backendType, nodeId, modelName, value) | ||
| }, | ||
| [backendType, nodeId] | ||
| [backendType, isRunning, nodeId] | ||
| ) | ||
|
|
||
| const transientPullProgress = transientModel | ||
|
|
@@ -159,19 +171,14 @@ export function ModelManager({ backend, nodeId }: { backend: BackendInfo; nodeId | |
| () => caps?.hasModelSearchOnlyWhenRunning ?? false, | ||
| [caps?.hasModelSearchOnlyWhenRunning] | ||
| ) | ||
| const modelOpsWhenStopped = useMemo( | ||
| () => caps?.modelOpsWhenStopped ?? false, | ||
| [caps?.modelOpsWhenStopped] | ||
| ) | ||
| const isRunning = useMemo(() => backend.processStatus === 'running', [backend.processStatus]) | ||
| const supportsSearch = useMemo( | ||
| () => caps !== undefined && (!hasModelSearchOnlyWhenRunning || isRunning), | ||
| [caps, hasModelSearchOnlyWhenRunning, isRunning] | ||
| ) | ||
|
|
||
| const handleDownload = useCallback( | ||
| (entries: ModelEntry[]) => { | ||
| if (!entries || entries.length === 0) return | ||
| if (!isRunning || !entries || entries.length === 0) return | ||
|
|
||
| setOpenModelHubModal(false) | ||
|
|
||
|
|
@@ -181,9 +188,17 @@ export function ModelManager({ backend, nodeId }: { backend: BackendInfo; nodeId | |
| } | ||
| } | ||
| }, | ||
| [backendType, nodeId] | ||
| [backendType, isRunning, nodeId] | ||
| ) | ||
|
|
||
| if (backend.processStatus === 'stopped') { | ||
| return ( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This guard handles only the exact stopped status. While the engine is stopping, model rows and controls still render; for vLLM, modelOpsWhenStopped may also leave Load enabled because isRunning is false. Could we explicitly distinguish stopped from transitional states and disable actions while stopping, while preserving the intended actions for a fully stopped vLLM engine? A stopping-state regression test would clarify the expected behavior. |
||
| <Text kind="body/regular/sm" className="text-subtle-color pl-2"> | ||
| Start engine to see models | ||
| </Text> | ||
| ) | ||
| } | ||
|
|
||
| return ( | ||
| <Stack gap="4"> | ||
| {transientModel && ( | ||
|
|
@@ -200,7 +215,7 @@ export function ModelManager({ backend, nodeId }: { backend: BackendInfo; nodeId | |
|
|
||
| {!isBusy && ( | ||
| <> | ||
| {(isRunning || modelOpsWhenStopped) && | ||
| {isRunning && | ||
| models.length === 0 && | ||
| incomingSyncs.length === 0 && | ||
| (backend.modelsKnown ? ( | ||
|
|
@@ -212,15 +227,6 @@ export function ModelManager({ backend, nodeId }: { backend: BackendInfo; nodeId | |
| Downloaded models unavailable | ||
| </Text> | ||
| ))} | ||
| {!modelOpsWhenStopped && | ||
| models.length === 0 && | ||
| incomingSyncs.length === 0 && | ||
| backend.processStatus === 'stopped' && ( | ||
| <Text kind="body/regular/sm" className="text-subtle-color pl-2"> | ||
| Start engine to see models | ||
| </Text> | ||
| )} | ||
|
|
||
| {models.length > 0 && ( | ||
| <Stack gap="1"> | ||
| {models.map(model => ( | ||
|
|
@@ -244,7 +250,7 @@ export function ModelManager({ backend, nodeId }: { backend: BackendInfo; nodeId | |
| )} | ||
|
|
||
| <ConfirmModal | ||
| open={modelPendingDelete !== null} | ||
| open={isRunning && modelPendingDelete !== null} | ||
| onOpenChange={open => { | ||
| if (!open) setModelPendingDelete(null) | ||
| }} | ||
|
|
@@ -261,12 +267,13 @@ export function ModelManager({ backend, nodeId }: { backend: BackendInfo; nodeId | |
| size="small" | ||
| kind="primary" | ||
| color="brand" | ||
| disabled={!isRunning} | ||
| onClick={() => setOpenModelHubModal(true)} | ||
| > | ||
| Add model | ||
| </Button> | ||
| <ModelHubModal | ||
| engine={openModelHubModal ? backend.type : null} | ||
| engine={isRunning && openModelHubModal ? backend.type : null} | ||
| onOpenChange={setOpenModelHubModal} | ||
| onSubmit={handleDownload} | ||
| downloadedModels={models} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we clear the modal state when the engine becomes stopped? This early return unmounts ModelHubModal and ConfirmModal but leaves openModelHubModal and modelPendingDelete set. If the engine starts again, the model hub—or a stale delete confirmation—could reappear. Consider resetting those states on stop and adding a stopped→running regression case.