Repository navigation
Hosted agents v2: boxes in their own cluster, with a warm pool, behind the v1/v2 switch (server and cloud) - #2216
niall-sandboxaq wants to merge 56 commits into
Conversation
A machine whose first launch is refused by the hosted controller's own checks, and that has never been ready, now records the reason `launch_refused`, and "Hosted machine launches failing" counts it, so a bad worker image pages instead of failing every new machine silently. Fixed words only in reasons, tags and log fields. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The software that runs inside a hosted agents v2 box: three packages under `console/packages/` (`agent-providers-box`, `agent-controller-box`, `switch-agent-runtime-box`), copies of the upstream agent packages pinned to an upstream commit with a drift guard, plus the changes a box needs. Nothing outside them changes, and nothing runs them until v2 is turned on. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Syncs the box copy of agent-controller with upstream main 3b503b5 and moves the pin there. Upstream changed eight agent-controller files since 9704ba1: a refusal saying account_suspended (the controller's owner is suspended) is not a revocation. The controller stops every agent by holding its assignment with each one stopped, keeps its credential, and the stream asks again every streamSuspendedRetryMs; once Switch lets it in, the assignment it pulls starts them again. The port is upstream's change as it is, merged with the box's own code in three places: the controller's description, the assignment pull (the box's split-gate clearing and daily cap stay beside upstream's suspended handling), and the fake Core (the box's forbidden switch stays beside upstream's ownerSuspended). A box test adds the case that matters for a box: restarted while its owner is suspended, it is refused 403 account_suspended from the token exchange on, keeps its credential and identity, doesn't exit (an exit 3 or 6 would have its entrypoint retire the identity), starts nothing, and starts its agent once the suspension is lifted. upstream-packages.json and the BOX.md notes move to 3b503b5. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The cluster side of hosted agents v2 under `deploy/hosted/`: the box provisioner and operator, the scaler, the node gate, egress lists and the proxy, the Kubernetes manifests and admission policies, and the box image. Boxes start and open their egress within seconds, event-driven rather than on timers. switch-core's chart gains its v2 values, all off by default, and renders unchanged without them; CI runs the hosted controller's tests and checks the chart. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The box clusters taint agent nodes switch.dev/pool=agents:NoSchedule, and box pods carry no
toleration, so no box could be scheduled there. The toleration now comes from the gvisor and
gvisor-tuned RuntimeClasses, which add it to every pod that names them. The box template and
P4 don't change.
- switch-gvisor-class-scope, for every account:
- only box namespaces (agents-user-k1- and the warm pool's agents-box-k1-), the node
gate's check namespaces, switch-placeholders and switch-drain-room may name a gVisor
class;
- outside kube-system, a pod whose tolerations cover the agents taint (by hand, or a
key-less Exists) must name a gVisor class.
- switch-operator-placeholder-shape: drain placeholders must run under gvisor, and may carry
the agent pool toleration the class adds, beside the two defaults.
- The node gate's check-pod rule allows the same toleration, exactly.
- Tests: both classes, both scope rules' allow and refuse cases, both pod rules, and P4.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…agent nodes A box cluster's agent nodes are tainted switch.dev/pool=agents, and the gvisor RuntimeClasses now carry the agents toleration. This makes everything that must land on an agent node use them: - A drain placeholder (which holds a box-sized slot on an agent node in the box's zone) now runs under the gvisor class, like everything on an agent node: the class adds the agents node selector and the toleration, so nothing is written by hand and agent nodes run only sandboxed pods. Its own node selector keeps only the zone; a placeholder for any pool but agents is refused. - test_box_pod_tolerates_agent_nodes.py renders the box's pod as the operator makes it, merges each gVisor class's scheduling the way the API server does, and checks it tolerates every NoSchedule taint an agent node carries (mirrored from the box cluster's agent node group; the gate-1 start-up taint deliberately not tolerated), that the classes add exactly that one toleration, and that switch-gvisor-class-scope names exactly the two box name shapes (the operator's person-keyed pattern, and the exact box-keyed one the warm pool uses). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Core's side of hosted agents v2, behind `HOSTED_BOX_PROVISIONING`, where anything unclear reads as off: asking the box cluster for a person's box through every gate (allow-lists, pause and per-workspace turn-off, capacity, the per-minute limit and box ceiling), enrolment and the box's controllers, sleep and wake with the owner re-checked, retention and removal with controllers revoked, the Switch operator role and its rate- limited, audited actions, and the hosted screens and monitors. With v2 off, nothing changes. Main's account and agent suspensions sit beside v2's box refusals, and both sides' monitors, reason codes and allow-lists are kept. An Alembic merge revision joins v2's head with main's latest; no existing revision is re-parented. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A box is ready when the second of its two signals arrives, whichever comes first: the scaler's `running`, or a report from the box's controller, at the current revision, from that workspace's own live controller; and the owner's summary shows it ready at once. Each stage of a box start is timed (`switch.hosted.start_seconds`, by case and stage only). A box the cluster reports missing is asked for again once, through every gate, with its old controllers revoked and audited first. A box retained or wanted deleted is never woken by a message. With v2 off, nothing changes. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The owner's machine summary gains `start` with hosted agents v2 on: null, or
`{kind, since}` while a box wanted running is queued or provisioning, with
`since` from the start-timing clock at the current revision. Retry and the
missing-box re-ask start that clock too. The Console shows "Starting your
agent…" or "Waking your agent…", then "Still starting…" after 30 s (first
start) or 20 s (wake) from `since`, and "Couldn't start your agent" only
when the server reports an error. v1 machines and v2 off are unchanged.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…h workspace With v2 on, an unset `allowed_tenant_ids` or `allowed_user_ids` admits nobody; `"*"`, alone, admits everyone, and beside names it stops the server at start. With v2 off, the lists behave exactly as before. The mode comes from the server's config, at load and at every check. Core warns at start when v2 is on and a list is unset, or when no per-workspace limit is set. `HOSTED_LAUNCH_CAPACITY_PER_WORKSPACE` (v2 only, 0 for none) caps the live machines serving one workspace, under the server-wide capacity and the claims lock, with its own refusal message and an untagged count. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Adds switch-hosted-migration, an operator command that moves one person's v1 cloud machine to a v2 box in place, on the same machine row, in recorded steps: freeze the v1 machine, record its disk snapshot, flip the row to a box, hold the box after its first start, record the copy, release, and finish. Each step can be rolled back until the clean-up window passes. Every command is a dry run unless --execute is given, and --execute needs the keyed-id key so every change is audited under keyed ids. Hosted agents v2 only: with v2 off every command refuses. Adds the hosted_migrations table, machine_workspaces .moving_from_controller_id and the `migration` stop reason, in migration c118ea00053c, which follows the twelfth merge d9e4b7a2c615 in one linear chain. The controller revoke the command shares with agent management (`revoke_controller_rows`) keeps main's audit entry for every revoke, and the moved machine's summary holds its agents on the v1 controller after the workspace's own state is worked out. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Suspending an account (`accounts/suspension.py`) now also stops the owner's hosted agents v2 box in the same transaction: wanted stopped, a new revision (so the box scaler scales it to 0 on its next pass), and a new stop reason, `suspended`, which no other stop but an administrator's replaces and nothing starts. A suspension replaces a pause, a turn-off or a move's hold. While the suspension lasts, every gate blocks the owner as a pause does (`block_reason`, `SUSPENDED_BLOCKS_AS`): no wake by a message or placement, no start, no claim, no enrolment code from `prepare`, and no step of a move to a box (`switch-hosted-migration` refuses with `suspended`). Lifting the suspension leaves the box asleep (`idle`), so the next message wakes it, through every gate again. A v1 machine is left to the suspension's own controller refusals, as before. The suspension's audit entry says when a box was stopped. One additive migration, after the hosted migrations, widens the `cloud_machines.stop_reason` check. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Text only: comments, docstrings and test section headings that named internal review items or working labels now describe the thing itself. No code or behaviour changes. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
| for bad in ( | ||
| "http://core.example.invalid", | ||
| "http://127.0.0.1:8510", # the Mac's tunnel is not for the cluster | ||
| f"https://user:{TOKEN}@core.example.invalid", |
There was a problem hiding this comment.
🟡 Medium severity issue identified in your code:
Hardcoded sensitive data leaked
Semgrep has detected a leak of sensitive data in this code. This secret data could be used by internal or external malicious actors. We highly recommend you change, reset, or rotate the sensitive data.
A secret is hard-coded in the application. Secrets stored in source code, such as credentials, identifiers, and other types of sensitive data, can be leaked and used by internal or external malicious actors. It is recommended to rotate the secret and retrieve them from a secure secret vault or Hardware Security Module (HSM), alternatively environment variables can be used if allowed by your company policy.
View Dataflow Graph
flowchart LR
classDef invis fill:white, stroke: none
classDef default fill:#e7f5ff, color:#1c7fd6, stroke: none
subgraph File0["<b>deploy/hosted/controller/tests/test_workers_main.py</b>"]
direction LR
%% Source
subgraph Source
direction LR
v0["<a href=https://github.com/sandbox-quantum/switch/blob/329c35bd91efc4a77eb5398fbef7a9c59399e83b/deploy/hosted/controller/tests/test_workers_main.py#L35 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 35] TOKEN = "TOKEN-CANARY-3f9a-never-logged"</a>"]
end
%% Intermediate
subgraph Traces0[Traces]
direction TB
v2["<a href=https://github.com/sandbox-quantum/switch/blob/329c35bd91efc4a77eb5398fbef7a9c59399e83b/deploy/hosted/controller/tests/test_workers_main.py#L35 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 35] TOKEN</a>"]
end
%% Sink
subgraph Sink
direction LR
v1["<a href=https://github.com/sandbox-quantum/switch/blob/329c35bd91efc4a77eb5398fbef7a9c59399e83b/deploy/hosted/controller/tests/test_workers_main.py#L208 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 208] TOKEN</a>"]
end
end
%% Class Assignment
Source:::invis
Sink:::invis
Traces0:::invis
File0:::invis
%% Connections
Source --> Traces0
Traces0 --> Sink
💬 To ignore this, reply with:
• /fp <comment> for false positive
• /ar <comment> for acceptable risk
• /other <comment> for all other reasons
Alternatively, triage in Semgrep AppSec Platform to ignore the finding created by http.
| const transport = new StreamableHTTPServerTransport({ | ||
| sessionIdGenerator: undefined, | ||
| enableJsonResponse: true, | ||
| }); |
There was a problem hiding this comment.
🟠 High severity and reachable issue identified in your code:
Line 681 has a potentially vulnerable usage of @modelcontextprotocol/sdk, possibly introducing a high severity vulnerability.
ℹ️ Why this is reachable
A reachable issue is a possible security risk because your project actually executes the vulnerable code. This issue is reachable because your code calls vulnerable code in this version of @modelcontextprotocol/sdk.
Affected versions of @modelcontextprotocol/hono, @modelcontextprotocol/node, @modelcontextprotocol/sdk, and @modelcontextprotocol/server are vulnerable to Allocation of Resources Without Limits or Throttling. The MCP TypeScript SDK Streamable HTTP server transports and HTTP handlers (StreamableHTTPServerTransport, WebStandardStreamableHTTPServerTransport, NodeStreamableHTTPServerTransport, createMcpHandler, isLegacyRequest, legacyStatelessFallback, toNodeHandler/toWebRequest, createMcpHonoApp) read POST request bodies without a size limit and dispatch JSON-RPC batches of unbounded length. An unauthenticated remote client can exhaust server memory with an oversized body or block other clients with a very long batch, causing denial of service.
References: GHSA
To resolve this comment:
Upgrade this dependency to at least version 1.30.1 at console/pnpm-lock.yaml.
💬 Ignore this finding
To ignore this, reply with:
/fp <comment>for false positive/ar <comment>for acceptable risk/other <comment>for all other reasons
You can view more details on this finding in the Semgrep AppSec Platform here.
With hosted agents v2 on, an unset user list admits nobody, and the shared hosted-app fixture starts with `["*"]`. The box-missing retry test put its owner back on the list by unsetting it, so the retry never asked for the box again. It now restores `["*"]`. The people-view test restores whatever list it found, rather than unsetting it. Tests only. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
SWITCH_EGRESS_OPEN (egress-lists; true in the shipped manifest, false by default in code): every box with a proxy login may reach any public host, by CONNECT to 443 or GET and HEAD on 80. With it off, the per-box allow-lists apply exactly as before; their settings are still read and checked either way. The node gate's login always keeps its fixed list. On a split box the agents' login is refused the AI provider hosts, so every AI call still goes through the controller's gateway and its daily cap; the controller's login keeps its list. In both modes, before any box's rule, squid now refuses: - a wider block list, checked against the address it connects to (so a public name resolving inside is refused too): 0.0.0.0/8, 127.0.0.0/8, 192.0.0.0/24, 198.18.0.0/15, 224.0.0.0/4 and 240.0.0.0/4 beside the private, shared and link-local ranges; ::1, fc00::/7, fe80::/10 and the IPv4-mapped ::ffff:0:0/96; and the box cluster's own VPC and service ranges (template values, --cluster-vpc-cidr and --cluster-service-cidr, checked by fill-placeholders); - any CONNECT but to 443, and any plain request but GET or HEAD on 80; - a box over 128 connections at once (squid counts per client address, one per box pod), logged as one fixed line in the in-cluster access log. Each box's traffic is paced at 5 MB/s down after a 100 MB burst, and 2 MB/s up after 20 MB. squid's network policy lets it out on 80 as well as 443, to the same public addresses only. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
squid's block list now also refuses 64:ff9b::/96 (NAT64), 2002::/16 (6to4) and 2001::/32 (Teredo) whole, beside the IPv4-mapped range, so no IPv6 spelling of an internal IPv4 address reaches one behind. Tests check the NAT64 and 6to4 forms of loopback, metadata and a private address, and a Teredo address, land in the list. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The monitor checker needs exactly one category tag on every monitor, and the "Hosted box first starts slow" monitor had none. It's an ops alert like the other hosted monitors. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A suspension replaces a pause, a move's hold or a turn-off on its owner's box, and lifting it used to leave the box asleep (`idle`), so a message could wake a box that a pause, a move or a turn-off should still hold. Now the lift restores, in the stop rule's order: `paused` while the operator's pause mark is set; `migration` while a move holds the box; `turned_off` while the owner is turned off in every workspace the box serves (the condition under which a turn-off stops the box); otherwise `idle`, as before. An administrator's stop, which replaces a suspension, is left as it is. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The gVisor scope rule refused the repo's own squid, which runs under gvisor in egress-proxy, so its next pod after the policy is applied would have been refused. Squid now has its own service account (no token, no RBAC), and the scope rule allows exactly egress-proxy with that account. GuardDuty's runtime agent tolerates every taint by design. The hand-written-toleration rule now excepts exactly its namespace and service account, as it does kube-system. Tests: every gvisor pod template in these files must pass the scope rule; squid's account is its own, with no token; both exceptions refuse any other account or namespace. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Hosted agents v2 works through today's Console as it is, so this change
keeps the server, the box runtime and the cloud setup, and takes out what
only a new Console screen would use:
- the cloud machine card's start and wake messages, and the `start` field
on the machine summary they read (start timing stays, as a metric);
- browsing a box's files from the Console: its routes, the controller's
file replies, the `hosted_cloud_files` flag and their tests;
- the reads behind a People tab, a Usage tab and a per-agent list:
`GET /tenants/{id}/hosted-people`, `GET /tenants/{id}/hosted-usage` and
`GET /shared-cloud/agents`.
What stays: every gate, the admin's per-person turn-off
(`PUT /tenants/{id}/hosted-people/{user}`), the operator's overview and
"Show name" (pause, resume, restart and drain take the keyed ids they
give), the audit reads, and the usage metrics. The box runtime's file
handling stays as synced from upstream; with no route asking, it is idle.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Step 5 of the warm pool box side: - egress-lists reads box-owners (by name) as well as the box map. A box-keyed box takes its owner's settings: the entry named after the person (agents-user-<their keyed id>), the same one their person-keyed box uses, so a setting follows the person across boxes. An owner with no entry gets the defaults; a box-keyed box with no owner gets no login at all, never the defaults. Settings keyed by a box-keyed name are refused. With the open web on (SWITCH_EGRESS_OPEN), a box-keyed box with an owner gets it like every box with a login; with no owner it still gets nothing. A person-keyed box is unchanged. In squid a box-keyed box's id is the box's identity (box-k1-...), never the person's. - A box-keyed provision (a new box when no pool box is free) writes its box-owners entry before its box-map entry, as a bind's B2 before B4. - BOX_KEYED_EGRESS_READY and POOL_BIND_READY are both on: box_keyed_names is listed once the dry run passes, and pool and bind while t2 is admitted. (test_reaper.py: formatting only.) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The walk checked for at least 20 new routes, and taking out the Console's reads left 17, so it failed. It now lists every route v2 adds, so a route added or dropped without meaning to fails here too. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The egress generator refused all of `box-owners` when any one entry was not a box-keyed namespace with a keyed id. The list is add-only, so a bad entry could never be removed, and every box's egress stayed at the last good pass for good (or got none at all after a restart). Now a bad entry is skipped with an alert. Its box has no owner, so it gets no login (fail closed, as for any box-keyed box with no owner), and every other box keeps its egress. The alert names the namespace only when it is a box-keyed name, and never logs the value. The box map is still refused whole. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…d reaper interfaces hosted_pool_boxes and hosted_operator_reports (global tables, one additive migration); HostedPoolStore; per-claim operator capabilities deciding each action's kind and namespace (fixed on first hand-out); a long-poll claim; the re-check and the write-ahead owner_writing step; pool results; refill (only with a recently seen pool-capable operator, never the last per-minute slot); the scaler's pool list; the reaper's two routes on a fourth bearer, reaper_token. The claim (T1), the bind timeout and late done, refill in the sweep, the ceilings and metrics come next. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
T1, the claim, runs inside `CloudMachineStore.claim` under `lock_claims`, only where a brand-new box row would be inserted, after every check the claim already makes: an owner with a live or revivable row never takes a pool box. `box_provision.claim_pool_box` takes the oldest waiting box at the operator's current template revision and up within 24 hours (`FOR UPDATE SKIP LOCKED`), marks it claimed (checked to change exactly one row), and writes the `hosted.pool_box_claimed` entry and the `bind` request; the machine row takes the pool box's id, in the same transaction, so all of it commits together or none of it does. It takes nothing, and the person gets a box made from scratch at once, when there's no current box, no keyed-id key, no box operator seen within five minutes that can bind and name boxes by box, the person or workspace is off the lists, paused, turned off or suspended, or the per-minute window is full (a claim counts as a request in it). The pool is refilled just after a claim commits, as well as on the sweep. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A bind that fails, reported by the operator or not finished 30 seconds after Core asked for it (`expire_binds`, on the sweep, recorded as failed at `bind_timeout`), fails its claim (`fail_bind`): the claim never goes back to the pool, and the machine row is deleted at once and never revived (`bind_failed`), so the person's next click gets a new machine. Before the bind's write-ahead `owner_writing`, nothing of the person's reached the box, so its pool row retires as `failed_before_owner` for the reaper. From `owner_writing` on, the box is the person's: a `hosted.box_to_remove` entry names it for removal, and the reaper never touches it. Both run under the action's lock, as `owner_writing` does, so a timeout and a late owner can't cross; a `done` after the timeout is refused, the action having its result. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The sweep's pool pass, under the claims lock: a waiting box made at a template revision other than the operator's current one retires as `image`, one up longer than a day as `age`, and any beyond HOSTED_POOL_SIZE as `size` (requested first, then the newest waiting), so a size of 0 retires them all; each is reapable. Then the pool is refilled to its size. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Requested and waiting pool boxes count towards HOSTED_LAUNCH_CAPACITY in the claim, and towards HOSTED_BOX_CEILING in `boxes_made` (with a claimed one until its bind is done, then as its machine). Taking a waiting box adds nothing, so a full server still hands one to a person who would get a brand-new row, never to one whose row would be revived. Core refuses to start when HOSTED_POOL_SIZE would leave fewer than 2 of either for people. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
switch.hosted.pool.size and .boxes by state (sampled with the hosted gauges), .claims by path (pool or fallback, for every new box with the pool on), .retired by reason, .refill_seconds, and .reap_refused, which replaces the alert placeholder. Tags are fixed words only, never who. Two monitors: the pool short of its size for 10 minutes (ops), and any reaper report Core refused (security). Four panels on the main and hosted boards, in the same words. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
With v2's box provisioning on, a sign-up no longer claims a machine and asks for its box (`_prewarm`): a box is made, or taken from the warm pool, at the person's first start, so pool boxes go to people who use them. The sign-up answer still says `starting`, which Console shows as nothing wrong. With v2 off, a sign-up warms a v1 machine as before. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The box scaler gives a starting box up to 6 minutes waiting for room and 3 more once it's placed. Core must not call a start that never connected a failure before that (MACHINE_CONNECT_TIMEOUT, at least 600 s), or a box the scaler would still bring up is marked in error first. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…l path From the bind's write-ahead `owner_writing` the box is the person's, which the reaper never touches, so its machine row is no longer deleted at once (nothing would then track the box). It's wanted deleted instead and goes down the normal removal path: the box scaler takes it to 0, `box_deleted` names it for removal (keeping the `bind_failed` mark, so the row is never revived), and its controllers are revoked once the failure commits. Before `owner_writing` the row is deleted at once and the reaper takes the box, as before. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
With hosted agents v2 on and no warm pool (`HOSTED_POOL_SIZE` 0), a sign-up asks for the person's box as it did before the pool, so turning v2 on without a pool changes nothing here. Only with a pool does the first box wait for the person's first start, so pool boxes go to people who use them. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…s written `prepare` refuses (409) a warm pool box given to its person until a bind of it has recorded `owner_writing` (or is done): before then the box could still go to the reaper, so no enrolment code exists and nothing can enrol on it. From `owner_writing` on the box is the person's, and its code is given without waiting for `done`: the box scaler asks once the box map entry (the bind's last step) is written, and a refusal would hold it back for minutes. A box whose bind failed before its owner is deleted and refused as before; a box made from scratch, with no bind, is prepared as before. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Once a box registers, the scaler removes its one-time code from the `switch-enrol` Secret. But the t2 starter waited for a code on every boot, so a registered box that stopped (idle, an eviction, a drain) waited in its starter until the start limit and then showed an error. The box itself only reads the code on its first start. Now the scaler marks the Secret `registered` (a fixed value) in the same write that removes the code, and writing a new code takes the mark out again. The starter waits for a code or the mark, plus the proxy login as before. No code is kept. The cluster's admission policy lets `switch-enrol` hold exactly `code` and `registered`. Tests run the starter's own script against the Secret's keys as the scaler leaves them: a registered box starts again, and an empty Secret (a pool box before its owner is written) still waits. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A warm pool box is already running when it's given to its owner, its starter waiting for a code it couldn't have before. The scaler only asked for a code for a running box after 90 seconds, and then stopped and restarted it, so the box lost most of its head start. Now, when a box's starter is still waiting and its Secret holds no code, the scaler asks Core on that pass and writes the code, with no restart. The starter picks it up when the kubelet refreshes the Secret. If Core says the box is registered, it writes the `registered` mark instead. A refused or failed ask there is tried again after 10 seconds, not 5 minutes, so a refusal can't hold a claimed box past its start limit. A box past its starter, or one without a starter, keeps the old path: asked after 90 seconds and restarted with its new code. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Main's `e223eae63078` (drop server connectors) is a second head beside the hosted-agents v2 chain's `b3e9a4c71d52`. The thirteenth merge revision, `f7c2a5e9d304`, joins them without re-parenting either, and the migration test checks it is the one head. Main also removed the four pre-tool-call mediation routes from the agent bridge, so the route walk's list of main's routes is regenerated from main `908a23b70` the same way as before. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
… and the reaper The cluster's admission policies and RBAC, matched to what the operator, scaler, egress lists and reaper make on this branch. - P1: a box namespace is agents-user-k1-<16 hex> or agents-box-k1-<16 hex>, each with its own name label (switch.dev/user or switch.dev/box). A new policy, for every account, keeps a box namespace's switch.dev/machine-id and name label fixed. - P4: template t2's one init container, the starter, exactly as the operator makes it (its command, uid 2001, resources and two read-only mounts), and its one-key login-check volume; template t1 still passes. The template's name label follows the namespace's shape, and the starter's image must be an allowed one. - pool-map and box-owners: add-only, like box-map, with each new entry's shape checked. A second policy, for every account (admins included), refuses any change to or removal of an existing entry, and deleting a list that holds entries. box-map now takes both name shapes. The provisioner may update the three lists; egress-lists may read box-owners by name. - The reaper: its account, Deployment, egress NetworkPolicy and rights (get the three lists, get and delete namespaces, list persistent volumes), and a policy that limits its delete to a box-keyed namespace with no box-owners entry. - The eviction, P2, P6, P7 and P8 rules, and squid's NetworkPolicy, also cover box-keyed boxes. - DEPLOY.md: pool-map, box-owners and the reaper's token Secret are made before the first apply. - Tests run the operator's own objects through each rule, and check the base64 patterns against sample names. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Five services (the drain worker, controller, operator, provisioner and egress lists) selected `switch.dev/pool: agents` with no toleration. On an agents group with its taint they could never be placed, and the cluster's rules refuse both ways a service could tolerate it (a written toleration, or a gVisor class outside the box namespaces). They now carry no node selector and a preferred, never required, affinity for `switch.dev/pool=system`. Where agent nodes are tainted they land on the system nodes; where there are no system nodes yet they still start, on any node that doesn't refuse them. Each also carries a required anti-affinity to any box's pod (`app=switch-box`, in any namespace) per node. These services hold the operator's, the provisioner's and Core's credentials, so they never share a node with a box, whatever the taints say. The drain worker's earlier preferred rule becomes this required one. A test checks that no workload in the manifests asks for agent nodes unless it runs under a gVisor class, and that each of the five carries the preferred affinity, the required anti-affinity, and nothing that would put it on an agent node. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…-path tests The ninth, eleventh and twelfth merge upgrade tests compared the whole run, which now also holds main's e223eae63078 (after its parent c18f5ebeef66) and the thirteenth merge f7c2a5e9d304 (last). Check where those two sit, then compare the rest as before. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Each bus resyncs after `connected` is set, and a resync revokes a held controller with no database row, as the tests' "c1" is. Waiting only for `connected` let the test attach "c1" while the other process's first resync was still running, so it was revoked rather than suspended. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
switch-core reads HOSTED_POOL_SIZE and HOSTED_LAUNCH_CAPACITY_PER_WORKSPACE, but the chart had no value for either, so a Helm deploy could not turn the warm pool on. switchCore.hostedPoolSize and switchCore.hostedLaunchCapacityPerWorkspace are empty by default and render only when set, so the default render is unchanged; the example values and the README show both, and the chart check covers each. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The operator only told Core about a failure when the cluster refused a create with a 403 or 422. Anything else in a box's steps (a refused list write, a 404, a 5xx, a timeout) failed the round unreported, so the box stayed queued while the action's lease ran out and was retried, until the action expired. A list made with labels showed this: replacing the Secret whole dropped them, the cluster's rule that labels stay as they are refused every write with a 422, and no box was ever finished. Now every cluster call in a box's steps goes through one place. A 5xx, 429, timeout or lost connection is tried again after 1, 3 and 6 seconds. Any other error, or one still failing, is reported to Core as a failure with the step's existing code (name_refused, policy_refused or object_refused for a create, box_map_failed for a list), so the person sees an error at once and can retry. The log gives the error's type and HTTP status, so a cluster error can be told from a refusal. A refusal is reported at once as before, and a failed call to Core is still left to the lease, since there's no one to report to. A list write now keeps the labels and annotations its read found, so a labelled list still takes an entry. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
When a box waited for room for the full 6 minutes, the scaler reported an error with the generic `machine_needs_attention` code, so Core couldn't tell "the cluster had no room" from a box that failed. Now that observation carries `error_code: no_room`, so Core can show its own cap message with Retry. A Core without the code refuses it with a 422; the observation then goes again as before, and the code isn't offered again for an hour, the same way the waiting-for-room field backs off. A start timeout never carries it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Each claim now also carries the box map's size (`boxes_live`), the operator's ceiling, and the box namespaces themselves (`boxes`), so Core can alert before the ceiling is reached and find boxes it no longer knows about. A Core from before refuses unknown claim fields with a 422: the claim goes again at once without them, and they aren't offered again for an hour. A box map that can't be read leaves the fields out, so a claim never waits on it. Namespaces only: nothing else about a person. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Hosted agents v2 in one PR, server and cloud side: each person's agents run in their own sandboxed box in a separate cluster, instead of a cloud VM per person. Everything is behind
HOSTED_BOX_PROVISIONING, where anything unclear reads as off. With v2 off, nothing changes for v1. v2 works through today's Console as it is: this PR has no Console app change (see the last section).This replaces #1986, #2017, #2021, #2042, #2112, #2166 and #2201, and two stacked changes that were never opened as PRs. One commit per area, in this order, so each can be read on its own, then follow-up commits and one removal commit at the end.
1. Page on hosted launches that are refused or never come up
A machine whose first launch the hosted controller refuses, and that has never been ready, now records
launch_refused, and "Hosted machine launches failing" counts it. Fixed words only in reasons, tags and log fields.2. Box runtime packages, and 3. their sync to main
console/packages/agent-providers-box,agent-controller-boxandswitch-agent-runtime-box: copies of the upstream agent packages, pinned to an upstream commit with a drift guard, plus what a box needs (the provider gateway in the controller, sealed logins opened only on the box, the box's start-up and enrolment, the memory guard). The copies are synced to this branch's base, which brings upstream's handling of a suspended owner (stop agents, keep the credential, retry) into the box controller.4. Cloud setup, with boxes that start in seconds
deploy/hosted/: the box provisioner and operator, the scaler, the node gate, egress lists and the proxy with a login per box, the manifests and admission policies, and the box image. Boxes start and open their egress within seconds, event-driven rather than on timers. switch-core's chart gains its v2 values, all off by default, and renders byte for byte as before without them; CI runs the hosted controller's tests and checks the chart.5 and 6. Only sandboxed pods on agent nodes
The box clusters taint agent nodes, so the
gvisorandgvisor-tunedRuntimeClasses now carry the agents toleration, and every pod that runs under them gets it. A cluster-wide policy lets only box namespaces, the placeholders and the drain room use a gVisor class, and requires one for any pod that tolerates the agents taint by hand. Drain placeholders run under gVisor too. The box template and its admission policy don't change.7. The server, behind the v1/v2 switch
Asking the box cluster for a person's box through every gate (allow-lists, pause and per-workspace turn-off, capacity, the per-minute limit and box ceiling), enrolment and the box's controllers, sleep and wake with the owner re-checked, retention and removal with controllers revoked, the Switch operator role with its rate-limited, audited actions, the operator overview and audit reads, and the monitors. Alembic merge revisions join v2's migrations with main's. No revision on main changes. One v2 revision, the move's (
c118ea00053c, section 11), now follows the last merge revision instead of its original parent, so the migrations keep a single head.8. A box ready in seconds on the server
A box is ready on the second of its two signals, whichever comes first, and shows as ready on screen at once. Each stage of a start is timed (
switch.hosted.start_seconds, by case and stage only). A box the cluster reports missing is asked for again once, through every gate, with its old controllers revoked and audited first. A box retained or wanted deleted is never woken by a message.9. Start states on the cloud machine card
Taken out again by the last commit, with the Console's other v2 screens (below).
10. Closed by default, and a cap per workspace
With v2 on, an unset
allowed_tenant_idsorallowed_user_idsadmits nobody, and"*", alone, admits everyone. A server turning v2 on must set both lists, to names or"*". With v2 off, the lists behave exactly as before.HOSTED_LAUNCH_CAPACITY_PER_WORKSPACE(v2 only, 0 for none) caps the live machines serving one workspace, under the server-wide capacity. "Live" means not deleted, so a retained machine still counts against its workspace's limit until its retention ends (7 days by default), as it does against the server-wide capacity.11. Move a person from a v1 cloud machine to a v2 box
switch-hosted-migration, an operator command that moves one person's v1 machine to a box in place, in recorded steps that can be rolled back. A dry run unless--execute; v2 only.12. A suspended owner's box stops at once and never wakes
Suspending an account also stops the owner's box in the same transaction, with a
suspendedstop reason, and every gate blocks them as a pause does, moves included. Lifting the suspension gives the box back a pause, a move's hold or a turn-off that still applies; otherwise it's left asleep, so the next message wakes it, through every gate again.13. Plain words for internal labels
Text only, in comments, docstrings and test headings.
14. A warm pool, and boxes ready for an autoscaling cluster (box side)
The cluster can keep a few boxes started ahead of need, and a person's first start takes one and binds it to them instead of waiting for a new box. Off unless the pool size is above 0, and used only when the operator reports it supports the pool and binding.
agents-box-k1-…), with one shared name pattern; readers still accept the olderagents-user-…names.safe-to-evict: "false", so a node with a box is never taken, and the scaler reports a box that's waiting for a node, which doesn't count against its start limit.On the server: a person's first start takes a waiting pool box inside the claim, in the same transaction, and otherwise makes one as before. A bind has 30 seconds; one that fails before the owner is written goes back to the reaper, and one that fails after goes down the normal removal path. No enrolment code is given until the owner is written. The sweep retires stale pool boxes and refills. Pool boxes count towards the launch capacity and the box ceiling, and Core refuses to start if
HOSTED_POOL_SIZEwould leave fewer than 2 of either for people. The reaper has its own bearer (reaper_token), accepted on its two routes only. With a pool, a sign-up no longer makes a box; with none, it does as before. Metrics, two monitors and dashboard panels cover it.The pool stays off until
HOSTED_POOL_SIZEis set above 0 (default 0), and the operator only offers pool boxes once the cluster's pool policies are in place. Those admission policy changes follow as a commit on this branch. A box made with the starter starts again after it has registered (the scaler leaves a fixedregisteredvalue in place of the spent code), and a claimed warm box gets its code at once, without a restart.Left for a later Console change
The last commit takes out what only a new Console screen would use, so this PR is the server, the box runtime and the cloud setup:
startfield (start timing stays, as a metric);hosted_cloud_files), its routes and the controller's file replies. The box runtime's own file handling stays as synced from upstream, idle with no route asking;GET /tenants/{id}/hosted-people,GET /tenants/{id}/hosted-usageandGET /shared-cloud/agents.What stays: every gate, the admin's per-person turn-off (
PUT /tenants/{id}/hosted-people/{user}, which takes the person's user id), the operator's overview and "Show name" (pause, resume, restart and drain take the keyed ids they give), the audit reads and the usage metrics.With v2, today's card shows a box that's paused, turned off or being moved as "Stopped". Pressing Start then shows the server's plain reason under the card. Telling those apart on the card needs the later Console change.
Testing, and what follows
gateway/,visibility/,management/and the v2 switch tests in both modes (4,675 each), apart from the route walk's old minimum, which the exact route list replaces.SWITCH_EGRESS_OPEN(off in code), with private, cluster and metadata addresses refused first, and IPv6 forms that carry an IPv4 address refused too;category:tag on the box first-start monitor, which the monitor check caught;box-ownersentry is skipped with an alert, so only that box loses its egress, instead of every box.🤖 Generated with Claude Code