mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 02:47:34 +00:00
refactor(cloud): hosted driver implements the upstream EnvironmentProviderDriver
Upstream now ships the generic interface (results are recipe documents; no lease, rollover, egress or entitlement concepts). Hosted extensions move to hosted-environment-provider.ts: HostedEnvironmentProviderDriver adds renewLease / rollover / leaseExpiresAt / egressInjection, and entitlement denials become HostedEntitlementDeniedError (code unauthorized, reason = deny reason). The capped-session rollover check moves from the shared kit into the hosted test.
This commit is contained in:
@@ -7,7 +7,7 @@ import {
|
||||
type JsonValue
|
||||
} from '../../shared/ephemeral-vm-recipes'
|
||||
import type { EphemeralVmCheckoutMode } from '../../shared/orca-yaml-hook-types'
|
||||
import type { EnvironmentHandle, EnvironmentReady } from './environment-provider-driver'
|
||||
import type { EnvironmentHandle } from './environment-provider-driver'
|
||||
|
||||
const USER_DATA_KEY = 'environmentDriver'
|
||||
|
||||
@@ -19,18 +19,23 @@ const HandleSchema = z
|
||||
})
|
||||
.strict()
|
||||
|
||||
export function environmentReadyToRecipeResult(
|
||||
ready: EnvironmentReady,
|
||||
export function environmentRecipeResult(
|
||||
handle: EnvironmentHandle,
|
||||
orcaServer: { pairingCode: string; projectRoot: string },
|
||||
checkoutMode: EphemeralVmCheckoutMode
|
||||
): EphemeralVmRecipeResult {
|
||||
const userData: Record<string, JsonValue> = {
|
||||
[USER_DATA_KEY]: {
|
||||
driverId: ready.handle.driverId,
|
||||
environmentId: ready.handle.environmentId,
|
||||
driverState: ready.handle.driverState
|
||||
driverId: handle.driverId,
|
||||
environmentId: handle.environmentId,
|
||||
driverState: handle.driverState
|
||||
}
|
||||
}
|
||||
const connection = { ...ready.connection }
|
||||
const connection = {
|
||||
type: 'orca-server' as const,
|
||||
pairingCode: orcaServer.pairingCode,
|
||||
projectRoot: orcaServer.projectRoot
|
||||
}
|
||||
return checkoutMode === 'provisioned-root'
|
||||
? { schemaVersion: 2, checkoutMode: 'provisioned-root', connection, userData }
|
||||
: { schemaVersion: 1, connection, userData }
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
// Orca Cloud's additions on top of the upstream EnvironmentProviderDriver: a lease on a capped
|
||||
// session, rollover onto the same disk, egress-injected secrets and plan entitlement denials.
|
||||
import {
|
||||
EnvironmentProviderError,
|
||||
type EnvironmentHandle,
|
||||
type EnvironmentProviderCallContext,
|
||||
type EnvironmentProviderCapabilities,
|
||||
type EnvironmentProviderDriver,
|
||||
type EnvironmentReady,
|
||||
type EnvironmentSessionInfo,
|
||||
type EnvironmentStatus
|
||||
} from '../environment-providers/environment-provider-driver'
|
||||
|
||||
export type HostedEnvironmentCapabilities = EnvironmentProviderCapabilities &
|
||||
Readonly<{
|
||||
/** Secrets can be injected at the egress proxy instead of living in the VM. */
|
||||
egressInjection: boolean
|
||||
}>
|
||||
|
||||
export type HostedSessionInfo = EnvironmentSessionInfo & {
|
||||
/** When the current Orca lease lapses unless renewed. */
|
||||
leaseExpiresAt: number | null
|
||||
}
|
||||
|
||||
export type HostedStatusSnapshot = {
|
||||
status: EnvironmentStatus
|
||||
session: HostedSessionInfo | null
|
||||
}
|
||||
|
||||
export type HostedEnvironmentReady = EnvironmentReady & { session: HostedSessionInfo }
|
||||
|
||||
// Narrows the upstream return types; still assignable wherever an EnvironmentProviderDriver is expected.
|
||||
export type HostedEnvironmentProviderDriver = Omit<
|
||||
EnvironmentProviderDriver,
|
||||
'capabilities' | 'create' | 'resume' | 'suspend' | 'status'
|
||||
> & {
|
||||
readonly capabilities: HostedEnvironmentCapabilities
|
||||
create(...args: Parameters<EnvironmentProviderDriver['create']>): Promise<HostedEnvironmentReady>
|
||||
resume(
|
||||
handle: EnvironmentHandle,
|
||||
ctx?: EnvironmentProviderCallContext
|
||||
): Promise<HostedEnvironmentReady>
|
||||
suspend(
|
||||
handle: EnvironmentHandle,
|
||||
ctx?: EnvironmentProviderCallContext
|
||||
): Promise<HostedStatusSnapshot>
|
||||
status(
|
||||
handle: EnvironmentHandle,
|
||||
ctx?: EnvironmentProviderCallContext
|
||||
): Promise<HostedStatusSnapshot>
|
||||
/** Keep the capped session alive while Orca reports work. */
|
||||
renewLease(
|
||||
handle: EnvironmentHandle,
|
||||
extendMs: number,
|
||||
ctx?: EnvironmentProviderCallContext
|
||||
): Promise<HostedStatusSnapshot>
|
||||
/** End this session and start a fresh one from the same disk. */
|
||||
rollover(
|
||||
handle: EnvironmentHandle,
|
||||
ctx?: EnvironmentProviderCallContext
|
||||
): Promise<HostedEnvironmentReady>
|
||||
}
|
||||
|
||||
/** The plan refused the start; `reason` is the billing deny reason. Reads as `unauthorized` generically. */
|
||||
export class HostedEntitlementDeniedError extends EnvironmentProviderError {
|
||||
constructor(message: string, reason: string | null) {
|
||||
super('unauthorized', message, reason)
|
||||
this.name = 'HostedEntitlementDeniedError'
|
||||
}
|
||||
}
|
||||
|
||||
export function isHostedEntitlementDenied(error: unknown): error is HostedEntitlementDeniedError {
|
||||
return error instanceof HostedEntitlementDeniedError
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
// HTTPS client for the Orca sandbox control plane. The desktop holds only a short-lived Orca token;
|
||||
// the provider credential never leaves the control plane.
|
||||
import type { z } from 'zod'
|
||||
import { HostedEntitlementDeniedError } from './hosted-environment-provider'
|
||||
import {
|
||||
HostedSandboxErrorResponseSchema,
|
||||
HostedSandboxListResponseSchema,
|
||||
@@ -176,7 +177,6 @@ const STATUS_CODES: Record<string, EnvironmentProviderErrorCode> = {
|
||||
forbidden: 'unauthorized',
|
||||
not_found: 'not_found',
|
||||
conflict: 'conflict',
|
||||
entitlement_denied: 'entitlement_denied',
|
||||
invalid_request: 'invalid_request',
|
||||
invalid_json: 'invalid_request',
|
||||
billing_unavailable: 'unavailable',
|
||||
@@ -187,6 +187,12 @@ const STATUS_CODES: Record<string, EnvironmentProviderErrorCode> = {
|
||||
|
||||
function errorFromResponse(status: number, payload: unknown): EnvironmentProviderError {
|
||||
const parsed = HostedSandboxErrorResponseSchema.safeParse(payload)
|
||||
if (parsed.success && parsed.data.error === 'entitlement_denied') {
|
||||
return new HostedEntitlementDeniedError(
|
||||
'Orca Cloud refused the request (entitlement_denied).',
|
||||
parsed.data.reason ?? null
|
||||
)
|
||||
}
|
||||
if (parsed.success) {
|
||||
const code = STATUS_CODES[parsed.data.error] ?? 'unavailable'
|
||||
return new EnvironmentProviderError(
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { parseEphemeralVmRecipeResult } from '../../shared/ephemeral-vm-recipes'
|
||||
import {
|
||||
getEphemeralVmRecipeResultConnection,
|
||||
parseEphemeralVmRecipeResult
|
||||
} from '../../shared/ephemeral-vm-recipes'
|
||||
import { isEnvironmentProviderError } from '../environment-providers/environment-provider-driver'
|
||||
import { runEnvironmentProviderDriverContract } from '../environment-providers/environment-provider-driver-contract.test-support'
|
||||
import {
|
||||
environmentHandleFromRecipeResult,
|
||||
environmentReadyToRecipeResult
|
||||
environmentRecipeResult
|
||||
} from '../environment-providers/environment-provider-recipe-adapter'
|
||||
import { isHostedEntitlementDenied } from './hosted-environment-provider'
|
||||
import { createHostedSandboxControlPlaneClient } from './hosted-sandbox-control-plane-client'
|
||||
import { createHostedSandboxDriver, HOSTED_SANDBOX_DRIVER_ID } from './hosted-sandbox-driver'
|
||||
import { createFakeHostedControlPlane } from './fake-hosted-control-plane.test-support'
|
||||
@@ -17,7 +21,7 @@ function setup(options: { token?: string; fetch?: typeof fetch } = {}) {
|
||||
getAccessToken: async () => options.token ?? plane.token,
|
||||
fetch: options.fetch ?? plane.fetch
|
||||
})
|
||||
return { plane, driver: createHostedSandboxDriver(client) }
|
||||
return { plane, client, driver: createHostedSandboxDriver(client) }
|
||||
}
|
||||
|
||||
async function rejection(promise: Promise<unknown>): Promise<unknown> {
|
||||
@@ -28,11 +32,12 @@ async function rejection(promise: Promise<unknown>): Promise<unknown> {
|
||||
}
|
||||
|
||||
runEnvironmentProviderDriverContract('HostedSandboxDriver', async () => {
|
||||
const { plane, driver } = setup()
|
||||
const { plane, client, driver } = setup()
|
||||
return {
|
||||
driver,
|
||||
liveEnvironmentIds: async () =>
|
||||
[...plane.sandboxes.values()].filter((s) => s.status !== 'destroyed').map((s) => s.id)
|
||||
[...plane.sandboxes.values()].filter((s) => s.status !== 'destroyed').map((s) => s.id),
|
||||
reopenDriver: () => createHostedSandboxDriver(client)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -41,7 +46,7 @@ describe('HostedSandboxDriver', () => {
|
||||
const { plane, driver } = setup()
|
||||
plane.denyNextStart('included_hours_exhausted')
|
||||
const error = await rejection(driver.create({ workspaceId: 'ws-1' }))
|
||||
expect(isEnvironmentProviderError(error, 'entitlement_denied')).toBe(true)
|
||||
expect(isHostedEntitlementDenied(error)).toBe(true)
|
||||
expect(isEnvironmentProviderError(error) && error.reason).toBe('included_hours_exhausted')
|
||||
})
|
||||
|
||||
@@ -83,7 +88,14 @@ describe('HostedSandboxDriver', () => {
|
||||
it('round-trips through the recipe result the runtime record stores', async () => {
|
||||
const { driver } = setup()
|
||||
const ready = await driver.create({ workspaceId: 'ws-1' })
|
||||
const recipeResult = environmentReadyToRecipeResult(ready, 'provisioned-root')
|
||||
expect(ready.result).toEqual(
|
||||
environmentRecipeResult(ready.handle, readyConnection(ready), 'orca-worktree')
|
||||
)
|
||||
const recipeResult = environmentRecipeResult(
|
||||
ready.handle,
|
||||
readyConnection(ready),
|
||||
'provisioned-root'
|
||||
)
|
||||
const parsed = parseEphemeralVmRecipeResult(JSON.stringify(recipeResult))
|
||||
expect(parsed.ok).toBe(true)
|
||||
if (!parsed.ok) {
|
||||
@@ -97,4 +109,30 @@ describe('HostedSandboxDriver', () => {
|
||||
ready.handle.environmentId
|
||||
)
|
||||
})
|
||||
|
||||
it('keeps a capped session alive and rolls it over onto the same disk', async () => {
|
||||
const { driver } = setup()
|
||||
const created = await driver.create({ workspaceId: 'ws-rollover' })
|
||||
const renewed = await driver.renewLease(created.handle, 10 * 60_000)
|
||||
expect(renewed.status).toBe('running')
|
||||
expect(renewed.session!.leaseExpiresAt!).toBeLessThanOrEqual(renewed.session!.deadlineAt!)
|
||||
|
||||
const rolled = await driver.rollover(created.handle)
|
||||
expect(rolled.handle.environmentId).toBe(created.handle.environmentId)
|
||||
expect(rolled.session.startedAt).toBeGreaterThan(created.session.startedAt)
|
||||
expect(rolled.session.deadlineAt! - rolled.session.startedAt).toBeLessThanOrEqual(
|
||||
driver.capabilities.maxSessionMs!
|
||||
)
|
||||
await driver.destroy(created.handle)
|
||||
})
|
||||
})
|
||||
|
||||
function readyConnection(ready: {
|
||||
result: Parameters<typeof getEphemeralVmRecipeResultConnection>[0]
|
||||
}) {
|
||||
const connection = getEphemeralVmRecipeResultConnection(ready.result)
|
||||
if (connection.type !== 'orca-server') {
|
||||
throw new Error('expected an orca-server connection')
|
||||
}
|
||||
return connection
|
||||
}
|
||||
|
||||
@@ -10,19 +10,22 @@ import {
|
||||
EnvironmentProviderError,
|
||||
isEnvironmentProviderError,
|
||||
type EnvironmentHandle,
|
||||
type EnvironmentProviderCapabilities,
|
||||
type EnvironmentProviderDriver,
|
||||
type EnvironmentReady,
|
||||
type EnvironmentSessionInfo,
|
||||
type EnvironmentStatus,
|
||||
type EnvironmentStatusSnapshot
|
||||
type EnvironmentStatus
|
||||
} from '../environment-providers/environment-provider-driver'
|
||||
import { environmentRecipeResult } from '../environment-providers/environment-provider-recipe-adapter'
|
||||
import type {
|
||||
HostedEnvironmentCapabilities,
|
||||
HostedEnvironmentProviderDriver,
|
||||
HostedEnvironmentReady,
|
||||
HostedSessionInfo,
|
||||
HostedStatusSnapshot
|
||||
} from './hosted-environment-provider'
|
||||
import type { HostedSandboxControlPlaneClient } from './hosted-sandbox-control-plane-client'
|
||||
|
||||
export const HOSTED_SANDBOX_DRIVER_ID = 'orca-cloud'
|
||||
|
||||
/** Measured on Vercel: stop is a reboot (PTYs lost), disk persists, Pro caps a session at 24h. */
|
||||
export const HOSTED_SANDBOX_CAPABILITIES: EnvironmentProviderCapabilities = Object.freeze({
|
||||
export const HOSTED_SANDBOX_CAPABILITIES: HostedEnvironmentCapabilities = Object.freeze({
|
||||
memoryPause: false,
|
||||
maxSessionMs: 24 * 60 * 60_000,
|
||||
fsPersistOnStop: true,
|
||||
@@ -43,13 +46,12 @@ const STATUS: Record<HostedSandboxView['status'], EnvironmentStatus> = {
|
||||
|
||||
export function createHostedSandboxDriver(
|
||||
client: HostedSandboxControlPlaneClient
|
||||
): EnvironmentProviderDriver {
|
||||
): HostedEnvironmentProviderDriver {
|
||||
return {
|
||||
id: HOSTED_SANDBOX_DRIVER_ID,
|
||||
capabilities: HOSTED_SANDBOX_CAPABILITIES,
|
||||
|
||||
async create(spec, ctx) {
|
||||
ctx?.onProgress?.({ phase: 'checking-entitlement' })
|
||||
const machineSize = toMachineSize(spec.machineSize)
|
||||
ctx?.onProgress?.({ phase: 'provisioning' })
|
||||
const ready = await client.create(
|
||||
@@ -94,12 +96,11 @@ export function createHostedSandboxDriver(
|
||||
},
|
||||
|
||||
async renewLease(handle, extendMs, ctx) {
|
||||
ctx?.onProgress?.({ phase: 'renewing' })
|
||||
return toSnapshot(await client.renewLease(sandboxIdOf(handle), extendMs, ctx?.signal))
|
||||
},
|
||||
|
||||
async rollover(handle, ctx) {
|
||||
ctx?.onProgress?.({ phase: 'rolling-over' })
|
||||
ctx?.onProgress?.({ phase: 'resuming' })
|
||||
const ready = await client.rollover(sandboxIdOf(handle), ctx?.signal)
|
||||
ctx?.onProgress?.({ phase: 'connecting' })
|
||||
return toReady(ready)
|
||||
@@ -126,7 +127,7 @@ function sandboxIdOf(handle: EnvironmentHandle): string {
|
||||
return id
|
||||
}
|
||||
|
||||
function toSession(view: HostedSandboxView): EnvironmentSessionInfo | null {
|
||||
function toSession(view: HostedSandboxView): HostedSessionInfo | null {
|
||||
return view.session
|
||||
? {
|
||||
startedAt: view.session.startedAt,
|
||||
@@ -136,11 +137,11 @@ function toSession(view: HostedSandboxView): EnvironmentSessionInfo | null {
|
||||
: null
|
||||
}
|
||||
|
||||
function toSnapshot(view: HostedSandboxView): EnvironmentStatusSnapshot {
|
||||
function toSnapshot(view: HostedSandboxView): HostedStatusSnapshot {
|
||||
return { status: STATUS[view.status], session: toSession(view) }
|
||||
}
|
||||
|
||||
function toReady(ready: HostedSandboxReadyResponse): EnvironmentReady {
|
||||
function toReady(ready: HostedSandboxReadyResponse): HostedEnvironmentReady {
|
||||
const session = toSession(ready.sandbox)
|
||||
if (ready.sandbox.status !== 'running' || !session) {
|
||||
throw new EnvironmentProviderError(
|
||||
@@ -148,13 +149,14 @@ function toReady(ready: HostedSandboxReadyResponse): EnvironmentReady {
|
||||
'Orca Cloud reported a connection for an environment that is not running.'
|
||||
)
|
||||
}
|
||||
const handle: EnvironmentHandle = {
|
||||
driverId: HOSTED_SANDBOX_DRIVER_ID,
|
||||
environmentId: ready.sandbox.id,
|
||||
driverState: { sandboxId: ready.sandbox.id }
|
||||
}
|
||||
return {
|
||||
handle: {
|
||||
driverId: HOSTED_SANDBOX_DRIVER_ID,
|
||||
environmentId: ready.sandbox.id,
|
||||
driverState: { sandboxId: ready.sandbox.id }
|
||||
},
|
||||
connection: ready.connection,
|
||||
handle,
|
||||
result: environmentRecipeResult(handle, ready.connection, 'orca-worktree'),
|
||||
session
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,15 +11,13 @@ import {
|
||||
type RecipeStepProviderResult
|
||||
} from '../../shared/ephemeral-vm-recipe-step-providers'
|
||||
import { getRemoteUrl } from '../git/repo'
|
||||
import { isEnvironmentProviderError } from '../environment-providers/environment-provider-driver'
|
||||
import { environmentHandleFromRecipeResult } from '../environment-providers/environment-provider-recipe-adapter'
|
||||
import {
|
||||
isEnvironmentProviderError,
|
||||
type EnvironmentProviderDriver,
|
||||
type EnvironmentReady
|
||||
} from '../environment-providers/environment-provider-driver'
|
||||
import {
|
||||
environmentHandleFromRecipeResult,
|
||||
environmentReadyToRecipeResult
|
||||
} from '../environment-providers/environment-provider-recipe-adapter'
|
||||
isHostedEntitlementDenied,
|
||||
type HostedEnvironmentProviderDriver,
|
||||
type HostedEnvironmentReady
|
||||
} from './hosted-environment-provider'
|
||||
import { createHostedSandboxControlPlaneClient } from './hosted-sandbox-control-plane-client'
|
||||
import { createHostedSandboxDriver, HOSTED_SANDBOX_DRIVER_ID } from './hosted-sandbox-driver'
|
||||
import type { HostedSandboxConfig } from './hosted-sandbox-config'
|
||||
@@ -43,7 +41,7 @@ const LifecyclePayload = z.looseObject({ recipeResult: EphemeralVmRecipeResultSc
|
||||
|
||||
export function createHostedSandboxRecipeDriver(
|
||||
config: HostedSandboxConfig
|
||||
): EnvironmentProviderDriver {
|
||||
): HostedEnvironmentProviderDriver {
|
||||
return createHostedSandboxDriver(
|
||||
createHostedSandboxControlPlaneClient({
|
||||
baseUrl: config.controlPlaneUrl,
|
||||
@@ -66,7 +64,7 @@ function ok(stdout: string): RecipeStepProviderResult {
|
||||
function failed(error: unknown): RecipeStepProviderResult {
|
||||
const base = { stdout: '', exitCode: 1, signal: null }
|
||||
if (
|
||||
isEnvironmentProviderError(error, 'entitlement_denied') &&
|
||||
isHostedEntitlementDenied(error) &&
|
||||
(error.reason === 'concurrency_limit' || error.reason === 'member_concurrency_limit')
|
||||
) {
|
||||
return {
|
||||
@@ -75,7 +73,7 @@ function failed(error: unknown): RecipeStepProviderResult {
|
||||
failure: ephemeralVmFailure('cloudConcurrencyLimit')
|
||||
}
|
||||
}
|
||||
if (isEnvironmentProviderError(error, 'entitlement_denied')) {
|
||||
if (isHostedEntitlementDenied(error)) {
|
||||
return {
|
||||
...base,
|
||||
stderr: `Orca Cloud: ${error.reason ?? 'no plan'}\n`,
|
||||
@@ -99,9 +97,9 @@ function failed(error: unknown): RecipeStepProviderResult {
|
||||
}
|
||||
|
||||
export function createHostedSandboxStepProvider(
|
||||
driver: EnvironmentProviderDriver,
|
||||
driver: HostedEnvironmentProviderDriver,
|
||||
hooks: {
|
||||
onReady?: (ready: EnvironmentReady) => void
|
||||
onReady?: (ready: HostedEnvironmentReady) => void
|
||||
onStopped?: (environmentId: string) => void
|
||||
} = {}
|
||||
): RecipeStepProvider {
|
||||
@@ -125,7 +123,7 @@ export function createHostedSandboxStepProvider(
|
||||
ctx
|
||||
)
|
||||
hooks.onReady?.(ready)
|
||||
return ok(JSON.stringify(environmentReadyToRecipeResult(ready, 'orca-worktree')))
|
||||
return ok(JSON.stringify(ready.result))
|
||||
}
|
||||
const payload = LifecyclePayload.parse(JSON.parse(stdin ?? '{}'))
|
||||
const handle = payload.recipeResult
|
||||
@@ -137,7 +135,7 @@ export function createHostedSandboxStepProvider(
|
||||
if (mode === 'resume') {
|
||||
const ready = await driver.resume(handle, ctx)
|
||||
hooks.onReady?.(ready)
|
||||
return ok(JSON.stringify(environmentReadyToRecipeResult(ready, 'orca-worktree')))
|
||||
return ok(JSON.stringify(ready.result))
|
||||
}
|
||||
await (mode === 'suspend' ? driver.suspend(handle, ctx) : driver.destroy(handle, ctx))
|
||||
hooks.onStopped?.(handle.environmentId)
|
||||
@@ -149,7 +147,7 @@ export function createHostedSandboxStepProvider(
|
||||
}
|
||||
|
||||
export function registerHostedSandboxRecipe(
|
||||
driver: EnvironmentProviderDriver,
|
||||
driver: HostedEnvironmentProviderDriver,
|
||||
hooks: Parameters<typeof createHostedSandboxStepProvider>[1] = {}
|
||||
): () => void {
|
||||
return registerEphemeralVmRecipeStepProvider(
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
// What to do next with a session-capped, no-memory-pause environment (Vercel: stop = reboot, 24h cap).
|
||||
// Idle stop, the opportunistic refresh and the forced cap rollover are one decision so they never race.
|
||||
import type {
|
||||
EnvironmentProviderCapabilities,
|
||||
EnvironmentSessionInfo
|
||||
} from '../environment-providers/environment-provider-driver'
|
||||
import type { EnvironmentProviderCapabilities } from '../environment-providers/environment-provider-driver'
|
||||
import type { HostedSessionInfo } from './hosted-environment-provider'
|
||||
|
||||
export type HostedActivitySample = {
|
||||
/** orcad's idle probes: clients, terminals, agents, automations. Unverifiable counts as busy. */
|
||||
@@ -36,7 +34,7 @@ export const HOSTED_LEASE_POLICY = {
|
||||
export function decideHostedLeaseAction(input: {
|
||||
now: number
|
||||
capabilities: EnvironmentProviderCapabilities
|
||||
session: EnvironmentSessionInfo
|
||||
session: HostedSessionInfo
|
||||
activity: HostedActivitySample
|
||||
warned: ReadonlySet<HostedLeaseWarning>
|
||||
}): HostedLeaseAction {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// Drives one Orca Cloud environment's session: renews Orca's lease while work runs, warns before the
|
||||
// cap, suspends when idle, and rolls the session over (drain → stop → boot → re-pair → continue agents).
|
||||
import type { EnvironmentHandle } from '../environment-providers/environment-provider-driver'
|
||||
import type {
|
||||
EnvironmentHandle,
|
||||
EnvironmentProviderDriver,
|
||||
EnvironmentReady,
|
||||
EnvironmentSessionInfo
|
||||
} from '../environment-providers/environment-provider-driver'
|
||||
HostedEnvironmentProviderDriver,
|
||||
HostedEnvironmentReady,
|
||||
HostedSessionInfo
|
||||
} from './hosted-environment-provider'
|
||||
import type { HostedAgentAutoResumeOutcome } from './hosted-agent-auto-resume'
|
||||
import {
|
||||
HOSTED_LEASE_POLICY,
|
||||
@@ -16,13 +16,13 @@ import {
|
||||
} from './hosted-session-lease-policy'
|
||||
|
||||
export type HostedSessionLeasePorts = {
|
||||
driver: EnvironmentProviderDriver
|
||||
driver: HostedEnvironmentProviderDriver
|
||||
handle: EnvironmentHandle
|
||||
session: EnvironmentSessionInfo
|
||||
session: HostedSessionInfo
|
||||
readActivity: () => Promise<HostedActivitySample>
|
||||
warn: (minutesLeft: HostedLeaseWarning) => void
|
||||
/** Re-pairs with the rebooted orcad; resolves once the runtime answers again. */
|
||||
reconnect: (ready: EnvironmentReady) => Promise<void>
|
||||
reconnect: (ready: HostedEnvironmentReady) => Promise<void>
|
||||
resumeAgents: (drainStartedAt: number) => Promise<HostedAgentAutoResumeOutcome>
|
||||
onSuspended: () => void
|
||||
/** Replaces the driver suspend, e.g. to run the window's ordinary Sleep for the workspace. */
|
||||
@@ -38,7 +38,7 @@ const UNVERIFIABLE: HostedActivitySample = {
|
||||
}
|
||||
|
||||
export class HostedSessionLeaseScheduler {
|
||||
private session: EnvironmentSessionInfo
|
||||
private session: HostedSessionInfo
|
||||
private readonly warned = new Set<HostedLeaseWarning>()
|
||||
private timer: ReturnType<typeof setTimeout> | null = null
|
||||
private running: Promise<HostedLeaseAction> | null = null
|
||||
@@ -84,7 +84,7 @@ export class HostedSessionLeaseScheduler {
|
||||
})
|
||||
switch (action.kind) {
|
||||
case 'renew': {
|
||||
const renewed = await this.ports.driver.renewLease?.(this.ports.handle, action.extendMs)
|
||||
const renewed = await this.ports.driver.renewLease(this.ports.handle, action.extendMs)
|
||||
if (renewed?.session) {
|
||||
this.session = renewed.session
|
||||
}
|
||||
@@ -117,9 +117,6 @@ export class HostedSessionLeaseScheduler {
|
||||
|
||||
private async rollover(reason: 'opportunistic' | 'forced'): Promise<void> {
|
||||
const { driver, handle } = this.ports
|
||||
if (!driver.rollover) {
|
||||
return
|
||||
}
|
||||
const drainStartedAt = this.now()
|
||||
this.log(`[orca-cloud] ${reason} rollover`)
|
||||
const ready = await driver.rollover(handle)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import type { EnvironmentReady } from '../environment-providers/environment-provider-driver'
|
||||
import type { HostedEnvironmentReady } from './hosted-environment-provider'
|
||||
import { autoResumeAgentsAfterRollover } from './hosted-agent-auto-resume'
|
||||
import { createHostedSandboxControlPlaneClient } from './hosted-sandbox-control-plane-client'
|
||||
import { createHostedSandboxDriver, HOSTED_SANDBOX_CAPABILITIES } from './hosted-sandbox-driver'
|
||||
@@ -76,7 +76,7 @@ describe('hosted session lease scheduler', () => {
|
||||
})
|
||||
)
|
||||
const created = await driver.create({ workspaceId: 'ws-1' })
|
||||
const reconnect = vi.fn(async (_ready: EnvironmentReady) => {})
|
||||
const reconnect = vi.fn(async (_ready: HostedEnvironmentReady) => {})
|
||||
const resumeAgents = vi.fn(async () => ({
|
||||
offered: 2,
|
||||
continued: 2,
|
||||
|
||||
@@ -15,11 +15,9 @@ import { callRuntimeEnvironment } from '../ipc/runtime-environments/runtime-envi
|
||||
import { invalidateRuntimeEnvironmentTransport } from '../ipc/runtime-environments/runtime-environments'
|
||||
import { applyResumedRuntimePairing } from '../ephemeral-vm/runtime-resume-pairing'
|
||||
import { noteRecipeVmWakePairing } from '../ephemeral-vm/recipe-vm-wake-pairings'
|
||||
import type { EnvironmentProviderDriver } from '../environment-providers/environment-provider-driver'
|
||||
import {
|
||||
environmentHandleFromRecipeResult,
|
||||
environmentReadyToRecipeResult
|
||||
} from '../environment-providers/environment-provider-recipe-adapter'
|
||||
import { getEphemeralVmRecipeResultPairingCode } from '../../shared/ephemeral-vm-recipes'
|
||||
import { environmentHandleFromRecipeResult } from '../environment-providers/environment-provider-recipe-adapter'
|
||||
import type { HostedEnvironmentProviderDriver } from './hosted-environment-provider'
|
||||
import { autoResumeAgentsAfterRollover } from './hosted-agent-auto-resume'
|
||||
import { HOSTED_SANDBOX_DRIVER_ID } from './hosted-sandbox-driver'
|
||||
import { createHostedRuntimeEnvironmentCall } from './hosted-runtime-environment-call'
|
||||
@@ -43,7 +41,7 @@ export type HostedSessionRegistry = {
|
||||
|
||||
export function createHostedSessionRegistry(deps: {
|
||||
userDataPath: string
|
||||
driver: EnvironmentProviderDriver
|
||||
driver: HostedEnvironmentProviderDriver
|
||||
windows: () => readonly BrowserWindow[]
|
||||
log?: (line: string) => void
|
||||
}): HostedSessionRegistry {
|
||||
@@ -100,12 +98,12 @@ export function createHostedSessionRegistry(deps: {
|
||||
},
|
||||
reconnect: async (ready) => {
|
||||
updateEphemeralVmRuntimeStatus(deps.userDataPath, runtime.id, {
|
||||
recipeResult: environmentReadyToRecipeResult(ready, 'orca-worktree')
|
||||
recipeResult: ready.result
|
||||
})
|
||||
const { environment } = await applyResumedRuntimePairing({
|
||||
userDataPath: deps.userDataPath,
|
||||
environmentId: runtimeEnvironmentId,
|
||||
pairingCode: ready.connection.pairingCode,
|
||||
pairingCode: getEphemeralVmRecipeResultPairingCode(ready.result) ?? '',
|
||||
invalidateTransport: invalidateRuntimeEnvironmentTransport
|
||||
})
|
||||
noteRecipeVmWakePairing(
|
||||
|
||||
Reference in New Issue
Block a user