Repository navigation
Lease machines from cloud peers (provider commands) - #32
Conversation
A cloud peer is an errand daemon with machine offers. When no runner you own matches --where (new terms: gpu, gpus>=N, gpu=MODEL, vram>=N), it leases a machine, the machine joins as a runner, and the job runs there. Leases end on idle, at a max lifetime, or with `errand leases rm`, and survive restarts. Providers are two commands (acquire, release) or the built-in Lambda Cloud provider, which installs errand over SSH and never leaves an instance billing after a crash. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
- Ctrl-C during the lease request no longer drops the lease: the request finishes, and the launching lease it names is released. - A launch is canceled at the offer's max_lifetime, not only at acquire_timeout. - A lease is ready only once that is recorded; a failed write releases it instead of leaving a record a restart would release under a job. - The running broker forgets leases that ended over a week ago, as startup already did. - Offers are shown only to callers that may see their lease IDs, so a caller without the lease action never forgets live lease peers. - doctor still runs its automatic-apply checks when a run would lease. - GPU facts refresh in the background, so a hung nvidia-smi cannot push /v0/info past the client's placement deadline. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
Without tailscale_auth_key_file, a leased Lambda machine runs its runner with transport = "ssh": no network port, and jobs reach it over SSH on port 22 like any SSH peer. Clients' public keys come from the offer's authorized_keys. The lease carries the host key the machine booted with, and errand pins it for that target, so no known_hosts entry or prompt is needed and a reused IP cannot impersonate the machine. The cloud peer watches the runner with the key it installed it with. Command providers can return the same host_key with an ssh target. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
- A workspace's own run.where never rents a machine; personal defaults, profiles and --where can. - Lease requests must be application/json without an Origin header, so a web page cannot start a billable machine. - A run rents a machine only after its local preparation (forwards, snapshot) succeeds. - Placement drops ended lease peers and runs again, even when the machine still answers. - Releases are acknowledged only once recorded. - The reaper checks max lifetime before probing and probes ready leases concurrently. - static-pool.sh claims a slot and records its lease in one atomic step. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
The cloud peer makes its own SSH key on first use, adds it to the Lambda account, and installs and watches machines with it, so ssh_key_name and ssh_private_key_file are gone. Each client makes an errand SSH key of its own and sends the public half with the lease request; the machine admits only that key, so authorized_keys is gone too. A lease is reused only for the same client key. Command providers get the key as ERRAND_LEASE_SSH_KEY. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
- Tailnet leases run Tailscale-only, so no SSH key reaches their runner. - A runner with active leases refuses to start without its [cloud] section, and a command offer's leases are bound to its exact commands. - Host key pins live in the state directory and are written before the lease is recorded; pinned connections get their own control path. - The idle check records a release before destroying the machine. - Lease records keep their cloud peer's entry, so release works after the name changes. - workspaces create rents only after its snapshot is prepared. - Provider stderr is drained past an over-long line. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
The cloud peer now drives each lease with one worker goroutine that makes every provider call. Every change goes through one update that writes the whole record before readers see it, and only moves leases forward. A lease records how to release itself (release command or Lambda API key file), its idle timeout and the key the cloud peer probes it with, so changing or removing offers or the whole [cloud] section only stops new leases. Every runner now has a broker; the refuse-to-start checks are gone. A restart still releases interrupted launches. Clients keep no lease records, pin files or peer aliases. /v0/info lists the caller's active leases with their targets, host keys and admitted SSH key; placement, ps, peers and lease peer names (cloud-7f3a, any unambiguous ending of the lease ID) all come from that list, and host keys are trusted in memory for the process. Lease requests carry a request ID, so a client that lost the answer gets the same lease again. Release cancels a running acquire or probe. Leases reached over the tailnet are reused across a user's machines; SSH ones only by the machine whose key they admit. Offer gpus is capped at 64 and acquire stdout at 16 KiB, which keeps release's state within Windows' environment limit. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
…lease Ctrl-C before the job starts now withdraws the run's lease request. The cloud peer ends the lease only if that request made it and no other request was handed it; a ready lease is released at its next check unless a job is running on it. This replaces the client deciding from the lease state. Also: a cloud peer without offers keeps leftover [cloud] settings and stays listed by errand leases while it holds leases, and the client SSH key is placed private half first, with a missing public half derived again. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
… terminated A leased machine admits its owner for every action, so holding a lease needs submit on the cloud peer. A caller without it is no longer shown lease targets, and its leases end when it next asks about them. Lambda release now counts only once Lambda's instance list shows every instance of the lease terminated (or gone). Release returns ReleasePending while termination is under way, and the broker asks again shortly. Docs say the idle and lifetime limits hold only while the cloud peer runs and are not a spending cap. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
…s leases A lease now records each request it was handed. An interrupted run withdraws its own request, and the lease ends only once no request still holds it; a job seen running, or more than 32 requests, leaves it to the idle rule. A withdrawal the cloud peer no longer ties to a lease is reported as kept rather than as a failure. errand leases also asks the implicit local peer, which placement can rent from. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
A run that resolved a lease now withdraws its request whenever it ends before anything was submitted there, not only on Ctrl-C. The idle deadline is derived from when the lease was last busy, so it is right after a restart. The state directory is made absolute so recorded identity paths survive a different working directory, and pinned lease sessions offer only their own keys. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
A machine resolved for one run is now held by an explicit claim, which the run settles once with what became of its request there: nothing admitted (not submitted, or definitely refused) withdraws the lease request; admitted, or possibly admitted after a lost answer, leaves the lease to the cloud peer's idle rule. Run and workspace creation share the contract, and a target never tried also gives up its claim. The cloud peer decides an automatic release against the lease record as it is when the release is recorded, not as it was when the idle probe began, so a lease handed to a request during a probe is not released. Handing out a ready lease counts as use. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
The broker's ownership fields (request ID, request list, kept, unwanted) become one holder set and a "a job has used this machine" bit, from which everything else is derived. docs/DESIGN.md states the lease guarantees, and the broker tests name the guarantee they check. A lease takes at most 32 waiting runs. From the first real Lambda run: errand leases rm finds a bare lease ID's cloud peer without --on, and the cloud peer logs each lease's lifecycle. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
Runners report the GPUs nvidia-smi lists, refreshed at most once a minute in the background so a slow driver never holds up info. --where gains gpu, gpus>=N, gpu=MODEL and vram>=N, combined per GPU, plus os=windows. Runners recheck them at admission, and errand peers shows a GPUS column. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
…ases # Conflicts: # cmd/errand/peers_render.go # docs/CONFIGURATION.md # internal/daemon/server.go # internal/placement/requirements.go # internal/placement/requirements_test.go
This branch carries cloud leasing with provider commands: the broker, the CLI, the daemon endpoints and the client lease flow. The built-in Lambda provider follows separately. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
Active copied the stored lease instead of its view, so /v0/info listed ready leases without the derived idle deadline. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
The test waited for a second probe that a withdraw could make unnecessary, so it sometimes hung. It now reuses the lease while the first idle probe is held, which is the window the guarantee is about. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
…s --on errand peers lists leased machines, so peers --on now accepts their names too. leases rm becomes leases release, which says what it does to a rented machine. The lease endpoints, including the internal per-run withdraw, are written down with the rest of the protocol. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
launch looked up the lease's offer and creation time without the lock while a withdraw could replace the record, which the race detector caught in CI. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
Every reachable cloud peer with a matching offer can supply a machine. --where ranks their cheapest matching offers by price, priced before unpriced and equal ones at random, and asks the next cloud peer when one turns the request down before starting anything. A cloud peer leases its own cheapest matching offer the same way. The default peer and a cloud peer's own load play no part. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
When ssh exited with 255 before saying anything, a read reported the peer unreachable but a write reported only that ssh ended. Whether the request write or the response read hit the closed pipe first depended on timing, so TestSSHConnectFailureIsUnreachable was flaky in CI. Both now explain the error through one function. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
|
The same run also caught a data race in this PR's own code: Generated by Claude Code |
|
The only red check left is Generated by Claude Code |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
Security findingsAdvisory findings (1)ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
The check that ends the leases of a caller that lost submit ran only in lease handlers and in /v0/info behind the lease action, so a caller left with read-own, or with nothing at all, kept its leased machine until the idle or lifetime limit. It now runs in the auth wrapper for every identified caller, before the action check. Also take lease offers only from configured peers. A leased runner that offers machines itself is probed as a runner, and renting from it would leave a machine nobody ends once the intermediate lease goes idle. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
/bin/true is /usr/bin/true on macOS, so the lease ended in the first step stayed releasing and the next step saw two leases. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
…eases # Conflicts: # cmd/errand/peers_render.go # docs/CONFIGURATION.md # internal/daemon/server.go # internal/placement/requirements.go # internal/placement/requirements_test.go
|
@codex security review Generated by Claude Code |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 48e5fafa2a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
A buffer that limits what it keeps by overriding Write while embedding bytes.Buffer also exposes Buffer.ReadFrom. exec.Cmd copies a child's output with io.Copy, which prefers ReadFrom, so the limit never applied: git merge-file's stderr was kept in full. internal/limitbuf wraps the buffer instead, and merge uses it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
limitedBuffer embedded bytes.Buffer, so exec copied acquire's stdout and release's output through Buffer.ReadFrom and never hit the limit: an acquire that printed more than 16 KiB was accepted and kept in memory in full. The provider now uses limitbuf.Buffer, which is also on its way to main for the same bug in merge. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
5aea0d2 to
1a52e8c
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1a52e8ce77
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
A caller that keeps the lease action but loses submit has its leases ended, and list and get already hid their targets from it. Release returned the raw lease, so its target leaked. Every response that carries one lease now goes through leaseView. Also covers a child of the acquire command that keeps stderr open: a release still goes ahead once the command is stopped. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0600050769
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
--where turned a ready lease the cloud peer listed into an ordinary candidate and ran on it directly. Nothing then held the lease for the run, so it could go idle and be released while the run was still preparing (lease guarantee 5). A ready lease is no longer a placement candidate: the run asks the cloud peer, whose Acquire already hands a matching ready lease to the request as a holder and starts a full idle window. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 307e8df40a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Here are some automated security review suggestions for this pull request.
Reviewed commit: 307e8df40a
ℹ️ About Codex security reviews in GitHub
This is an experimental Codex feature. Security reviews are triggered when:
- You comment "@codex security review"
- A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
A caller with lease but not submit was shown its leases without their targets, but the progress and error lines still carried the provider's output, and a pool provider prints the URL it claimed. Those callers now see neither. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 84a351249d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Since 307e8df every --where run that reuses a ready lease is handed it by the cloud peer, and each hand-out added a holder. A run whose job started and ended between two idle checks never withdraws, so holders piled up until the 32-holder bound turned later runs away. Handing out a ready lease now counts as use, as a job seen on the machine does: holders stop mattering and only the idle and lifetime rules end it. The latest run is kept as the one holder, so its retry and withdrawal still find the lease. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
The release script returns at once, so by the time info answers the lease can already be released and is no longer listed. What the test checks is that no listed lease shows its target. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fcf95d817b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Before: when
--wherematched none of your runners, the run failed.After: a runner with
[[cloud.offers]]becomes a cloud peer. When no runner of yours matches but a cloud peer's offer does,--whereleases a machine, waits until it answers as an errand runner with matching facts, and runs the job there directly. Machines come from two provider commands (acquire, release);docs/cloud/static-pool.shis a complete example.Which cloud peer supplies the machine: every reachable cloud peer with a matching offer can. The cheapest matching offer wins (priced before unpriced, equal ones at random). If a cloud peer turns the request down before starting anything (no permission, nothing matches, or it is at
max_leases), the next one is asked. Neither the default peer nor a cloud peer's own load plays a part, and there is no new setting.The surface stays narrow. A ready lease shows up as a peer, so
errand peers,errand peers --on cabal-7f3a,--on cabal-7f3aand job handles all work on it.errand leaseslists your leases through their whole lifecycle, anderrand leases release cabal-7f3areleases one and waits until the provider confirms the machine is gone. You can only get a lease through--where. The per-run withdraw endpoint (DELETE /v0/lease-requests/<id>) is part of acquisition and has no command.This is the second of three PRs split out of #26. The first, #31 (GPU where terms), is merged, and this PR now targets main. The built-in Lambda provider stays in #26, which is stacked on this one, as is #35 (SSH leases usable from all your devices).
The lease rules are written down in docs/DESIGN.md under "Lease guarantees", and each broker test names the guarantee it checks. In short:
How: the cloud peer keeps the only lease record. One worker goroutine per lease makes every provider call, and every change is checked, persisted and only then made visible. Ownership is a set of holder requests plus one bit for "a job has run here". The client keeps no lease state: it finds its leases in
/v0/infoand settles one claim per run. It also has its own SSH key and pins host keys for machines reached over SSH. Callers need a newleaseaction in the errand capability on top ofsubmit. A caller that losessubmitloses its leases at its next request of any kind.🤖 Generated with Claude Code
https://claude.ai/code/session_013BQxiCNDXMnjv5pvmgo5E6