Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions docs/spec-cards/launch-admission.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Spec Card: Launch admission (`Orb.LaunchAdmission` / `OrbCore.LaunchAdmission`)

- **Covered files:**
- `lean/Orb/LaunchAdmission.lean`: the pure decision (`harnessRoute`, `vpnBlocksOwnLogin`,
`chooseAccount`, `antigravityHostRoute`, `antigravityNodeCandidates`, `vpnExitRefusal`).
- `lean/OrbCore/OrbCore/LaunchAdmission.lean`: the per-request gate on Core's router
(`proxyAccountRefusal?`, `admitRequest`) and `admitLaunch`, launch then first request.
- Callers: `Control.resolveLocalCoreHarnessSetup` (Core host), `Control.handleProxyRequest`
(`/v1`), `RemoteDispatch.prepareRemoteHarnessCommand` / `adminDirectAntigravityStaticTarget?` /
`chooseAntigravityAccount?` / `launchAccounts` (nodes), `RemoteFleetAndRelay.remoteRequiresProxyHarnesses`,
`OrbLocald.Rpc.coreAccountsSetup` (this computer).
- Matrix: `shared/orb-spec/fixtures/launch-admission.json`, replayed by
`lean/OrbCore/OrbCore/LaunchAdmissionTests.lean` (in `orb-core-test`).
- **Intent:** a mission is admitted or refused by one rule wherever it runs, and a refusal names
its cause with a stable code. A harness never reaches a provider from an address its account's
VPN route forbids, and a Daybreak/CVP request never goes to an account not marked with it.

## The rule

A launch picks a **route**: `router` (Core's model router, mission proxy token), `own_login` (the
login on the machine that runs the harness), or `account:<id>` (Antigravity as that Core account,
its own login, through its exit when routed). `router` means: Core host, the router is bound;
node, Core's public proxy URL is set; this computer, the mission is on Core accounts.

| Placement | Harness | Router | Decision |
| --- | --- | --- | --- |
| this computer | any | no (Local login) | `own_login` |
| this computer | Claude Code, Codex, OpenCode | yes | `router` |
| this computer | Pi, Grok, Antigravity | yes | `core_accounts_harness_unavailable` |
| Core host | Claude Code, Codex, OpenCode, Pi, Grok | yes | `router` |
| Core host | Claude Code / Codex / Grok | no | `local_harness_vpn_requires_router` if an account of its own provider has a VPN route, else `own_login` |
| Core host | OpenCode, Pi | no | `local_harness_vpn_requires_router` if any account has a route, else `own_login` |
| Core host | Antigravity (unbound) | — | no route on any Antigravity account: `own_login`; else `chooseAccount` over the enabled accounts, or `antigravity_vpn_requires_account_binding` |
| node | Claude Code, Codex, OpenCode, Pi | no | `REMOTE_AUTH_REQUIRED` |
| node | Grok | no | `grok_vpn_requires_proxy_base_url` if an xAI account has a route, else `own_login` |
| node | Antigravity (admin node path) | — | `chooseAccount` over the enabled accounts (routed ones only when the node reaches their exit) |

`chooseAccount`: in priority order, the first account with a login that is usable and whose VPN
route is not waiting; else the first usable one that is waiting (its route then refuses with
`antigravity_vpn_unavailable:<reason>`, `vpnExitRefusal`); else the first with a login.

A `router` turn is then admitted per request (`admitRequest`): after
`Proxy.applyCyberAccountPolicy`, a model with targets the owner may use but none left answers
`403 no_cyber_access_account` when the request needs Daybreak/CVP (also when no account is
marked), else `403 only_reserved_accounts`.

## Regressions the matrix replays

- **#2355:** an xAI or ChatGPT route refused every local Claude Code/Codex mission (now only
a route on the harness's own provider does); Core-host Antigravity was refused when its first
account's exit was in use (now the next account runs); a Mythos request with no marked account
must answer `403 no_cyber_access_account`.
- **#2359:** missions on this computer on Core accounts go through the router for Claude Code,
Codex and OpenCode, with the same cyber gate; other harnesses are refused.

## Epistemic boundary

- **Tested, not proved:** every cell of harness (6) × placement (3) × router (2) × VPN state (4) ×
marks (3 for Claude/ChatGPT, else 1) × request (2 for Claude/ChatGPT, else 1) is decided by
`admitLaunch` and must equal the first matching fixture rule; every rule must decide a cell.
- **Not covered by the matrix:** quota exhaustion (every account usable), bound Antigravity
missions, the native Antigravity subscription path, VPN pool and relay failures, and per-request
VPN routing inside the proxy. These keep their per-path tests (`ProviderContractTests`,
`HarnessProxyTests`).
155 changes: 155 additions & 0 deletions lean/Orb/LaunchAdmission.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import Orb.AccountVpn

/-!
# Launch admission (`docs/spec-cards/launch-admission.md`)

Which way a harness turn reaches its models, or the code it is refused with, decided from what
Core knows about the accounts. Every launch path calls these functions instead of deciding
inline: Core-host turns (`Control.resolveLocalCoreHarnessSetup`), node turns
(`RemoteDispatch.prepareRemoteHarnessCommand`, `adminDirectAntigravityStaticTarget?`) and missions
on this computer on Core accounts (`OrbLocald.Rpc.coreAccountsSetup`). Requests that go through
Core's router are then admitted per request by `OrbCore.LaunchAdmission.proxyAccountRefusal?`.
The matrix in `shared/orb-spec/fixtures/launch-admission.json` checks every combination.

Refusal codes are stable: clients and tests match on them.
-/
namespace Orb.LaunchAdmission

/-- Where the harness process runs. -/
inductive Placement where
/-- On the Core host (`launchLocalCoreMissionTurn`). -/
| core
/-- On a fleet or managed node. -/
| remote
/-- On the user's computer through `orb-locald`. -/
| client
deriving DecidableEq, Repr, Inhabited

def Placement.ofString? : String → Option Placement
| "core" => some .core
| "remote" => some .remote
| "client" => some .client
| _ => none

/-- One provider account as a launch sees it. `enabled` already folds in the owner's provider
preferences; `hasLogin` is whether the account has a login file of its own (Antigravity). -/
structure Account where
id : String
provider : String
vpn : Bool := false
enabled : Bool := true
hasLogin : Bool := true
deriving DecidableEq, Repr, Inhabited

/-- How an admitted turn reaches its models. -/
inductive Route where
/-- Through Core's model router with a mission proxy token. -/
| router
/-- With the harness's own login on the machine that runs it. -/
| ownLogin
/-- As this Core account, with its own login, and through its VPN exit when it has a route. -/
| account (id : String)
deriving DecidableEq, Repr, Inhabited

def Route.label : Route → String
| .router => "router"
| .ownLogin => "own_login"
| .account id => s!"account:{id}"

def normalizeHarness (raw : String) : String :=
let h := raw.trimAscii.toString.toLower
if h == "claude" then "claudecode" else h

/-- Harnesses a Core-host turn points at Core's router when it is bound. -/
def coreRouterHarnesses : Array String := #["opencode", "pi", "claudecode", "codex", "grok"]

/-- Harnesses a node turn runs only through Core's router (`REMOTE_AUTH_REQUIRED` without it). -/
def remoteRouterOnlyHarnesses : Array String := #["claudecode", "opencode", "pi", "codex"]

/-- Harnesses a mission on this computer can run on Core's accounts. -/
def clientCoreAccountHarnesses : Array String := #["claudecode", "codex", "opencode"]

/-- Provider category (`Orb.AccountVpn.canonicalCategory`) whose login a harness uses when it
runs without Core's router: Claude Code uses a Claude login, Codex a ChatGPT login, Grok an xAI
login. `none` for harnesses that can reach any provider (OpenCode, Pi). -/
def harnessVpnCategory? (harness : String) : Option String :=
match normalizeHarness harness with
| "claudecode" => some "anthropic"
| "codex" => some "openai"
| "grok" => some "xai"
| _ => none

/-- Whether an account the harness could reach without Core's router has a VPN route: an account
of its category (`harnessVpnCategory?`), or any account at all for OpenCode and Pi. Running
on its own login would then reach that provider from the host's own address. A route on an
account of another provider never blocks it. -/
def vpnBlocksOwnLogin (harness : String) (accounts : Array Account) : Bool :=
match harnessVpnCategory? harness with
| some c => accounts.any fun a => a.vpn && Orb.AccountVpn.canonicalCategory a.provider == c
| none => accounts.any (·.vpn)

/-- Admission of every harness except Antigravity (`antigravityHostRoute`,
`antigravityNodeCandidates`). `router` means: on Core, Core's router is bound; on a node, Core's
public proxy URL is configured; on this computer, the mission runs on Core accounts.
`accounts` is read only when the harness would run on its own login. -/
def harnessRoute (placement : Placement) (rawHarness : String) (router : Bool)
(accounts : Array Account) : Except String Route :=
let h := normalizeHarness rawHarness
match placement with
| .client =>
if !router then .ok .ownLogin
else if clientCoreAccountHarnesses.contains h then .ok .router
else .error "core_accounts_harness_unavailable"
| .core =>
if !coreRouterHarnesses.contains h then .ok .ownLogin
else if router then .ok .router
else if vpnBlocksOwnLogin h accounts then .error "local_harness_vpn_requires_router"
else .ok .ownLogin
| .remote =>
if remoteRouterOnlyHarnesses.contains h then
if router then .ok .router else .error "REMOTE_AUTH_REQUIRED"
else if h == "grok" then
if router then .ok .router
else if vpnBlocksOwnLogin h accounts then .error "grok_vpn_requires_proxy_base_url"
else .ok .ownLogin
else .ok .ownLogin

/-- The account to run on among `candidates` (in priority order). The first one with a login that
is `usable` (neither out of quota nor rejected) and not `blocked` (its VPN route is waiting)
wins. `blocked` is asked in priority order and only for usable accounts, because the check
starts the tunnel. When none qualifies: the first usable account whose route is waiting, so
the refusal names its route; else the first candidate with a login. A waiting account never
runs without its route: the caller still resolves the route and fails closed. -/
def chooseAccount {m : Type → Type} [Monad m] {α : Type} (candidates : Array α)
(hasLogin : α → Bool) (usable blocked : α → m Bool) : m (Option α) := do
let withLogin := candidates.filter hasLogin
let mut waiting? : Option α := none
for a in withLogin do
if ← usable a then
if !(← blocked a) then return some a
if waiting?.isNone then waiting? := some a
return waiting?.orElse (fun _ => withLogin[0]?)

/-- An unbound Antigravity turn on the Core host. With no VPN route on any Antigravity account it
runs on the host's own login. Otherwise the host's login could be any of them reaching Google
from Core's address, so it runs as the account `chooseAccount` picks among the enabled ones,
or is refused when none has a login. -/
def antigravityHostRoute {m : Type → Type} [Monad m] (accounts : Array Account)
(usable blocked : Account → m Bool) : m (Except String Route) := do
let ag := accounts.filter (·.provider == "antigravity")
if !ag.any (·.vpn) then return .ok .ownLogin
match ← chooseAccount (ag.filter (·.enabled)) (·.hasLogin) usable blocked with
| some a => return .ok (.account a.id)
| none => return .error "antigravity_vpn_requires_account_binding"

/-- Antigravity accounts an admin node turn may run as: enabled ones, and a VPN-routed one only
when the node can reach its exit (`allowVpn`). -/
def antigravityNodeCandidates (accounts : Array Account) (allowVpn : Bool) : Array Account :=
accounts.filter fun a => a.provider == "antigravity" && a.enabled && (!a.vpn || allowVpn)

/-- The code a turn is refused with when its account's VPN route cannot be had (`reason` from the
VPN pool). Reasons the pool already names for Antigravity pass through. -/
def vpnExitRefusal (reason : String) : String :=
if reason.startsWith "antigravity_" then reason else s!"antigravity_vpn_unavailable:{reason}"

end Orb.LaunchAdmission
68 changes: 32 additions & 36 deletions lean/OrbCore/OrbCore/Control.lean
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import OrbCore.AccountVpnRelay
import OrbCore.NativeGoalApproval
import OrbCore.AutoPlacement
import OrbCore.RemoteDispatch
import OrbCore.LaunchAdmission
import OrbCore.MachineTransfer
import OrbCore.ProjectFilesAndController
import OrbCore.CloudHttpAndWorker
Expand Down Expand Up @@ -2371,17 +2372,14 @@ private def handleProxyRequest (st : CoreAppState) (req : HttpRequest) (cleanPat
let cyberRows ← match ← listAccountAccess st.store with
| .ok rows => pure rows
| .error _ => return mkJson 503 "{\"error\":\"cyber_access_store_unavailable\"}"
let activeChain := applyCyberAccountPolicy prefsChain (accountAccessPairs cyberRows) cyberNeed?
(reservedAccountIds cyberRows)
if !prefsChain.targets.isEmpty && activeChain.targets.isEmpty then
match cyberNeed? with
| some need =>
return mkJson 403 (renderCompact (.obj #[
("error", .str "no_cyber_access_account"),
("message", .str (noCompatibleAccountMessage need (cyberRows.any (·.access == need))))]))
| none =>
return mkJson 403 (renderCompact (.obj #[
("error", .str "only_reserved_accounts"), ("message", .str onlyReservedAccountsMessage)]))
let activeChain ← match OrbCore.LaunchAdmission.admitRequest prefsChain (accountAccessPairs cyberRows)
(reservedAccountIds cyberRows) cyberNeed? with
| .ok chain => pure chain
| .error code =>
let message := match cyberNeed? with
| some need => noCompatibleAccountMessage need (cyberRows.any (·.access == need))
| none => onlyReservedAccountsMessage
return mkJson 403 (renderCompact (.obj #[("error", .str code), ("message", .str message)]))
let proxySecretBearer :=
!st.cfg.proxySecret.isEmpty &&
match extractBearerToken? req.headers nowEpochSec with
Expand Down Expand Up @@ -3187,7 +3185,7 @@ def resolveLocalCoreHarnessSetup
let normHarness := if hLow == "claude" then "claudecode" else hLow
let cleanModel := rawModel.trimAscii.toString
let model? := if cleanModel.isEmpty then none else some cleanModel
if normHarness == "opencode" || normHarness == "pi" || normHarness == "claudecode" || normHarness == "codex" || normHarness == "grok" then
if Orb.LaunchAdmission.coreRouterHarnesses.contains normHarness then
if boundPort > 0 then
match ← mintMissionProxyToken st.store missionId ownerUserId (nowSec + 86400) with
| .error e => return .error s!"failed to mint mission proxy token: {e}"
Expand All @@ -3211,11 +3209,11 @@ def resolveLocalCoreHarnessSetup
else
-- Without the router the harness uses Core's own login of its provider: only a VPN route
-- on an account of that provider stops it (any account for OpenCode and Pi).
match ← OrbCore.RemoteDispatch.anyVpnConfiguredFor? st.store st.cfg.workingDir
(OrbCore.RemoteDispatch.harnessVpnCategory? normHarness) with
| .error _ => return .error "local_harness_vpn_route_store_unavailable"
| .ok true => return .error "local_harness_vpn_requires_router"
| .ok false => return .ok { model := model? }
let .ok accounts ← OrbCore.RemoteDispatch.launchAccounts st.store st.cfg.workingDir
| return .error "local_harness_vpn_route_store_unavailable"
match Orb.LaunchAdmission.harnessRoute .core normHarness false accounts with
| .error e => return .error e
| .ok _ => return .ok { model := model? }
else if normHarness == "antigravity" then
let .ok bound? ← nativeMissionAccount? st.store missionId
| return .error "antigravity_binding_unavailable"
Expand All @@ -3228,8 +3226,7 @@ def resolveLocalCoreHarnessSetup
AccountVpnPool.allocate pool st.store.rootDir st.vpnCoordinatorDir st.store.missionsDb acctId "antigravity" pref
let allocateSocks := fun (acctId : String) (pref : AccountVpnRoutes.Preference) => do
match ← allocate acctId pref with
| .error e =>
return .error (if e.startsWith "antigravity_" then e else s!"antigravity_vpn_unavailable:{e}")
| .error e => return .error (Orb.LaunchAdmission.vpnExitRefusal e)
| .ok _ =>
let some proxyUrl := st.vpnRelayPort?.bind (fun port =>
AccountVpnRelay.proxyUrl (effectiveJwtSecret st.cfg) port "antigravity" acctId "127.0.0.1" "socks5h")
Expand All @@ -3255,28 +3252,27 @@ def resolveLocalCoreHarnessSetup
| .ok none => return .ok { model := model? }
| .ok (some pref) => allocateSocks acctId pref
| none =>
let hydrated ← loadHydratedProviders st.store st.cfg.workingDir
let agAccounts := hydrated.filter (·.providerType == "antigravity")
let mut anyVpn := false
for hp in agAccounts do
match ← AccountVpnRoutes.snapshot st.store.missionsDb hp.id with
| .error _ => return .error "antigravity_vpn_route_store_unavailable"
| .ok (.vpn _) => anyVpn := true
| .ok (.direct _) => pure ()
if !anyVpn then
return .ok { model := model? }
-- With a VPN route on any account, the host's own login could be that account (or another
-- one) reaching Google from Core's address. Choose the account as node dispatch does, in
-- priority order, passing over one whose route cannot be had now, and run as that account
-- with its own login and, when VPN-routed, only through its exit.
let prefs ← getUserProviderPrefs st.store ownerUserId
let candidates := agAccounts.filter fun hp => hp.enabled && isUserProviderEnabled prefs hp.id
let vpnBlocked := fun (acctId : String) => do
match ← AccountVpnRoutes.read st.store.missionsDb acctId with
| .ok (some pref) => return (← allocate acctId pref).toOption.isNone
let .ok accounts ← OrbCore.RemoteDispatch.launchAccounts st.store st.cfg.workingDir ownerUserId
| return .error "antigravity_vpn_route_store_unavailable"
let hydrated ← loadHydratedProviders st.store st.cfg.workingDir
let agAccounts := hydrated.filter (·.providerType == "antigravity")
let usable := fun (a : Orb.LaunchAdmission.Account) => do
match agAccounts.find? (·.id == a.id) with
| some hp => OrbCore.RemoteDispatch.antigravityAccountUsable st.store st.providerHub? hp nowSec
| none => return false
let vpnBlocked := fun (a : Orb.LaunchAdmission.Account) => do
match ← AccountVpnRoutes.read st.store.missionsDb a.id with
| .ok (some pref) => return (← allocate a.id pref).toOption.isNone
| _ => return false
let some hp ← OrbCore.RemoteDispatch.chooseAntigravityAccount? st.store st.providerHub? nowSec
candidates vpnBlocked
let chosenId ← match ← Orb.LaunchAdmission.antigravityHostRoute accounts usable vpnBlocked with
| .error e => return .error e
| .ok (.account id) => pure id
| .ok _ => return .ok { model := model? }
let some hp := agAccounts.find? (·.id == chosenId)
| return .error "antigravity_vpn_requires_account_binding"
let route ← match ← AccountVpnRoutes.read st.store.missionsDb hp.id with
| .ok r => pure r
Expand Down
Loading
Loading