From 062747a768f92e339070eb1f170412cf0b2a0cc5 Mon Sep 17 00:00:00 2001 From: Neil Date: Mon, 9 Nov 2026 20:14:58 -0800 Subject: [PATCH 1/2] =?UTF-8?q?copy(mobile):=20at-cap=20on=20wake=20names?= =?UTF-8?q?=20the=20owner's=20seat=20from=20the=20team=20registry=20(Alex?= =?UTF-8?q?=20is=20at=20their=20limit=E2=80=A6=20/=20You're=20at=20your=20?= =?UTF-8?q?limit=E2=80=A6);=20generic=20only=20when=20the=20owner=20is=20u?= =?UTF-8?q?nknown?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/cloud/cloud-control-plane-client.ts | 28 +++++ .../src/cloud/cloud-entitlement-copy.test.ts | 102 +++++++++++++++++- mobile/src/cloud/cloud-entitlement-copy.ts | 65 ++++++++--- mobile/src/cloud/cloud-workspace-copy.ts | 7 +- mobile/src/cloud/use-cloud-workspace-run.ts | 14 ++- mobile/src/i18n/locales/en.json | 3 + 6 files changed, 200 insertions(+), 19 deletions(-) diff --git a/mobile/src/cloud/cloud-control-plane-client.ts b/mobile/src/cloud/cloud-control-plane-client.ts index e91dcbf81ff..f04d1e612a2 100644 --- a/mobile/src/cloud/cloud-control-plane-client.ts +++ b/mobile/src/cloud/cloud-control-plane-client.ts @@ -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 { + // 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() diff --git a/mobile/src/cloud/cloud-entitlement-copy.test.ts b/mobile/src/cloud/cloud-entitlement-copy.test.ts index c9f40a74899..49697c7dcee 100644 --- a/mobile/src/cloud/cloud-entitlement-copy.test.ts +++ b/mobile/src/cloud/cloud-entitlement-copy.test.ts @@ -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) => @@ -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)).toContain( + 'if it’s your workspace' + ) + }) +}) + +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 | 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 diff --git a/mobile/src/cloud/cloud-entitlement-copy.ts b/mobile/src/cloud/cloud-entitlement-copy.ts index 55d83792cc3..c2b637dc3f1 100644 --- a/mobile/src/cloud/cloud-entitlement-copy.ts +++ b/mobile/src/cloud/cloud-entitlement-copy.ts @@ -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 { + 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.ownerSeatLimit', + 'The workspace owner is at their limit of running sandboxes, and this workspace runs on their seat.' + ) case 'other': return t('cloud.denied.other', 'Your team’s plan doesn’t allow this right now.') } @@ -78,11 +111,18 @@ 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.teammateSeatLimit', + 'Ask them to put one to sleep, then try again.' + ) + } + if (when === 'existing' && !owner) { 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.' @@ -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) }) } diff --git a/mobile/src/cloud/cloud-workspace-copy.ts b/mobile/src/cloud/cloud-workspace-copy.ts index 102766a138a..76388468114 100644 --- a/mobile/src/cloud/cloud-workspace-copy.ts +++ b/mobile/src/cloud/cloud-workspace-copy.ts @@ -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( diff --git a/mobile/src/cloud/use-cloud-workspace-run.ts b/mobile/src/cloud/use-cloud-workspace-run.ts index bf4076f22c5..70d95e613fc 100644 --- a/mobile/src/cloud/use-cloud-workspace-run.ts +++ b/mobile/src/cloud/use-cloud-workspace-run.ts @@ -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 diff --git a/mobile/src/i18n/locales/en.json b/mobile/src/i18n/locales/en.json index 76d235c38f0..8fa6bb429c1 100644 --- a/mobile/src/i18n/locales/en.json +++ b/mobile/src/i18n/locales/en.json @@ -5131,10 +5131,13 @@ "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.", + "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.", + "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.", From 850f1b8167a3564e736d16a95eed1ec8976411f3 Mon Sep 17 00:00:00 2001 From: Neil Date: Mon, 9 Nov 2026 20:16:18 -0800 Subject: [PATCH 2/2] =?UTF-8?q?copy(mobile):=20W10=20=E2=80=94=20registry-?= =?UTF-8?q?unreachable=20fallback=20without=20the=20parenthetical=20hedge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mobile/src/cloud/cloud-entitlement-copy.test.ts | 6 +++--- mobile/src/cloud/cloud-entitlement-copy.ts | 8 ++++---- mobile/src/i18n/locales/en.json | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mobile/src/cloud/cloud-entitlement-copy.test.ts b/mobile/src/cloud/cloud-entitlement-copy.test.ts index 49697c7dcee..362641a6dde 100644 --- a/mobile/src/cloud/cloud-entitlement-copy.test.ts +++ b/mobile/src/cloud/cloud-entitlement-copy.test.ts @@ -56,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) @@ -84,8 +84,8 @@ describe('per-seat limit on an existing workspace', () => { ).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)).toContain( - 'if it’s your workspace' + 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.' ) }) }) diff --git a/mobile/src/cloud/cloud-entitlement-copy.ts b/mobile/src/cloud/cloud-entitlement-copy.ts index c2b637dc3f1..b62e90662e8 100644 --- a/mobile/src/cloud/cloud-entitlement-copy.ts +++ b/mobile/src/cloud/cloud-entitlement-copy.ts @@ -99,8 +99,8 @@ function problem( ) } return t( - 'cloud.denied.ownerSeatLimit', - 'The workspace owner is at their limit of running sandboxes, and this workspace runs on their seat.' + '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.') @@ -124,8 +124,8 @@ function nextStep( } if (when === 'existing' && !owner) { 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.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.') diff --git a/mobile/src/i18n/locales/en.json b/mobile/src/i18n/locales/en.json index 8fa6bb429c1..0e59444c54f 100644 --- a/mobile/src/i18n/locales/en.json +++ b/mobile/src/i18n/locales/en.json @@ -5130,13 +5130,13 @@ "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.",