Repository navigation
Hosted agents v2: a warm pool of boxes - #2231
Merged
Merged
Conversation
Core issues a box's registration code for 15 minutes (MACHINE_ENROLLMENT_CODE_LIFETIME; 30 with hosted agents v2 off) and mints a new one only once the last has expired. The module text and one log line said 30 minutes. Wording only. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The warm pool's first box-side step. box_names.py is now the one place box namespace patterns live, and a test fails on a pattern compiled anywhere else (the placer had its own copy): - BOX_NAMESPACE_RE, exact: agents-user-k1-<16 hex> (person-keyed, every box so far) and agents-box-k1-<16 hex> (box-keyed). Everything the operator makes or names. - KNOWN_BOX_NAMESPACE_RE, for the readers of the box map: the exact box-keyed shape, or a person-keyed name as loosely as before, so a legacy name never stops every box. The workers' round line counts legacy names (legacy_names=, a count only) so the allowance can go later. The operator makes the namespace Core names for each action, checked to be one of the two that action may have (person-keyed, or box-keyed for the box Core names); anything else is refused and nothing made. A Core that names none gets the person-keyed name, as before. A box-keyed box's identity is box-k1-…: its hostname, and its one name label, switch.dev/box (never switch.dev/user). A person-keyed box is made exactly as before, so existing boxes still match on re-claim (tested for both shapes). Each claim now tells Core this build's template revision and capabilities. box_keyed_names is listed only while a server-side dry run (dryRun=All) of creating a fixed probe namespace passes admission, checked at start and hourly: a refusal drops it, an error keeps the last answer. So until P1 admits the new shape, Core keeps naming boxes after the person. It also needs BOX_KEYED_EGRESS_READY, False in this build: a box-keyed box gets no egress login until egress reads box-owners (a later step), so no box is made box-keyed before then. Pool and bind actions are refused until this operator lists them. Egress fails closed for a box-keyed box: no login (so no egress) until its owner's settings are read from box-owners, never the defaults; settings keyed by a box-keyed name are refused. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A box's 3-minute start limit counted from "wanted running", including time its pod sat Pending with no node to run on. A new node takes 1½ to 3 minutes plus the image pull, so with autoscaling a box that would have come up could be reported as an error. The scaler now reads the box's pod (from the eviction watch's last look, or box-0 by name) while it waits. While the pod is Pending and the scheduler has said Unschedulable, the time isn't counted: the 3-minute limit starts once the pod is placed. Waiting for room has its own cap, 6 minutes, so room plus the start limit stays within Core's 10-minute connect timeout (pinned by a test, as is the cap staying under the box code lifetime); past it the box is reported as error with its own text. Core is told with the existing observation path: state provisioning plus waiting_for_room: true. A Core without the field refuses it with a 422; the observation goes again without it, and the field isn't sent again for an hour or until a restart. No new rights. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Template t2 (warm pool): - A starter container (init) runs the box's own image and waits until the code (switch-enrol) and the proxy login (one key, https_proxy, by items, presence only) are both there, checking every 0.5 s, then exits with a fixed line. The main containers are created after it, so they start once and read both. It's hardened as the controller is, with small fixed limits; it never prints a file. - switch-enrol is mounted with defaultMode 0440 (Secret files are root-owned, so the pod's group reads it, only in the containers that mount it: the controller and the starter). The login check volume is the starter's alone; the main containers keep the login in their environment. The egress pod-spec check allows exactly that one volume of the login Secret, mounted read-only by the starter, and nothing else. - The pod template carries cluster-autoscaler safe-to-evict "false", so the autoscaler never removes a box's node. Our own drain and moves evict through the API and don't read it. A box made by template t1 is still its own on re-claim (earlier shape "before the starter container", for both name shapes; the daily-call-cap shape now builds on it). The ticked-template test checks t2's three additions exactly, then compares the rest with the reviewed render. The template revision becomes t2-<image>. Deploy order: P4 must accept the starter, the login check volume and the annotation before this operator runs, or new boxes are refused. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A safety net behind the deploy order (P4 first): if the cluster's admission refuses the t2 StatefulSet (a 403 or 422 from a policy; not a network error, which stays a failure to retry), the operator makes the same box as template t1 in the same step, logs a fixed line with the status, and for an hour neither tries t2 again nor lists pool or bind, so Core makes no pool boxes while a pool box couldn't have its starter. Normal boxes start on t1 exactly as before, and a t1 box made this way is re-used later. Pool and bind are listed only by the build that makes pool boxes (POOL_BIND_READY, False here). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The operator's warm pool steps, against Core's provisioner interfaces: - pool: a normal new box made early under the box-keyed name Core gives, without its agent-egress rule and without a box-map entry, so it reaches nothing and nothing that serves people knows it; plus a pool-map entry. - bind, every step adding only, the box map last: B1 the namespace's machine-id annotation is the machine Core binds (else bind_machine_mismatch, nothing written); owner_writing recorded with Core first (its 409 is bind_closed, nothing written); B2 box-owners[namespace] = person (another owner already there is bind_owner_taken, with a fixed alert line); B3 the box's agent-egress rule; a re-check that the claim is still open (else bind_closed, the box map never written); B4 the box-map entry, then done. A bind retried after a crash at any step carries on and ends bound once. - pool and bind name only box-keyed namespaces. The two lists are read and replaced at their resourceVersion, add-only (the cluster's policy is the backstop). The claim token goes only in X-Claim-Token on the two bind calls and never reaches a log. - The claim long-polls (wait_s=25); an empty answer goes straight to the next claim, one that came back at once still pauses. - The scaler starts and stops the pool boxes Core lists, and does nothing else for them: no observation, no code. Pool and bind stay unlisted (POOL_BIND_READY False) until the build whose egress reads box-owners, together with box-keyed names. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
switch-hosted-reaper (reaper.py, reaper_main.py) is its own program on its own account and its own Core credential (reaper_token). Each pass it reads Core's retiring list and, for each pool box, checks on the cluster that the namespace is an exact box-keyed name, is in pool-map under that pool box's id, and is in neither box-map nor box-owners, before deleting anything; anything else is refused with a fixed alert line and never deleted. It then deletes the namespace (its only write), and only once the namespace is gone and no persistent volume still names it does it tell Core the box is gone. A box still going is looked at again next pass; one failing never stops the others. Its Kubernetes client refuses any namespace that isn't box-keyed and any Secret but the three lists. The cluster's admission policy is the last word on the delete. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
test_pool_bind_crash.py drives bind(stop_after=...) and reap_once(stop_after=...) with a BaseException, so nothing in the operator can catch it, and retries with a fresh operator against the same fakes. A crash before the owner is reapable; from owner_writing on the box is the person's and never goes live after a closed claim; after B4 a retry writes nothing again; the reaper never deletes a box that reached its owner and never deletes twice. Mutation proofs: without the re-check before B4, or the owner_writing check, or the reaper's box-owners check, the tests fail. 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>
Collaborator
Author
|
Folded into #2216, which now carries the warm pool as well. Further pool commits go there. 🤖 Generated with Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A warm pool for hosted agents v2, stacked on #2216: the cluster keeps 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 set above 0, and only used when the operator says it supports the pool and binding.
This draft has the box side so far. The server side (taking a pool box inside the claim, refill and retire, capacity, metrics) and the admission policy changes follow as commits on this branch.
Box side, in this order
agents-box-k1-…), with one shared name pattern; readers still accept the olderagents-user-…names.Testing
🤖 Generated with Claude Code