Merge pull request #289 from nwparker/cloud/agents-provider-state

fix(cloud): tell 'provider never offered' (flag off) from the kill switch
This commit is contained in:
Neil
2026-11-10 09:10:58 -08:00
committed by GitHub
17 changed files with 225 additions and 27 deletions
@@ -1,5 +1,5 @@
// Account credentials for agents (agent-sources contract D11): one per person per agent, Personal only.
// GET /v1/agent-credentials -> {claude, codex: {state, label?, expiresAt?}, providerEnabled}
// GET /v1/agent-credentials -> {claude, codex: {state, label?, expiresAt?}, providerEnabled, providerState}
// PUT /v1/agent-credentials/claude {token, label?, expiresAt?} (flag S1; desktop main runs `claude setup-token`)
// DELETE /v1/agent-credentials/:agent
// Values are never returned or logged. They leave the Worker only when the egress proxy swaps them into a
@@ -42,12 +42,24 @@ export class AgentCredentialError extends Error {
/** The AAD every account credential is sealed with; the Codex lease refresher must reuse it exactly. */
export const credentialBinding = (userId: string, agent: CredentialAgent): SecretBinding => ({ scope: 'account', ownerId: userId, name: agent })
/**
* Why a provider is or isn't usable, so clients word it right: `off` = flag S1/S2 not on (never offered here),
* `disabled` = the operator kill switch on a launched provider (temporary).
*/
export type ProviderState = 'on' | 'off' | 'disabled'
export function providerStates(env: Pick<Env, 'AGENT_ACCOUNTS_CLAUDE' | 'AGENT_ACCOUNTS_CLAUDE_DISABLED' | 'AGENT_ACCOUNTS_CODEX' | 'AGENT_ACCOUNTS_CODEX_DISABLED'>): Record<CredentialAgent, ProviderState> {
const state = (flag: string | undefined, disabled: string | undefined): ProviderState => (flag !== 'on' ? 'off' : disabled === '1' ? 'disabled' : 'on')
return {
claude: state(env.AGENT_ACCOUNTS_CLAUDE, env.AGENT_ACCOUNTS_CLAUDE_DISABLED),
codex: state(env.AGENT_ACCOUNTS_CODEX, env.AGENT_ACCOUNTS_CODEX_DISABLED)
}
}
/** Flags S1/S2 turn a provider on; the *_DISABLED switch turns it off again (kill switch, operator-only). */
export function providerEnabled(env: Pick<Env, 'AGENT_ACCOUNTS_CLAUDE' | 'AGENT_ACCOUNTS_CLAUDE_DISABLED' | 'AGENT_ACCOUNTS_CODEX' | 'AGENT_ACCOUNTS_CODEX_DISABLED'>): Record<CredentialAgent, boolean> {
return {
claude: env.AGENT_ACCOUNTS_CLAUDE === 'on' && env.AGENT_ACCOUNTS_CLAUDE_DISABLED !== '1',
codex: env.AGENT_ACCOUNTS_CODEX === 'on' && env.AGENT_ACCOUNTS_CODEX_DISABLED !== '1'
}
const states = providerStates(env)
return { claude: states.claude === 'on', codex: states.codex === 'on' }
}
export function credentialState(row: Pick<CredentialRow, 'state' | 'expires_at'> | null, now: number): CredentialState {
@@ -129,7 +141,7 @@ export async function agentCredentialsView(db: D1Database, env: Env, userId: str
const state = credentialState(row, now)
return { state, ...(row?.label ? { label: row.label } : {}), ...(row?.expires_at ? { expiresAt: row.expires_at } : {}) }
}
return { claude: view('claude'), codex: view('codex'), providerEnabled: providerEnabled(env) }
return { claude: view('claude'), codex: view('codex'), providerEnabled: providerEnabled(env), providerState: providerStates(env) }
}
// A Claude setup-token: `sk-ant-oat01-` then URL-safe characters. Shape-checked, never logged.
@@ -95,6 +95,8 @@ describe('Orca-account credentials (D11)', () => {
expect(put.status).toBe(200)
expect(put.body.claude).toMatchObject({ state: 'active', label: 'mia@example.com' })
expect(put.body.providerEnabled).toEqual({ claude: true, codex: false })
// Codex's flag was never turned on: `off`, which clients word differently from the kill switch.
expect(put.body.providerState).toEqual({ claude: 'on', codex: 'off' })
expect(JSON.stringify(put.body)).not.toContain(SETUP_TOKEN)
// Someone else sees nothing of Mia's.
expect((await h.call('GET', '/v1/agent-credentials', { bearer: await as('bob') })).body.claude.state).toBe('none')
@@ -197,7 +199,9 @@ describe('egress-time Source (D10) and shared workspaces (D13)', () => {
const env = lastEnv(START_COMMAND)
expect(env.CLAUDE_CODE_OAUTH_TOKEN).toBeUndefined()
expect(env.ANTHROPIC_API_KEY).toBeUndefined()
expect((await h.call('GET', '/v1/agent-credentials', { bearer: mia })).body.providerEnabled.claude).toBe(false)
const view = (await h.call('GET', '/v1/agent-credentials', { bearer: mia })).body
expect(view.providerEnabled.claude).toBe(false)
expect(view.providerState.claude).toBe('disabled')
})
})
@@ -148,6 +148,20 @@ export function AccountRow({
/>
)
break
case 'unavailable':
content = (
<RowShell
agent={agent}
tone="info"
title={t('orcaCloudAccounts.unavailable', 'Signs in for each cloud workspace')}
detail={t(
'orcaCloudAccounts.unavailableDetail',
'Signing in once with your {{product}} account isn’t available in Orca Cloud yet. Each new cloud workspace asks you to sign in.',
{ product }
)}
/>
)
break
}
if (!rowError) {
return content
@@ -156,6 +156,18 @@ export const killSwitch = fixture({
codex: { kind: 'killSwitch' }
})
/** Flag off on this server: never offered, so nothing reads as paused. */
export const unavailable = fixture({
claude: CLAUDE_ACTIVE,
codex: { kind: 'unavailable' }
})
/** Neither provider offered: the section collapses to one muted line. */
export const allUnavailable = fixture({
claude: { kind: 'unavailable' },
codex: { kind: 'unavailable' }
})
export const setupFailed = fixture({
claude: { kind: 'failed', error: 'denied' },
codex: { kind: 'failed', error: 'code_expired' }
@@ -121,6 +121,20 @@ describe('OrcaCloudAccountsView', () => {
it('shows the kill switch as info with no action, and signed out with Sign in', () => {
view({ claude: { kind: 'killSwitch' }, codex: NOT_SET_UP })
expect(screen.getByText('Signs in for each cloud workspace')).toBeTruthy()
expect(screen.getByText(/right now/)).toBeTruthy()
cleanup()
// Flag off: same title, but never worded as paused ("right now", "until it’s back").
view({ claude: { kind: 'unavailable' }, codex: NOT_SET_UP })
expect(screen.getByText(/isn’t available in Orca Cloud yet/)).toBeTruthy()
expect(screen.queryByText(/right now|until it’s back/)).toBeNull()
cleanup()
// Both off: one muted line under the heading, no rows and no actions.
view({ claude: { kind: 'unavailable' }, codex: { kind: 'unavailable' } })
expect(
screen.getByText('Claude and Codex sign in for each cloud workspace for now.')
).toBeTruthy()
expect(screen.queryByText(/isn’t available in Orca Cloud yet/)).toBeNull()
expect(screen.queryByRole('button')).toBeNull()
cleanup()
const handlers = actions()
render(
@@ -85,6 +85,20 @@ export function OrcaCloudAccountsView({
if (load.kind === 'unavailable') {
return null
}
if (rows && ORCA_CLOUD_ACCOUNT_AGENTS.every((agent) => rows[agent].kind === 'unavailable')) {
// Neither provider is offered on this server: one muted line keeps the section findable.
return (
<section id={ORCA_CLOUD_ACCOUNTS_SECTION_ID} className="space-y-3">
<SettingsGroupHeader
title={t('orcaCloudAccounts.title', 'Orca Cloud')}
description={t(
'orcaCloudAccounts.allUnavailable',
'Claude and Codex sign in for each cloud workspace for now.'
)}
/>
</section>
)
}
const signedOut = load.kind === 'failed' && load.error === 'signed_out'
let body: React.JSX.Element
if (load.kind === 'loading' || (load.kind === 'ready' && !rows)) {
@@ -138,7 +138,10 @@ export function buildAgentsRowText(
title: t('vmBuildAgents.agentSignIn', '{{agent}} sign-in', {
agent: agentName(model.agent, t)
}),
tag: t('vmBuildAgents.paused', 'Orca account sign-in is paused'),
tag:
model.reason === 'paused'
? t('vmBuildAgents.paused', 'Orca account sign-in is paused')
: t('vmBuildAgents.notOffered', 'Signs in for each cloud workspace for now'),
detail: t('vmBuildAgents.pausedDetail', 'This sign-in stays with this workspace')
}
case 'desktopKey':
@@ -135,9 +135,15 @@ export const agentsDesktopKeyFailed = agents(
},
{ desktopKeySave: { kind: 'failed', error: 'unavailable' } }
)
export const agentsKillSwitch = agents({ kind: 'killSwitch', agent: 'claude' })
export const agentsKillSwitch = agents({ kind: 'killSwitch', agent: 'claude', reason: 'paused' })
/** Flag off on this server: same sign-in-here action, never worded as paused. */
export const agentsNotOffered = agents({
kind: 'killSwitch',
agent: 'claude',
reason: 'notOffered'
})
export const agentsKillSwitchQueued = agents(
{ kind: 'killSwitch', agent: 'claude' },
{ kind: 'killSwitch', agent: 'claude', reason: 'paused' },
{ queued: true }
)
export const agentsLoading = agents({ kind: 'loading' })
+6 -2
View File
@@ -27689,7 +27689,10 @@
"repository": "repository key",
"personal": "your API key"
},
"copyAndOpen": "Copy code and open"
"copyAndOpen": "Copy code and open",
"unavailable": "Signs in for each cloud workspace",
"unavailableDetail": "Signing in once with your {{product}} account isn’t available in Orca Cloud yet. Each new cloud workspace asks you to sign in.",
"allUnavailable": "Claude and Codex sign in for each cloud workspace for now."
},
"vmBuildAgents": {
"menu": {
@@ -27743,6 +27746,7 @@
"error": "Couldn’t check agent sign-in",
"errorDetail": "The workspace still opens. Agents can sign in later.",
"groupAccount": "{{agents}} from your Orca account",
"groupKey": "{{agents}} with {{key}}"
"groupKey": "{{agents}} with {{key}}",
"notOffered": "Signs in for each cloud workspace for now"
}
}
@@ -9,6 +9,8 @@ import {
function status(overrides: {
claude?: OrcaCloudAgentsStatus['credentials']['claude']
enabled?: boolean
/** Omitted: an older server that sends only providerEnabled. */
provider?: 'on' | 'off' | 'disabled'
covered?: boolean
defaultSource?: 'sign-in' | 'key' | null
}): OrcaCloudAgentsStatus {
@@ -16,7 +18,8 @@ function status(overrides: {
credentials: {
claude: overrides.claude ?? { state: 'none' },
codex: { state: 'none' },
providerEnabled: { claude: overrides.enabled ?? true, codex: true }
providerEnabled: { claude: overrides.enabled ?? true, codex: true },
...(overrides.provider ? { providerState: { claude: overrides.provider, codex: 'on' } } : {})
},
sources: {
defaults: { claude: overrides.defaultSource ?? null },
@@ -86,6 +89,14 @@ describe('orcaCloudAccountRow', () => {
orcaCloudAccountRow('claude', status({ claude: ACTIVE, enabled: false }), IDLE, null)
).toEqual({ kind: 'killSwitch' })
const browser = { phase: 'browser', startedAt: 1, canReopen: false } as const
expect(
orcaCloudAccountRow(
'claude',
status({ claude: ACTIVE, enabled: false, provider: 'disabled' }),
IDLE,
null
)
).toEqual({ kind: 'killSwitch' })
expect(orcaCloudAccountRow('claude', status({}), browser, null)).toEqual({
kind: 'setup',
setup: browser
@@ -96,6 +107,31 @@ describe('orcaCloudAccountRow', () => {
})
})
describe('flag off vs kill switch', () => {
it('reads a never-offered provider as unavailable, not paused', () => {
const off = status({ enabled: false, provider: 'off' })
expect(orcaCloudAccountRow('claude', off, IDLE, null)).toEqual({ kind: 'unavailable' })
expect(orcaCloudAgentCoverage('claude', off, null)).toEqual({ kind: 'unavailable' })
// A key still covers it either way.
expect(
orcaCloudAgentCoverage(
'claude',
status({ enabled: false, provider: 'off', covered: true }),
'team'
)
).toEqual({ kind: 'key', keyKind: 'team' })
})
it('never trusts a providerState that contradicts providerEnabled', () => {
expect(
orcaCloudAccountRow('claude', status({ enabled: false, provider: 'on' }), IDLE, null)
).toEqual({ kind: 'killSwitch' })
expect(
orcaCloudAccountRow('claude', status({ enabled: true, provider: 'off' }), IDLE, null).kind
).toBe('notSetUp')
})
})
describe('orcaCloudAgentCoverage', () => {
it('says how a new cloud workspace authenticates', () => {
expect(orcaCloudAgentCoverage('claude', status({ claude: ACTIVE }), null)).toEqual({
@@ -3,6 +3,7 @@
import type { CloudEffectiveSecret } from '../../../../shared/cloud-secrets/cloud-secrets-wire'
import {
isUsableAgentCredential,
orcaCloudProviderState,
type AgentKeyKind,
type OrcaCloudAccountAgent,
type OrcaCloudAgentSetup,
@@ -62,8 +63,10 @@ export type OrcaCloudAccountRow =
covered: boolean
}
| { kind: 'expired'; keyKind: AgentKeyKind | null; covered: boolean }
/** §5c: the provider's Orca-account path is off. Info only; the stored credential is kept. */
/** §5c: the provider's Orca-account path is paused (kill switch). Info only; the stored credential is kept. */
| { kind: 'killSwitch' }
/** This server never offered the provider (flag off): nothing to set up, nothing paused. */
| { kind: 'unavailable' }
export function orcaCloudAccountRow(
agent: OrcaCloudAccountAgent,
@@ -74,8 +77,13 @@ export function orcaCloudAccountRow(
const credential = status.credentials[agent]
const covered = status.sources.coveredByKey[agent]
const fallbackKey = covered ? (keyKind ?? 'team') : null
if (!status.credentials.providerEnabled[agent]) {
return { kind: 'killSwitch' }
switch (orcaCloudProviderState(status.credentials, agent)) {
case 'off':
return { kind: 'unavailable' }
case 'disabled':
return { kind: 'killSwitch' }
case 'on':
break
}
if (setup.phase === 'failed') {
return { kind: 'failed', error: setup.error }
@@ -113,6 +121,8 @@ export type OrcaCloudAgentCoverage =
| { kind: 'expired' }
/** §5c without a key: each new cloud workspace asks once. */
| { kind: 'killSwitch' }
/** Flag off without a key: no Orca-account path here, so nothing to show. */
| { kind: 'unavailable' }
export function orcaCloudAgentCoverage(
agent: OrcaCloudAccountAgent,
@@ -120,9 +130,9 @@ export function orcaCloudAgentCoverage(
keyKind: AgentKeyKind | null
): OrcaCloudAgentCoverage {
const credential = status.credentials[agent]
const enabled = status.credentials.providerEnabled[agent]
const provider = orcaCloudProviderState(status.credentials, agent)
const covered = status.sources.coveredByKey[agent]
const usable = enabled && isUsableAgentCredential(credential.state)
const usable = provider === 'on' && isUsableAgentCredential(credential.state)
const source = status.sources.effective?.[agent]?.source ?? status.sources.defaults[agent] ?? null
const key: OrcaCloudAgentCoverage = { kind: 'key', keyKind: keyKind ?? 'team' }
if (usable && (source === 'sign-in' || !covered)) {
@@ -131,8 +141,8 @@ export function orcaCloudAgentCoverage(
if (covered) {
return key
}
if (!enabled) {
return { kind: 'killSwitch' }
if (provider !== 'on') {
return { kind: provider === 'off' ? 'unavailable' : 'killSwitch' }
}
return credential.state === 'expired' || credential.state === 'revoked'
? { kind: 'expired' }
@@ -50,6 +50,18 @@ describe('orcaCloudAgentSetupRow', () => {
expect(row('claude', { kind: 'ready', status: paused }).kind).toBe('killSwitch')
})
it('is hidden when this server never offered the provider (flag off)', () => {
const off: OrcaCloudAgentsStatus = {
...READY,
credentials: {
...READY.credentials,
providerEnabled: { claude: false, codex: true },
providerState: { claude: 'off', codex: 'on' }
}
}
expect(row('claude', { kind: 'ready', status: off }).kind).toBe('hidden')
})
it('is hidden for agents without an account path, members blocked by billing, and GitHub blocks', () => {
expect(row('cursor').kind).toBe('hidden')
expect(row(null).kind).toBe('hidden')
@@ -78,5 +78,8 @@ export function orcaCloudAgentSetupRow({
return { kind: 'expired', agent }
case 'killSwitch':
return { kind: 'killSwitch', agent }
case 'unavailable':
// Never offered here: like an agent without an account path, the composer shows no row.
return { kind: 'hidden' }
}
}
@@ -76,9 +76,31 @@ describe('buildAgentsRow', () => {
expect(buildAgentsToSetUp(model)).toEqual(['claude'])
})
it('signs a never-offered provider in for this workspace, not paused and never Set up', () => {
const off = withClaude('none', {
providerEnabled: { claude: false, codex: true },
providerState: { claude: 'off', codex: 'on' }
})
const model = row(accounts(off))
expect(model).toEqual({ kind: 'killSwitch', agent: 'claude', reason: 'notOffered' })
expect(buildAgentsToSetUp(model)).toEqual([])
// Both off: still one sign-in-here row, never an offer.
const bothOff = withClaude('none', {
providerEnabled: { claude: false, codex: false },
providerState: { claude: 'off', codex: 'off' }
})
expect(row(accounts(bothOff)).kind).toBe('killSwitch')
// The kill switch on one agent wins over the other never being offered.
const mixed = withClaude('active', {
providerEnabled: { claude: false, codex: false },
providerState: { claude: 'off', codex: 'disabled' }
})
expect(row(accounts(mixed))).toEqual({ kind: 'killSwitch', agent: 'codex', reason: 'paused' })
})
it('puts the kill switch first, then an expiry, both only when no key covers the agent', () => {
const paused = withClaude('active', { providerEnabled: { claude: false, codex: true } })
expect(row(accounts(paused))).toEqual({ kind: 'killSwitch', agent: 'claude' })
expect(row(accounts(paused))).toEqual({ kind: 'killSwitch', agent: 'claude', reason: 'paused' })
expect(row(accounts(withClaude('revoked')))).toEqual({ kind: 'expired', agent: 'claude' })
const keyed = {
...paused,
@@ -48,8 +48,11 @@ export type BuildAgentsRowModel =
| { kind: 'failed'; agent: OrcaCloudAccountAgent; error: OrcaCloudAgentSetupFailure }
/** R10 / R1b: the account credential expired or was revoked and no key covers the agent. */
| { kind: 'expired'; agent: OrcaCloudAccountAgent }
/** R12 (§5c): the provider's Orca-account path is off and no key covers the agent. */
| { kind: 'killSwitch'; agent: OrcaCloudAccountAgent }
/**
* R12 (§5c): no Orca-account path for the agent and no key covers it, so it signs in inside this
* workspace. `paused` = the kill switch; `notOffered` = this server never offered it (flag off).
*/
| { kind: 'killSwitch'; agent: OrcaCloudAccountAgent; reason: 'paused' | 'notOffered' }
/** S1-c (A5/A6): a key only in this computer's vault; it never reaches the sandbox unasked. */
| { kind: 'desktopKey'; key: CloudOfferableDesktopKey }
/** Couldn't read the Orca account; the workspace still opens. */
@@ -64,6 +67,7 @@ function covered(coverage: OrcaCloudAgentCoverage): BuildAgentVia | null {
case 'notSetUp':
case 'expired':
case 'killSwitch':
case 'unavailable':
return null
}
}
@@ -109,7 +113,12 @@ export function buildAgentsRow(args: {
}))
const paused = coverage.find((entry) => entry.coverage.kind === 'killSwitch')
if (paused) {
return { kind: 'killSwitch', agent: paused.agent }
return { kind: 'killSwitch', agent: paused.agent, reason: 'paused' }
}
// Never offered: no Set up to show, so the agent signs in inside the workspace like the kill switch.
const notOffered = coverage.find((entry) => entry.coverage.kind === 'unavailable')
if (notOffered) {
return { kind: 'killSwitch', agent: notOffered.agent, reason: 'notOffered' }
}
const expired = coverage.find((entry) => entry.coverage.kind === 'expired')
if (expired) {
@@ -29,14 +29,36 @@ const CredentialView = z.object({
})
export type AgentCredentialView = z.infer<typeof CredentialView>
// An unknown future state reads as the kill switch: unusable, and worded as temporary.
const ProviderState = z.enum(['on', 'off', 'disabled']).catch('disabled')
export type OrcaCloudProviderState = z.infer<typeof ProviderState>
export const AgentCredentialsResponseSchema = z.object({
claude: CredentialView,
codex: CredentialView,
/** false is the per-provider kill switch (spec §5c). */
providerEnabled: z.object({ claude: z.boolean(), codex: z.boolean() })
/** false: the provider's Orca-account path is unusable (flag off or kill switch; see providerState). */
providerEnabled: z.object({ claude: z.boolean(), codex: z.boolean() }),
/**
* Why: `off` = never offered on this server (flag S1/S2 off), `disabled` = the kill switch (spec §5c).
* Older servers omit it; read it through `orcaCloudProviderState`.
*/
providerState: z.object({ claude: ProviderState, codex: ProviderState }).optional()
})
export type AgentCredentialsView = z.infer<typeof AgentCredentialsResponseSchema>
/** The provider's state; without `providerState` (older server) a disabled provider reads as the kill switch. */
export function orcaCloudProviderState(
view: AgentCredentialsView,
agent: OrcaCloudAccountAgent
): OrcaCloudProviderState {
const state = view.providerState?.[agent]
if (state) {
// Never trust a state that contradicts providerEnabled.
return view.providerEnabled[agent] ? 'on' : state === 'on' ? 'disabled' : state
}
return view.providerEnabled[agent] ? 'on' : 'disabled'
}
const Source = z.enum(['sign-in', 'key']).nullable()
export type AgentSource = z.infer<typeof Source>
const PerAgentSource = z.object({ claude: Source.optional(), codex: Source.optional() })
@@ -44,7 +44,8 @@ const LATER: readonly Model[] = [
{ kind: 'setup', agent: 'claude', setup: { phase: 'saving' }, step: 1, of: 1 },
{ kind: 'failed', agent: 'claude', error: 'denied' },
{ kind: 'expired', agent: 'claude' },
{ kind: 'killSwitch', agent: 'claude' },
{ kind: 'killSwitch', agent: 'claude', reason: 'paused' },
{ kind: 'killSwitch', agent: 'claude', reason: 'notOffered' },
{
kind: 'desktopKey',
key: { id: 'k1', agent: 'claude', envName: 'ANTHROPIC_API_KEY', hint: 'x4Qa' }