fix(cloud): CLOUD-HELD-SURFACE a VM create's route is decided at submit, not taken from the agent menu (which has no VM host to ask and always says terminal)

This commit is contained in:
Neil
2026-11-13 06:39:52 -08:00
parent 7a55601415
commit 5fa069bc05
3 changed files with 180 additions and 25 deletions
@@ -0,0 +1,108 @@
// CLOUD-HELD-SURFACE (END-PASS n49): the real composer hands its create the agent menu's choice.
// With Orca Cloud selected the menu has no host to ask, so that choice says "terminal" whatever the
// person prefers (Settings › Chat UI). A VM create's route is decided here unless a surface was picked.
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { STRUCTURED_AGENT_SESSION_RUNTIME_CAPABILITY } from '../../../../shared/agent-session/agent-session-runtime-capabilities'
import type { AgentLaunchRouteStore } from '@/lib/agent-session/launch/routing/agent-launch-route-input'
import type { AgentLaunchChoice } from '@/lib/agent-session/launch/routing/agent-menu-selection'
import { composerCreateLaunchRoute } from './composer-create-launch-route'
vi.mock('@/runtime/hosts/preflight/local-preflight-context', () => ({
getLocalProjectExecutionRuntimeContext: () => undefined,
getLocalRepoProjectExecutionRuntimeContext: () => undefined
}))
vi.mock('@/app-shell/platform/web-client-location', () => ({ isWebClientLocation: () => false }))
vi.mock('@/runtime/hosts/capabilities/local-runtime-capabilities', () => ({
readLocalRuntimeCapabilitiesOrUnknown: () => [STRUCTURED_AGENT_SESSION_RUNTIME_CAPABILITY],
awaitLocalRuntimeCapabilities: async () => undefined
}))
vi.mock('@/lib/agent-session/launch/continuation/structured-agent-launch-settlement', () => ({}))
// What Settings › Chat UI › "Turn on" writes, with Claude set to Chat.
const CHAT_UI_ON = {
agentDefaultSurface: 'chat',
nativeChatProviders: { claude: true },
agentCmdOverrides: {},
agentDefaultArgs: {},
agentDefaultEnv: {}
}
const store = (settings: Record<string, unknown>): AgentLaunchRouteStore =>
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: a route store with only the settings the route reads
({ settings }) as unknown as AgentLaunchRouteStore
// The agent menu with no host to ask (agentRows null for a VM create): answer 'no-chats'.
const MENU_NO_HOST: AgentLaunchChoice = {
agent: 'claude',
route: 'terminal-tui',
executionHostId: 'local'
}
const create = (
vmRecipeId: string | undefined,
launchChoice: AgentLaunchChoice | undefined = MENU_NO_HOST
) => ({
agent: 'claude' as const,
launchChoice,
vmRecipeId,
workspace: { kind: 'git-worktree' as const, repoId: 'hello-world' },
prompt: '',
promptDelivery: 'auto-submit' as const
})
let warn: ReturnType<typeof vi.spyOn>
beforeEach(() => {
warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined)
})
afterEach(() => {
warn.mockRestore()
})
describe('composerCreateLaunchRoute', () => {
it('Orca Cloud with Chat UI on: a chat, even though the menu said terminal', () => {
expect(composerCreateLaunchRoute(store(CHAT_UI_ON), create('cloud'))).toBe(
'structured-native-chat'
)
})
it('Orca Cloud with Chat UI off: a terminal', () => {
expect(
composerCreateLaunchRoute(
store({ ...CHAT_UI_ON, agentDefaultSurface: 'terminal', nativeChatProviders: {} }),
create('cloud')
)
).toBe('terminal-tui')
})
it('a surface the person picked for a VM create is kept', () => {
const picked: AgentLaunchChoice = { ...MENU_NO_HOST, requestedSurface: 'terminal' }
expect(composerCreateLaunchRoute(store(CHAT_UI_ON), create('cloud', picked))).toBe(
'terminal-tui'
)
})
it('another VM recipe (no image list): a terminal, and the downgrade is logged', () => {
expect(composerCreateLaunchRoute(store(CHAT_UI_ON), create('custom-vm'))).toBe('terminal-tui')
expect(warn).toHaveBeenCalledWith(
expect.stringContaining(
'[agent-launch-route] claude opens terminal-tui: runtime-capability-unknown'
)
)
})
it('a create on an existing host keeps the menu choice (it asked that host)', () => {
const local: AgentLaunchChoice = {
agent: 'claude',
route: 'structured-native-chat',
executionHostId: 'local'
}
expect(composerCreateLaunchRoute(store(CHAT_UI_ON), create(undefined, local))).toBe(
'structured-native-chat'
)
expect(composerCreateLaunchRoute(store(CHAT_UI_ON), create(undefined))).toBe('terminal-tui')
})
it('no agent: a terminal', () => {
expect(composerCreateLaunchRoute(store(CHAT_UI_ON), { ...create('cloud'), agent: null })).toBe(
'terminal-tui'
)
})
})
@@ -0,0 +1,59 @@
import { resolveAgentSessionLaunchRoute } from '@/lib/agent-session/launch/routing/agent-session-launch-plan'
import type { AgentLaunchChoice } from '@/lib/agent-session/launch/routing/agent-menu-selection'
import type {
AgentLaunchRouteArgs,
AgentLaunchRouteStore,
ProspectiveWorkspace
} from '@/lib/agent-session/launch/routing/agent-launch-route-input'
import type { AgentLaunchRoute } from '@/lib/agent-session/launch/routing/agent-launch-routing'
import { ORCA_CLOUD_PENDING_HOST_CAPABILITIES } from '@/lib/orca-cloud/orca-cloud-pending-host-capabilities'
import { ORCA_CLOUD_RECIPE_ID } from '../../../../shared/hosted-sandbox/orca-cloud-recipe-id'
import type { TuiAgent } from '../../../../shared/agent-launch/catalog/tui-agent'
/** The pending VM's host until the create pairs it. */
const PENDING_VM_HOST_ID = 'runtime:pending-ephemeral-vm'
/**
* The composer create's chat-or-terminal route, stored on the request and never re-derived.
* CLOUD-HELD-SURFACE: for a VM create the agent menu has no host to ask (the VM doesn't exist yet),
* so its choice says "terminal" whatever the person prefers. Unless the person picked a surface, a
* VM create's route is decided here instead; an Orca Cloud VM's image capabilities stand in for the
* unverified pending host.
*/
export function composerCreateLaunchRoute(
store: AgentLaunchRouteStore,
args: {
agent: TuiAgent | null
launchChoice: AgentLaunchChoice | undefined
/** The VM recipe this create provisions, when it provisions one. */
vmRecipeId: string | undefined
workspace: ProspectiveWorkspace
prompt: string
promptDelivery: AgentLaunchRouteArgs['promptDelivery']
}
): AgentLaunchRoute {
const { agent, launchChoice, vmRecipeId } = args
if (!agent) {
return 'terminal-tui'
}
const menuDecides = vmRecipeId === undefined || launchChoice?.requestedSurface !== undefined
if (menuDecides && launchChoice) {
return launchChoice.route
}
return resolveAgentSessionLaunchRoute(
store,
{
agent,
workspace: {
...args.workspace,
...(vmRecipeId !== undefined ? { executionHostId: PENDING_VM_HOST_ID } : {})
},
prompt: args.prompt,
promptDelivery: args.promptDelivery,
...(vmRecipeId === ORCA_CLOUD_RECIPE_ID
? { pendingHostCapabilities: ORCA_CLOUD_PENDING_HOST_CAPABILITIES }
: {})
},
{ reportDowngrade: true }
)
}
@@ -13,11 +13,10 @@ import { translate } from '@/i18n/i18n'
import { prepareQuickComposerStartup } from './quick-startup-plan'
import { buildQuickCreationRequest, type QuickSubmitOptions } from './quick-creation-request'
import type { PendingSmartGitHubSubmitResolution } from './source-selection-decisions'
import { resolveAgentSessionLaunchRoute } from '@/lib/agent-session/launch/routing/agent-session-launch-plan'
import { composerCreateLaunchRoute } from './composer-create-launch-route'
import { ORCA_CLOUD_RECIPE_ID } from '../../../../shared/hosted-sandbox/orca-cloud-recipe-id'
import { parentWorktreeForRunOn } from '@/components/new-workspace/run-on/cloud-advanced-options'
import { reportCloudStartAgentCoverage } from '@/lib/orca-cloud/cloud-first-start-agent-coverage'
import { ORCA_CLOUD_PENDING_HOST_CAPABILITIES } from '@/lib/orca-cloud/orca-cloud-pending-host-capabilities'
export function useQuickCreationExecution(input: QuickCreationExecutionInput) {
const {
@@ -139,29 +138,18 @@ export function useQuickCreationExecution(input: QuickCreationExecutionInput) {
const promptDelivery = quickDraftPrompt ? 'draft' : 'auto-submit'
// Why: the verdict is persisted on the request as data and re-entered once the worktree exists.
const agentLaunchRoute = !agent
? 'terminal-tui'
: (options?.launchChoice?.route ??
resolveAgentSessionLaunchRoute(
useAppStore.getState(),
{
agent,
workspace: {
kind: selectedRepoIsGit ? 'git-worktree' : 'folder',
repoId,
executionHostId: ephemeralVmRecipe
? 'runtime:pending-ephemeral-vm'
: (workspaceRunContext?.hostId ?? selectedRepoExecutionHostId ?? undefined)
},
prompt: quickDraftPrompt ?? quickPrompt,
promptDelivery,
// CLOUD-HELD-SURFACE: the VM doesn't exist yet; its image's capabilities stand in.
...(ephemeralVmRecipe?.recipeId === ORCA_CLOUD_RECIPE_ID
? { pendingHostCapabilities: ORCA_CLOUD_PENDING_HOST_CAPABILITIES }
: {})
},
{ reportDowngrade: true }
))
const agentLaunchRoute = composerCreateLaunchRoute(useAppStore.getState(), {
agent,
launchChoice: options?.launchChoice,
vmRecipeId: ephemeralVmRecipe?.recipeId,
workspace: {
kind: selectedRepoIsGit ? 'git-worktree' : 'folder',
repoId,
executionHostId: workspaceRunContext?.hostId ?? selectedRepoExecutionHostId ?? undefined
},
prompt: quickDraftPrompt ?? quickPrompt,
promptDelivery
})
const structuredLaunch = agentLaunchRoute === 'structured-native-chat'
const quickStartup = await prepareQuickComposerStartup({