Skip to content

Make a hosted agents v2 box ready in seconds on the server - #2201

Closed
niall-sandboxaq wants to merge 6 commits into
hosted-v2-serverfrom
hosted-v2-fast-start-core
Closed

niall-sandboxaq wants to merge 6 commits into
hosted-v2-serverfrom
hosted-v2-fast-start-core

Conversation

@niall-sandboxaq

@niall-sandboxaq niall-sandboxaq commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #2042. Core's side of making a hosted agents v2 box ready in seconds, plus a box-missing re-ask and one wake fix. With v2 off nothing changes.

Ready when both signals are in

  • A box becomes ready when the second of its two signals arrives, whichever comes first: the scaler's running, or a report from the box's controller. Before, Core waited for the controller's next periodic report after running, which added about a minute to nearly every start.
  • One helper, cloud_controllers.ready_if_both_signals, makes the decision for both paths. On the running path it re-checks that the recorded report is at the current revision, from the controller still on this machine for that workspace, and not revoked.

Ready on screen at once

  • The owner's machine summary counted a workspace's report only if it came after running. Since the controller nearly always reports first, a box that was ready still showed as starting until its next report.
  • For a v2 box, a report made at the machine's current revision now counts too, under the same conditions as the ready check: made by that workspace's own controller, which must be unrevoked and still have its key, and counted for that workspace only. v1 machines, and everything with v2 off, keep the old rule.

Start timing

  • switch.hosted.start_seconds, tagged only with a case (first_start, wake) and a stage, from one fixed list in observability/hosted.py. The first click and the box request are timed separately.
  • Two panels on both dashboards, and a "Hosted box first starts slow" alert at p90 over 30 s. A test checks every case and stage they use is in the list.

Re-asking for a missing box

  • Core's machine list marks a v2 box it counts as made (box_expected): one with a finished provision since its latest revival.
  • When the scaler reports box_missing at the current revision, Core records it and asks for the box again once per revision, through every gate. It never re-asks for a box whose disk is set for removal, whose controller was revoked, or whose owner may no longer have a box. Those go to error.
  • On that re-ask, or on a Retry of the error, the old box's controllers are revoked and their enrolment codes cleared, so the new box can enrol. An audit entry is committed before any revoke.
  • The revoke and the re-ask aren't one transaction: each workspace's revoke commits in its own scoped session, as a revival's does. If the later step fails, the next report puts the machine in error and a Retry recovers it.
  • The audit entry is written by box_provision.record_controllers_revoked, so cloud_controllers opens no unbound session and the tenant exemption allowlist is unchanged.

A kept box is never woken

  • A box that was retained, or wanted deleted, but still had stop reason turned_off could be switched back to wanted running by a message to one of its agents. It no longer can.

Not in this PR

  • total ends at Core's ready. Egress opening, when the box's first model call can get out, isn't timed yet. That needs the box controller to report it.
  • Only first starts and wakes are timed, not a new agent or a resume on a box that's already running.

Testing

  • New tests for each part, including both signal orders, a revoked or another controller's report, a revision bump, crashes between the box-missing steps, a failed revoke still leaving its audit entry, every stop reason for the wake fix, and the on-screen state in report-first order (with another workspace's, another controller's and a revoked controller's report, and v2 off).
  • Full suite on Postgres 16, v2 on and off, on this branch's head: 17,330 collected, 17,329 passed and 1 expected failure in each mode, 0 errors.

🤖 Generated with Claude Code

niall-sandboxaq and others added 6 commits November 19, 2026 17:02
Core waited for a controller report that came after the scaler's
running, so a box usually sat a full report interval before ready. One
helper now marks a box ready when the second signal arrives, in either
order, and re-checks that the report is current, from this machine's
controller, and not revoked. With v2 off nothing changes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Records switch.hosted.start_seconds tagged by case and stage only, from
one fixed list, with the first click and the box request timed apart.
Adds start panels to both dashboards and an alert when first starts are
slow.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Core's machine list marks a v2 box it counts as made. When the scaler
reports it missing at the current revision, Core asks for it again once
per revision through every gate, never for a box set for removal, with a
revoked controller, or whose owner may no longer have one. On that
re-ask or a Retry, the old box's controllers are revoked and their codes
cleared, after an audit entry is committed.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A box retained or wanted deleted, but stopped as turned off, could be
switched back to wanted running by a message to one of its agents. The
wake path now refuses it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The `hosted.box_controllers_revoked` audit entry is now written by
`box_provision.record_controllers_revoked`, which already writes the other
box provision entries in unbound sessions that touch only
`server_audit_events`. `cloud_controllers` opens no raw session again, so
the tenant exemption allowlist stays as it was. Same order: the entry is
committed before any revoke.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A v2 box's controller nearly always reports before the scaler sees the box
running, and F1 then makes the box ready on `running`. But the owner's
summary counted a workspace's report only if it came after
`running_observed_at`, so the workspace still showed `provisioning` until the
controller's next report.

Each workspace's report now records its revision and controller (v2 boxes
only). `workspace_reported` also counts a report made at the machine's
current revision, by that workspace's own live, unrevoked controller, for
that workspace only: F1's own rule. v1 and v2-off unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@niall-sandboxaq

Copy link
Copy Markdown
Collaborator Author

Closing: this is being folded into a single hosted agents v2 PR, built from current main. A link will be added here once it's up. The branch is kept for history.

@niall-sandboxaq

Copy link
Copy Markdown
Collaborator Author

Folded into #2216, which brings all of hosted agents v2 into one PR with one commit per area. Closing this one in its favour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant