mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
fix(cloud): PAIRED-HELD-STRIPS a paired-from-birth Orca Cloud workspace holds and strips like any other
On a workspace created from a GitHub-only repo (a paired server, no local runtime record), #562's shared check makes every strip gate pass; two causes remained: - orcaCloudSandboxIdFor (main) only searched local ephemeral-VM runtime records, so D13's workspace Sources read answered not_found and the expired strip after a revoke never showed; setWorkspaceSource and cloud secrets failed the same way. It now falls back to the pairing binding (same sandbox id). - startCloudWorkspaceFromGitHub launched the agent only with a typed prompt and an already-listed worktree, so a new user who picked Claude never saw "Claude isn't set up · Set up once". It now starts the chosen agent with no prompt (once per create), waits up to 90 s for the repo's first worktree, and if that runs out logs it and says "{{agent}} didn't start because the workspace was still getting ready…" (not over Settings; dismissed once the workspace becomes ready).
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
// PAIRED-HELD-STRIPS: a paired-from-birth Orca Cloud workspace (no local runtime record, only its
|
||||
// pairing binding) resolves in every main-side lookup keyed by its runtime environment: the D13
|
||||
// workspace Sources read, setting a workspace source, and the cloud secrets calls.
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const calls = vi.hoisted(() => {
|
||||
const state: { list: string[] } = { list: [] }
|
||||
return state
|
||||
})
|
||||
const handlers = vi.hoisted(() => new Map<string, (event: unknown, raw: unknown) => unknown>())
|
||||
|
||||
vi.mock('electron', () => ({
|
||||
app: { isPackaged: false, getPath: () => '/u' },
|
||||
shell: { openExternal: vi.fn() },
|
||||
BrowserWindow: { getAllWindows: () => [] },
|
||||
ipcMain: {
|
||||
handle: (channel: string, fn: (event: unknown, raw: unknown) => unknown) => {
|
||||
handlers.set(channel, fn)
|
||||
},
|
||||
removeHandler: (channel: string) => handlers.delete(channel)
|
||||
}
|
||||
}))
|
||||
vi.mock('../../shared/ephemeral-vm-runtime-store', () => ({ listEphemeralVmRuntimes: () => [] }))
|
||||
vi.mock('./hosted-sandbox-config', () => ({
|
||||
getHostedSandboxConfig: () => ({ controlPlaneUrl: 'https://cp.test' })
|
||||
}))
|
||||
vi.mock('../orca-cloud-agents/orca-cloud-agents-service', () => ({
|
||||
createOrcaCloudAgentsService: () => ({
|
||||
workspaceSources: async (workspaceId: string) => {
|
||||
calls.list.push(`sources:${workspaceId}`)
|
||||
return { ok: true, value: {} }
|
||||
},
|
||||
setWorkspaceSource: async (_agent: string, _source: string, workspaceId: string) => {
|
||||
calls.list.push(`setSource:${workspaceId}`)
|
||||
return { ok: true, value: {} }
|
||||
}
|
||||
})
|
||||
}))
|
||||
vi.mock('../cloud-secrets/cloud-secrets-client', async (importOriginal) => ({
|
||||
...(await importOriginal<object>()),
|
||||
createCloudSecretsClient: () => ({
|
||||
workspaceSharing: async (sandboxId: string) => {
|
||||
calls.list.push(`sharing:${sandboxId}`)
|
||||
return {}
|
||||
},
|
||||
refreshEnv: async (sandboxId: string) => {
|
||||
calls.list.push(`refresh:${sandboxId}`)
|
||||
return {}
|
||||
}
|
||||
})
|
||||
}))
|
||||
|
||||
const { noteCloudPairingBindings } =
|
||||
await import('../cloud-workspaces/cloud-paired-environment-ids')
|
||||
const { registerOrcaCloudAgentsHandlers } =
|
||||
await import('../orca-cloud-agents/orca-cloud-agents-ipc')
|
||||
const { registerCloudSecretsHandlers } = await import('../cloud-secrets/cloud-secrets-ipc')
|
||||
|
||||
const call = (channel: string, raw: unknown) => {
|
||||
const handler = handlers.get(channel)
|
||||
if (!handler) {
|
||||
throw new Error(`no handler for ${channel}`)
|
||||
}
|
||||
return handler({}, raw)
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
calls.list = []
|
||||
noteCloudPairingBindings({ sbx_paired: { environmentId: 'env-paired' } })
|
||||
registerOrcaCloudAgentsHandlers('/u')
|
||||
registerCloudSecretsHandlers('/u')
|
||||
})
|
||||
|
||||
describe('a paired workspace resolves in every environment-keyed lookup', () => {
|
||||
it('the D13 workspace Sources read reaches its sandbox', async () => {
|
||||
await call('orcaCloudAgents:workspaceSources', { runtimeEnvironmentId: 'env-paired' })
|
||||
expect(calls.list).toEqual(['sources:sbx_paired'])
|
||||
})
|
||||
|
||||
it('setting a workspace source reaches its sandbox', async () => {
|
||||
await call('orcaCloudAgents:setWorkspaceSource', {
|
||||
agent: 'claude',
|
||||
source: 'sign-in',
|
||||
runtimeEnvironmentId: 'env-paired'
|
||||
})
|
||||
expect(calls.list).toEqual(['setSource:sbx_paired'])
|
||||
})
|
||||
|
||||
it('cloud secrets reach its sandbox', async () => {
|
||||
await call('cloudSecrets:workspaceSharing', { runtimeEnvironmentId: 'env-paired' })
|
||||
await call('cloudSecrets:refreshEnv', { runtimeEnvironmentId: 'env-paired' })
|
||||
expect(calls.list).toEqual(['sharing:sbx_paired', 'refresh:sbx_paired'])
|
||||
})
|
||||
|
||||
it('an environment with no pairing and no runtime still answers not_found', async () => {
|
||||
expect(
|
||||
await call('orcaCloudAgents:workspaceSources', { runtimeEnvironmentId: 'env-other' })
|
||||
).toEqual({ ok: false, error: 'not_found' })
|
||||
expect(calls.list).toEqual([])
|
||||
})
|
||||
})
|
||||
@@ -10,6 +10,8 @@ vi.mock('../environment-providers/environment-provider-recipe-adapter', () => ({
|
||||
}))
|
||||
|
||||
const { orcaCloudSandboxIdFor } = await import('./orca-cloud-sandbox-id')
|
||||
const { noteCloudPairingBindings } =
|
||||
await import('../cloud-workspaces/cloud-paired-environment-ids')
|
||||
|
||||
describe('orcaCloudSandboxIdFor', () => {
|
||||
it('resolves composer-created cloud workspaces whose recipe has no provider (RA-11)', () => {
|
||||
@@ -42,4 +44,12 @@ describe('orcaCloudSandboxIdFor', () => {
|
||||
expect(orcaCloudSandboxIdFor('/u', 'env-d')).toBeNull()
|
||||
expect(orcaCloudSandboxIdFor('/u', 'env-zzz')).toBeNull()
|
||||
})
|
||||
|
||||
it('resolves a paired workspace (no local runtime record) from its pairing binding', () => {
|
||||
runtimes.list = []
|
||||
noteCloudPairingBindings({ sbx_paired: { environmentId: 'env-paired' } })
|
||||
expect(orcaCloudSandboxIdFor('/u', 'env-paired')).toBe('sbx_paired')
|
||||
expect(orcaCloudSandboxIdFor('/u', 'env-unknown')).toBeNull()
|
||||
noteCloudPairingBindings({})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
// The Orca Cloud sandbox id (the control plane's workspaceId) behind a runtime environment on this
|
||||
// computer. Only an Orca Cloud runtime this desktop provisioned resolves, so the renderer can't name
|
||||
// an arbitrary sandbox.
|
||||
// computer. Only an Orca Cloud runtime this desktop provisioned or paired resolves, so the renderer
|
||||
// can't name an arbitrary sandbox.
|
||||
import { listEphemeralVmRuntimes } from '../../shared/ephemeral-vm-runtime-store'
|
||||
import { environmentHandleFromRecipeResult } from '../environment-providers/environment-provider-recipe-adapter'
|
||||
import { HOSTED_SANDBOX_DRIVER_ID } from './hosted-sandbox-driver'
|
||||
import { cloudPairedSandboxesByEnvironment } from '../cloud-workspaces/cloud-paired-environment-ids'
|
||||
|
||||
export function orcaCloudSandboxIdFor(
|
||||
userDataPath: string,
|
||||
@@ -19,5 +20,9 @@ export function orcaCloudSandboxIdFor(
|
||||
const handle = runtime?.recipeResult
|
||||
? environmentHandleFromRecipeResult(runtime.recipeResult, HOSTED_SANDBOX_DRIVER_ID)
|
||||
: null
|
||||
return handle?.environmentId ?? null
|
||||
// PAIRED-HELD-STRIPS: a paired workspace (opened here, created elsewhere or from a GitHub-only
|
||||
// repo) has no local runtime record; its pairing binding names the same sandbox.
|
||||
return (
|
||||
handle?.environmentId ?? cloudPairedSandboxesByEnvironment().get(runtimeEnvironmentId) ?? null
|
||||
)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import { describeError, isUnknownServerFailure } from './cloud-workspace-errors'
|
||||
|
||||
/** On success, the worktree that was revealed (null when its projects are still syncing). */
|
||||
export type OpenOutcome =
|
||||
| { ok: true; worktreeId: string | null }
|
||||
| { ok: true; worktreeId: string | null; hostId?: string }
|
||||
/** `unknownServerError`: the wake failed on the server for no known reason (shared copy). */
|
||||
| { ok: false; message: string; unknownServerError?: boolean }
|
||||
|
||||
@@ -46,7 +46,7 @@ export function cloudWorkspaceTitle(
|
||||
: (repoName ?? w.workspaceId)
|
||||
}
|
||||
|
||||
function firstWorktreeOnHost(hostId: string): string | null {
|
||||
export function firstWorktreeOnHost(hostId: string): string | null {
|
||||
const state = useAppStore.getState()
|
||||
for (const [repoId, worktrees] of Object.entries(selectWorktreesByRepo(state))) {
|
||||
const repo = state.repos.find((r) => r.id === repoId)
|
||||
@@ -106,7 +106,7 @@ async function connectAndReveal(environmentId: string, name: string): Promise<Op
|
||||
)
|
||||
)
|
||||
}
|
||||
return { ok: true, worktreeId }
|
||||
return { ok: true, worktreeId, hostId }
|
||||
}
|
||||
|
||||
/** Drops this device's previous pairing so re-pairing does not leave a dead server and grant. */
|
||||
|
||||
@@ -23917,6 +23917,8 @@
|
||||
"startFailed": "Couldn’t start the cloud workspace. Nothing was created, and you weren’t charged.",
|
||||
"starting": "Starting {{repo}} in Orca Cloud…",
|
||||
"openLater": "Your cloud workspace started, but this computer couldn’t open it yet. Open it from Cloud workspaces.",
|
||||
"agentNotStarted": "{{agent}} didn’t start because the workspace was still getting ready. Start it from the workspace.",
|
||||
"theAgent": "The agent",
|
||||
"showMore": "Show more repositories…",
|
||||
"folderDetail": "Orca Cloud starts from a GitHub repository. This project is a folder on this computer.",
|
||||
"headingShort": "GitHub",
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
// @vitest-environment happy-dom
|
||||
// PAIRED-HELD-STRIPS: "Start in Orca Cloud" from a GitHub-only repo starts the chosen agent once per
|
||||
// create, even with no prompt (its launch is what shows "isn't set up · Set up once" when it can't
|
||||
// run yet); a repo still cloning is waited for, and a wait that runs out says so.
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { useAppStore } from '@/store'
|
||||
|
||||
const mocks = vi.hoisted(() => {
|
||||
const state: {
|
||||
opened: { ok: true; worktreeId: string | null; hostId?: string }
|
||||
worktree: string | null
|
||||
launches: { agent: string; prompt?: string; worktreeId: string }[]
|
||||
toasts: string[]
|
||||
dismissed: string[]
|
||||
} = {
|
||||
opened: { ok: true, worktreeId: 'wt-1' },
|
||||
worktree: null,
|
||||
launches: [],
|
||||
toasts: [],
|
||||
dismissed: []
|
||||
}
|
||||
return state
|
||||
})
|
||||
|
||||
vi.mock('sonner', () => {
|
||||
const toast = Object.assign((text: string) => mocks.toasts.push(text), {
|
||||
loading: () => 'toast-1',
|
||||
error: (text: string) => mocks.toasts.push(text),
|
||||
dismiss: (id?: string) => {
|
||||
if (id) {
|
||||
mocks.dismissed.push(id)
|
||||
}
|
||||
}
|
||||
})
|
||||
return { toast }
|
||||
})
|
||||
vi.mock('@/components/cloud-workspaces/open-cloud-workspace', () => ({
|
||||
openCloudWorkspace: async () => mocks.opened,
|
||||
firstWorktreeOnHost: () => mocks.worktree
|
||||
}))
|
||||
vi.mock('@/lib/agent-session/launch/new-tab/launch-agent-in-new-tab', () => ({
|
||||
launchAgentInNewTabWithOutcome: (args: {
|
||||
agent: string
|
||||
prompt?: string
|
||||
worktreeId: string
|
||||
}) => {
|
||||
mocks.launches.push({ agent: args.agent, prompt: args.prompt, worktreeId: args.worktreeId })
|
||||
}
|
||||
}))
|
||||
vi.mock('@/components/agent-tab-launch-context', () => ({
|
||||
captureAgentTabLaunchContext: () => ({})
|
||||
}))
|
||||
vi.mock('@/lib/agent-session/launch/shortcuts/agent-tab-shortcuts', () => ({
|
||||
resolveDefaultAgentForWorktree: async () => 'claude'
|
||||
}))
|
||||
|
||||
const { startCloudWorkspaceFromGitHub } = await import('./start-cloud-workspace-from-github')
|
||||
|
||||
const request = (prompt: string, agent: string | null = 'claude') => ({
|
||||
repoUrl: 'https://github.com/acme/web',
|
||||
fullName: 'acme/web',
|
||||
prompt,
|
||||
agent
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
mocks.opened = { ok: true, worktreeId: 'wt-1' }
|
||||
mocks.worktree = null
|
||||
mocks.launches = []
|
||||
mocks.toasts = []
|
||||
mocks.dismissed = []
|
||||
Object.defineProperty(window, 'api', {
|
||||
configurable: true,
|
||||
value: {
|
||||
orcaCloudWorkspace: {
|
||||
createFromGitHub: async () => ({ ok: true, value: { sandboxId: 'sbx_1' } })
|
||||
},
|
||||
cloudWorkspaces: { get: async () => ({ ok: true, value: { workspaceId: 'sbx_1' } }) }
|
||||
}
|
||||
})
|
||||
})
|
||||
afterEach(() => vi.useRealTimers())
|
||||
|
||||
describe('startCloudWorkspaceFromGitHub', () => {
|
||||
it('starts the chosen agent with no prompt, once', async () => {
|
||||
await startCloudWorkspaceFromGitHub(request(''))
|
||||
expect(mocks.launches).toEqual([{ agent: 'claude', prompt: undefined, worktreeId: 'wt-1' }])
|
||||
})
|
||||
|
||||
it('sends a typed prompt with it', async () => {
|
||||
await startCloudWorkspaceFromGitHub(request('fix the flaky test'))
|
||||
expect(mocks.launches).toEqual([
|
||||
{ agent: 'claude', prompt: 'fix the flaky test', worktreeId: 'wt-1' }
|
||||
])
|
||||
})
|
||||
|
||||
it('no agent chosen and no prompt: starts nothing', async () => {
|
||||
await startCloudWorkspaceFromGitHub(request('', null))
|
||||
expect(mocks.launches).toEqual([])
|
||||
})
|
||||
|
||||
it('a repo still cloning is waited for, then the agent starts', async () => {
|
||||
mocks.opened = { ok: true, worktreeId: null, hostId: 'runtime:env-1' }
|
||||
const started = startCloudWorkspaceFromGitHub(request(''))
|
||||
await new Promise((resolve) => setTimeout(resolve, 0))
|
||||
expect(mocks.launches).toEqual([])
|
||||
mocks.worktree = 'wt-late'
|
||||
useAppStore.setState({})
|
||||
await started
|
||||
expect(mocks.launches).toEqual([{ agent: 'claude', prompt: undefined, worktreeId: 'wt-late' }])
|
||||
})
|
||||
|
||||
it('a wait that runs out says so and starts nothing', async () => {
|
||||
vi.useFakeTimers()
|
||||
mocks.opened = { ok: true, worktreeId: null, hostId: 'runtime:env-1' }
|
||||
const info = vi.spyOn(console, 'info').mockImplementation(() => undefined)
|
||||
const started = startCloudWorkspaceFromGitHub(request(''))
|
||||
await vi.advanceTimersByTimeAsync(90_000)
|
||||
await started
|
||||
expect(mocks.launches).toEqual([])
|
||||
expect(mocks.toasts.at(-1)).toBe(
|
||||
'Claude didn’t start because the workspace was still getting ready. Start it from the workspace.'
|
||||
)
|
||||
expect(info).toHaveBeenCalledWith(expect.stringContaining('agent was not started'))
|
||||
info.mockRestore()
|
||||
})
|
||||
|
||||
it('the notice goes away if the workspace becomes ready after all', async () => {
|
||||
vi.useFakeTimers()
|
||||
mocks.opened = { ok: true, worktreeId: null, hostId: 'runtime:env-1' }
|
||||
const info = vi.spyOn(console, 'info').mockImplementation(() => undefined)
|
||||
const started = startCloudWorkspaceFromGitHub(request(''))
|
||||
await vi.advanceTimersByTimeAsync(90_000)
|
||||
await started
|
||||
expect(mocks.dismissed).toEqual(['toast-1'])
|
||||
mocks.worktree = 'wt-late'
|
||||
useAppStore.setState({})
|
||||
await vi.advanceTimersByTimeAsync(0)
|
||||
expect(mocks.dismissed).toContain('cloud-agent-not-started:runtime:env-1')
|
||||
info.mockRestore()
|
||||
})
|
||||
})
|
||||
@@ -4,12 +4,16 @@
|
||||
import { toast } from 'sonner'
|
||||
import { useAppStore } from '@/store'
|
||||
import { translate } from '@/i18n/i18n'
|
||||
import { openCloudWorkspace } from '@/components/cloud-workspaces/open-cloud-workspace'
|
||||
import {
|
||||
firstWorktreeOnHost,
|
||||
openCloudWorkspace
|
||||
} from '@/components/cloud-workspaces/open-cloud-workspace'
|
||||
import { launchAgentInNewTabWithOutcome } from '@/lib/agent-session/launch/new-tab/launch-agent-in-new-tab'
|
||||
import { createNonSecureContextUuid } from '../../../../shared/non-secure-context-uuid'
|
||||
import { resolveDefaultAgentForWorktree } from '@/lib/agent-session/launch/shortcuts/agent-tab-shortcuts'
|
||||
import { captureAgentTabLaunchContext } from '@/components/agent-tab-launch-context'
|
||||
import { isTuiAgent } from '../../../../shared/agent-launch/catalog/tui-agent-config'
|
||||
import { tuiAgentDisplayName } from '../../../../shared/agent-launch/catalog/tui-agent-display-names'
|
||||
|
||||
export type StartFromGitHubRequest = {
|
||||
repoUrl: string
|
||||
@@ -56,8 +60,16 @@ export async function startCloudWorkspaceFromGitHub(
|
||||
return true
|
||||
}
|
||||
toast.dismiss(toastId)
|
||||
const worktreeId = opened.worktreeId
|
||||
if (!worktreeId || !request.prompt.trim()) {
|
||||
// PAIRED-HELD-STRIPS: the chosen agent starts even with no prompt (its launch is what shows
|
||||
// "isn't set up · Set up once" when it can't run yet), and a repo still syncing is waited for
|
||||
// rather than dropping the launch.
|
||||
if (!request.prompt.trim() && !isTuiAgent(request.agent)) {
|
||||
return true
|
||||
}
|
||||
const worktreeId =
|
||||
opened.worktreeId ?? (opened.hostId ? await waitForFirstWorktree(opened.hostId) : null)
|
||||
if (!worktreeId) {
|
||||
agentNotStartedNotice(request, opened.hostId)
|
||||
return true
|
||||
}
|
||||
const agent = isTuiAgent(request.agent)
|
||||
@@ -69,10 +81,75 @@ export async function startCloudWorkspaceFromGitHub(
|
||||
...captureAgentTabLaunchContext(worktreeId),
|
||||
agent,
|
||||
worktreeId,
|
||||
prompt: request.prompt,
|
||||
promptDelivery: 'submit-after-ready',
|
||||
...(request.prompt.trim()
|
||||
? { prompt: request.prompt, promptDelivery: 'submit-after-ready' as const }
|
||||
: {}),
|
||||
launchSource: 'unknown'
|
||||
})
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/** How long a freshly paired host may take to list its first worktree (the repo is cloning). */
|
||||
const FIRST_WORKTREE_WAIT_MS = 90_000
|
||||
|
||||
function waitForFirstWorktree(
|
||||
hostId: string,
|
||||
waitMs: number = FIRST_WORKTREE_WAIT_MS
|
||||
): Promise<string | null> {
|
||||
const found = firstWorktreeOnHost(hostId)
|
||||
if (found) {
|
||||
return Promise.resolve(found)
|
||||
}
|
||||
return new Promise((resolve) => {
|
||||
const finish = (worktreeId: string | null): void => {
|
||||
unsubscribe()
|
||||
clearTimeout(timer)
|
||||
resolve(worktreeId)
|
||||
}
|
||||
const unsubscribe = useAppStore.subscribe(() => {
|
||||
const worktreeId = firstWorktreeOnHost(hostId)
|
||||
if (worktreeId) {
|
||||
finish(worktreeId)
|
||||
}
|
||||
})
|
||||
const timer = setTimeout(() => finish(null), waitMs)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Never silent: the workspace opened, but its agent couldn't start because no worktree was listed
|
||||
* in time. Not over Settings (N-03; with no worktree there is no workspace to scope it to), and gone
|
||||
* once the workspace is ready after all.
|
||||
*/
|
||||
function agentNotStartedNotice(request: StartFromGitHubRequest, hostId: string | undefined): void {
|
||||
console.info(
|
||||
`[orca-cloud] ${request.fullName}: no worktree listed in time; the agent was not started`
|
||||
)
|
||||
if (useAppStore.getState().activeView === 'settings') {
|
||||
return
|
||||
}
|
||||
const toastId = `cloud-agent-not-started:${hostId ?? request.fullName}`
|
||||
toast(
|
||||
translate(
|
||||
'components.newWorkspace.cloudOnly.agentNotStarted',
|
||||
'{{agent}} didn’t start because the workspace was still getting ready. Start it from the workspace.',
|
||||
{
|
||||
agent:
|
||||
tuiAgentDisplayName(request.agent ?? '') ??
|
||||
translate('components.newWorkspace.cloudOnly.theAgent', 'The agent')
|
||||
}
|
||||
),
|
||||
{ id: toastId }
|
||||
)
|
||||
if (hostId) {
|
||||
void waitForFirstWorktree(hostId, NOTICE_DISMISS_WAIT_MS).then((worktreeId) => {
|
||||
if (worktreeId) {
|
||||
toast.dismiss(toastId)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/** How long the "didn't start" notice watches for the workspace becoming ready after all. */
|
||||
const NOTICE_DISMISS_WAIT_MS = 10 * 60_000
|
||||
|
||||
Reference in New Issue
Block a user