Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/composables/__mocks__/useFeatureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const defaultFlags: FeatureFlags = {
partnerNodeGovernanceEnabled: false,
partnerRunGateEnabled: false,
partnerNodeTokenEnabled: false,
deploymentStartEnabled: false,
userSecretsEnabled: false,
nodeReplacementsEnabled: false,
deployToCloud: false,
Expand Down
6 changes: 6 additions & 0 deletions src/composables/useFeatureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ export function useFeatureFlags() {
true
)
},
get deploymentStartEnabled() {
return resolveStrictBooleanFlag(
ServerFeatureFlag.DEPLOYMENT_START_ENABLED,
remoteConfig.value.deployment_start_enabled
)
},
get partnerNodeTokenEnabled() {
return resolveStrictBooleanFlag(
ServerFeatureFlag.PARTNER_NODE_TOKEN,
Expand Down
22 changes: 20 additions & 2 deletions src/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -4165,10 +4165,28 @@
"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."
},
"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}",
"startOnPlatformLabel": "Start {deployment} on the Developer Platform",
"retryLabel": "Retry starting {deployment}",
"startFailed": "{deployment} didn't start.",
"startFix": {
"noCredits": "Add credits, then retry.",
"tooManyRunning": "Stop another deployment, then retry.",
"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.",
"pickFailed": "{deployment} failed, so jobs won't run. Start it again, or pick a ready deployment.",
"stoppedStartTooltip": "Running on {deployment}. It's stopped, so jobs won't run. Open this menu to start it.",
"failedStartTooltip": "Running on {deployment}. It failed, so jobs won't run. Open this menu to start it again."
},
"selectionToolbox": {
"executeButton": {
Expand Down
1 change: 1 addition & 0 deletions src/platform/remoteConfig/serverFeatureFlag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions src/platform/remoteConfig/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ export type RemoteConfig = Partial<GetFeaturesResponses[200]> & {
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
Expand Down
1 change: 1 addition & 0 deletions src/platform/workspace/api/__mocks__/workspaceApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const workspaceApi = vi.mockObject<typeof realWorkspaceApi>(
listDeployments: async () => ({ items: [], builds_visible: true }),
pickDeployment: async () => {},
clearDeployment: async () => {},
startDeployment: async () => ({ deployment_id: '', status: 'starting' }),
setDefaultDeployment: async () => {},
clearDefaultDeployment: async () => {},
getDeploymentCpuServer: async () => ({ cpu_server: 'none' }),
Expand Down
6 changes: 6 additions & 0 deletions src/platform/workspace/api/deploymentListingTimeouts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ 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 long a Start request may take once sent. */
export const DEPLOYMENT_START_TIMEOUT_MS = 30_000

/** How often the open menu refreshes the listing while a deployment starts. */
export const DEPLOYMENT_START_POLL_MS = 5_000
51 changes: 49 additions & 2 deletions src/platform/workspace/api/workspaceApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,15 @@ describe('workspaceApi', () => {
const data = { items: [], builds_visible: true }
mockAxiosInstance.get.mockResolvedValue({ data })

const result = await workspaceApi.listDeployments('ws-1')
const result = await workspaceApi.listDeployments('ws-1', [])

expect(mockAxiosInstance.get).toHaveBeenCalledWith(
'/api/workspaces/ws-1/deployments',
{ headers: AUTH_HEADER, timeout: 30_000, __skipStatusRetry: true }
expect.objectContaining({
headers: AUTH_HEADER,
timeout: 30_000,
__skipStatusRetry: true
})
)
expect(result).toEqual(data)
})
Expand Down Expand Up @@ -498,6 +502,49 @@ describe('workspaceApi', () => {
)
})

it('startDeployment() sends POST /workspaces/:id/deployments/:deployment/start with no body and a 30 second timeout', async () => {
const data = { deployment_id: 'dep-1/x', status: 'queued' }
mockAxiosInstance.post.mockResolvedValue({ data })

const result = await workspaceApi.startDeployment('ws-1', 'dep-1/x')

expect(mockAxiosInstance.post).toHaveBeenCalledWith(
'/api/workspaces/ws-1/deployments/dep-1%2Fx/start',
undefined,
{ headers: AUTH_HEADER, timeout: 30_000 }
)
expect(result).toEqual(data)
})

it('startDeployment() rejects an answer that does not say the status', async () => {
mockAxiosInstance.post.mockResolvedValue({
data: { deployment_id: 'dep-1' }
})

await expect(
workspaceApi.startDeployment('ws-1', 'dep-1')
).rejects.toThrow()
})

it('startDeployment() turns a refusal into a WorkspaceApiError with its code and message', async () => {
mockAxiosInstance.post.mockRejectedValue(
axiosRejection(429, {
code: 'CONCURRENCY_LIMIT',
message: 'Three deployments are already running.'
})
)

await expect(
workspaceApi.startDeployment('ws-1', 'dep-1')
).rejects.toMatchObject({
name: 'WorkspaceApiError',
status: 429,
code: 'CONCURRENCY_LIMIT',
message: 'Three deployments are already running.',
operation: 'startDeployment'
})
})

it('does not dispatch a canceled deployment selection when authorization finishes late', async () => {
let finishAuth!: (headers: typeof AUTH_HEADER) => void
const pendingAuth = new Promise<typeof AUTH_HEADER>((resolve) => {
Expand Down
30 changes: 28 additions & 2 deletions src/platform/workspace/api/workspaceApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
PendingInvite,
PickWorkspaceDeploymentRequest,
ReleaseUnsupportedPacks,
StartWorkspaceDeploymentResult,
UpdateWorkspaceRequest,
WorkspaceDeployment,
WorkspaceDeploymentCpuServer,
Expand All @@ -23,9 +24,13 @@ import type {
import {
zDeploymentCompatibility,
zReleaseUnsupportedPacks,
zStartWorkspaceDeploymentResult,
zWorkspaceDeploymentCpuServer
} from '@comfyorg/ingest-types/zod'
import { DEPLOYMENT_LISTING_TIMEOUT_MS } from './deploymentListingTimeouts'
import {
DEPLOYMENT_LISTING_TIMEOUT_MS,
DEPLOYMENT_START_TIMEOUT_MS
} from './deploymentListingTimeouts'
import type {
WorkspaceId,
WorkspaceInviteId
Expand Down Expand Up @@ -135,14 +140,17 @@ export const workspaceApi = {
}
},
async listDeployments(
workspaceId: WorkspaceId
workspaceId: WorkspaceId,
startedDeploymentIds: readonly string[]
): Promise<WorkspaceDeploymentList> {
const auth = await requestAuth()
try {
const response = await workspaceApiClient.get<WorkspaceDeploymentList>(
ingestApiUrl(`/workspaces/${workspaceId}/deployments`),
{
...auth,
params: { started_deployment_id: startedDeploymentIds },
paramsSerializer: { indexes: null },
timeout: DEPLOYMENT_LISTING_TIMEOUT_MS,
__skipStatusRetry: true
}
Expand All @@ -169,6 +177,24 @@ export const workspaceApi = {
handleAxiosError(err, 'pickDeployment')
}
},
async startDeployment(
workspaceId: WorkspaceId,
deploymentId: string
): Promise<StartWorkspaceDeploymentResult> {
const auth = await requestAuth()
try {
const response = await workspaceApiClient.post<unknown>(
ingestApiUrl(
`/workspaces/${workspaceId}/deployments/${encodeURIComponent(deploymentId)}/start`
),
undefined,
{ ...auth, timeout: DEPLOYMENT_START_TIMEOUT_MS }
)
return zStartWorkspaceDeploymentResult.parse(response.data)
} catch (err) {
handleAxiosError(err, 'startDeployment')
}
},
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
async clearDeployment(
workspaceId: WorkspaceId,
options: { follow?: 'workspace' } = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,33 @@ describe('workspaceApi on the web session', () => {
it('sends the deployment listing once, leaving retries to its boot loop', async () => {
const send = provideSessionSending(unavailable())

await expect(workspaceApi.listDeployments('ws-1')).rejects.toMatchObject({
await expect(
workspaceApi.listDeployments('ws-1', [])
).rejects.toMatchObject({
status: 503
})
expect(send).toHaveBeenCalledTimes(1)
})

it.for([
{ started: [], url: '/api/workspaces/ws-1/deployments' },
{
started: ['dep-1', 'dep-2'],
url: '/api/workspaces/ws-1/deployments?started_deployment_id=dep-1&started_deployment_id=dep-2'
}
])(
'asks for $url, naming each deployment this browser started',
async ({ started, url }) => {
const send = provideSessionSending(
new Response('{"items":[],"builds_visible":true}', { status: 200 })
)

await workspaceApi.listDeployments('ws-1', started)

expect(send.mock.calls.map(([sentUrl]) => sentUrl)).toEqual([url])
}
)

it('does not retry a write that got a 503', async () => {
const send = provideSessionSending(unavailable())

Expand Down
Loading
Loading