mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 19:07:41 +00:00
Merge remote-tracking branch 'private/cloud/ra11-running-strip' into cloud/pc3b-not-set-up-hold
# Conflicts: # src/renderer/src/i18n/locales/en.json
This commit is contained in:
@@ -185,7 +185,14 @@ export const runningRestarting = fixture({
|
||||
})
|
||||
/** RA-11: nothing relaunched in time. */
|
||||
export const runningRestartFailed = fixture({
|
||||
restart: { phase: 'failed', agent: 'claude', resumable: true, ptyId: 'p', launchedAt: null }
|
||||
restart: {
|
||||
phase: 'failed',
|
||||
agent: 'claude',
|
||||
resumable: true,
|
||||
ptyId: 'p',
|
||||
launchedAt: null,
|
||||
failure: 'hostUnresponsive'
|
||||
}
|
||||
})
|
||||
|
||||
/** PC-3b: the launch holds; Set up once runs the one-time Orca Cloud setup in the pane. */
|
||||
|
||||
@@ -295,10 +295,11 @@ export function CloudAgentSignInStrip({
|
||||
</DropdownMenu>
|
||||
) : null}
|
||||
{/* Renew and Restart are the whole action and the strip leaves on its own; Escape still cancels. */}
|
||||
{!model.dismiss &&
|
||||
(model.status === 'done' ||
|
||||
primary?.action.kind === 'renew' ||
|
||||
primary?.action.kind === 'restart') ? null : (
|
||||
{model.noClose ||
|
||||
(!model.dismiss &&
|
||||
(model.status === 'done' ||
|
||||
primary?.action.kind === 'renew' ||
|
||||
primary?.action.kind === 'restart')) ? null : (
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
|
||||
@@ -37,6 +37,7 @@ import {
|
||||
cloudStripWidth,
|
||||
type CloudStripActions
|
||||
} from './CloudAgentSignInStrip'
|
||||
import { watchCloudAgentRestartPane } from '@/lib/orca-cloud/cloud-agent-restart-pane-watch'
|
||||
import { cloudRestartAttemptModel, cloudRunningStripModel } from './cloud-running-strip-model'
|
||||
|
||||
function openAccounts(): void {
|
||||
@@ -109,6 +110,7 @@ export function CloudRunningStripPortal({
|
||||
beginCloudAgentRestart(paneKey, { ...args, ptyId }, () =>
|
||||
useAppStore.getState().queuePaneAccountRestarts([ptyId], args.agent)
|
||||
)
|
||||
watchCloudAgentRestartPane(paneKey, worktreeId, args.agent)
|
||||
}
|
||||
// A Restart in flight (or failed) owns the strip even while the pane has no agent status.
|
||||
if (attempt && cloud) {
|
||||
|
||||
@@ -50,6 +50,8 @@ export type CloudStripModel = {
|
||||
codeStep?: boolean
|
||||
/** RA-11 state 2: a dismiss × with this label (the strip otherwise drops its × on Renew). */
|
||||
dismiss?: string
|
||||
/** RA-11 "Restarting…": nothing to close; the strip leaves with the result. */
|
||||
noClose?: boolean
|
||||
/** One sentence for the polite region. */
|
||||
announcement: string
|
||||
}
|
||||
|
||||
@@ -5,22 +5,34 @@ import { cloudRestartAttemptModel } from './cloud-running-strip-model'
|
||||
const attempt = { agent: 'claude' as const, resumable: true, ptyId: 'p', launchedAt: null }
|
||||
|
||||
describe('RA-11 Restart feedback copy', () => {
|
||||
it('restarting: spinner, title, the button disabled, no dismiss', () => {
|
||||
it('restarting: spinner and words only, no button and nothing to close', () => {
|
||||
const model = cloudRestartAttemptModel({ ...attempt, phase: 'restarting' }, translate)
|
||||
expect(model).toMatchObject({
|
||||
status: 'busy',
|
||||
title: 'Restarting Claude…',
|
||||
primary: { label: 'Restart Claude', action: { kind: 'restart' }, busy: true }
|
||||
detail: 'Picking up where you left off.',
|
||||
primary: null,
|
||||
noClose: true
|
||||
})
|
||||
expect(model.dismiss).toBeUndefined()
|
||||
const fresh = cloudRestartAttemptModel(
|
||||
{ ...attempt, resumable: false, phase: 'restarting' },
|
||||
translate
|
||||
)
|
||||
expect(fresh.detail).toBe('Starts a new conversation.')
|
||||
})
|
||||
|
||||
it('failed: says so and offers Try again and a dismiss', () => {
|
||||
it('failed: says so once, the reason when known, and offers Try again and a dismiss', () => {
|
||||
const unresponsive = cloudRestartAttemptModel(
|
||||
{ ...attempt, phase: 'failed', failure: 'hostUnresponsive' },
|
||||
translate
|
||||
)
|
||||
expect(unresponsive.detail).toBe('The workspace didn’t respond.')
|
||||
const model = cloudRestartAttemptModel({ ...attempt, phase: 'failed' }, translate)
|
||||
expect(model).toMatchObject({
|
||||
status: 'error',
|
||||
title: 'Couldn’t restart Claude',
|
||||
detail: 'Try again.',
|
||||
detail: '',
|
||||
primary: { label: 'Try again', action: { kind: 'restart' } },
|
||||
dismiss: 'Dismiss',
|
||||
announcement: 'Couldn’t restart Claude. Try again.'
|
||||
|
||||
@@ -69,12 +69,9 @@ export function cloudRestartAttemptModel(
|
||||
detail: attempt.resumable
|
||||
? t('agentSignInStrip.restartingResume', 'Picking up where you left off.')
|
||||
: t('agentSignInStrip.renewedFresh', 'Starts a new conversation.'),
|
||||
primary: {
|
||||
label: t('agentSignInStrip.restartAgent', 'Restart {{agent}}', { agent }),
|
||||
narrowLabel: t('agentSignInStrip.restart', 'Restart'),
|
||||
action: { kind: 'restart' },
|
||||
busy: true
|
||||
},
|
||||
// The spinner and the words are the whole state: no button to click twice.
|
||||
primary: null,
|
||||
noClose: true,
|
||||
announcement: title
|
||||
}
|
||||
}
|
||||
@@ -84,7 +81,11 @@ export function cloudRestartAttemptModel(
|
||||
status: 'error',
|
||||
title,
|
||||
compactTitle: title,
|
||||
detail: t('agentSignInStrip.tryAgainDetail', 'Try again.'),
|
||||
// Never "Try again." twice: the body names the reason when one is known, else stays empty.
|
||||
detail:
|
||||
attempt.failure === 'hostUnresponsive'
|
||||
? t('agentSignInStrip.restartHostUnresponsive', 'The workspace didn’t respond.')
|
||||
: '',
|
||||
primary: {
|
||||
label: t('agentSignInStrip.tryAgain', 'Try again'),
|
||||
action: { kind: 'restart' }
|
||||
|
||||
+64
@@ -242,6 +242,11 @@ describe('RA-11 Restart on a paired (remote) pane', () => {
|
||||
{ focus: false }
|
||||
)
|
||||
expect(cloudAgentRestartAttempt(PANE_KEY, 0)?.launchedAt).not.toBeNull()
|
||||
// Never closes a tab or pane: the same tab and leaf are there after the restart.
|
||||
const state = useAppStore.getState()
|
||||
expect(state.tabsByWorktree['wt-1']?.map((t) => t.id)).toEqual([TAB, OTHER_TAB])
|
||||
expect(state.terminalLayoutsByTabId[TAB]?.root).toEqual({ type: 'leaf', leafId: LEAF })
|
||||
expect(state.terminalLayoutsByTabId[OTHER_TAB]?.ptyIdsByLeafId).toEqual({ [OTHER_LEAF]: OTHER })
|
||||
})
|
||||
|
||||
it('shows the failure and never reconnects when the host terminal could not be stopped', async () => {
|
||||
@@ -257,6 +262,65 @@ describe('RA-11 Restart on a paired (remote) pane', () => {
|
||||
expect(useAppStore.getState().suppressedPtyExitIds[REMOTE]).toBeUndefined()
|
||||
})
|
||||
|
||||
it('a resumable pane is relaunched on its own conversation in the same pane, after the stop', async () => {
|
||||
clickRemoteRestart()
|
||||
const order: string[] = []
|
||||
const providerSession = { key: 'session_id' as const, id: 'sess-tab-1' }
|
||||
const resumeRemotePane = vi.fn(async () => {
|
||||
order.push('resume')
|
||||
})
|
||||
const handleRestartPane = vi.fn(() => order.push('reconnect'))
|
||||
runReadyPaneAccountRestarts({
|
||||
panes: [{ id: 7, leafId: LEAF }],
|
||||
ptyIdOf: () => REMOTE,
|
||||
readyRestartPtyIds: selectReadyAccountRestartPtyIds(useAppStore.getState(), TAB),
|
||||
tabId: TAB,
|
||||
consumePendingPaneAccountRestart: useAppStore.getState().consumePendingPaneAccountRestart,
|
||||
buildAccountRestartStartup: () => ({
|
||||
command: 'claude',
|
||||
resumeProviderSession: providerSession
|
||||
}),
|
||||
handleRestartPane,
|
||||
stopRemotePane: async () => {
|
||||
order.push('stop')
|
||||
},
|
||||
resumeRemotePane
|
||||
})
|
||||
await vi.waitFor(() => expect(handleRestartPane).toHaveBeenCalledTimes(1))
|
||||
expect(order).toEqual(['stop', 'resume', 'reconnect'])
|
||||
expect(resumeRemotePane).toHaveBeenCalledWith({
|
||||
ptyId: REMOTE,
|
||||
worktreeId: 'wt-1',
|
||||
tabId: TAB,
|
||||
leafId: LEAF,
|
||||
agent: 'claude',
|
||||
providerSession
|
||||
})
|
||||
})
|
||||
|
||||
it('a failed resume on the host shows the failure and never reconnects', async () => {
|
||||
clickRemoteRestart()
|
||||
const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined)
|
||||
const handleRestartPane = vi.fn()
|
||||
runReadyPaneAccountRestarts({
|
||||
panes: [{ id: 7, leafId: LEAF }],
|
||||
ptyIdOf: () => REMOTE,
|
||||
readyRestartPtyIds: selectReadyAccountRestartPtyIds(useAppStore.getState(), TAB),
|
||||
tabId: TAB,
|
||||
consumePendingPaneAccountRestart: useAppStore.getState().consumePendingPaneAccountRestart,
|
||||
buildAccountRestartStartup: () => ({
|
||||
command: 'claude',
|
||||
resumeProviderSession: { key: 'session_id' as const, id: 'sess-tab-1' }
|
||||
}),
|
||||
handleRestartPane,
|
||||
stopRemotePane: () => Promise.resolve(),
|
||||
resumeRemotePane: () => Promise.reject(new Error('agent_session_resume_failed'))
|
||||
})
|
||||
await vi.waitFor(() => expect(cloudAgentRestartAttempt(PANE_KEY, 0)?.phase).toBe('failed'))
|
||||
warn.mockRestore()
|
||||
expect(handleRestartPane).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('a reconnect that never binds a new PTY fails at the timeout', async () => {
|
||||
clickRemoteRestart()
|
||||
const handleRestartPane = runRemote(() => Promise.resolve())
|
||||
|
||||
+35
-8
@@ -12,7 +12,11 @@ import {
|
||||
} from '@/lib/orca-cloud/cloud-agent-restart-attempt'
|
||||
import type { TerminalPaneCloseController } from '../layout/close/use-terminal-pane-close-actions'
|
||||
import type { usePaneProcessRestart } from '../process-exit/use-pane-process-restart'
|
||||
import { stopRemotePaneTerminalForRestart } from '@/lib/orca-cloud/cloud-pane-restart-stop'
|
||||
import {
|
||||
resumeRemotePaneAgent,
|
||||
stopRemotePaneTerminalForRestart
|
||||
} from '@/lib/orca-cloud/cloud-pane-restart-stop'
|
||||
import type { AgentProviderSessionMetadata } from '../../../../../shared/agent-session/lifecycle/agent-session-resume'
|
||||
import { isRemoteRuntimePtyId } from '../../../../../shared/remote-runtime/remote-runtime-pty-id'
|
||||
import type { AccountRestartAgent } from '@/store/terminals/terminal-contracts'
|
||||
import type { usePaneAccountRestartStartup } from './use-pane-account-restart-startup'
|
||||
@@ -80,7 +84,9 @@ function worktreeIdForTab(tabId: string): string | null {
|
||||
return null
|
||||
}
|
||||
|
||||
export function runReadyPaneAccountRestarts<Startup>(input: {
|
||||
export function runReadyPaneAccountRestarts<
|
||||
Startup extends { resumeProviderSession?: AgentProviderSessionMetadata }
|
||||
>(input: {
|
||||
panes: readonly ReadyRestartPane[]
|
||||
ptyIdOf: (paneId: number) => string | null
|
||||
readyRestartPtyIds: readonly string[]
|
||||
@@ -90,8 +96,14 @@ export function runReadyPaneAccountRestarts<Startup>(input: {
|
||||
handleRestartPane: (paneId: number, startup: Startup, options: { focus: boolean }) => void
|
||||
/** Stops the one host terminal behind a paired pane before its restart reconnects. */
|
||||
stopRemotePane?: (ptyId: string, worktreeId: string) => Promise<void>
|
||||
/** Relaunches the paired pane's agent on its own conversation, in the same pane. */
|
||||
resumeRemotePane?: typeof resumeRemotePaneAgent
|
||||
}): void {
|
||||
const args = { stopRemotePane: stopRemotePaneTerminalForRestart, ...input }
|
||||
const args = {
|
||||
stopRemotePane: stopRemotePaneTerminalForRestart,
|
||||
resumeRemotePane: resumeRemotePaneAgent,
|
||||
...input
|
||||
}
|
||||
for (const pane of args.panes) {
|
||||
const ptyId = args.ptyIdOf(pane.id)
|
||||
if (
|
||||
@@ -136,10 +148,25 @@ export function runReadyPaneAccountRestarts<Startup>(input: {
|
||||
// terminal first (its exit is ours, not the pane's), then reconnect.
|
||||
const store = useAppStore.getState()
|
||||
store.suppressPtyExit(ptyId)
|
||||
void args.stopRemotePane(ptyId, worktreeId).then(launch, (err: unknown) => {
|
||||
console.warn('[orca-cloud] restart could not stop the pane’s host terminal:', err)
|
||||
useAppStore.getState().consumeSuppressedPtyExit(ptyId)
|
||||
failCloudAgentRestart(ptyId)
|
||||
})
|
||||
const providerSession = launchedStartup.resumeProviderSession ?? null
|
||||
void args
|
||||
.stopRemotePane(ptyId, worktreeId)
|
||||
.then(() =>
|
||||
providerSession
|
||||
? args.resumeRemotePane({
|
||||
ptyId,
|
||||
worktreeId,
|
||||
tabId: args.tabId,
|
||||
leafId: pane.leafId,
|
||||
agent,
|
||||
providerSession
|
||||
})
|
||||
: undefined
|
||||
)
|
||||
.then(launch, (err: unknown) => {
|
||||
console.warn('[orca-cloud] restart could not relaunch the pane’s agent on its host:', err)
|
||||
useAppStore.getState().consumeSuppressedPtyExit(ptyId)
|
||||
failCloudAgentRestart(ptyId)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28061,8 +28061,10 @@
|
||||
"restarting": "Restarting {{agent}}…",
|
||||
"restartingResume": "Picking up where you left off.",
|
||||
"restartFailed": "Couldn’t restart {{agent}}",
|
||||
"tryAgainDetail": "Try again.",
|
||||
"restartHostUnresponsive": "The workspace didn’t respond.",
|
||||
"restartFailedAnnounce": "Couldn’t restart {{agent}}. Try again.",
|
||||
"restartFailedIn": "Couldn’t restart {{agent}} in {{workspace}}.",
|
||||
"openWorkspace": "Open workspace",
|
||||
"notSetUp": "{{agent}} isn’t set up for Orca Cloud",
|
||||
"notSetUpCompact": "{{agent}} not set up",
|
||||
"notSetUpDetail": "Set up once. Every cloud workspace uses it.",
|
||||
|
||||
@@ -25,6 +25,8 @@ export type CloudAgentRestartAttempt = {
|
||||
ptyId: string
|
||||
/** Set when the pane's restart actually ran (a new PTY was asked for). */
|
||||
launchedAt: number | null
|
||||
/** Why it failed, when known: the workspace's host did not do what was asked. */
|
||||
failure?: 'hostUnresponsive'
|
||||
}
|
||||
|
||||
export const CLOUD_AGENT_RESTART_TIMEOUT_MS = 10_000
|
||||
@@ -99,13 +101,16 @@ export function noteCloudAgentRestartLaunched(ptyId: string, now = Date.now()):
|
||||
}
|
||||
|
||||
/** The pane's restart could not run (no startup to launch, or it threw). */
|
||||
export function failCloudAgentRestart(ptyId: string): void {
|
||||
export function failCloudAgentRestart(
|
||||
ptyId: string,
|
||||
failure?: CloudAgentRestartAttempt['failure']
|
||||
): void {
|
||||
forcedRestarts.delete(ptyId)
|
||||
const paneKey = attemptKeyForPty(ptyId)
|
||||
const attempt = paneKey ? restarts.get(paneKey) : undefined
|
||||
if (paneKey && attempt) {
|
||||
stopRestartTimer(paneKey)
|
||||
restarts.set(paneKey, { ...attempt, phase: 'failed' })
|
||||
restarts.set(paneKey, { ...attempt, phase: 'failed', ...(failure ? { failure } : {}) })
|
||||
notifyCloudRunningStrips()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const toastError = vi.fn()
|
||||
vi.mock('sonner', () => ({ toast: { error: (...args: unknown[]) => toastError(...args) } }))
|
||||
const activate = vi.fn()
|
||||
vi.mock('@/lib/workspace/activation/worktree-activation', () => ({
|
||||
activateAndRevealWorktree: (id: string) => activate(id)
|
||||
}))
|
||||
|
||||
const { useAppStore } = await import('@/store')
|
||||
const { makePaneKey } = await import('../../../../shared/workspace-layout/stable-pane-id')
|
||||
const attempts = await import('./cloud-agent-restart-attempt')
|
||||
const { restartPaneExists, watchCloudAgentRestartPane } =
|
||||
await import('./cloud-agent-restart-pane-watch')
|
||||
|
||||
const TAB = 'tab-1'
|
||||
const LEAF = '11111111-1111-4111-8111-111111111111'
|
||||
const PANE = makePaneKey(TAB, LEAF)
|
||||
const PTY = 'remote:env-1@@term_a'
|
||||
|
||||
function seed(): void {
|
||||
useAppStore.setState({
|
||||
tabsByWorktree: {
|
||||
'wt-1': [
|
||||
{
|
||||
id: TAB,
|
||||
ptyId: PTY,
|
||||
worktreeId: 'wt-1',
|
||||
title: 'claude',
|
||||
customTitle: null,
|
||||
color: null,
|
||||
sortOrder: 0,
|
||||
createdAt: 1
|
||||
}
|
||||
]
|
||||
},
|
||||
terminalLayoutsByTabId: {
|
||||
[TAB]: {
|
||||
root: { type: 'leaf', leafId: LEAF },
|
||||
activeLeafId: LEAF,
|
||||
expandedLeafId: null,
|
||||
ptyIdsByLeafId: { [LEAF]: PTY }
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
describe('RA-11 Restart when its pane goes away', () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers()
|
||||
toastError.mockClear()
|
||||
activate.mockClear()
|
||||
attempts.resetCloudAgentRestartsForTest()
|
||||
seed()
|
||||
attempts.beginCloudAgentRestart(
|
||||
PANE,
|
||||
{ agent: 'claude', resumable: true, ptyId: PTY },
|
||||
() => undefined
|
||||
)
|
||||
})
|
||||
afterEach(() => {
|
||||
attempts.resetCloudAgentRestartsForTest()
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
it('a restart rebinding the leaf’s PTY keeps the pane: same tab, same leaf, no toast', () => {
|
||||
watchCloudAgentRestartPane(PANE, 'wt-1', 'claude')
|
||||
useAppStore.setState({
|
||||
terminalLayoutsByTabId: {
|
||||
[TAB]: {
|
||||
root: { type: 'leaf', leafId: LEAF },
|
||||
activeLeafId: LEAF,
|
||||
expandedLeafId: null,
|
||||
ptyIdsByLeafId: {}
|
||||
}
|
||||
}
|
||||
})
|
||||
expect(restartPaneExists(useAppStore.getState(), PANE)).toBe(true)
|
||||
expect(toastError).not.toHaveBeenCalled()
|
||||
expect(attempts.cloudAgentRestartAttempt(PANE, 0)?.phase).toBe('restarting')
|
||||
})
|
||||
|
||||
it('the tab closing mid-restart ends the attempt with a toast naming the workspace', () => {
|
||||
watchCloudAgentRestartPane(PANE, 'wt-1', 'claude')
|
||||
useAppStore.setState({ tabsByWorktree: { 'wt-1': [] }, terminalLayoutsByTabId: {} })
|
||||
expect(attempts.cloudAgentRestartAttempt(PANE, 0)).toBeNull()
|
||||
expect(toastError).toHaveBeenCalledTimes(1)
|
||||
const [title, options] = toastError.mock.calls[0]
|
||||
expect(title).toBe('Couldn’t restart Claude in wt-1.')
|
||||
options.action.onClick()
|
||||
expect(activate).toHaveBeenCalledWith('wt-1')
|
||||
})
|
||||
|
||||
it('stops watching once the attempt settled', () => {
|
||||
const stop = watchCloudAgentRestartPane(PANE, 'wt-1', 'claude')
|
||||
attempts.dismissCloudAgentRestart(PANE)
|
||||
useAppStore.setState({ tabsByWorktree: { 'wt-1': [] } })
|
||||
expect(toastError).not.toHaveBeenCalled()
|
||||
stop()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,74 @@
|
||||
// RA-11: a Restart must never vanish without a result. If its pane goes away while the restart runs
|
||||
// (or after it failed), the strip has nowhere to show; say so in a toast that names the workspace.
|
||||
import { toast } from 'sonner'
|
||||
import { translate } from '@/i18n/i18n'
|
||||
import { useAppStore } from '@/store'
|
||||
import type { AppState } from '@/store/types'
|
||||
import { activateAndRevealWorktree } from '@/lib/workspace/activation/worktree-activation'
|
||||
import { resolveWorktreeDisplayName } from '@/lib/worktree-default-display-name'
|
||||
import { parsePaneKey } from '../../../../shared/workspace-layout/stable-pane-id'
|
||||
import type { TerminalPaneLayoutNode } from '../../../../shared/workspace-layout/terminal-tab-types'
|
||||
import {
|
||||
HOST_AGENT_SIGN_IN_AGENT_NAME,
|
||||
type HostAgentSignInAgent
|
||||
} from '../../../../shared/host-agent-sign-in-status'
|
||||
import { cloudAgentRestartAttempt, dismissCloudAgentRestart } from './cloud-agent-restart-attempt'
|
||||
|
||||
function hasLeaf(node: TerminalPaneLayoutNode | null | undefined, leafId: string): boolean {
|
||||
if (!node) {
|
||||
return false
|
||||
}
|
||||
return node.type === 'leaf'
|
||||
? node.leafId === leafId
|
||||
: hasLeaf(node.first, leafId) || hasLeaf(node.second, leafId)
|
||||
}
|
||||
|
||||
/** Whether the pane (its tab and its leaf) still exists. A restart only rebinds the leaf's PTY. */
|
||||
export function restartPaneExists(state: AppState, paneKey: string): boolean {
|
||||
const parsed = parsePaneKey(paneKey)
|
||||
if (!parsed) {
|
||||
return false
|
||||
}
|
||||
const tabExists = Object.values(state.tabsByWorktree).some((tabs) =>
|
||||
tabs.some((tab) => tab.id === parsed.tabId)
|
||||
)
|
||||
return tabExists && hasLeaf(state.terminalLayoutsByTabId[parsed.tabId]?.root, parsed.leafId)
|
||||
}
|
||||
|
||||
/** Watch the pane for the attempt's life; returns the unsubscribe. */
|
||||
export function watchCloudAgentRestartPane(
|
||||
paneKey: string,
|
||||
worktreeId: string,
|
||||
agent: HostAgentSignInAgent
|
||||
): () => void {
|
||||
const unsubscribe = useAppStore.subscribe((state) => {
|
||||
if (!cloudAgentRestartAttempt(paneKey, 0)) {
|
||||
unsubscribe()
|
||||
return
|
||||
}
|
||||
if (restartPaneExists(state, paneKey)) {
|
||||
return
|
||||
}
|
||||
unsubscribe()
|
||||
dismissCloudAgentRestart(paneKey)
|
||||
const worktree = state.getKnownWorktreeById(worktreeId)
|
||||
const workspace = worktree ? resolveWorktreeDisplayName(worktree) : worktreeId
|
||||
toast.error(
|
||||
translate(
|
||||
'agentSignInStrip.restartFailedIn',
|
||||
'Couldn’t restart {{agent}} in {{workspace}}.',
|
||||
{
|
||||
agent: HOST_AGENT_SIGN_IN_AGENT_NAME[agent],
|
||||
workspace
|
||||
}
|
||||
),
|
||||
{
|
||||
action: {
|
||||
label: translate('agentSignInStrip.openWorkspace', 'Open workspace'),
|
||||
onClick: () => activateAndRevealWorktree(worktreeId)
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
return unsubscribe
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const calls: { method: string; params: unknown; environmentId: string }[] = []
|
||||
let showPtyId: string | null = 'host-pty-7'
|
||||
let stopResult: Record<string, unknown> = {}
|
||||
|
||||
vi.mock('@/runtime/rpc/calls/runtime-rpc-call', () => ({
|
||||
callRuntimeRpc: async (target: { environmentId: string }, method: string, params: unknown) => {
|
||||
calls.push({ method, params, environmentId: target.environmentId })
|
||||
return method === 'terminal.show' ? { terminal: { ptyId: showPtyId } } : stopResult
|
||||
}
|
||||
}))
|
||||
|
||||
vi.mock(
|
||||
'@/runtime/hosted-terminals/creation/agent-launch/agent-session-ensure-provider-session',
|
||||
() => ({ agentProviderSessionForHostEnsure: async (_env: string, session: unknown) => session })
|
||||
)
|
||||
|
||||
const { resumeRemotePaneAgent, stopRemotePaneTerminalForRestart } =
|
||||
await import('./cloud-pane-restart-stop')
|
||||
|
||||
describe('stopRemotePaneTerminalForRestart (RA-11 paired pane)', () => {
|
||||
beforeEach(() => {
|
||||
calls.length = 0
|
||||
showPtyId = 'host-pty-7'
|
||||
stopResult = { stoppedPtyIds: ['host-pty-7'], postStopVerified: true }
|
||||
})
|
||||
|
||||
it('puts exactly that one host terminal to sleep (reversible, target only), never a close', async () => {
|
||||
await stopRemotePaneTerminalForRestart('remote:env-1@@term_a', 'wt-1')
|
||||
expect(calls.map((c) => c.method)).toEqual(['terminal.show', 'terminal.stopExact'])
|
||||
expect(calls[0]).toMatchObject({ environmentId: 'env-1', params: { terminal: 'term_a' } })
|
||||
expect(calls[1]).toMatchObject({
|
||||
environmentId: 'env-1',
|
||||
params: { expectedPtyIds: ['host-pty-7'], keepHistory: true, targetOnly: true }
|
||||
})
|
||||
})
|
||||
|
||||
it('throws when the host has no live terminal for the pane, or does not confirm the stop', async () => {
|
||||
showPtyId = null
|
||||
await expect(stopRemotePaneTerminalForRestart('remote:env-1@@term_a', 'wt-1')).rejects.toThrow(
|
||||
'restart_remote_pane_not_live'
|
||||
)
|
||||
showPtyId = 'host-pty-7'
|
||||
stopResult = { stoppedPtyIds: ['host-pty-7'], postStopVerified: false }
|
||||
await expect(stopRemotePaneTerminalForRestart('remote:env-1@@term_a', 'wt-1')).rejects.toThrow()
|
||||
})
|
||||
|
||||
it('refuses a pane id without an owning environment', async () => {
|
||||
await expect(stopRemotePaneTerminalForRestart('remote:term_a', 'wt-1')).rejects.toThrow(
|
||||
'restart_remote_pane_unowned'
|
||||
)
|
||||
expect(calls).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('resumeRemotePaneAgent (RA-11 paired pane)', () => {
|
||||
beforeEach(() => {
|
||||
calls.length = 0
|
||||
})
|
||||
|
||||
it('ensures the agent on its own session, placed in the same host tab and leaf', async () => {
|
||||
await resumeRemotePaneAgent({
|
||||
ptyId: 'remote:env-1@@term_a',
|
||||
worktreeId: 'wt-1',
|
||||
tabId: 'web-terminal-host-tab%3A%3Aleaf',
|
||||
leafId: 'leaf-1',
|
||||
agent: 'claude',
|
||||
providerSession: { key: 'session_id', id: 'sess-1' }
|
||||
})
|
||||
expect(calls).toHaveLength(1)
|
||||
expect(calls[0]).toMatchObject({
|
||||
method: 'terminal.ensureAgentSession',
|
||||
environmentId: 'env-1',
|
||||
params: {
|
||||
kind: 'explicit',
|
||||
agent: 'claude',
|
||||
providerSession: { key: 'session_id', id: 'sess-1' },
|
||||
placement: { tabId: 'host-tab::leaf', leafId: 'leaf-1' }
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,10 +1,16 @@
|
||||
// RA-11: Restart on a paired (web-host) pane. The host already runs a terminal in that pane, so a
|
||||
// desktop reconnect reattaches to it (ensureAgentSession hands back the live session) and nothing
|
||||
// relaunches. Stop exactly that one host terminal first; the reconnect then starts the agent anew.
|
||||
// relaunches. Put exactly that one host terminal to sleep first (the reversible stop the pane-sleep
|
||||
// path uses: the leaf stays, as a sleeping surface); the reconnect then wakes it with --resume.
|
||||
// A plain stop is a close: the host drops the tab and there is nothing left to relaunch into.
|
||||
import { parseRemoteRuntimePtyId } from '../../../../shared/remote-runtime/remote-runtime-pty-id'
|
||||
import type { RuntimeTerminalShow } from '../../../../shared/runtime-terminal-contracts'
|
||||
import { callRuntimeRpc } from '@/runtime/rpc/calls/runtime-rpc-call'
|
||||
import { toRuntimeWorktreeSelector } from '@/runtime/rpc/targets/runtime-worktree-selector'
|
||||
import { agentProviderSessionForHostEnsure } from '@/runtime/hosted-terminals/creation/agent-launch/agent-session-ensure-provider-session'
|
||||
import { toHostSessionTabId } from '../../../../shared/workspace-layout/terminal-surface-id'
|
||||
import type { AgentProviderSessionMetadata } from '../../../../shared/agent-session/lifecycle/agent-session-resume'
|
||||
import type { AccountRestartAgent } from '@/store/terminals/terminal-contracts'
|
||||
|
||||
type StopExactResult = {
|
||||
stoppedPtyIds?: string[]
|
||||
@@ -39,6 +45,8 @@ export async function stopRemotePaneTerminalForRestart(
|
||||
{
|
||||
worktree: toRuntimeWorktreeSelector(worktreeId),
|
||||
expectedPtyIds: [hostPtyId],
|
||||
// Reversible: the host keeps the pane (and its scrollback) for the wake.
|
||||
keepHistory: true,
|
||||
// Only this pane: every other terminal in the workspace keeps running.
|
||||
targetOnly: true
|
||||
},
|
||||
@@ -48,3 +56,36 @@ export async function stopRemotePaneTerminalForRestart(
|
||||
throw new Error(result.postStopFailure ?? 'restart_remote_pane_stop_unverified')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Relaunch the pane's agent on its own conversation, in the same pane. Without this the host wakes
|
||||
* the sleeping pane with its original launch (a new conversation). Only for a resumable session;
|
||||
* a pane with none takes the host's fresh launch, which is what "Starts a new conversation" says.
|
||||
*/
|
||||
export async function resumeRemotePaneAgent(args: {
|
||||
ptyId: string
|
||||
worktreeId: string
|
||||
tabId: string
|
||||
leafId: string
|
||||
agent: AccountRestartAgent
|
||||
providerSession: AgentProviderSessionMetadata
|
||||
}): Promise<void> {
|
||||
const environmentId = parseRemoteRuntimePtyId(args.ptyId)?.environmentId
|
||||
if (!environmentId) {
|
||||
throw new Error('restart_remote_pane_unowned')
|
||||
}
|
||||
await callRuntimeRpc(
|
||||
{ kind: 'environment', environmentId },
|
||||
'terminal.ensureAgentSession',
|
||||
{
|
||||
kind: 'explicit',
|
||||
worktree: toRuntimeWorktreeSelector(args.worktreeId),
|
||||
agent: args.agent,
|
||||
providerSession: await agentProviderSessionForHostEnsure(environmentId, args.providerSession),
|
||||
// The same pane: the host tab and leaf the stopped terminal lived in.
|
||||
placement: { tabId: toHostSessionTabId(args.tabId), leafId: args.leafId },
|
||||
presentation: 'background'
|
||||
},
|
||||
{ timeoutMs: 15_000 }
|
||||
)
|
||||
}
|
||||
|
||||
@@ -147,23 +147,23 @@ test('RA-11: state 1 offers Renew only; state 2 offers Restart and a dismiss cle
|
||||
expect(dismiss.y).toBeGreaterThanOrEqual(close.y + close.height)
|
||||
})
|
||||
|
||||
test('RA-11 Restart: "Restarting Claude…" keeps the strip with the button disabled; a failure offers Try again', async ({
|
||||
test('RA-11 Restart: "Restarting Claude…" is the spinner and words only; a failure offers Try again once', async ({
|
||||
page
|
||||
}) => {
|
||||
await page.goto('/fixtures.html?id=agent-sign-in-strip/CloudAgentSignInStrip:runningRestarting')
|
||||
await expect(page.locator('html')).toHaveAttribute('data-fixture-state', 'ready')
|
||||
const strip = page.locator('[data-cloud-sign-in-strip]')
|
||||
await expect(strip).toContainText('Restarting Claude…')
|
||||
const busy = strip.getByRole('button', { name: 'Restart Claude' })
|
||||
await expect(busy).toHaveAttribute('aria-disabled', 'true')
|
||||
// Nothing to close while it runs: the strip leaves with a result.
|
||||
await expect(strip.getByRole('button')).toHaveCount(1)
|
||||
await expect(strip).toContainText('Picking up where you left off.')
|
||||
// Nothing to click twice, nothing to close: the strip leaves with a result.
|
||||
await expect(strip.getByRole('button')).toHaveCount(0)
|
||||
await page.goto(
|
||||
'/fixtures.html?id=agent-sign-in-strip/CloudAgentSignInStrip:runningRestartFailed'
|
||||
)
|
||||
await expect(page.locator('html')).toHaveAttribute('data-fixture-state', 'ready')
|
||||
await expect(strip).toContainText('Couldn’t restart Claude')
|
||||
await expect(strip).toContainText('Try again.')
|
||||
await expect(strip).toContainText('The workspace didn’t respond.')
|
||||
await expect(strip).not.toContainText('Try again.')
|
||||
await expect(strip.getByRole('button', { name: 'Try again' })).toBeEnabled()
|
||||
await expect(strip.getByRole('button', { name: 'Dismiss' })).toBeVisible()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user