From c8509643c3cc1d34810e953c34a1a0e17163f2b1 Mon Sep 17 00:00:00 2001 From: shrimbly Date: Sat, 24 Oct 2026 11:56:05 +1300 Subject: [PATCH 1/6] feat(workspace): start a stopped deployment from the Run on menu - With the deployment_start_enabled flag on, a stopped or failed row offers Start. Choosing it calls the start service, the row reads Starting, and the open menu refreshes the listing every 5 s until the deployment is ready. Nothing switches by itself. - A refused Start says what went wrong, shows the server's own message, and says how to fix it; Retry starts it again. A 403 tells the viewer to ask a workspace owner and offers no Retry. - On a stopped deployment this browser runs on, the list opens with a notice and the engine button's tooltip says to open the menu to start it. - workspaceApi.startDeployment calls a proposed ingest route, POST /api/workspaces/:id/deployments/:deploymentId/start, which ingest does not serve yet. --- src/composables/__mocks__/useFeatureFlags.ts | 1 + src/composables/useFeatureFlags.ts | 7 + src/locales/en/main.json | 21 +- .../remoteConfig/serverFeatureFlag.ts | 1 + src/platform/remoteConfig/types.ts | 2 + .../workspace/api/__mocks__/workspaceApi.ts | 1 + .../api/deploymentListingTimeouts.ts | 3 + src/platform/workspace/api/workspaceApi.ts | 17 ++ .../components/DeploymentSwitcher.test.ts | 166 ++++++++++++- .../components/DeploymentSwitcher.vue | 32 ++- .../components/DeploymentSwitcherList.vue | 31 ++- .../components/DeploymentSwitcherRow.vue | 31 ++- .../composables/useDeploymentRows.ts | 174 ++++++++++---- .../workspace/deploymentStartState.test.ts | 221 ++++++++++++++++++ .../workspace/deploymentStartState.ts | 145 ++++++++++++ .../workspace/stores/deploymentStartStore.ts | 75 ++++++ 16 files changed, 869 insertions(+), 59 deletions(-) create mode 100644 src/platform/workspace/deploymentStartState.test.ts create mode 100644 src/platform/workspace/deploymentStartState.ts create mode 100644 src/platform/workspace/stores/deploymentStartStore.ts diff --git a/src/composables/__mocks__/useFeatureFlags.ts b/src/composables/__mocks__/useFeatureFlags.ts index b19e896293b..6e94870c3f9 100644 --- a/src/composables/__mocks__/useFeatureFlags.ts +++ b/src/composables/__mocks__/useFeatureFlags.ts @@ -19,6 +19,7 @@ const defaultFlags: FeatureFlags = { partnerNodeGovernanceEnabled: false, partnerRunGateEnabled: false, partnerNodeTokenEnabled: false, + deploymentStartEnabled: false, userSecretsEnabled: false, nodeReplacementsEnabled: false, deployToCloud: false, diff --git a/src/composables/useFeatureFlags.ts b/src/composables/useFeatureFlags.ts index 71faf891047..657b76ef0d9 100644 --- a/src/composables/useFeatureFlags.ts +++ b/src/composables/useFeatureFlags.ts @@ -185,6 +185,13 @@ export function useFeatureFlags() { true ) }, + get deploymentStartEnabled() { + return resolveFlag( + ServerFeatureFlag.DEPLOYMENT_START_ENABLED, + remoteConfig.value.deployment_start_enabled, + false + ) + }, get partnerNodeTokenEnabled() { return resolveStrictBooleanFlag( ServerFeatureFlag.PARTNER_NODE_TOKEN, diff --git a/src/locales/en/main.json b/src/locales/en/main.json index 42e495d93be..83c42d51369 100644 --- a/src/locales/en/main.json +++ b/src/locales/en/main.json @@ -4165,10 +4165,27 @@ "reason": { "starting": "{deployment} is starting. Pick it once it's ready.", "startElsewhere": "{deployment} isn't running. Start it on the Developer Platform, then pick it.", - "notReady": "{deployment} isn't ready. Pick it once it's ready." + "notReady": "{deployment} isn't ready. Pick it once it's ready.", + "stopped": "{deployment} is stopped. Start it to run jobs on it.", + "failed": "{deployment} failed. Start it again to run jobs on it.", + "notAllowed": "{deployment} is stopped. Ask a workspace owner to start it." }, "missingNodesAfterReason": "It cannot run this workflow. It is missing {nodes}.", - "notCheckedAfterReason": "Could not check whether it can run this workflow." + "notCheckedAfterReason": "Could not check whether it can run this workflow.", + "start": "Start", + "retry": "Retry", + "startLabel": "Start {deployment}", + "retryLabel": "Retry starting {deployment}", + "startFailed": "{deployment} didn't start.", + "startFix": { + "noCredits": "Add credits, then retry.", + "tooManyRunning": "Stop another deployment, then retry.", + "notAllowed": "Ask a workspace owner to start it.", + "unavailable": "Start it on the Developer Platform for now.", + "failed": "Retry, or check it on the Developer Platform." + }, + "pickStopped": "{deployment} is stopped, so jobs won't run. Start it, or pick a ready deployment.", + "stoppedStartTooltip": "Running on {deployment}. It's stopped, so jobs won't run. Open this menu to start it." }, "selectionToolbox": { "executeButton": { diff --git a/src/platform/remoteConfig/serverFeatureFlag.ts b/src/platform/remoteConfig/serverFeatureFlag.ts index c3b106d452d..72a4f262dec 100644 --- a/src/platform/remoteConfig/serverFeatureFlag.ts +++ b/src/platform/remoteConfig/serverFeatureFlag.ts @@ -12,6 +12,7 @@ export enum ServerFeatureFlag { PARTNER_NODE_GOVERNANCE_ENABLED = 'partner_node_governance_enabled', PARTNER_RUN_GATE_ENABLED = 'partner_run_gate_enabled', PARTNER_NODE_TOKEN = 'partner_node_token', + DEPLOYMENT_START_ENABLED = 'deployment_start_enabled', USER_SECRETS_ENABLED = 'user_secrets_enabled', NODE_REPLACEMENTS = 'node_replacements', DEPLOY_TO_CLOUD = 'deploy_to_cloud', diff --git a/src/platform/remoteConfig/types.ts b/src/platform/remoteConfig/types.ts index 5abde97dfbc..9286ab474c5 100644 --- a/src/platform/remoteConfig/types.ts +++ b/src/platform/remoteConfig/types.ts @@ -114,6 +114,8 @@ export type RemoteConfig = Partial & { partner_run_gate_enabled?: boolean /** Local prompts carry a renewable partner-node token instead of the workspace token. */ partner_node_token?: boolean + /** Offers Start on a stopped deployment in the Run bar's deployment menu. */ + deployment_start_enabled?: boolean user_secrets_enabled?: boolean node_library_essentials_enabled?: boolean supports_model_type_tags?: boolean diff --git a/src/platform/workspace/api/__mocks__/workspaceApi.ts b/src/platform/workspace/api/__mocks__/workspaceApi.ts index 2afad2ee3ad..69a3d618fe7 100644 --- a/src/platform/workspace/api/__mocks__/workspaceApi.ts +++ b/src/platform/workspace/api/__mocks__/workspaceApi.ts @@ -31,6 +31,7 @@ export const workspaceApi = vi.mockObject( listDeployments: async () => ({ items: [], builds_visible: true }), pickDeployment: async () => {}, clearDeployment: async () => {}, + startDeployment: async () => {}, setDefaultDeployment: async () => {}, clearDefaultDeployment: async () => {}, getDeploymentCpuServer: async () => ({ cpu_server: 'none' }), diff --git a/src/platform/workspace/api/deploymentListingTimeouts.ts b/src/platform/workspace/api/deploymentListingTimeouts.ts index 62ec65308f0..35b1f0233a6 100644 --- a/src/platform/workspace/api/deploymentListingTimeouts.ts +++ b/src/platform/workspace/api/deploymentListingTimeouts.ts @@ -34,3 +34,6 @@ export const DEPLOYMENT_LISTING_EXTENSIONS_WAIT_MS = 5_000 /** Minimum gap between focus-triggered listing retries. */ export const DEPLOYMENT_LISTING_FOCUS_RETRY_MS = 60_000 + +/** How often the open menu refreshes the listing while a deployment starts. */ +export const DEPLOYMENT_START_POLL_MS = 5_000 diff --git a/src/platform/workspace/api/workspaceApi.ts b/src/platform/workspace/api/workspaceApi.ts index b2460c16b98..7351d3428c7 100644 --- a/src/platform/workspace/api/workspaceApi.ts +++ b/src/platform/workspace/api/workspaceApi.ts @@ -169,6 +169,23 @@ export const workspaceApi = { handleAxiosError(err, 'pickDeployment') } }, + async startDeployment( + workspaceId: WorkspaceId, + deploymentId: string + ): Promise { + const auth = await requestAuth() + try { + await workspaceApiClient.post( + ingestApiUrl( + `/workspaces/${workspaceId}/deployments/${deploymentId}/start` + ), + undefined, + auth + ) + } catch (err) { + handleAxiosError(err, 'startDeployment') + } + }, async clearDeployment( workspaceId: WorkspaceId, options: { follow?: 'workspace' } = {} diff --git a/src/platform/workspace/components/DeploymentSwitcher.test.ts b/src/platform/workspace/components/DeploymentSwitcher.test.ts index b7088049bff..67e744b2c57 100644 --- a/src/platform/workspace/components/DeploymentSwitcher.test.ts +++ b/src/platform/workspace/components/DeploymentSwitcher.test.ts @@ -23,7 +23,10 @@ import { useWorkflowService } from '@/platform/workflow/core/services/workflowSe import { useSettingStore } from '@/platform/settings/settingStore' import { takeLeavePromptSkip } from '@/platform/workflow/management/leavePrompt' import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore' -import { DEPLOYMENT_LISTING_BACKSTOP_MS } from '@/platform/workspace/api/deploymentListingTimeouts' +import { + DEPLOYMENT_LISTING_BACKSTOP_MS, + DEPLOYMENT_START_POLL_MS +} from '@/platform/workspace/api/deploymentListingTimeouts' import { WorkspaceApiError } from '@/platform/remote/ingest/ingestApiError' import { useDeploymentPickStore } from '@/platform/workspace/stores/deploymentPickStore' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' @@ -36,6 +39,7 @@ import DeploymentSwitcher from './DeploymentSwitcher.vue' const mockWorkspaceApi = vi.hoisted(() => ({ listDeployments: vi.fn(), pickDeployment: vi.fn(), + startDeployment: vi.fn(), clearDeployment: vi.fn(), setDefaultDeployment: vi.fn(), clearDefaultDeployment: vi.fn(), @@ -1628,3 +1632,163 @@ describe('DeploymentSwitcher', () => { }) }) }) + +describe('DeploymentSwitcher, starting a stopped deployment', () => { + const staging = listing.items[1] + + function withStaging(status: string): WorkspaceDeploymentList { + return { ...listing, items: [listing.items[0], { ...staging, status }] } + } + + function offerStart() { + vi.mocked(useFeatureFlags().flags).deploymentStartEnabled = true + } + + function stagingRow() { + return screen.getByTestId(`deployment-row-${D1}`) + } + + beforeEach(() => { + hoisted.rootGraph = undefined + sessionStorage.clear() + Object.assign(useTeamWorkspaceStore(), { workspaceId: 'ws-1' }) + Object.defineProperty(window, 'location', { + value: { reload: vi.fn(), origin: 'http://localhost' }, + writable: true, + configurable: true + }) + }) + + it('offers Start on a stopped row, and choosing it starts the deployment instead of switching to it', async () => { + offerStart() + mockWorkspaceApi.listDeployments.mockResolvedValue(withStaging('stopped')) + mockWorkspaceApi.startDeployment.mockReturnValue(new Promise(() => {})) + const user = renderSwitcher() + await openList(user) + + const start = screen.getByRole('menuitemradio', { + name: 'Start Studio Build · staging' + }) + expect(within(start).getByText('Start')).toBeVisible() + await user.click(start) + + expect(mockWorkspaceApi.startDeployment).toHaveBeenCalledWith('ws-1', D1) + expect(mockWorkspaceApi.pickDeployment).not.toHaveBeenCalled() + expect(screen.getByRole('menu')).toBeVisible() + expect(within(stagingRow()).getByText('Starting')).toBeVisible() + }) + + it('shows a started deployment as Starting, refreshes the open list every 5 s, and lets it be picked once ready', async () => { + offerStart() + let current = withStaging('stopped') + mockWorkspaceApi.listDeployments.mockImplementation(async () => current) + mockWorkspaceApi.startDeployment.mockImplementation(async () => { + current = withStaging('starting') + }) + mockWorkspaceApi.pickDeployment.mockReturnValue(new Promise(() => {})) + const user = renderSwitcher() + await openList(user) + + await user.click( + screen.getByRole('menuitemradio', { + name: 'Start Studio Build · staging' + }) + ) + await waitFor(() => + expect(within(stagingRow()).getByText('Starting')).toBeVisible() + ) + expect(stagingRow()).toHaveAttribute('aria-disabled', 'true') + + current = withStaging('ready') + await vi.advanceTimersByTimeAsync(DEPLOYMENT_START_POLL_MS) + await waitFor(() => + expect(within(stagingRow()).getByText('v1')).toBeVisible() + ) + expect(stagingRow()).not.toHaveAttribute('aria-disabled') + expect(mockWorkspaceApi.pickDeployment).not.toHaveBeenCalled() + + await user.click(stagingRow()) + expect(mockWorkspaceApi.pickDeployment).toHaveBeenCalledWith('ws-1', { + deployment_id: D1 + }) + }) + + it("says why a Start failed with the server's own message, and starts again on Retry", async () => { + offerStart() + mockWorkspaceApi.listDeployments.mockResolvedValue(withStaging('stopped')) + mockWorkspaceApi.startDeployment + .mockRejectedValueOnce( + new WorkspaceApiError('The workspace has no credits left.', 402) + ) + .mockReturnValueOnce(new Promise(() => {})) + const user = renderSwitcher() + await openList(user) + + await user.click( + screen.getByRole('menuitemradio', { + name: 'Start Studio Build · staging' + }) + ) + const problem = await screen.findByTestId('deployment-row-problem') + expect(problem).toHaveTextContent( + "Studio Build · staging didn't start. The workspace has no credits left." + ) + expect(problem).toHaveTextContent('Add credits, then retry.') + + await user.click( + screen.getByRole('menuitemradio', { + name: 'Retry starting Studio Build · staging' + }) + ) + expect(mockWorkspaceApi.startDeployment).toHaveBeenCalledTimes(2) + await waitFor(() => + expect(screen.queryByTestId('deployment-row-problem')).toBeNull() + ) + expect(within(stagingRow()).getByText('Starting')).toBeVisible() + }) + + it('tells a viewer the server will not let start it who can, and offers no Start or Retry', async () => { + offerStart() + mockWorkspaceApi.listDeployments.mockResolvedValue(withStaging('stopped')) + mockWorkspaceApi.startDeployment.mockRejectedValue( + new WorkspaceApiError('Only workspace owners can start deployments.', 403) + ) + const user = renderSwitcher() + await openList(user) + + await user.click( + screen.getByRole('menuitemradio', { + name: 'Start Studio Build · staging' + }) + ) + expect( + await screen.findByTestId('deployment-row-problem') + ).toHaveTextContent('Ask a workspace owner to start it.') + expect(within(stagingRow()).getByText('Stopped')).toBeVisible() + expect(stagingRow()).toHaveAttribute('aria-disabled', 'true') + + await user.click(stagingRow()) + expect(mockWorkspaceApi.startDeployment).toHaveBeenCalledTimes(1) + }) + + it('says jobs will not run on a stopped deployment this browser is on, on hover and at the top of the list', async () => { + offerStart() + mockWorkspaceApi.listDeployments.mockResolvedValue({ + ...withStaging('stopped'), + picked_deployment_id: D1, + pick_source: 'browser' + }) + const user = renderSwitcher() + const trigger = await screen.findByTestId('deployment-switcher-trigger') + + await user.hover(trigger) + expect(await screen.findByRole('tooltip')).toHaveTextContent( + "Running on Studio Build · staging. It's stopped, so jobs won't run. Open this menu to start it." + ) + await openList(user) + + expect(screen.getByTestId('deployment-switcher-notice')).toHaveTextContent( + "Studio Build · staging is stopped, so jobs won't run. Start it, or pick a ready deployment." + ) + }) +}) diff --git a/src/platform/workspace/components/DeploymentSwitcher.vue b/src/platform/workspace/components/DeploymentSwitcher.vue index a91a9cbcb02..460ce07a792 100644 --- a/src/platform/workspace/components/DeploymentSwitcher.vue +++ b/src/platform/workspace/components/DeploymentSwitcher.vue @@ -54,7 +54,7 @@