From e141a74eada055bd3b4f88e765fa46b7a0d8b76d Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Mon, 9 Nov 2026 07:15:51 -0800 Subject: [PATCH] feat(cloud): one idle-sleep constant (ORCA_CLOUD_IDLE_SLEEP_MINUTES = 15) for control plane, desktop scheduler, billing plans and toasts; GET /v1/config serves it (#80) Plans said 15 minutes, the desktop slept at 20. The shared wire module now owns the value; the control plane serves it at GET /v1/config (public product constants), the desktop driver's idleStopMs, billing's Team plan idleSleepMinutes and the billing fixtures read the constant, and the idle-sleep toast already prints the scheduler's value from the event. --- cloud/apps/billing/src/plans.ts | 4 +++- cloud/apps/sandbox-control/src/index.ts | 5 +++++ cloud/apps/sandbox-control/test/config.test.ts | 18 ++++++++++++++++++ .../hosted-sandbox/hosted-sandbox-driver.ts | 3 ++- .../billing/plan-billing-fixtures.ts | 3 ++- .../src/lib/orca-cloud-session-events.ts | 2 +- .../hosted-sandbox/hosted-sandbox-wire.ts | 12 ++++++++++++ 7 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 cloud/apps/sandbox-control/test/config.test.ts diff --git a/cloud/apps/billing/src/plans.ts b/cloud/apps/billing/src/plans.ts index 854b1d5f75a..86f9062f85f 100644 --- a/cloud/apps/billing/src/plans.ts +++ b/cloud/apps/billing/src/plans.ts @@ -6,6 +6,7 @@ // included hour is one hour on the Standard 4 vCPU / 8 GB box and a Large box burns 2x. // Included hours are a MONTHLY per-seat allowance pooled across the org, for annual plans too. import { z } from 'zod' +import { ORCA_CLOUD_IDLE_SLEEP_MINUTES } from '../../../../src/shared/hosted-sandbox/hosted-sandbox-wire' import type { Env } from './env' export const PLAN_IDS = ['team'] as const @@ -65,7 +66,8 @@ export const DEFAULT_PLANS: PlanCatalog = { includedHoursPerSeat: 60, concurrentSandboxesPerSeat: 3, machineSizes: ['standard', 'large'], - idleSleepMinutes: 15, + // Same constant the control plane enforces and serves (GET /v1/config); never a literal here. + idleSleepMinutes: ORCA_CLOUD_IDLE_SLEEP_MINUTES, overageCentsPerHour: 75, defaultSpendCapCents: 2500, maxSpendCapCents: 500_000, diff --git a/cloud/apps/sandbox-control/src/index.ts b/cloud/apps/sandbox-control/src/index.ts index 28c2f13fcb6..91dcaf9e9a6 100644 --- a/cloud/apps/sandbox-control/src/index.ts +++ b/cloud/apps/sandbox-control/src/index.ts @@ -30,6 +30,7 @@ // Operator (OPERATOR_TOKEN): /v1/internal/* (see operator.ts) // Public share links (src/share-gateway.ts): /s//*, plus the root-path cookie fallback // Vercel network-policy forwardURL target (Vercel sandbox OIDC): /v1/egress/proxy +import { ORCA_CLOUD_IDLE_SLEEP_MINUTES } from '../../../../src/shared/hosted-sandbox/hosted-sandbox-wire' import { z } from 'zod' import { maintainPool, poolConfigFromEnv } from './pool' import { authenticateDesktop } from './auth' @@ -751,6 +752,10 @@ export async function handleRequest(request: Request, env: Env, deps: Deps = {}) })) ?? fail('not_found', 404) ) } + if (url.pathname === '/v1/config' && request.method === 'GET') { + // Public product constants (no auth): every client reads these instead of hardcoding them. + return json({ idleSleepMinutes: ORCA_CLOUD_IDLE_SLEEP_MINUTES }) + } if (url.pathname === '/v1/github/dev-connect' && env.SANDBOX_ENV !== 'prod') { // Dev-only, link-shareable start of the user flow: mints a fresh 10-min state per click for a dev: // account (desktop builds call POST /v1/github/connect instead). diff --git a/cloud/apps/sandbox-control/test/config.test.ts b/cloud/apps/sandbox-control/test/config.test.ts new file mode 100644 index 00000000000..1d43a6d9da1 --- /dev/null +++ b/cloud/apps/sandbox-control/test/config.test.ts @@ -0,0 +1,18 @@ +import { describe, expect, it } from 'vitest' +import { + HostedSandboxConfigResponseSchema, + ORCA_CLOUD_IDLE_SLEEP_MINUTES +} from '../../../../src/shared/hosted-sandbox/hosted-sandbox-wire' +import { DEFAULT_PLANS } from '../../billing/src/plans' +import { createHarness } from './harness' + +describe('GET /v1/config', () => { + it('serves the idle-sleep minutes every client reads; billing advertises the same constant', async () => { + const h = await createHarness() + const res = await h.send(new Request('https://sandbox.test/v1/config')) + expect(res.status).toBe(200) + const body = HostedSandboxConfigResponseSchema.parse(await res.json()) + expect(body.idleSleepMinutes).toBe(ORCA_CLOUD_IDLE_SLEEP_MINUTES) + expect(DEFAULT_PLANS.team.idleSleepMinutes).toBe(ORCA_CLOUD_IDLE_SLEEP_MINUTES) + }) +}) diff --git a/src/main/hosted-sandbox/hosted-sandbox-driver.ts b/src/main/hosted-sandbox/hosted-sandbox-driver.ts index 2882ecb4e41..b77dbbab561 100644 --- a/src/main/hosted-sandbox/hosted-sandbox-driver.ts +++ b/src/main/hosted-sandbox/hosted-sandbox-driver.ts @@ -2,6 +2,7 @@ // Which provider runs the VM (Vercel today) is a control-plane detail the desktop never sees. import { HOSTED_SANDBOX_MACHINE_SIZES, + ORCA_CLOUD_IDLE_SLEEP_MINUTES, type HostedSandboxMachineSize, type HostedSandboxReadyResponse, type HostedSandboxView @@ -30,7 +31,7 @@ export const HOSTED_SANDBOX_CAPABILITIES: HostedEnvironmentCapabilities = Object maxSessionMs: 24 * 60 * 60_000, fsPersistOnStop: true, egressInjection: true, - idleStopMs: 20 * 60_000 + idleStopMs: ORCA_CLOUD_IDLE_SLEEP_MINUTES * 60_000 }) const STATUS: Record = { diff --git a/src/renderer/src/components/billing/plan-billing-fixtures.ts b/src/renderer/src/components/billing/plan-billing-fixtures.ts index 396ba70166d..ec3dc45cb75 100644 --- a/src/renderer/src/components/billing/plan-billing-fixtures.ts +++ b/src/renderer/src/components/billing/plan-billing-fixtures.ts @@ -1,5 +1,6 @@ // Shared sample entitlements for billing tests and component fixtures. import type { OrcaBillingEntitlement, OrcaBillingOffers } from '../../../../shared/orca-billing' +import { ORCA_CLOUD_IDLE_SLEEP_MINUTES } from '../../../../shared/hosted-sandbox/hosted-sandbox-wire' const HOUR = 3600 @@ -13,7 +14,7 @@ export const sampleOffers: OrcaBillingOffers = { largeMachineWeight: 2, includedHoursPerSeat: 60, concurrentSandboxesPerSeat: 3, - idleSleepMinutes: 15, + idleSleepMinutes: ORCA_CLOUD_IDLE_SLEEP_MINUTES, overageCentsPerHour: 75, defaultSpendCapCents: 2500 }, diff --git a/src/renderer/src/lib/orca-cloud-session-events.ts b/src/renderer/src/lib/orca-cloud-session-events.ts index 723b8e3bd0b..8bece89fa77 100644 --- a/src/renderer/src/lib/orca-cloud-session-events.ts +++ b/src/renderer/src/lib/orca-cloud-session-events.ts @@ -87,7 +87,7 @@ export function showOrcaCloudPlanUpsell(message: string): void { }) } -/** " slept after 20 minutes idle · Wake": the quiet receipt for an automatic sleep. */ +/** " slept after {{n}} minutes idle · Wake" (n = ORCA_CLOUD_IDLE_SLEEP_MINUTES, via the event): the quiet receipt for an automatic sleep. */ export function showIdleSleepNotice( workspaceId: string, name: string, diff --git a/src/shared/hosted-sandbox/hosted-sandbox-wire.ts b/src/shared/hosted-sandbox/hosted-sandbox-wire.ts index b075d8b4295..133f36be511 100644 --- a/src/shared/hosted-sandbox/hosted-sandbox-wire.ts +++ b/src/shared/hosted-sandbox/hosted-sandbox-wire.ts @@ -2,6 +2,18 @@ // The Worker's tests parse its responses with these schemas, so either side drifting fails a test. import { z } from 'zod' +/** + * Minutes of no agent work and no input before a cloud sandbox sleeps. The one source for every + * surface: the control plane serves it (GET /v1/config), the desktop scheduler enforces it, billing's + * plan card and the idle-sleep toast print it. Never write the number anywhere else. + */ +export const ORCA_CLOUD_IDLE_SLEEP_MINUTES = 15 + +/** GET /v1/config: product constants clients (desktop, mobile, CLI, marketing) must not hardcode. */ +export const HostedSandboxConfigResponseSchema = z.object({ + idleSleepMinutes: z.number().int().positive() +}) + // Billing sells exactly these; larger boxes need a Vercel Enterprise plan. export const HOSTED_SANDBOX_MACHINE_SIZES = ['standard', 'large'] as const export type HostedSandboxMachineSize = (typeof HOSTED_SANDBOX_MACHINE_SIZES)[number]