mirror of
https://github.com/stablyai/orca.git
synced 2026-11-15 18:37:24 +00:00
fix(w8): DS-27 phone cloud states: sign in when not connected (returns to the link), 'Couldn't reach Orca Cloud' on errors, Not responding + owner Restart, Deleting, glossary-only headline, asleep cloud host gate (Wake), banner 'Try again'; state logic tested (#227)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { useLocalSearchParams } from 'expo-router'
|
||||
import { CloudHostAsleepGate } from '../../../src/cloud/CloudHostAsleepGate'
|
||||
import { firstParam } from '../../../src/navigation/route-param-reader'
|
||||
import { MobileWebShellScreen } from '../../../src/mobile-web-shell/MobileWebShellScreen'
|
||||
import { shellScreenRoute } from '../../../src/mobile-web-shell/shell-screen-route'
|
||||
@@ -24,14 +25,17 @@ function HostListScreen() {
|
||||
return <PageRouteUnavailableScreen hostId={hostId} />
|
||||
}
|
||||
return (
|
||||
<MobileWebShellScreen
|
||||
// Remount on host change to discard the old session’s grants; `open` updates the document in place.
|
||||
key={hostId}
|
||||
hostId={hostId}
|
||||
route={route}
|
||||
onRouteParamClear={onRouteParamClear}
|
||||
onPageLocation={onPageLocation}
|
||||
/>
|
||||
// An asleep cloud workspace's VM is not an offline computer: say so and offer Wake first.
|
||||
<CloudHostAsleepGate hostId={hostId}>
|
||||
<MobileWebShellScreen
|
||||
// Remount on host change to discard the old session’s grants; `open` updates the document in place.
|
||||
key={hostId}
|
||||
hostId={hostId}
|
||||
route={route}
|
||||
onRouteParamClear={onRouteParamClear}
|
||||
onPageLocation={onPageLocation}
|
||||
/>
|
||||
</CloudHostAsleepGate>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { CloudHostAsleepGate } from '../../../../src/cloud/CloudHostAsleepGate'
|
||||
import { withWorkspaceRoute } from '../../../../src/navigation/workspace-route'
|
||||
import {
|
||||
useWorkspaceExecutionHost,
|
||||
@@ -68,11 +69,13 @@ export default withWorkspaceRoute(function MobileSessionScreen() {
|
||||
// Keep shared shellScreenRouteKey unchanged because other screens treat param changes as identity changes.
|
||||
const { paneKey: _paneKey, paneView: _paneView, ...identity } = routeParams
|
||||
return (
|
||||
<MobileWebShellScreen
|
||||
key={shellScreenRouteKey({ pathname: route.pathname, params: identity })}
|
||||
hostId={hostId}
|
||||
route={route}
|
||||
onRouteParamClear={erasePaneKey}
|
||||
/>
|
||||
<CloudHostAsleepGate hostId={hostId}>
|
||||
<MobileWebShellScreen
|
||||
key={shellScreenRouteKey({ pathname: route.pathname, params: identity })}
|
||||
hostId={hostId}
|
||||
route={route}
|
||||
onRouteParamClear={erasePaneKey}
|
||||
/>
|
||||
</CloudHostAsleepGate>
|
||||
)
|
||||
})
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
import { useRouter } from 'expo-router'
|
||||
import { Moon } from 'lucide-react-native'
|
||||
import { useEffect, useState, type ReactNode } from 'react'
|
||||
import { ActivityIndicator, View } from 'react-native'
|
||||
import { SafeAreaView } from 'react-native-safe-area-context'
|
||||
import { MobileStateView } from '../components/MobileStateView'
|
||||
import { useMobileTranslation } from '../i18n/use-mobile-translation'
|
||||
import { SettingsNavBar } from '../settings/settings-screen-frame'
|
||||
import { colors } from '../theme/mobile-theme'
|
||||
import { useMobileColorScheme } from '../theme/use-mobile-color-scheme'
|
||||
import { cloudHostGate } from './cloud-screen-states'
|
||||
import { cloudWorkspaceIdForHost } from './cloud-workspace-links'
|
||||
import { useCloudEnrollment, useCloudWorkspace } from './use-cloud-workspaces'
|
||||
|
||||
/**
|
||||
* A cloud workspace's VM is a paired host, but an asleep one is not "a computer that's offline":
|
||||
* before its page loads, say it's asleep and offer Wake (the normal wake → access → connect flow,
|
||||
* which lands back on this host). Every other host, and a cloud host that is up, passes through.
|
||||
* One component with fixed hooks, and the page is mounted only once the answer is known, so it is
|
||||
* never mounted and then thrown away.
|
||||
*/
|
||||
export function CloudHostAsleepGate(props: { hostId: string; children: ReactNode }) {
|
||||
useMobileColorScheme()
|
||||
const t = useMobileTranslation()
|
||||
const router = useRouter()
|
||||
// The answer is kept with the host it was looked up for: a gate reused for another host waits
|
||||
// instead of reading the previous host's workspace for a render.
|
||||
const [lookup, setLookup] = useState<{ hostId: string; sandboxId: string | null } | null>(null)
|
||||
useEffect(() => {
|
||||
let live = true
|
||||
const hostId = props.hostId
|
||||
void cloudWorkspaceIdForHost(hostId)
|
||||
.then((id) => live && setLookup({ hostId, sandboxId: id }))
|
||||
.catch(() => live && setLookup({ hostId, sandboxId: null }))
|
||||
return () => {
|
||||
live = false
|
||||
}
|
||||
}, [props.hostId])
|
||||
const sandboxId = lookup?.hostId === props.hostId ? lookup.sandboxId : undefined
|
||||
const enrollment = useCloudEnrollment()
|
||||
const listed = useCloudWorkspace(enrollment, sandboxId ?? '')
|
||||
const gate = cloudHostGate({
|
||||
sandboxId,
|
||||
enrollment,
|
||||
isPending: listed.isPending,
|
||||
isError: listed.isError,
|
||||
status: listed.workspace?.status ?? null
|
||||
})
|
||||
if (gate === 'pass') {
|
||||
return props.children
|
||||
}
|
||||
if (gate === 'wait') {
|
||||
return (
|
||||
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
|
||||
<ActivityIndicator color={colors.textMuted} />
|
||||
</View>
|
||||
)
|
||||
}
|
||||
const sleeping = listed.workspace
|
||||
return (
|
||||
<SafeAreaView style={{ flex: 1, backgroundColor: colors.bgBase }} edges={['top']}>
|
||||
<SettingsNavBar title={sleeping?.title ?? ''} onBack={() => router.back()} />
|
||||
<MobileStateView
|
||||
icon={Moon}
|
||||
title={t('cloud.host.asleep', '{{name}} is asleep', { name: sleeping?.title ?? '' })}
|
||||
message={t('cloud.host.asleepDetail', 'Files are kept. Wake it to keep working.')}
|
||||
action={{
|
||||
label: t('cloud.host.wake', 'Wake'),
|
||||
onPress: () => router.replace(`/cloud/${encodeURIComponent(sandboxId ?? '')}?autostart=1`)
|
||||
}}
|
||||
/>
|
||||
</SafeAreaView>
|
||||
)
|
||||
}
|
||||
@@ -67,11 +67,9 @@ export function CloudStatusCard(props: {
|
||||
<View style={styles.statusHeadline}>
|
||||
<CloudStatusDot status={active ? 'waking' : workspace.status} warn={notConnected} />
|
||||
<Text style={styles.statusLabel} accessibilityRole="header">
|
||||
{active
|
||||
? t('cloud.status.waking', 'Waking')
|
||||
: notConnected
|
||||
? t('cloud.status.cantConnect', 'Can’t connect')
|
||||
: cloudStatusLabel(workspace.status, t)}
|
||||
{/* Only glossary states: a running workspace this phone can't reach still reads
|
||||
"Running" (with the warning dot); the error banner below says what went wrong. */}
|
||||
{active ? t('cloud.status.waking', 'Waking') : cloudStatusLabel(workspace.status, t)}
|
||||
</Text>
|
||||
</View>
|
||||
{active ? (
|
||||
|
||||
@@ -23,7 +23,11 @@ import { CloudPromptQueueSection } from './CloudPromptQueueSection'
|
||||
import { CloudReadSnapshotSection } from './CloudReadSnapshotSection'
|
||||
import { CloudStatusCard } from './CloudStatusCard'
|
||||
import { CloudWorkspaceActions } from './CloudWorkspaceActions'
|
||||
import { archiveCloudWorkspace, sleepCloudWorkspace } from './cloud-control-plane-client'
|
||||
import {
|
||||
archiveCloudWorkspace,
|
||||
restartCloudWorkspace,
|
||||
sleepCloudWorkspace
|
||||
} from './cloud-control-plane-client'
|
||||
import { CloudRequestError } from './cloud-control-plane-request'
|
||||
import {
|
||||
enqueueCloudPrompt,
|
||||
@@ -37,6 +41,8 @@ import {
|
||||
useCloudHostRemoval
|
||||
} from './cloud-session'
|
||||
import { attachErrorMessage, phaseLabel } from './cloud-workspace-copy'
|
||||
import { setCloudReturnTo } from './cloud-return-to'
|
||||
import { cloudMissingState } from './cloud-screen-states'
|
||||
import { cloudRepoLine } from './cloud-workspace-display'
|
||||
import {
|
||||
cloudScrollBottomPadding,
|
||||
@@ -65,8 +71,14 @@ export function CloudWorkspaceScreen({
|
||||
const insets = useSafeAreaInsets()
|
||||
const removal = useCloudHostRemoval()
|
||||
const enrollment = useCloudEnrollment()
|
||||
const { workspace, isPending, isFetching, refetch } = useCloudWorkspace(enrollment, sandboxId)
|
||||
const live = useCloudWorkspaceLiveStatus(sandboxId, workspace?.status === 'running')
|
||||
const listed = useCloudWorkspace(enrollment, sandboxId)
|
||||
const { isPending, isFetching, isError, refetch } = listed
|
||||
const live = useCloudWorkspaceLiveStatus(sandboxId, listed.workspace?.status === 'running')
|
||||
// The registry only knows "running"; the live status knows when it is up but not answering.
|
||||
const workspace =
|
||||
listed.workspace?.status === 'running' && live.data?.state === 'unresponsive'
|
||||
? { ...listed.workspace, status: 'unresponsive' as const }
|
||||
: listed.workspace
|
||||
// Asleep: read its last sealed snapshot instead of waking it. Nothing here ever wakes it.
|
||||
const asleep = workspace?.status === 'sleeping'
|
||||
const snapshot = useCloudReadSnapshot(sandboxId, asleep, workspace?.readSnapshotAt ?? null)
|
||||
@@ -80,7 +92,7 @@ export function CloudWorkspaceScreen({
|
||||
// keychain), the button already reads Waking rather than keeping "Wake to continue".
|
||||
const [wakeTappedAt, setWakeTappedAt] = useState<CloudWorkspaceRun | null>(null)
|
||||
const wakePending = wakeTappedAt !== null && wakeTappedAt === run
|
||||
const [busyAction, setBusyAction] = useState<'sleep' | 'archive' | null>(null)
|
||||
const [busyAction, setBusyAction] = useState<'sleep' | 'archive' | 'restart' | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
const load = () =>
|
||||
@@ -124,7 +136,7 @@ export function CloudWorkspaceScreen({
|
||||
)
|
||||
|
||||
const lifecycle = useCallback(
|
||||
async (action: 'sleep' | 'archive') => {
|
||||
async (action: 'sleep' | 'archive' | 'restart') => {
|
||||
const plane = await loadCloudControlPlane()
|
||||
if (!plane || !workspace) {
|
||||
return
|
||||
@@ -132,7 +144,9 @@ export function CloudWorkspaceScreen({
|
||||
clearError()
|
||||
setBusyAction(action)
|
||||
try {
|
||||
if (action === 'sleep') {
|
||||
if (action === 'restart') {
|
||||
await restartCloudWorkspace(plane, workspace.id)
|
||||
} else if (action === 'sleep') {
|
||||
await sleepCloudWorkspace(plane, workspace.id)
|
||||
} else {
|
||||
await archiveCloudWorkspace(plane, workspace.id)
|
||||
@@ -141,12 +155,17 @@ export function CloudWorkspaceScreen({
|
||||
} catch (error) {
|
||||
await forgetRevokedCloudSession(error, removal)
|
||||
fail(
|
||||
action === 'archive' && error instanceof CloudRequestError && error.status === 404
|
||||
action === 'restart' && error instanceof CloudRequestError && error.status === 404
|
||||
? t(
|
||||
'cloud.error.archiveUnavailable',
|
||||
'Archiving isn’t available yet. Put it to sleep instead.'
|
||||
'cloud.error.restartOwner',
|
||||
'Only the workspace’s owner can restart it. Your files are safe.'
|
||||
)
|
||||
: attachErrorMessage(error, t)
|
||||
: action === 'archive' && error instanceof CloudRequestError && error.status === 404
|
||||
? t(
|
||||
'cloud.error.archiveUnavailable',
|
||||
'Archiving isn’t available yet. Put it to sleep instead.'
|
||||
)
|
||||
: attachErrorMessage(error, t)
|
||||
)
|
||||
} finally {
|
||||
setBusyAction(null)
|
||||
@@ -157,6 +176,7 @@ export function CloudWorkspaceScreen({
|
||||
)
|
||||
|
||||
if (!workspace) {
|
||||
const missing = cloudMissingState({ enrollment, isPending, isFetching, isError })
|
||||
return (
|
||||
<SafeAreaView style={styles.container} edges={['top']}>
|
||||
<SettingsNavBar
|
||||
@@ -164,15 +184,38 @@ export function CloudWorkspaceScreen({
|
||||
onBack={() => router.back()}
|
||||
/>
|
||||
<View style={styles.centered}>
|
||||
{isPending || isFetching || enrollment === undefined ? (
|
||||
{missing === 'signin' ? (
|
||||
// A share link opened on a phone that isn't connected yet: the list query never runs.
|
||||
<>
|
||||
<Text style={styles.emptyText}>
|
||||
{t('cloud.workspace.signIn', 'Sign in to Orca Cloud on this phone')}
|
||||
</Text>
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
onPress={() => {
|
||||
// Connect on Home, then come straight back to this workspace.
|
||||
setCloudReturnTo(`/cloud/${sandboxId}`)
|
||||
router.replace('/')
|
||||
}}
|
||||
style={styles.linkButton}
|
||||
>
|
||||
<Text style={styles.link}>{t('cloud.workspace.signInAction', 'Sign in')}</Text>
|
||||
</Pressable>
|
||||
</>
|
||||
) : missing === 'loading' ? (
|
||||
<ActivityIndicator color={colors.textMuted} />
|
||||
) : (
|
||||
<>
|
||||
<Text style={styles.emptyText}>
|
||||
{t(
|
||||
'cloud.workspace.missing',
|
||||
'This workspace is gone or you no longer have access.'
|
||||
)}
|
||||
{missing === 'unreachable'
|
||||
? t(
|
||||
'cloud.workspace.unreachable',
|
||||
'Couldn’t reach Orca Cloud. Check your connection and try again.'
|
||||
)
|
||||
: t(
|
||||
'cloud.workspace.missing',
|
||||
'This workspace is gone or you no longer have access.'
|
||||
)}
|
||||
</Text>
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
@@ -188,10 +231,12 @@ export function CloudWorkspaceScreen({
|
||||
)
|
||||
}
|
||||
|
||||
const awake = workspace.status === 'running'
|
||||
// Up either way: a prompt sent now goes out without a wake.
|
||||
const awake = workspace.status === 'running' || workspace.status === 'unresponsive'
|
||||
const unavailable =
|
||||
workspace.status === 'creating' ||
|
||||
workspace.status === 'stopping' ||
|
||||
workspace.status === 'deleting' ||
|
||||
workspace.status === 'archived'
|
||||
const waking =
|
||||
wakePending ||
|
||||
@@ -200,7 +245,9 @@ export function CloudWorkspaceScreen({
|
||||
workspace.status === 'waking'
|
||||
// Asleep, or waking from it: the read-only copy stays readable (header says Waking) until it opens.
|
||||
const showSnapshot = asleep || (waking && !awake && snapshot.data !== undefined)
|
||||
const busy = active || wakePending
|
||||
// Up but not answering: the one thing that helps is a restart (glossary "Restarting").
|
||||
const restartable = workspace.status === 'unresponsive' && run.kind !== 'launched' && !active
|
||||
const busy = active || wakePending || busyAction === 'restart'
|
||||
const primaryLabel = wakePending
|
||||
? phaseLabel('waking', t)
|
||||
: run.kind === 'launched'
|
||||
@@ -213,11 +260,17 @@ export function CloudWorkspaceScreen({
|
||||
? t('cloud.action.settingUp', 'Starting…')
|
||||
: workspace.status === 'archived'
|
||||
? t('cloud.status.archived', 'Archived')
|
||||
: awake
|
||||
? t('cloud.action.open', 'Open workspace')
|
||||
: asleep
|
||||
? t('cloud.action.wakeToContinue', 'Wake to continue')
|
||||
: t('cloud.action.wakeOpen', 'Wake and open workspace')
|
||||
: workspace.status === 'deleting'
|
||||
? t('cloud.status.deleting', 'Deleting')
|
||||
: busyAction === 'restart'
|
||||
? t('cloud.status.restarting', 'Restarting')
|
||||
: restartable
|
||||
? t('cloud.action.restart', 'Restart sandbox')
|
||||
: awake
|
||||
? t('cloud.action.open', 'Open workspace')
|
||||
: asleep
|
||||
? t('cloud.action.wakeToContinue', 'Wake to continue')
|
||||
: t('cloud.action.wakeOpen', 'Wake and open workspace')
|
||||
const primaryDisabled = busy || unavailable
|
||||
|
||||
return (
|
||||
@@ -305,7 +358,7 @@ export function CloudWorkspaceScreen({
|
||||
|
||||
<CloudWorkspaceActions
|
||||
workspace={workspace}
|
||||
busy={busyAction}
|
||||
busy={busyAction === 'restart' ? null : busyAction}
|
||||
disabled={active || busyAction !== null}
|
||||
onSleep={() => void lifecycle('sleep')}
|
||||
onArchive={() => void lifecycle('archive')}
|
||||
@@ -322,6 +375,10 @@ export function CloudWorkspaceScreen({
|
||||
openSession('chat')
|
||||
return
|
||||
}
|
||||
if (restartable) {
|
||||
void lifecycle('restart')
|
||||
return
|
||||
}
|
||||
setWakeTappedAt(run)
|
||||
void start('open').finally(() => setWakeTappedAt(null))
|
||||
}}
|
||||
|
||||
@@ -27,6 +27,9 @@ export type CloudWorkspaceStatus =
|
||||
| 'sleeping'
|
||||
| 'archived'
|
||||
| 'failed'
|
||||
/** Up but not answering (glossary "Not responding"); a restart usually fixes it. */
|
||||
| 'unresponsive'
|
||||
| 'deleting'
|
||||
|
||||
export type CloudWorkspace = {
|
||||
/** The sandbox row id: stable across sleep, wake and rollover. */
|
||||
@@ -57,8 +60,8 @@ const SANDBOX_STATUS: Record<string, CloudWorkspaceStatus> = {
|
||||
sleeping: 'sleeping',
|
||||
archived: 'archived',
|
||||
failed: 'failed',
|
||||
unresponsive: 'failed',
|
||||
destroying: 'stopping'
|
||||
unresponsive: 'unresponsive',
|
||||
destroying: 'deleting'
|
||||
}
|
||||
|
||||
const SandboxViewSchema = z.object({
|
||||
@@ -200,6 +203,20 @@ export async function sleepCloudWorkspace(
|
||||
)
|
||||
}
|
||||
|
||||
/** "Not responding": restart the sandbox (files kept). Owner route; a teammate gets not_found. */
|
||||
export async function restartCloudWorkspace(
|
||||
plane: CloudControlPlane,
|
||||
sandboxId: string
|
||||
): Promise<void> {
|
||||
await request(
|
||||
plane,
|
||||
'POST',
|
||||
`/v1/sandboxes/${encodeURIComponent(sandboxId)}/restart`,
|
||||
z.unknown(),
|
||||
{ body: {}, timeoutMs: 120_000 }
|
||||
)
|
||||
}
|
||||
|
||||
export async function archiveCloudWorkspace(
|
||||
plane: CloudControlPlane,
|
||||
sandboxId: string
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// Where to go once this phone is connected to Orca Cloud: a team link opened before connecting
|
||||
// (e.g. /cloud/<id>) is returned to after "Connect Orca Cloud" on Home succeeds. Memory only, and
|
||||
// short-lived: a user who gave up on that link and connects later isn't sent back to it.
|
||||
|
||||
const TTL_MS = 10 * 60_000
|
||||
let returnTo: { path: string; at: number } | null = null
|
||||
|
||||
export function setCloudReturnTo(path: string, now: number = Date.now()): void {
|
||||
// Only an in-app cloud route, never an arbitrary destination.
|
||||
returnTo = /^\/cloud\/[A-Za-z0-9_-]+$/.test(path) ? { path, at: now } : null
|
||||
}
|
||||
|
||||
export function takeCloudReturnTo(now: number = Date.now()): string | null {
|
||||
const entry = returnTo
|
||||
returnTo = null
|
||||
return entry && now - entry.at <= TTL_MS ? entry.path : null
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { setCloudReturnTo, takeCloudReturnTo } from './cloud-return-to'
|
||||
import { cloudHostGate, cloudMissingState } from './cloud-screen-states'
|
||||
|
||||
const base = { isPending: false, isFetching: false, isError: false }
|
||||
|
||||
describe('cloud workspace screen without its workspace', () => {
|
||||
it('asks a phone that isn’t connected to sign in, instead of spinning on a query that never runs', () => {
|
||||
expect(cloudMissingState({ ...base, enrollment: null, isPending: true })).toBe('signin')
|
||||
})
|
||||
|
||||
it('spins while connecting or fetching, including a retry after an error', () => {
|
||||
expect(cloudMissingState({ ...base, enrollment: undefined })).toBe('loading')
|
||||
expect(cloudMissingState({ ...base, enrollment: {}, isPending: true })).toBe('loading')
|
||||
expect(cloudMissingState({ ...base, enrollment: {}, isError: true, isFetching: true })).toBe(
|
||||
'loading'
|
||||
)
|
||||
})
|
||||
|
||||
it('says Orca Cloud is unreachable on an error, and gone only when the list loaded without it', () => {
|
||||
expect(cloudMissingState({ ...base, enrollment: {}, isError: true, isPending: true })).toBe(
|
||||
'unreachable'
|
||||
)
|
||||
expect(cloudMissingState({ ...base, enrollment: {} })).toBe('gone')
|
||||
})
|
||||
})
|
||||
|
||||
describe('cloud host gate', () => {
|
||||
const known = { enrollment: {}, isPending: false, isError: false }
|
||||
|
||||
it('waits until it knows whether the host is a cloud workspace and what state it is in', () => {
|
||||
expect(cloudHostGate({ ...known, sandboxId: undefined, status: null })).toBe('wait')
|
||||
expect(cloudHostGate({ ...known, sandboxId: 'sbx', isPending: true, status: null })).toBe(
|
||||
'wait'
|
||||
)
|
||||
})
|
||||
|
||||
it('shows "asleep" only for an asleep cloud workspace', () => {
|
||||
expect(cloudHostGate({ ...known, sandboxId: 'sbx', status: 'sleeping' })).toBe('asleep')
|
||||
// Still going to sleep, or awake: the page handles it.
|
||||
expect(cloudHostGate({ ...known, sandboxId: 'sbx', status: 'stopping' })).toBe('pass')
|
||||
expect(cloudHostGate({ ...known, sandboxId: 'sbx', status: 'running' })).toBe('pass')
|
||||
})
|
||||
|
||||
it('passes through for desktops, an unconnected phone, or an unreachable registry', () => {
|
||||
expect(cloudHostGate({ ...known, sandboxId: null, status: null })).toBe('pass')
|
||||
expect(
|
||||
cloudHostGate({ ...known, sandboxId: 'sbx', enrollment: null, isPending: true, status: null })
|
||||
).toBe('pass')
|
||||
expect(cloudHostGate({ ...known, sandboxId: 'sbx', isError: true, status: null })).toBe('pass')
|
||||
})
|
||||
})
|
||||
|
||||
describe('return after connecting', () => {
|
||||
it('returns once to an in-app cloud workspace route, never anywhere else', () => {
|
||||
setCloudReturnTo('/cloud/sbx_abc')
|
||||
expect(takeCloudReturnTo()).toBe('/cloud/sbx_abc')
|
||||
expect(takeCloudReturnTo()).toBeNull()
|
||||
setCloudReturnTo('https://evil.example/cloud/x')
|
||||
expect(takeCloudReturnTo()).toBeNull()
|
||||
// Gave up on the link and connected much later: stay on Home.
|
||||
setCloudReturnTo('/cloud/sbx_abc', 0)
|
||||
expect(takeCloudReturnTo(11 * 60_000)).toBeNull()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,52 @@
|
||||
import type { CloudWorkspaceStatus } from './cloud-control-plane-client'
|
||||
|
||||
// Which state a cloud screen shows while its workspace isn't in hand. Pure, so each branch is tested.
|
||||
|
||||
export type CloudMissingState = 'signin' | 'loading' | 'unreachable' | 'gone'
|
||||
|
||||
/**
|
||||
* The workspace screen without its workspace. Not connected (enrollment null) means the list query
|
||||
* never runs: a share link opened on a fresh phone must ask to sign in, not spin forever. A refetch
|
||||
* after an error shows the spinner again.
|
||||
*/
|
||||
export function cloudMissingState(args: {
|
||||
enrollment: unknown | null | undefined
|
||||
isPending: boolean
|
||||
isFetching: boolean
|
||||
isError: boolean
|
||||
}): CloudMissingState {
|
||||
if (args.enrollment === null) {
|
||||
return 'signin'
|
||||
}
|
||||
if (args.enrollment === undefined || args.isFetching || (args.isPending && !args.isError)) {
|
||||
return 'loading'
|
||||
}
|
||||
return args.isError ? 'unreachable' : 'gone'
|
||||
}
|
||||
|
||||
export type CloudHostGate = 'wait' | 'pass' | 'asleep'
|
||||
|
||||
/**
|
||||
* Before a paired host's page loads: `wait` while it isn't known yet whether this host is an asleep
|
||||
* cloud workspace; `asleep` only for a workspace the registry says is asleep; anything else (not a
|
||||
* cloud host, not connected, registry unreachable, awake) passes through to the page.
|
||||
*/
|
||||
export function cloudHostGate(args: {
|
||||
/** undefined while the host → workspace lookup runs; null when it's not a cloud workspace. */
|
||||
sandboxId: string | null | undefined
|
||||
enrollment: unknown | null | undefined
|
||||
isPending: boolean
|
||||
isError: boolean
|
||||
status: CloudWorkspaceStatus | null
|
||||
}): CloudHostGate {
|
||||
if (args.sandboxId === undefined) {
|
||||
return 'wait'
|
||||
}
|
||||
if (args.sandboxId === null || args.enrollment === null || args.isError) {
|
||||
return 'pass'
|
||||
}
|
||||
if (args.enrollment === undefined || args.isPending) {
|
||||
return 'wait'
|
||||
}
|
||||
return args.status === 'sleeping' ? 'asleep' : 'pass'
|
||||
}
|
||||
@@ -105,6 +105,10 @@ export function statusSentence(
|
||||
return t('cloud.line.archived', 'Unarchive it on your computer to work in it again.')
|
||||
case 'failed':
|
||||
return t('cloud.line.failed', 'The sandbox couldn’t start. Your files are safe.')
|
||||
case 'unresponsive':
|
||||
return t('cloud.line.unresponsive', 'The sandbox isn’t responding. Your files are safe.')
|
||||
case 'deleting':
|
||||
return t('cloud.line.deleting', 'This workspace is being deleted.')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,10 @@ export function cloudStatusLabel(status: CloudWorkspaceStatus, t: Translate): st
|
||||
return t('cloud.status.archived', 'Archived')
|
||||
case 'failed':
|
||||
return t('cloud.status.failed', 'Couldn’t start')
|
||||
case 'unresponsive':
|
||||
return t('cloud.status.unresponsive', 'Not responding')
|
||||
case 'deleting':
|
||||
return t('cloud.status.deleting', 'Deleting')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +37,11 @@ export function cloudStatusColor(status: CloudWorkspaceStatus): string {
|
||||
return colors.textSecondary
|
||||
case 'failed':
|
||||
return colors.statusRed
|
||||
case 'unresponsive':
|
||||
// Glossary: "Not responding" uses the status-warning ink.
|
||||
return colors.statusAmber
|
||||
case 'deleting':
|
||||
return colors.textMuted
|
||||
case 'sleeping':
|
||||
case 'archived':
|
||||
return colors.textMuted
|
||||
@@ -40,7 +49,9 @@ export function cloudStatusColor(status: CloudWorkspaceStatus): string {
|
||||
}
|
||||
|
||||
export function isCloudStatusTransitional(status: CloudWorkspaceStatus): boolean {
|
||||
return status === 'creating' || status === 'waking' || status === 'stopping'
|
||||
return (
|
||||
status === 'creating' || status === 'waking' || status === 'stopping' || status === 'deleting'
|
||||
)
|
||||
}
|
||||
|
||||
const hourFormatters = new Map<string, Intl.NumberFormat>()
|
||||
|
||||
@@ -123,6 +123,12 @@ export async function cloudWorkspaceHostId(sandboxId: string): Promise<string |
|
||||
return host.id
|
||||
}
|
||||
|
||||
/** Which cloud workspace a paired host is, if it is one. */
|
||||
export async function cloudWorkspaceIdForHost(hostId: string): Promise<string | null> {
|
||||
const entry = Object.entries(await readLinks()).find(([, link]) => link.hostId === hostId)
|
||||
return entry?.[0] ?? null
|
||||
}
|
||||
|
||||
export async function cloudWorkspaceHostIds(): Promise<ReadonlySet<string>> {
|
||||
const ids = Object.values(await readLinks()).flatMap((link) => (link.hostId ? [link.hostId] : []))
|
||||
return new Set(ids)
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { Translate } from '../i18n/mobile-i18n'
|
||||
import { listCloudWorkspaces } from './cloud-control-plane-client'
|
||||
import { cloudStatusLabel } from './cloud-workspace-display'
|
||||
|
||||
const t: Translate = (_key, fallback) => fallback
|
||||
|
||||
describe('cloud workspace states (glossary)', () => {
|
||||
it('reads unresponsive as Not responding and destroying as Deleting, never Couldn’t start or Going to sleep', async () => {
|
||||
const plane = {
|
||||
baseUrl: 'https://cp.test',
|
||||
token: () => 'tok',
|
||||
fetch: async (input: RequestInfo | URL) =>
|
||||
new URL(String(input)).pathname === '/v1/sandboxes'
|
||||
? Response.json({
|
||||
sandboxes: [
|
||||
{
|
||||
id: 'sbx_a',
|
||||
workspaceId: 'ws-a',
|
||||
status: 'unresponsive',
|
||||
machineSize: 'standard',
|
||||
createdAt: 1
|
||||
},
|
||||
{
|
||||
id: 'sbx_b',
|
||||
workspaceId: 'ws-b',
|
||||
status: 'destroying',
|
||||
machineSize: 'standard',
|
||||
createdAt: 1
|
||||
}
|
||||
]
|
||||
})
|
||||
: Response.json({ error: 'not_found' }, { status: 404 })
|
||||
}
|
||||
const { workspaces } = await listCloudWorkspaces(plane)
|
||||
expect(workspaces.map((w) => [w.status, cloudStatusLabel(w.status, t)])).toEqual([
|
||||
['unresponsive', 'Not responding'],
|
||||
['deleting', 'Deleting']
|
||||
])
|
||||
})
|
||||
})
|
||||
@@ -24,7 +24,8 @@ import {
|
||||
const TRANSITIONAL: ReadonlySet<CloudWorkspace['status']> = new Set([
|
||||
'creating',
|
||||
'waking',
|
||||
'stopping'
|
||||
'stopping',
|
||||
'deleting'
|
||||
])
|
||||
|
||||
export const cloudWorkspacesQueryKey = (sessionId: string | null) =>
|
||||
|
||||
@@ -113,7 +113,7 @@ export function HostOfflineBanner({
|
||||
onPress={onRetry}
|
||||
accessibilityRole="button"
|
||||
>
|
||||
<Text style={styles.retryText}>{t('common.retry', 'Retry')}</Text>
|
||||
<Text style={styles.retryText}>{t('common.tryAgain', 'Try again')}</Text>
|
||||
</Pressable>
|
||||
) : null}
|
||||
</View>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useRouter } from 'expo-router'
|
||||
import { ChevronRight, Cloud, Plus, RotateCw } from 'lucide-react-native'
|
||||
import { Fragment, useState } from 'react'
|
||||
import { ActivityIndicator, Pressable, Text, View } from 'react-native'
|
||||
@@ -5,6 +6,7 @@ import { CloudStatusDot } from '../cloud/CloudStatusDot'
|
||||
import { formatReadSnapshotAsOf } from '../cloud/CloudReadSnapshotSection'
|
||||
import type { CloudWorkspace } from '../cloud/cloud-control-plane-client'
|
||||
import { CloudEnrollmentError, enrollCloudDevice } from '../cloud/cloud-device-enrollment'
|
||||
import { takeCloudReturnTo } from '../cloud/cloud-return-to'
|
||||
import type { CloudEnrollment } from '../cloud/cloud-device-identity'
|
||||
import { cloudRepoLine, cloudStatusLabel } from '../cloud/cloud-workspace-display'
|
||||
import { useCloudWorkspaces } from '../cloud/use-cloud-workspaces'
|
||||
@@ -212,6 +214,7 @@ function CloudConnectRow({
|
||||
deviceLabel: string
|
||||
}) {
|
||||
const t = useMobileTranslation()
|
||||
const router = useRouter()
|
||||
const [busy, setBusy] = useState(false)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const connect = async () => {
|
||||
@@ -222,6 +225,11 @@ function CloudConnectRow({
|
||||
setError(null)
|
||||
try {
|
||||
await enrollCloudDevice({ desktop: desktop.client, desktopName: desktop.name, deviceLabel })
|
||||
// Arrived here from a team link opened before connecting: go back to that workspace.
|
||||
const next = takeCloudReturnTo()
|
||||
if (next) {
|
||||
router.push(next)
|
||||
}
|
||||
} catch (failure) {
|
||||
const kind = failure instanceof CloudEnrollmentError ? failure.failure : 'unreachable'
|
||||
setError(
|
||||
|
||||
@@ -5001,13 +5001,15 @@
|
||||
},
|
||||
"status": {
|
||||
"waking": "Waking",
|
||||
"cantConnect": "Can’t connect",
|
||||
"archived": "Archived",
|
||||
"creating": "Starting",
|
||||
"running": "Running",
|
||||
"stopping": "Going to sleep",
|
||||
"sleeping": "Asleep",
|
||||
"failed": "Couldn’t start"
|
||||
"failed": "Couldn’t start",
|
||||
"deleting": "Deleting",
|
||||
"restarting": "Restarting",
|
||||
"unresponsive": "Not responding"
|
||||
},
|
||||
"actions": {
|
||||
"sleep": "Sleep",
|
||||
@@ -5039,18 +5041,23 @@
|
||||
"createUnknown": "Lost the connection while starting it. It may still appear in your list. Try again to pick it up.",
|
||||
"rateLimited": "Too many new workspaces at once. Wait a minute, then try again.",
|
||||
"create": "Couldn’t start your cloud workspace. Nothing was created, and you weren’t charged.",
|
||||
"deliver": "The workspace is running, but a prompt didn’t start. Your files are safe."
|
||||
"deliver": "The workspace is running, but a prompt didn’t start. Your files are safe.",
|
||||
"restartOwner": "Only the workspace’s owner can restart it. Your files are safe."
|
||||
},
|
||||
"workspace": {
|
||||
"title": "Cloud workspace",
|
||||
"missing": "This workspace is gone or you no longer have access."
|
||||
"missing": "This workspace is gone or you no longer have access.",
|
||||
"signIn": "Sign in to Orca Cloud on this phone",
|
||||
"signInAction": "Sign in",
|
||||
"unreachable": "Couldn’t reach Orca Cloud. Check your connection and try again."
|
||||
},
|
||||
"action": {
|
||||
"openSession": "Open session",
|
||||
"settingUp": "Starting…",
|
||||
"open": "Open workspace",
|
||||
"wakeOpen": "Wake and open workspace",
|
||||
"wakeToContinue": "Wake to continue"
|
||||
"wakeToContinue": "Wake to continue",
|
||||
"restart": "Restart sandbox"
|
||||
},
|
||||
"phase": {
|
||||
"delivering": "Starting your agent",
|
||||
@@ -5091,7 +5098,9 @@
|
||||
"waking": "Starting up. This usually takes about 5 seconds.",
|
||||
"stopping": "Files are kept.",
|
||||
"archived": "Unarchive it on your computer to work in it again.",
|
||||
"failed": "The sandbox couldn’t start. Your files are safe."
|
||||
"failed": "The sandbox couldn’t start. Your files are safe.",
|
||||
"unresponsive": "The sandbox isn’t responding. Your files are safe.",
|
||||
"deleting": "This workspace is being deleted."
|
||||
},
|
||||
"home": {
|
||||
"heading": "Cloud",
|
||||
@@ -5200,6 +5209,11 @@
|
||||
"asleep_other": "{{hours}} sandbox hours so far. Uses no sandbox hours while asleep.",
|
||||
"running_one": "{{hours}} sandbox hour so far. Uses sandbox hours while running.",
|
||||
"running_other": "{{hours}} sandbox hours so far. Uses sandbox hours while running."
|
||||
},
|
||||
"host": {
|
||||
"asleep": "{{name}} is asleep",
|
||||
"asleepDetail": "Files are kept. Wake it to keep working.",
|
||||
"wake": "Wake"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user