fix(cloud): RA-11 Restart with no session to resume starts a new conversation on Orca Cloud

design-squad's state 2 promises 'Starts a new conversation.' when there is nothing to resume, but the
account-restart path returned null for Claude without a session (Restart did nothing). On an Orca
Cloud pane it now starts Claude fresh (same builder Codex already used, generalised), after the
session-env refresh. Off Orca Cloud nothing changes. Tests cover resume, fresh, and off-cloud.
This commit is contained in:
Neil
2026-11-10 19:10:26 -08:00
parent c197c3de0b
commit decb280b01
3 changed files with 82 additions and 8 deletions
@@ -18,6 +18,11 @@ let projectRuntimeContext: ProjectExecutionRuntimeResolution | undefined
vi.mock('@/lib/agent-session/resume/agent-resume-launch-target', { spy: true })
const cloud = vi.hoisted(() => ({ on: false }))
vi.mock('@/lib/orca-cloud/orca-cloud-environment-id', () => ({
isOrcaCloudEnvironmentId: () => cloud.on
}))
vi.mock('@/lib/local-preflight-context', async (importOriginal) => ({
...(await importOriginal<typeof localPreflightContext>()),
getLocalProjectExecutionRuntimeContext: () => projectRuntimeContext
@@ -186,3 +191,55 @@ describe('buildPaneAccountRestartStartup for Claude', () => {
}
})
})
// RA-11: Restart on an Orca Cloud pane refreshes the shell's session env, and a Claude pane with no
// session to resume starts a new conversation instead of doing nothing.
describe('buildPaneAccountRestartStartup on Orca Cloud', () => {
const pane = { tabId: TAB_ID, leafId: LEAF_ID, worktreeId: WORKTREE_ID }
const REFRESH = 'eval "$(orca-env 2>/dev/null)"; '
beforeEach(() => {
cloud.on = true
projectRuntimeContext = undefined
useAppStore.setState({
settings: getDefaultSettings('/home/dev'),
tabsByWorktree: {},
worktreesByRepo: {},
terminalLayoutsByTabId: {
[TAB_ID]: {
root: { type: 'leaf', leafId: LEAF_ID },
activeLeafId: LEAF_ID,
expandedLeafId: null,
ptyIdsByLeafId: { [LEAF_ID]: 'remote:env-cloud@@term_1' }
}
}
})
})
it('resume: refreshes the session env, then resumes the pane’s own session', () => {
seedAgentStatus({
agentType: 'claude',
providerSession: { key: 'session_id', id: SESSION_ID }
})
const startup = buildPaneAccountRestartStartup('claude', pane)
expect(startup?.command.startsWith(REFRESH)).toBe(true)
expect(startup?.command).toContain(`'--resume' '${SESSION_ID}'`)
})
it('fresh: with no session to resume it starts a new Claude conversation (after the refresh)', () => {
seedAgentStatus({ agentType: 'claude' })
const startup = buildPaneAccountRestartStartup('claude', pane)
expect(startup).toMatchObject({ launchAgent: 'claude', startupCommandDelivery: 'shell-ready' })
expect(startup?.command.startsWith(REFRESH)).toBe(true)
expect(startup?.command).not.toContain('--resume')
expect(startup?.command).toMatch(/claude/)
})
it('off Orca Cloud a Claude pane with no session still has no restart, and nothing is prefixed', () => {
cloud.on = false
seedAgentStatus({ agentType: 'claude' })
expect(buildPaneAccountRestartStartup('claude', pane)).toBeNull()
seedAgentStatus({ agentType: 'codex' })
expect(buildPaneAccountRestartStartup('codex', pane)?.command.startsWith(REFRESH)).toBe(false)
})
})
@@ -24,7 +24,10 @@ import { resolveResumeLaunchRecipe } from '../../../../../shared/agent-launch/ch
import type { AccountRestartAgent } from '@/store/terminals/terminal-contracts'
import type { ProjectExecutionRuntimeResolution } from '../../../../../shared/execution-host/project-execution-runtime'
import { resolveAgentLaunchCommand } from '../../../../../shared/agent-launch/startup/tui-agent-launch-command'
import { withOrcaCloudSessionEnv } from '@/lib/orca-cloud/cloud-restart-session-env'
import {
isOrcaCloudPane,
withOrcaCloudSessionEnv
} from '@/lib/orca-cloud/cloud-restart-session-env'
import { resolveStartupShell } from '../../../../../shared/agent-launch/startup/tui-agent-startup-shell'
export type AgentAccountRestartStartup = {
@@ -132,13 +135,22 @@ export function buildPaneAccountRestartStartup(
) {
return null
}
const startup = resume ?? (agent === 'codex' ? buildCodexAccountRestartStartup(args) : null)
// RA-11: on Orca Cloud a Claude pane with no session to resume starts a new conversation.
const fresh = agent === 'codex' || isOrcaCloudPane(args)
const startup = resume ?? (fresh ? buildFreshAccountRestartStartup(agent, args) : null)
// Orca Cloud: refresh the shell's session env first, so a renewed account reaches the agent.
return startup ? withOrcaCloudSessionEnv(startup, args) : null
}
export function buildCodexAccountRestartStartup(
args: AccountRestartTarget
): AgentAccountRestartStartup {
return buildFreshAccountRestartStartup('codex', args)
}
function buildFreshAccountRestartStartup(
agent: AccountRestartAgent,
args: AccountRestartTarget
): AgentAccountRestartStartup {
const state = useAppStore.getState()
const target = resolveAccountRestartLaunchTarget(
@@ -147,7 +159,7 @@ export function buildCodexAccountRestartStartup(
getLocalProjectExecutionRuntimeContext(state, args.worktreeId)
)
const command = resolveAgentLaunchCommand({
agent: 'codex',
agent,
cmdOverrides: state.settings?.agentCmdOverrides ?? {},
platform: target.platform,
agentHostPlatform: target.agentHostPlatform,
@@ -159,7 +171,7 @@ export function buildCodexAccountRestartStartup(
return {
command: command.command,
startupCommandDelivery: 'shell-ready',
launchAgent: 'codex'
launchAgent: agent
}
}
@@ -9,14 +9,19 @@ import { isOrcaCloudEnvironmentId } from './orca-cloud-environment-id'
/** The prefix that refreshes a cloud shell's session env before the command; quiet off-cloud. */
export const ORCA_CLOUD_SESSION_ENV_REFRESH = 'eval "$(orca-env 2>/dev/null)"; '
/** True when this pane's terminal runs on an Orca Cloud sandbox. */
export function isOrcaCloudPane(pane: { tabId: string; leafId: string }): boolean {
const ptyId =
useAppStore.getState().terminalLayoutsByTabId[pane.tabId]?.ptyIdsByLeafId?.[pane.leafId] ?? null
const environmentId = ptyId ? parseRemoteRuntimePtyId(ptyId)?.environmentId : null
return Boolean(environmentId && isOrcaCloudEnvironmentId(environmentId))
}
export function withOrcaCloudSessionEnv<T extends { command: string }>(
startup: T,
pane: { tabId: string; leafId: string }
): T {
const ptyId =
useAppStore.getState().terminalLayoutsByTabId[pane.tabId]?.ptyIdsByLeafId?.[pane.leafId] ?? null
const environmentId = ptyId ? parseRemoteRuntimePtyId(ptyId)?.environmentId : null
if (!environmentId || !isOrcaCloudEnvironmentId(environmentId)) {
if (!isOrcaCloudPane(pane)) {
return startup
}
return startup.command.startsWith(ORCA_CLOUD_SESSION_ENV_REFRESH)