Merge pull request #160 from nwparker/cloud/phone-owner-seat-copy

copy(mobile): at-cap on wake names the owner's seat
This commit is contained in:
Neil
2026-11-09 20:17:36 -08:00
committed by GitHub
6 changed files with 205 additions and 24 deletions
@@ -1,6 +1,7 @@
import { z } from 'zod'
import {
CloudWorkspaceListResponseSchema,
CloudWorkspaceResponseSchema,
type CloudWorkspace as TeamWorkspace
} from '../../../src/shared/cloud-workspaces/cloud-workspaces-wire'
import {
@@ -294,6 +295,33 @@ export async function isCloudWorkspaceGoneFromRegistry(
}
}
/** Whose seat a start counts against: the per-seat running cap counts the workspace owner's. */
export type CloudSeatOwner = { self: boolean; name: string | null }
/**
* The workspace's owner as the team registry names them (GET /v1/team/workspaces/:id), so an
* at-cap error can say whose seat is full. `self` comes from the registry's `access`, not a
* client-side id compare.
*/
export async function readCloudWorkspaceOwner(
plane: CloudControlPlane,
sandboxId: string,
signal?: AbortSignal
): Promise<CloudSeatOwner> {
// Short, like the role read: the denial is already known and the generic copy is the fallback.
const { workspace } = await request(
plane,
'GET',
`/v1/team/workspaces/${encodeURIComponent(sandboxId)}`,
CloudWorkspaceResponseSchema,
{ timeoutMs: 3_000, signal }
)
return {
self: workspace.access === 'owner',
name: workspace.memberNames?.[workspace.ownerUserId] ?? null
}
}
export type CloudRole = 'owner' | 'admin' | 'member'
const MeSchema = z.object({ role: z.enum(['owner', 'admin', 'member']) }).passthrough()
+102 -2
View File
@@ -1,7 +1,11 @@
import { describe, expect, it } from 'vitest'
import type { Translate } from '../i18n/mobile-i18n'
import { CloudRequestError } from './cloud-control-plane-request'
import { entitlementDeniedMessage, roleForCloudError } from './cloud-entitlement-copy'
import {
entitlementDeniedMessage,
ownerForCloudError,
roleForCloudError
} from './cloud-entitlement-copy'
// The fallback text with {{vars}} filled in, as i18next does for a missing key.
const t: Translate = (_key, fallback, options) =>
@@ -52,7 +56,7 @@ describe('entitlementDeniedMessage', () => {
expect(
entitlementDeniedMessage(denied('member_concurrency_limit'), 'member', 'existing', t)
).toBe(
'The workspace owner is at their limit of running sandboxes, and this workspace runs on their seat. Your files are safe. Ask them to put one to sleep (or put one to sleep yourself if it’s your workspace), then try again.'
'This workspace’s owner is at their limit of running sandboxes. Your files are safe. Ask the owner to put one to sleep, or if it’s your workspace, put one to sleep or delete it, then try again.'
)
expect(
entitlementDeniedMessage(denied('member_concurrency_limit'), 'member', 'create', t)
@@ -62,6 +66,102 @@ describe('entitlementDeniedMessage', () => {
})
})
describe('per-seat limit on an existing workspace', () => {
it('names the teammate whose seat is full, speaks to the owner directly, and hedges only when unknown', () => {
const error = denied('member_concurrency_limit')
expect(
entitlementDeniedMessage(error, 'member', 'existing', t, { self: false, name: 'Alex' })
).toBe(
'Alex is at their limit of running sandboxes, and this workspace runs on their seat. Your files are safe. Ask them to put one to sleep, then try again.'
)
expect(
entitlementDeniedMessage(error, 'member', 'existing', t, { self: false, name: null })
).toMatch(
/^The workspace owner is at their limit of running sandboxes, and this workspace runs on their seat\. Your files are safe\. Ask them to put one to sleep, then try again\.$/
)
expect(
entitlementDeniedMessage(error, 'owner', 'existing', t, { self: true, name: 'Me' })
).toBe(
'You’re at your limit of running sandboxes. Your files are safe. Put one to sleep or delete it, then try again.'
)
expect(entitlementDeniedMessage(error, 'member', 'existing', t, null)).toBe(
'This workspace’s owner is at their limit of running sandboxes. Your files are safe. Ask the owner to put one to sleep, or if it’s your workspace, put one to sleep or delete it, then try again.'
)
})
})
describe('ownerForCloudError', () => {
const plane = (body: unknown, status = 200) => {
const paths: string[] = []
return {
paths,
plane: {
baseUrl: 'https://cp.test',
token: () => 'tok',
fetch: async (url: string | URL | Request) => {
paths.push(new URL(String(url)).pathname)
return new Response(JSON.stringify(body), { status })
}
}
}
}
const row = (access: string, names: Record<string, string> | undefined) => ({
workspace: {
id: 'sbx_1',
workspaceId: 'ws_1',
status: 'suspended',
machineSize: 'standard',
region: 'iad1',
createdAt: 1,
title: 'Fix login',
repo: null,
visibility: 'team',
section: null,
archivedAt: null,
createdBy: 'usr_alex',
ownerUserId: 'usr_alex',
lastActivityAt: 1,
lastActivityBy: null,
cost: {
computeMs: 0,
rateUsdMicrosPerHour: 0,
computeUsdMicros: 0,
tokenUsdMicros: null,
totalUsdMicros: 0
},
access,
presence: [],
memberNames: names
}
})
it('reads the owner from the team registry only for a per-seat limit', async () => {
const teammate = plane(row('can_open', { usr_alex: 'Alex' }))
await expect(
ownerForCloudError(denied('member_concurrency_limit'), teammate.plane, 'sbx_1')
).resolves.toEqual({ self: false, name: 'Alex' })
expect(teammate.paths).toEqual(['/v1/team/workspaces/sbx_1'])
const mine = plane(row('owner', undefined))
await expect(
ownerForCloudError(denied('member_concurrency_limit'), mine.plane, 'sbx_1')
).resolves.toEqual({ self: true, name: null })
const other = plane(row('can_open', {}))
await expect(
ownerForCloudError(denied('concurrency_limit'), other.plane, 'sbx_1')
).resolves.toBe(null)
expect(other.paths).toEqual([])
})
it('falls back to null (generic copy) when the registry cannot answer', async () => {
const failing = plane({ error: 'not_found' }, 404)
await expect(
ownerForCloudError(denied('member_concurrency_limit'), failing.plane, 'sbx_1')
).resolves.toBeNull()
})
})
describe('roleForCloudError', () => {
it('reads the role only for a plan denial, and falls back to null when it cannot', async () => {
let calls = 0
+55 -14
View File
@@ -1,5 +1,10 @@
import type { Translate } from '../i18n/mobile-i18n'
import { readCloudRole, type CloudRole } from './cloud-control-plane-client'
import {
readCloudRole,
readCloudWorkspaceOwner,
type CloudRole,
type CloudSeatOwner
} from './cloud-control-plane-client'
import { CloudRequestError, type CloudControlPlane } from './cloud-control-plane-request'
// What the phone says when the plan says no (glossary "Out of hours", "Payment problem"): what
@@ -45,7 +50,25 @@ export async function roleForCloudError(
return readCloudRole(plane, signal).catch(() => null)
}
function problem(denial: Denial, when: 'create' | 'existing', t: Translate): string {
/** Only a per-seat limit on an existing workspace needs its owner; anything else reads nothing. */
export async function ownerForCloudError(
error: unknown,
plane: CloudControlPlane | null,
sandboxId: string,
signal?: AbortSignal
): Promise<CloudSeatOwner | null> {
if (!plane || !isEntitlementDenied(error) || error.reason !== 'member_concurrency_limit') {
return null
}
return readCloudWorkspaceOwner(plane, sandboxId, signal).catch(() => null)
}
function problem(
denial: Denial,
when: 'create' | 'existing',
owner: CloudSeatOwner | null,
t: Translate
): string {
switch (denial) {
case 'hours':
return t('cloud.denied.hours', 'Out of sandbox hours.')
@@ -63,12 +86,22 @@ function problem(denial: Denial, when: 'create' | 'existing', t: Translate): str
case 'memberLimit':
// The per-seat cap counts the workspace owner's seat, not the seat of whoever wakes it, and
// the phone can't always tell whose workspace this is, so an existing one names the owner.
return when === 'create'
? t('cloud.denied.memberLimit', 'You’re at your limit of running sandboxes.')
: t(
'cloud.denied.ownerSeatLimit',
'The workspace owner is at their limit of running sandboxes, and this workspace runs on their seat.'
)
if (when === 'create' || owner?.self) {
return t('cloud.denied.memberLimit', 'You’re at your limit of running sandboxes.')
}
if (owner) {
return t(
'cloud.denied.teammateSeatLimit',
'{{name}} is at their limit of running sandboxes, and this workspace runs on their seat.',
{
name: owner.name ?? t('cloud.denied.seatOwnerFallback', 'The workspace owner')
}
)
}
return t(
'cloud.denied.ownerSeatLimit2',
'This workspace’s owner is at their limit of running sandboxes.'
)
case 'other':
return t('cloud.denied.other', 'Your team’s plan doesn’t allow this right now.')
}
@@ -78,14 +111,21 @@ function nextStep(
denial: Denial,
manager: boolean,
when: 'create' | 'existing',
owner: CloudSeatOwner | null,
t: Translate
): string {
switch (denial) {
case 'memberLimit':
if (when === 'existing') {
if (when === 'existing' && owner && !owner.self) {
return t(
'cloud.denied.next.ownerSeatLimit',
'Ask them to put one to sleep (or put one to sleep yourself if it’s your workspace), then try again.'
'cloud.denied.next.teammateSeatLimit',
'Ask them to put one to sleep, then try again.'
)
}
if (when === 'existing' && !owner) {
return t(
'cloud.denied.next.ownerSeatLimit2',
'Ask the owner to put one to sleep, or if it’s your workspace, put one to sleep or delete it, then try again.'
)
}
return t('cloud.denied.next.limit', 'Put one to sleep or delete it, then try again.')
@@ -128,16 +168,17 @@ export function entitlementDeniedMessage(
error: CloudRequestError,
role: CloudRole | null,
when: 'create' | 'existing',
t: Translate
t: Translate,
owner: CloudSeatOwner | null = null
): string {
const denial = denialOf(error.reason)
const manager = role === 'owner' || role === 'admin'
return t('cloud.denied.message', '{{problem}} {{safety}} {{next}}', {
problem: problem(denial, when, t),
problem: problem(denial, when, owner, t),
safety:
when === 'create'
? t('cloud.denied.safety.create', 'Nothing was created, and you weren’t charged.')
: t('cloud.denied.safety.existing', 'Your files are safe.'),
next: nextStep(denial, manager, when, t)
next: nextStep(denial, manager, when, owner, t)
})
}
+4 -3
View File
@@ -1,6 +1,6 @@
import type { Translate } from '../i18n/mobile-i18n'
import { isRpcDeliveryUnknown } from '../transport/rpc/rpc-delivery-ambiguity'
import type { CloudRole, CloudWorkspace } from './cloud-control-plane-client'
import type { CloudRole, CloudSeatOwner, CloudWorkspace } from './cloud-control-plane-client'
import { CloudRequestError } from './cloud-control-plane-request'
import { CloudAttachError, type CloudAttachPhase } from './cloud-workspace-attach'
import { entitlementDeniedMessage } from './cloud-entitlement-copy'
@@ -12,7 +12,8 @@ import { formatElapsed } from './cloud-workspace-display'
export function attachErrorMessage(
error: unknown,
t: Translate,
role: CloudRole | null = null
role: CloudRole | null = null,
owner: CloudSeatOwner | null = null
): string {
if (error instanceof CloudAttachError) {
switch (error.code) {
@@ -51,7 +52,7 @@ export function attachErrorMessage(
)
}
if (error.code === 'entitlement_denied') {
return entitlementDeniedMessage(error, role, 'existing', t)
return entitlementDeniedMessage(error, role, 'existing', t, owner)
}
if (error.code === 'network_error' || error.code === 'timeout') {
return t(
+11 -3
View File
@@ -34,7 +34,7 @@ import {
launchCloudPrompt,
type CloudLaunchedAgent
} from './cloud-workspace-host-operations'
import { roleForCloudError } from './cloud-entitlement-copy'
import { ownerForCloudError, roleForCloudError } from './cloud-entitlement-copy'
import { cloudWorkspaceProjectRoot, recordCloudWorkspaceHost } from './cloud-workspace-links'
import { removeHostAndCloseClient } from '../transport/hosts/host-removal-lifecycle'
import { useInvalidateCloudWorkspaces } from './use-cloud-workspaces'
@@ -261,11 +261,19 @@ export function useCloudWorkspaceRun(sandboxId: string, workspace: CloudWorkspac
}
// Prompts that were going out with this attach now say so, instead of "waiting".
await markWaitingCloudPromptsFailed(sandboxId, 'not_connected').catch(() => undefined)
const role = await roleForCloudError(error, plane, controller.signal)
// A per-seat limit counts the owner's seat, so the message names whose it is.
const [role, owner] = await Promise.all([
roleForCloudError(error, plane, controller.signal),
ownerForCloudError(error, plane, sandboxId, controller.signal)
])
if (controller.signal.aborted || !mountedRef.current) {
return
}
setRun({ kind: 'error', message: attachErrorMessage(error, t, role), retry: intent })
setRun({
kind: 'error',
message: attachErrorMessage(error, t, role, owner),
retry: intent
})
invalidate()
} finally {
inFlight.current = false
+5 -2
View File
@@ -5130,11 +5130,14 @@
"plan": "Orca Cloud needs a Team plan.",
"teamLimit": "Your team is at its limit of running sandboxes (3 per seat).",
"memberLimit": "You’re at your limit of running sandboxes.",
"ownerSeatLimit": "The workspace owner is at their limit of running sandboxes, and this workspace runs on their seat.",
"ownerSeatLimit2": "This workspace’s owner is at their limit of running sandboxes.",
"teammateSeatLimit": "{{name}} is at their limit of running sandboxes, and this workspace runs on their seat.",
"seatOwnerFallback": "The workspace owner",
"other": "Your team’s plan doesn’t allow this right now.",
"next": {
"limit": "Put one to sleep or delete it, then try again.",
"ownerSeatLimit": "Ask them to put one to sleep (or put one to sleep yourself if it’s your workspace), then try again.",
"ownerSeatLimit2": "Ask the owner to put one to sleep, or if it’s your workspace, put one to sleep or delete it, then try again.",
"teammateSeatLimit": "Ask them to put one to sleep, then try again.",
"hoursAdmin": "Turn on overage in Orca on your computer, then try again.",
"hoursMember": "Ask an owner or admin to add hours.",
"capAdmin": "Raise the spend cap in Orca on your computer, then try again.",