mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 10:58:10 +00:00
Merge pull request #158 from nwparker/cloud/cap-owner-seat-copy
docs+copy(cloud): per-seat running cap counts the workspace owner's seat
This commit is contained in:
@@ -63,10 +63,16 @@ everyone not suspended at renewal and prorates later additions.
|
||||
paid, so remove/re-add churn can neither dodge charges nor double-charge honest teams.
|
||||
- **Included hours and caps derive from billed seats**, not raw membership. Adding members never
|
||||
grants hours or concurrency the org hasn't paid for, and the paid peak keeps its hours until renewal.
|
||||
- **Per-member concurrency:** at most 3 running sandboxes per member (`member_concurrency_limit`), on
|
||||
top of the org cap of 3 × billed seats. One seat can't run the whole team's sandboxes.
|
||||
- **Attribution:** usage segments carry the `userId` that started the sandbox (`usage_events.user_id`)
|
||||
for per-member caps, reporting and abuse review.
|
||||
- **Per-seat concurrency counts the workspace owner's seat:** at most 3 running sandboxes per seat
|
||||
(`member_concurrency_limit`), on top of the org cap of 3 × billed seats. A sandbox always counts
|
||||
against its owner's seat (the row's `user_id`), never the seat of whoever wakes, opens or resumes
|
||||
it. The control plane checks every start with `requireStart(row.user_id)`: create, the owner's
|
||||
wake, a teammate's desktop team wake, grant-resume and the phone's team wake. A teammate can't
|
||||
move a sandbox onto their own seat by waking it, and one seat can't run the whole team's
|
||||
sandboxes. The at-cap error a teammate sees names the owner ("Alex already has 3 sandboxes
|
||||
running. This workspace runs on their seat…").
|
||||
- **Attribution:** usage segments carry the sandbox owner's `userId` (`usage_events.user_id`, from
|
||||
the sandbox row), not the waker's, for per-seat caps, reporting and abuse review.
|
||||
- **Membership changes are rate-limited** in auth: 10 per actor and 30 per org per minute
|
||||
(stablyai/orca-cloud#692). **The last owner is protected:** owners can't remove or demote
|
||||
themselves and admins can't act on owners, so an org always keeps an owner (pinned by tests there).
|
||||
|
||||
@@ -52,7 +52,12 @@ describe('entitlementDeniedMessage', () => {
|
||||
expect(
|
||||
entitlementDeniedMessage(denied('member_concurrency_limit'), 'member', 'existing', t)
|
||||
).toBe(
|
||||
'You’re at your limit of running sandboxes. Your files are safe. Put one to sleep or delete it, then try again.'
|
||||
'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.'
|
||||
)
|
||||
expect(
|
||||
entitlementDeniedMessage(denied('member_concurrency_limit'), 'member', 'create', t)
|
||||
).toBe(
|
||||
'You’re at your limit of running sandboxes. Nothing was created, and you weren’t charged. Put one to sleep or delete it, then try again.'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -45,7 +45,7 @@ export async function roleForCloudError(
|
||||
return readCloudRole(plane, signal).catch(() => null)
|
||||
}
|
||||
|
||||
function problem(denial: Denial, t: Translate): string {
|
||||
function problem(denial: Denial, when: 'create' | 'existing', t: Translate): string {
|
||||
switch (denial) {
|
||||
case 'hours':
|
||||
return t('cloud.denied.hours', 'Out of sandbox hours.')
|
||||
@@ -61,16 +61,35 @@ function problem(denial: Denial, t: Translate): string {
|
||||
'Your team is at its limit of running sandboxes (3 per seat).'
|
||||
)
|
||||
case 'memberLimit':
|
||||
return t('cloud.denied.memberLimit', 'You’re at your limit of running sandboxes.')
|
||||
// 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.'
|
||||
)
|
||||
case 'other':
|
||||
return t('cloud.denied.other', 'Your team’s plan doesn’t allow this right now.')
|
||||
}
|
||||
}
|
||||
|
||||
function nextStep(denial: Denial, manager: boolean, t: Translate): string {
|
||||
function nextStep(
|
||||
denial: Denial,
|
||||
manager: boolean,
|
||||
when: 'create' | 'existing',
|
||||
t: Translate
|
||||
): string {
|
||||
switch (denial) {
|
||||
case 'teamLimit':
|
||||
case 'memberLimit':
|
||||
if (when === 'existing') {
|
||||
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.'
|
||||
)
|
||||
}
|
||||
return t('cloud.denied.next.limit', 'Put one to sleep or delete it, then try again.')
|
||||
case 'teamLimit':
|
||||
return t('cloud.denied.next.limit', 'Put one to sleep or delete it, then try again.')
|
||||
case 'hours':
|
||||
return manager
|
||||
@@ -114,11 +133,11 @@ export function entitlementDeniedMessage(
|
||||
const denial = denialOf(error.reason)
|
||||
const manager = role === 'owner' || role === 'admin'
|
||||
return t('cloud.denied.message', '{{problem}} {{safety}} {{next}}', {
|
||||
problem: problem(denial, t),
|
||||
problem: problem(denial, when, 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, t)
|
||||
next: nextStep(denial, manager, when, t)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -5130,9 +5130,11 @@
|
||||
"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.",
|
||||
"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.",
|
||||
"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.",
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
import type { Translate } from '@/i18n/use-translate'
|
||||
import {
|
||||
recordBillingStatus,
|
||||
resetBillingSummary
|
||||
} from '@/components/billing/billing-summary-store'
|
||||
import { sampleOffers, sampleTeam } from '@/components/billing/plan-billing-fixtures'
|
||||
import { describeError } from './cloud-workspace-errors'
|
||||
|
||||
// English defaults with {{slots}} filled, like i18next with no catalog.
|
||||
const t: Translate = (_key, fallback, params) =>
|
||||
fallback.replace(/\{\{(\w+)\}\}/g, (_slot, name: string) => {
|
||||
const value = params?.[name]
|
||||
return typeof value === 'string' || typeof value === 'number' ? String(value) : ''
|
||||
})
|
||||
|
||||
function recordPerSeat(perSeat: number): void {
|
||||
recordBillingStatus({
|
||||
status: 'ok',
|
||||
entitlement: {
|
||||
...sampleTeam,
|
||||
offers: {
|
||||
...sampleOffers,
|
||||
team: { ...sampleOffers.team, concurrentSandboxesPerSeat: perSeat }
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
describe('describeError for the per-seat running cap', () => {
|
||||
afterEach(() => resetBillingSummary())
|
||||
|
||||
it("names the owner's seat when a teammate wakes their workspace", () => {
|
||||
recordPerSeat(3)
|
||||
expect(
|
||||
describeError('entitlement_denied', 'member_concurrency_limit', t, {
|
||||
self: false,
|
||||
name: 'Alex'
|
||||
})
|
||||
).toBe(
|
||||
'Alex already has 3 sandboxes running. This workspace runs on their seat, so ask them to put one to sleep, then try again.'
|
||||
)
|
||||
expect(
|
||||
describeError('entitlement_denied', 'member_concurrency_limit', t, {
|
||||
self: false,
|
||||
name: null
|
||||
})
|
||||
).toMatch(/^The workspace owner already has 3 sandboxes running\./)
|
||||
})
|
||||
|
||||
it('speaks to the owner about their own seat', () => {
|
||||
recordPerSeat(3)
|
||||
expect(
|
||||
describeError('entitlement_denied', 'member_concurrency_limit', t, { self: true, name: 'Me' })
|
||||
).toBe(
|
||||
'You already have 3 sandboxes running, the most one seat can run. Put one to sleep or delete it, then try again.'
|
||||
)
|
||||
})
|
||||
|
||||
it('falls back to copy without numbers before the plan loads', () => {
|
||||
expect(
|
||||
describeError('entitlement_denied', 'member_concurrency_limit', t, {
|
||||
self: false,
|
||||
name: 'Alex'
|
||||
})
|
||||
).toBe(
|
||||
'Alex is at their limit of running sandboxes. This workspace runs on their seat, so ask them to put one to sleep, then try again.'
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -4,7 +4,18 @@ import type { Translate } from '@/i18n/use-translate'
|
||||
import { getLastBillingStatus } from '@/components/billing/billing-summary-store'
|
||||
import { sandboxLimitFromBilling } from '@/components/worktree-creation/vm-build-failure-copy'
|
||||
|
||||
export function describeError(error: string, reason?: string, t: Translate = translate): string {
|
||||
/**
|
||||
* Whose seat a start counts against. The per-seat running cap counts the workspace owner's seat,
|
||||
* not the seat of whoever wakes or opens it (control plane `requireStart(row.user_id)`).
|
||||
*/
|
||||
export type CloudWorkspaceSeatOwner = { self: boolean; name: string | null }
|
||||
|
||||
export function describeError(
|
||||
error: string,
|
||||
reason?: string,
|
||||
t: Translate = translate,
|
||||
owner?: CloudWorkspaceSeatOwner
|
||||
): string {
|
||||
if (error === 'not_found') {
|
||||
return t(
|
||||
'auto.components.cloudWorkspaces.errorNotFound',
|
||||
@@ -25,15 +36,13 @@ export function describeError(error: string, reason?: string, t: Translate = tra
|
||||
"You're at your team's limit of running sandboxes. Put one to sleep or delete it, then try again."
|
||||
)
|
||||
}
|
||||
return reason === 'member_concurrency_limit'
|
||||
? t(
|
||||
'auto.components.cloudWorkspaces.errorMemberConcurrencyLimit',
|
||||
"You're at your limit of running sandboxes. Put one to sleep or delete it, then try again."
|
||||
)
|
||||
: t(
|
||||
'auto.components.cloudWorkspaces.errorEntitlementDenied',
|
||||
"Your team's plan can't start this workspace right now. Your files are safe. Ask an owner or admin to check the plan."
|
||||
)
|
||||
if (reason === 'member_concurrency_limit') {
|
||||
return describeSeatLimit(owner, t)
|
||||
}
|
||||
return t(
|
||||
'auto.components.cloudWorkspaces.errorEntitlementDenied',
|
||||
"Your team's plan can't start this workspace right now. Your files are safe. Ask an owner or admin to check the plan."
|
||||
)
|
||||
}
|
||||
if (error === 'forbidden') {
|
||||
return t(
|
||||
@@ -110,3 +119,32 @@ export function describeInlineError(
|
||||
'Something went wrong. Nothing was changed.'
|
||||
)
|
||||
}
|
||||
|
||||
function describeSeatLimit(owner: CloudWorkspaceSeatOwner | undefined, t: Translate): string {
|
||||
const perSeat = sandboxLimitFromBilling(getLastBillingStatus())?.perSeat
|
||||
if (!owner || owner.self) {
|
||||
return perSeat
|
||||
? t(
|
||||
'auto.components.cloudWorkspaces.errorSeatLimitSelf',
|
||||
'You already have {{value0}} sandboxes running, the most one seat can run. Put one to sleep or delete it, then try again.',
|
||||
{ value0: String(perSeat) }
|
||||
)
|
||||
: t(
|
||||
'auto.components.cloudWorkspaces.errorMemberConcurrencyLimit',
|
||||
"You're at your limit of running sandboxes. Put one to sleep or delete it, then try again."
|
||||
)
|
||||
}
|
||||
const name =
|
||||
owner.name ?? t('auto.components.cloudWorkspaces.seatOwnerFallback', 'The workspace owner')
|
||||
return perSeat
|
||||
? t(
|
||||
'auto.components.cloudWorkspaces.errorSeatLimitOwner',
|
||||
'{{value0}} already has {{value1}} sandboxes running. This workspace runs on their seat, so ask them to put one to sleep, then try again.',
|
||||
{ value0: name, value1: String(perSeat) }
|
||||
)
|
||||
: t(
|
||||
'auto.components.cloudWorkspaces.errorSeatLimitOwnerNoCount',
|
||||
'{{value0}} is at their limit of running sandboxes. This workspace runs on their seat, so ask them to put one to sleep, then try again.',
|
||||
{ value0: name }
|
||||
)
|
||||
}
|
||||
|
||||
@@ -142,7 +142,12 @@ async function pairAndReveal(workspace: CloudWorkspace, name: string): Promise<O
|
||||
}
|
||||
const grant = await api.openGrant(workspace.id)
|
||||
if (!grant.ok) {
|
||||
return { ok: false, message: describeError(grant.error, grant.reason) }
|
||||
// Waking counts against the owner's seat, so a teammate is told whose sandboxes to put to sleep.
|
||||
const owner = {
|
||||
self: workspace.access === 'owner',
|
||||
name: workspace.memberNames?.[workspace.ownerUserId] ?? null
|
||||
}
|
||||
return { ok: false, message: describeError(grant.error, grant.reason, translate, owner) }
|
||||
}
|
||||
const added = await window.api.runtimeEnvironments.verifyAndAddFromPairingCode({
|
||||
name: translate('auto.components.cloudWorkspaces.environmentName', '{{value0}} (cloud)', {
|
||||
|
||||
@@ -20747,6 +20747,10 @@
|
||||
"errorConcurrencyLimit": "You're at your team's limit of running sandboxes. Put one to sleep or delete it, then try again.",
|
||||
"errorConcurrencyLimitCount2": "Your team can run {{value0}} sandboxes at once ({{value1}} per seat). Put one to sleep or delete it, then try again.",
|
||||
"errorMemberConcurrencyLimit": "You're at your limit of running sandboxes. Put one to sleep or delete it, then try again.",
|
||||
"errorSeatLimitSelf": "You already have {{value0}} sandboxes running, the most one seat can run. Put one to sleep or delete it, then try again.",
|
||||
"errorSeatLimitOwner": "{{value0}} already has {{value1}} sandboxes running. This workspace runs on their seat, so ask them to put one to sleep, then try again.",
|
||||
"errorSeatLimitOwnerNoCount": "{{value0}} is at their limit of running sandboxes. This workspace runs on their seat, so ask them to put one to sleep, then try again.",
|
||||
"seatOwnerFallback": "The workspace owner",
|
||||
"errorConflict": "This workspace is still starting or going to sleep. Nothing was changed. Try again in a moment.",
|
||||
"errorConflictInline": "This workspace is still starting or going to sleep. Nothing was changed.",
|
||||
"errorEntitlementDenied": "Your team's plan can't start this workspace right now. Your files are safe. Ask an owner or admin to check the plan.",
|
||||
|
||||
Reference in New Issue
Block a user