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
28 changes: 28 additions & 0 deletions docs/specs/account-vpn.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,34 @@ the waiting account is kept, so the refusal names its route: the answer is
`409` with the `error` code, a `message` in plain words and
`retry_after_secs`. See [refused-launch.md](refused-launch.md).

A turn that runs on the Core host itself (`Control.resolveLocalCoreHarnessSetup`)
uses the same choice, `RemoteDispatch.chooseAntigravityAccount?`. While no
Antigravity account is VPN-routed it keeps the host's own `agy` login. Once one
is, the host login could belong to any of them, so the turn runs as the chosen
account: its login is written to a private home of the mission
(`<root>/core-turns/agy-home/<mission>`, `HOME` for that turn), and a
VPN-routed account goes only through its relay. Until 30 Nov 2026 this path
accepted exactly one enabled VPN account and otherwise failed with
`antigravity_vpn_requires_account_binding`.

A local Claude Code, Codex or Grok turn without Core's router uses the host's
login of its own provider. Only a VPN route on an account of that provider
(`RemoteDispatch.harnessVpnCategory?`, `anyVpnConfiguredFor?`) refuses it with
`local_harness_vpn_requires_router`; OpenCode and Pi, which can reach any
provider, are refused by a route on any account. Until 30 Nov 2026 any route
refused every local harness.

### Exits needed against exits configured

Two accounts of one provider category never share an exit, so a country needs
one server per VPN-routed account of the category. Allocation walks every
running and configured profile of the country before refusing; when a profile
exists but its exit is held by another account of the category, the answer is
`vpn_exit_in_use` (it used to be `vpn_no_compatible_profile`, which account
selection does not pass over). When the accounts routed to a country outnumber
its distinct configured servers, the refusal says so in numbers, in the account
row and in a refused launch (`AccountVpnPool.exitDemand`, `exitShortageNote`).

The WireGuard test changes the actual source address using SNAT inside the
test namespace. Each tunnel has IPv4 and IPv6 addresses. An IPv6-only
collision forces one ChatGPT account onto a verified third peer even though
Expand Down
33 changes: 24 additions & 9 deletions docs/specs/subscription-cyber-access.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ one value:
| `available` | the access this provider can hold, so a client knows what to offer |
| `source` | `operator` (set by hand) or `detected` (learned by Orb); `null` for `none` |
| `updated_at` | when it was last set, ISO 8601 UTC; `null` for `none` |
| `reserved` | `true`: kept for requests that ask for the access; ordinary requests never use it. Always `false` for `none` |

Storage: table `account_cyber_access(account_id, access, source, updated_at)`
Storage: table `account_cyber_access(account_id, access, source, updated_at, reserved)`
in the missions database. A row exists only for an account that has the access.

API:
Expand All @@ -144,7 +145,9 @@ API:
and holds no secret.
- `GET /api/ai/providers/:id/cyber-access` returns the object above.
- `PUT /api/ai/providers/:id/cyber-access` with `{"access": "none" | "daybreak"
| "cvp"}` sets it with `source = operator`. Admin only. The access must be the
| "cvp", "reserved"?: bool}` sets it with `source = operator`. Without
`reserved` the saved choice is kept; clearing the mark clears it, and
`reserved: true` with `access: "none"` is `400 cyber_access_reserve_needs_mark`. Admin only. The access must be the
one the account's provider can hold, else `400 cyber_access_not_applicable`.
The change is written to the provider audit log (field name only).

Expand Down Expand Up @@ -177,12 +180,20 @@ place accounts are ordered or excluded by cyber access.
- **Request that asks for the access**: only accounts recorded with that access
are used. If none is enabled and allowed for the mission's owner, the request
fails with `403 no_cyber_access_account` and a sentence that names the access
and says nothing was sent to another account.
and says nothing was sent to another account. This includes the case where no
account is marked at all: until 30 Nov 2026 such a request (a
`claude-mythos-*` model, say) went to whichever subscription the pool picked;
now the message asks the operator to mark the account that has the access.
- **Reserved account** (opt-in, per marked account, `reserved` below): an
ordinary request never uses it, not even as the last resort. A pool that
contains a reserved login and cannot be split login by login is dropped, since
the sidecar could pick that login. When only reserved accounts serve the model
the request fails with `403 only_reserved_accounts` and a sentence saying so.
- **Failover**: the proxy walks the resulting list in order and skips cooled
accounts, so quota failover obeys the same rule with no second code path.
- **Nothing recorded, nothing changes**: while no account is recorded with an
access, routing is exactly what it was. Orb then knows nothing and the
provider decides. Deploying this changes no mission until an account is marked.
- **Nothing recorded**: an ordinary request is routed exactly as before. A
request that asks for an access no account is recorded with is refused (see
above): Orb never guesses which login has it.
- **API-key accounts** are outside the rule: they are neither marked nor
filtered. The provider enforces access per key, as today.

Expand Down Expand Up @@ -269,9 +280,13 @@ takes effect for missions started from mobile, but mobile does not show it.
- `orb/tests/account-cyber-access.test.tsx`: the view model against the shared
fixture; the switch, its confirmation, its rollback and Retry; the member view.

Missing: an HTTP contract test for the new endpoint and for `cyber_access` on
the list, and a proxy test that sends a `claude-mythos-*` and a
`gpt-5.6-cyber` request through `handleProxyRequest` with a marked account.
- `ProviderContractTests.lean`, VPN settings block: the HTTP contract of
`/api/ai/providers/:id/cyber-access` (member read, admin-only write, wrong
family, API-key account, unknown account, reserve round trip, clearing) and
`cyber_access` on the list.

Missing: a proxy test that sends a `claude-mythos-*` and a `gpt-5.6-cyber`
request through `handleProxyRequest` with a marked account.

## Open questions

Expand Down
12 changes: 9 additions & 3 deletions lean/OrbCore/OrbCore/AccountVpnApi.lean
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ private def observed? (pool : AccountVpnPool.Pool) (account : String) (pref : Pr

def route (store : CoreStore) (pool? : Option AccountVpnPool.Pool) (dir account provider : String)
(canConfigure : Bool) (method : String) (body : ByteArray)
(configure? : Option (Bool → IO (Except String Unit)) := none) : IO (Nat × JVal) := do
(configure? : Option (Bool → IO (Except String Unit)) := none)
(accounts : Array (String × String) := #[]) : IO (Nat × JVal) := do
let err := fun (code : Nat) (reason : String) => (code, JVal.obj #[("error", .str reason)])
if method != "GET" && method != "PUT" then return err 405 "method_not_allowed"
if method == "PUT" then
Expand All @@ -63,8 +64,13 @@ def route (store : CoreStore) (pool? : Option AccountVpnPool.Pool) (dir account
fields := fields ++ #[("mode", .str "vpn"), ("country", .str pref.country)]
let mut reason := "vpn_awaiting_verification"
if dir.isEmpty || pool?.isNone then reason := "vpn_coordinator_unconfigured"
let blocked := fun cause => (200, JVal.obj (fields ++ #[("status", .str "blocked"), ("reason", .str cause),
("message", .str (reasonMessage cause))]))
let (needed, configured) ← AccountVpnPool.exitDemand store.rootDir store.missionsDb accounts
(canonicalCategory provider) pref.country
let blocked := fun cause =>
let note := if cause == "vpn_exit_in_use" || cause == "vpn_no_compatible_profile" then
AccountVpnPool.exitShortageNote needed configured pref.country else ""
(200, JVal.obj (fields ++ #[("status", .str "blocked"), ("reason", .str cause),
("message", .str (if note.isEmpty then reasonMessage cause else note))]))
if let some pool := pool? then
if method == "PUT" then
if let .error e ← AccountVpnPool.allocate pool store.rootDir dir store.missionsDb account provider pref then return blocked e
Expand Down
28 changes: 27 additions & 1 deletion lean/OrbCore/OrbCore/AccountVpnPool.lean
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,11 @@ private def allocateLocked (root dir : String) (db : SqliteDb) (account provider
for endpoint in candidates do
if let some t := available.find? (fun a => a.endpoint.device == endpoint.device) then
let ready := available.flatMap (fun a => a.occupants.map (·.binding))
if (choose req ready [t.evidence]).isNone then continue
if (choose req ready [t.evidence]).isNone then
-- Another account of this category holds this exit. Try the next profile; if none is
-- left the answer is that the exit is in use, not that a profile is missing.
if failure == "vpn_no_compatible_profile" then failure := "vpn_exit_in_use"
continue
let others := available.filter (fun a => a.tunnel.port != t.tunnel.port)
if (← t.tunnel.verify root endpoint.server pref.country) == some t.evidence then
match ← install dir db account cat pref t others with
Expand Down Expand Up @@ -238,6 +242,28 @@ def allocate (pool : Pool) (root dir : String) (db : SqliteDb) (account provider
(pref : Preference) : IO (Except String UInt16) := do
return (← allocateGateway pool root dir db account provider pref).map (·.port)

/-- Exits a provider category needs in a country, and how many it can have there. Accounts of one
category never share an exit, so each enabled account routed to `country` needs its own; two device
profiles on one server share its exit, so only distinct configured servers count. `accounts` are the
enabled accounts as `(id, providerType)`. -/
def exitDemand (root : String) (db : SqliteDb) (accounts : Array (String × String))
(category country : String) : IO (Nat × Nat) := do
let mut needed := 0
for (id, providerType) in accounts do
if canonicalCategory providerType == category then
if let .ok (some p) ← AccountVpnRoutes.read db id then
if p.country == country then needed := needed + 1
let servers := (((← endpoints root).filter (·.country == country)).map (·.server)).eraseDups
return (needed, servers.length)

/-- Sentence added to an exit refusal when the country has fewer servers than accounts need, empty
otherwise. -/
def exitShortageNote (needed configured : Nat) (country : String) : String :=
if needed ≤ configured then ""
else
let servers := if configured == 1 then "1 server is" else s!"{configured} servers are"
s!"{needed} accounts of this provider use {country}, and each needs its own exit, but only {servers} configured for {country}. Import a device profile for another {country} server in AirVPN Settings, or move one account to another country."

def resolve (pool? : Option Pool) (store : OrbCore.Store.CoreStore) (dir account : String) :
OrbBin.HttpClient.ResolveTransport :=
AccountVpnRoutes.resolve store.missionsDb account fun pref => do
Expand Down
Loading
Loading