fix(composer): RUNON-STICKY a picked Orca Cloud stays picked when the project changes

Picking "Run on: Orca Cloud" then another project reset Run on to this computer.
useEphemeralVmRecipeOptions reloads the project's recipes on every repo change with
load(resetSelection=true), which cleared the selection to null (Orca Cloud is the same for every
project, unlike a project's own orca.yaml recipes).

- A project change now carries Orca Cloud: it stays selected while the new project's options load
  (no flash to Local) and after, whenever the new project offers it.
- Only when the new project can't use it does Run on fall back, and a line under Run on says why:
  the project lives on another machine (SSH / remote server / not loadable here), Orca Cloud didn't
  answer, or it isn't offered for this project. The next pick clears it.
- A project's own recipe still doesn't carry to another project.

Tests: 5 new cases in useEphemeralVmRecipeOptions.test.tsx; 4 of them fail on the old hook.
This commit is contained in:
Neil
2026-11-15 20:48:37 -08:00
parent bb8fc53fb8
commit dbef31ce68
12 changed files with 250 additions and 15 deletions
@@ -1,3 +1,4 @@
import type { OrcaCloudDropReason } from '@/hooks/useEphemeralVmRecipeOptions'
import { useState } from 'react'
import { defineFixture } from '../../component-fixtures/component-fixture'
import type { NewWorkspaceProjectOption } from '@/lib/workspace/creation/new-workspace-project-options'
@@ -113,9 +114,12 @@ const handoffCloudStart = (githubHandoff: 'waiting' | 'timed-out'): CloudStartVi
function ProjectAndHostPreview({
folderOnly = false,
orcaCloud,
githubHandoff
githubHandoff,
cloudDropped
}: {
folderOnly?: boolean
/** RUNON-STICKY: a picked Orca Cloud didn't carry over to this project. */
cloudDropped?: OrcaCloudDropReason
/** Back from GitHub's access page (REPO-ACCESS-REFRESH). */
githubHandoff?: 'waiting' | 'timed-out'
/** Offers Orca Cloud with this entitlement. */
@@ -155,6 +159,7 @@ function ProjectAndHostPreview({
selectedEphemeralVmRecipeId={recipe}
onEphemeralVmRecipeChange={setRecipe}
{...(orcaCloud ? { orcaCloudAccess: orcaCloud } : {})}
{...(cloudDropped ? { orcaCloudDropped: cloudDropped } : {})}
{...(githubHandoff ? { cloudStart: handoffCloudStart(githubHandoff) } : {})}
handleAddSshHost={() => {}}
handleAddRemoteServer={() => {}}
@@ -251,3 +256,13 @@ export const githubHandoffTimedOut = defineFixture({
...closed,
render: () => <ProjectAndHostPreview orcaCloud={entitled} githubHandoff="timed-out" />
})
// RUNON-STICKY: Orca Cloud was picked, then a project that can't run on it.
export const cloudDroppedElsewhere = defineFixture({
...closed,
render: () => <ProjectAndHostPreview orcaCloud={entitled} cloudDropped="elsewhere" />
})
export const cloudDroppedUnavailable = defineFixture({
...closed,
render: () => <ProjectAndHostPreview orcaCloud={entitled} cloudDropped="unavailable" />
})
@@ -1,4 +1,5 @@
import { OrcaCloudNeedsRepoLine } from './run-on/OrcaCloudNeedsRepoLine'
import { OrcaCloudDroppedLine } from './run-on/OrcaCloudDroppedLine'
import { GitHubHandoffLine } from './run-on/GitHubHandoffLine'
import { ORCA_CLOUD_NEEDS_REPO_ID } from './run-on/cloud-start-view'
import React, { useMemo } from 'react'
@@ -46,6 +47,7 @@ type NewWorkspaceComposerProjectSectionProps = Pick<
| 'selectedEphemeralVmRecipeId'
| 'ephemeralVmRecipeError'
| 'orcaCloudAvailability'
| 'orcaCloudDropped'
| 'cloudStart'
> & {
disabled?: boolean
@@ -98,6 +100,7 @@ export function NewWorkspaceComposerProjectSection({
handleSetLocation,
ephemeralVmRecipeError,
orcaCloudAvailability = 'unavailable',
orcaCloudDropped = null,
selectedRepoRequiresConnection,
selectedRepoConnectionId,
selectedRepoConnectInProgress,
@@ -303,6 +306,8 @@ export function NewWorkspaceComposerProjectSection({
<p className="whitespace-pre-line text-[11px] text-destructive">
{ephemeralVmRecipeError}
</p>
) : orcaCloudDropped ? (
<OrcaCloudDroppedLine reason={orcaCloudDropped} />
) : null}
</div>
) : null}
@@ -1,3 +1,4 @@
import type { OrcaCloudDropReason } from '@/hooks/useEphemeralVmRecipeOptions'
import type { CloudStartView } from './run-on/use-cloud-start-composer'
import type {
AgentPickerDraft,
@@ -79,6 +80,8 @@ export type NewWorkspaceComposerCardProps = {
ephemeralVmRecipeError?: string | null
/** Orca Cloud for the selected project, from main; drives the picker's sign-in/upsell row. */
orcaCloudAvailability?: OrcaCloudAvailability
/** RUNON-STICKY: a picked Orca Cloud didn't carry over to this project; Run on says why. */
orcaCloudDropped?: OrcaCloudDropReason | null
repoBackedSearchRepos?: readonly RepoOption[]
repoBackedSourcesDisabled?: boolean
allowSmartNameAddProject?: boolean
@@ -0,0 +1,36 @@
import React from 'react'
import { useTranslate } from '@/i18n/use-translate'
import type { OrcaCloudDropReason } from '@/hooks/useEphemeralVmRecipeOptions'
/**
* RUNON-STICKY: a picked Orca Cloud stays picked across project changes. Only when the newly picked
* project can't run on it does Run on fall back to this project's own target, and this line says why
* instead of the switch happening silently. It goes away with the next pick.
*/
export function OrcaCloudDroppedLine({
reason
}: {
reason: OrcaCloudDropReason
}): React.JSX.Element {
const t = useTranslate()
const text =
reason === 'elsewhere'
? t(
'components.newWorkspace.runOn.cloudDroppedElsewhere',
'Orca Cloud can’t run this project: it lives on another machine. Running it there instead.'
)
: reason === 'unreachable'
? t(
'components.newWorkspace.runOn.cloudDroppedUnreachable',
'Couldn’t reach Orca Cloud for this project, so Run on switched back. Pick Orca Cloud again to retry.'
)
: t(
'components.newWorkspace.runOn.cloudDroppedUnavailable',
'Orca Cloud isn’t available for this project, so Run on switched back.'
)
return (
<p role="status" data-orca-cloud-dropped={reason} className="text-[11px] text-muted-foreground">
{text}
</p>
)
}
@@ -8,7 +8,9 @@ import { ORCA_CLOUD_IMAGE_AGENTS } from '../../../../shared/hosted-sandbox/orca-
import type { EphemeralVmRecipeOption } from './new-workspace-composer-card-props'
vi.mock('@/store/index', () => ({ useAppStore: { getState: () => ({}) } }))
vi.mock('@/lib/agent-session/launch/inventory/host-chat-program', () => ({ agentChoicePending: () => false }))
vi.mock('@/lib/agent-session/launch/inventory/host-chat-program', () => ({
agentChoicePending: () => false
}))
// This desktop has aider and claude; the host offers exactly what it detected.
vi.mock('@/lib/agent-session/launch/inventory/host-chat-program-acquisition', () => ({
useAgentsOfferedForLaunch: (_workspace: unknown, detected: ReadonlySet<TuiAgent> | null) =>
@@ -14,6 +14,7 @@ export type ComposerCardSourceProps = Pick<
| 'selectedEphemeralVmRecipeId'
| 'ephemeralVmRecipeError'
| 'orcaCloudAvailability'
| 'orcaCloudDropped'
| 'name'
| 'branchNameOverride'
| 'parentWorktreeId'
@@ -39,6 +39,7 @@ export function buildComposerCardProps(state: ComposerModel) {
ephemeralVmRecipes,
ephemeralVmsEnabled,
orcaCloudAvailability,
orcaCloudDropped,
filteredLinkItems,
folderDetectedAgentIds,
folderSourceRepos,
@@ -163,6 +164,7 @@ export function buildComposerCardProps(state: ComposerModel) {
isProjectGroupTarget || !ephemeralVmsEnabled ? null : selectedEphemeralVmRecipeId,
onEphemeralVmRecipeChange: setSelectedEphemeralVmRecipeId,
orcaCloudAvailability,
orcaCloudDropped,
ephemeralVmRecipeError:
isProjectGroupTarget || !ephemeralVmsEnabled ? null : ephemeralVmRecipeError,
repoBackedSearchRepos: isProjectGroupTarget ? folderSourceRepos : undefined,
@@ -5,6 +5,7 @@ import type { Repo } from '../../../../shared/repo-types'
import type { SshConnectionState, SshConnectionStatus } from '../../../../shared/ssh-types'
import type { TuiAgent } from '../../../../shared/agent-launch/catalog/tui-agent'
import type { OrcaCloudAvailability, OrcaVmRecipe } from '../../../../shared/orca-yaml-hook-types'
import type { OrcaCloudDropReason } from '@/hooks/useEphemeralVmRecipeOptions'
import type { AgentStartupShell } from '../../../../shared/agent-launch/startup/tui-agent-startup-shell'
import type { ExecutionHostPlatformFact } from '@/runtime/hosts/platform/execution-host-platform-fact'
import type { NewWorkspaceProjectOption } from '@/lib/workspace/creation/new-workspace-project-options'
@@ -54,6 +55,8 @@ export type ComposerRuntimeTargetModel = {
ephemeralVmsEnabled: boolean
/** Orca Cloud for this project, from main; drives the picker's sign-in/upsell row. */
orcaCloudAvailability: OrcaCloudAvailability
/** RUNON-STICKY: why a picked Orca Cloud didn't carry over to the newly picked project. */
orcaCloudDropped: OrcaCloudDropReason | null
ephemeralVmRecipes: OrcaVmRecipe[]
selectedEphemeralVmRecipeId: string | null
setSelectedEphemeralVmRecipeId: (recipeId: string | null) => void
@@ -257,7 +257,8 @@ export function useComposerRuntimeTargetSelection(input: ComposerRuntimeTargetSe
setSelectedRecipeId: setSelectedEphemeralVmRecipeId,
error: ephemeralVmRecipeError,
offered: ephemeralVmsEnabled,
orcaCloud: orcaCloudAvailability
orcaCloud: orcaCloudAvailability,
orcaCloudDropped
} = useEphemeralVmRecipeOptions({
// Only probe enabled experiments or hidden features can raise setup errors.
customRecipesEnabled: settings?.experimentalEphemeralVms === true,
@@ -277,9 +278,7 @@ export function useComposerRuntimeTargetSelection(input: ComposerRuntimeTargetSe
)
: null
const selectedRepoConnectionId = selectedRepoSshGateInput?.connectionId ?? null
const selectedRepoSshState = selectedRepoConnectionId
? (sshConnectionStates.get(selectedRepoConnectionId) ?? null)
: null
const selectedRepoSshState = sshConnectionStates.get(selectedRepoConnectionId ?? '') ?? null
const { selectedRepoSshStatus, selectedRepoRequiresConnection, selectedRepoConnectInProgress } =
getSelectedRepoSshGate({
@@ -329,6 +328,7 @@ export function useComposerRuntimeTargetSelection(input: ComposerRuntimeTargetSe
selectedRecipeRepoConnectionId,
ephemeralVmsEnabled,
orcaCloudAvailability,
orcaCloudDropped,
ephemeralVmRecipes,
selectedEphemeralVmRecipeId,
setSelectedEphemeralVmRecipeId,
@@ -4,6 +4,7 @@ import { StrictMode, act } from 'react'
import { createRoot, type Root } from 'react-dom/client'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { useEphemeralVmRecipeOptions } from './useEphemeralVmRecipeOptions'
import { ORCA_CLOUD_RECIPE_ID } from '../../../shared/hosted-sandbox/orca-cloud-recipe-id'
import { useAppStore } from '@/store'
import { requestOrcaCloudSelectionAfterSignIn } from '@/lib/orca-cloud-select-after-sign-in'
@@ -63,20 +64,22 @@ function Harness({
initialRecipeId,
enabled = true,
customRecipesEnabled = true,
repoExecutionHostId = 'local'
repoExecutionHostId = 'local',
repoConnectionId = null
}: {
repoId: string
initialRecipeId?: string
enabled?: boolean
customRecipesEnabled?: boolean
repoExecutionHostId?: 'local' | `runtime:${string}`
repoConnectionId?: string | null
}): React.JSX.Element {
const state = useEphemeralVmRecipeOptions({
enabled,
customRecipesEnabled,
repoId,
repoIsGit: true,
repoConnectionId: null,
repoConnectionId,
repoExecutionHostId,
projectGroupTarget: false,
initialRecipeId
@@ -87,6 +90,17 @@ function Harness({
<span data-testid="recipes">{state.recipes.map((recipe) => recipe.id).join(',')}</span>
<span data-testid="selected">{state.selectedRecipeId ?? 'none'}</span>
<span data-testid="error">{state.error ?? 'none'}</span>
<span data-testid="dropped">{state.orcaCloudDropped ?? 'none'}</span>
<button
type="button"
data-testid="pick-cloud"
onClick={() => state.setSelectedRecipeId(ORCA_CLOUD_RECIPE_ID)}
/>
<button
type="button"
data-testid="pick-devbox"
onClick={() => state.setSelectedRecipeId('devbox')}
/>
</div>
)
}
@@ -297,4 +311,105 @@ describe('useEphemeralVmRecipeOptions', () => {
)
expect(container.querySelector('[data-testid="recipes"]')?.textContent).toBe('')
})
// RUNON-STICKY (Neil): picking Orca Cloud, then another project, reset Run on to this computer.
describe('a picked Orca Cloud across project changes', () => {
const CLOUD = {
id: ORCA_CLOUD_RECIPE_ID,
name: 'Orca Cloud',
provider: 'orca-cloud' as const,
create: 'orca-cloud create'
}
const withCloud = (ids: string[] = []): RecipeListResult => ({
...result(ids),
recipes: [CLOUD, ...ids.map((id) => ({ id, name: id, create: `create-${id}` }))],
orcaCloud: 'offered'
})
const text = (container: HTMLElement, id: string) =>
container.querySelector(`[data-testid="${id}"]`)?.textContent
const pick = async (container: HTMLElement, id: string) =>
act(async () =>
(container.querySelector(`[data-testid="${id}"]`) as HTMLButtonElement).click()
)
it('stays picked when the new project can use it, without flashing back to this computer', async () => {
const next = deferred<RecipeListResult>()
installApi(
vi
.fn()
.mockResolvedValueOnce(withCloud(['devbox']))
.mockReturnValueOnce(next.promise)
)
const { root, container } = await render(<Harness repoId="repo-1" />)
await vi.waitFor(() => expect(text(container, 'recipes')).toContain(ORCA_CLOUD_RECIPE_ID))
await pick(container, 'pick-cloud')
expect(text(container, 'selected')).toBe(ORCA_CLOUD_RECIPE_ID)
await act(async () => root.render(<Harness repoId="repo-2" />))
// While the new project's options load, Run on still reads Orca Cloud.
expect(text(container, 'selected')).toBe(ORCA_CLOUD_RECIPE_ID)
await act(async () => next.resolve(withCloud()))
expect(text(container, 'selected')).toBe(ORCA_CLOUD_RECIPE_ID)
expect(text(container, 'dropped')).toBe('none')
})
it('falls back only when the new project can’t use it, and says why', async () => {
installApi(
vi
.fn()
.mockResolvedValueOnce(withCloud())
.mockResolvedValueOnce({ ...result([]), orcaCloud: 'unavailable' })
)
const { root, container } = await render(<Harness repoId="repo-1" />)
await vi.waitFor(() => expect(text(container, 'recipes')).toContain(ORCA_CLOUD_RECIPE_ID))
await pick(container, 'pick-cloud')
await act(async () => root.render(<Harness repoId="repo-2" />))
await vi.waitFor(() => expect(text(container, 'selected')).toBe('none'))
expect(text(container, 'dropped')).toBe('unavailable')
// The next pick clears the reason.
await pick(container, 'pick-cloud')
expect(text(container, 'dropped')).toBe('none')
})
it('a project on another machine (SSH): falls back and says it lives elsewhere', async () => {
installApi(vi.fn().mockResolvedValueOnce(withCloud()))
const { root, container } = await render(<Harness repoId="repo-1" />)
await vi.waitFor(() => expect(text(container, 'recipes')).toContain(ORCA_CLOUD_RECIPE_ID))
await pick(container, 'pick-cloud')
await act(async () => root.render(<Harness repoId="repo-ssh" repoConnectionId="ssh-1" />))
expect(text(container, 'selected')).toBe('none')
expect(text(container, 'dropped')).toBe('elsewhere')
})
it('Orca Cloud not answering for the new project: falls back with unreachable', async () => {
installApi(
vi.fn().mockResolvedValueOnce(withCloud()).mockRejectedValueOnce(new Error('offline'))
)
const { root, container } = await render(
<Harness repoId="repo-1" customRecipesEnabled={false} />
)
await vi.waitFor(() => expect(text(container, 'recipes')).toContain(ORCA_CLOUD_RECIPE_ID))
await pick(container, 'pick-cloud')
await act(async () => root.render(<Harness repoId="repo-2" customRecipesEnabled={false} />))
await vi.waitFor(() => expect(text(container, 'dropped')).toBe('unreachable'))
expect(text(container, 'selected')).toBe('none')
})
it('a project’s own recipe still doesn’t carry to another project', async () => {
installApi(
vi
.fn()
.mockResolvedValueOnce(withCloud(['devbox']))
.mockResolvedValueOnce(withCloud(['devbox']))
)
const { root, container } = await render(<Harness repoId="repo-1" />)
await vi.waitFor(() => expect(text(container, 'recipes')).toContain('devbox'))
await pick(container, 'pick-devbox')
await act(async () => root.render(<Harness repoId="repo-2" />))
await vi.waitFor(() => expect(text(container, 'recipes')).toContain('devbox'))
expect(text(container, 'selected')).toBe('none')
expect(text(container, 'dropped')).toBe('none')
})
})
})
@@ -58,6 +58,13 @@ export function withOrcaCloudSetupRecipe(
return [ORCA_CLOUD_SETUP_RECIPE, ...recipes]
}
/**
* RUNON-STICKY: why a picked Orca Cloud didn't carry over to a newly picked project. `elsewhere`:
* the project lives on another machine (SSH or a remote server's own target) or is a project group;
* `unreachable`: Orca Cloud didn't answer; `unavailable`: it isn't offered for this project.
*/
export type OrcaCloudDropReason = 'elsewhere' | 'unreachable' | 'unavailable'
export function useEphemeralVmRecipeOptions(args: EphemeralVmRecipeOptionsArgs): {
recipes: OrcaVmRecipe[]
selectedRecipeId: string | null
@@ -67,9 +74,22 @@ export function useEphemeralVmRecipeOptions(args: EphemeralVmRecipeOptionsArgs):
offered: boolean
/** Orca Cloud for this target as main reports it; `unavailable` where recipe VMs can't run. */
orcaCloud: OrcaCloudAvailability
/** Set when a project change had to drop a picked Orca Cloud; cleared by the next pick. */
orcaCloudDropped: OrcaCloudDropReason | null
} {
const [recipes, setRecipes] = useState<OrcaVmRecipe[]>([])
const [selectedRecipeId, setSelectedRecipeId] = useState<string | null>(null)
const [selectedRecipeId, setSelectedRecipeIdState] = useState<string | null>(null)
const [orcaCloudDropped, setOrcaCloudDropped] = useState<OrcaCloudDropReason | null>(null)
// The pick as of the last render: a project change carries Orca Cloud over (RUNON-STICKY).
const selectedRef = useRef<string | null>(null)
// Declared before the load effect, so a project change's load sees the pick it replaces.
useEffect(() => {
selectedRef.current = selectedRecipeId
}, [selectedRecipeId])
const setSelectedRecipeId = useCallback((recipeId: string | null) => {
setOrcaCloudDropped(null)
setSelectedRecipeIdState(recipeId)
}, [])
// Failures stay coded until render so a language switch relocalizes them.
const [errors, setErrors] = useState<EphemeralVmFailure[]>([])
const [orcaCloud, setOrcaCloud] = useState<OrcaCloudAvailability>('unavailable')
@@ -90,12 +110,25 @@ export function useEphemeralVmRecipeOptions(args: EphemeralVmRecipeOptionsArgs):
const load = useCallback(
(resetSelection: boolean): void => {
const generation = ++requestGeneration.current
// RUNON-STICKY: Orca Cloud isn't tied to a project, so a project change keeps it picked while
// the new project's options load, and only drops it (saying why) when that project can't use it.
const carryCloud = resetSelection && selectedRef.current === ORCA_CLOUD_RECIPE_ID
if (resetSelection) {
setRecipes([])
setSelectedRecipeId(null)
setRecipes((current) =>
carryCloud ? current.filter((r) => r.id === ORCA_CLOUD_RECIPE_ID) : []
)
if (!carryCloud) {
setSelectedRecipeIdState(null)
}
setOrcaCloudDropped(null)
setErrors([])
}
if (!canLoad || !args.repoId) {
if (carryCloud && args.repoId) {
setRecipes([])
setSelectedRecipeIdState(null)
setOrcaCloudDropped(args.enabled === false ? 'unavailable' : 'elsewhere')
}
return
}
const repoId = args.repoId
@@ -128,8 +161,20 @@ export function useEphemeralVmRecipeOptions(args: EphemeralVmRecipeOptionsArgs):
// says what's missing instead of the pick silently falling back to this computer.
const keeps = (recipeId: string): boolean =>
nextRecipes.some((recipe) => recipe.id === recipeId)
setSelectedRecipeId((current) => {
if (carryCloud && !keeps(ORCA_CLOUD_RECIPE_ID)) {
setOrcaCloudDropped(
result.orcaCloud === 'unreachable'
? 'unreachable'
: remoteServer
? 'elsewhere'
: 'unavailable'
)
}
setSelectedRecipeIdState((current) => {
if (resetSelection) {
if (carryCloud && keeps(ORCA_CLOUD_RECIPE_ID)) {
return ORCA_CLOUD_RECIPE_ID
}
return args.initialRecipeId && keeps(args.initialRecipeId)
? args.initialRecipeId
: null
@@ -166,7 +211,10 @@ export function useEphemeralVmRecipeOptions(args: EphemeralVmRecipeOptionsArgs):
return
}
setRecipes([])
setSelectedRecipeId(null)
if (carryCloud) {
setOrcaCloudDropped('unreachable')
}
setSelectedRecipeIdState(null)
setErrors(
args.customRecipesEnabled
? [{ error: cause instanceof Error ? cause.message : String(cause) }]
@@ -176,6 +224,7 @@ export function useEphemeralVmRecipeOptions(args: EphemeralVmRecipeOptionsArgs):
},
[
args.customRecipesEnabled,
args.enabled,
args.initialRecipeId,
args.repoId,
args.repoIsGit,
@@ -224,6 +273,7 @@ export function useEphemeralVmRecipeOptions(args: EphemeralVmRecipeOptionsArgs):
setSelectedRecipeId,
error,
offered: (args.customRecipesEnabled && args.repoIsGit) || recipes.length > 0,
orcaCloud: canLoad ? orcaCloud : 'unavailable'
orcaCloud: canLoad ? orcaCloud : 'unavailable',
orcaCloudDropped
}
}
+4 -1
View File
@@ -23690,7 +23690,10 @@
},
"runOn": {
"thisComputer": "This computer",
"orcaCloud": "Orca Cloud"
"orcaCloud": "Orca Cloud",
"cloudDroppedElsewhere": "Orca Cloud can’t run this project: it lives on another machine. Running it there instead.",
"cloudDroppedUnreachable": "Couldn’t reach Orca Cloud for this project, so Run on switched back. Pick Orca Cloud again to retry.",
"cloudDroppedUnavailable": "Orca Cloud isn’t available for this project, so Run on switched back."
},
"cloudHours": {
"trialChip_one": "Trial · {{hours}} sandbox hour left",