Take a lease before heavy or shared work and release it after, with `fleetlayer lease` (Fleetlayer's leases plugin): a slot on a shared build server before a big compile or test run, a lock on one named thing (a Terraform component while you plan and apply it), or a claim the person approves once (a mail filter while you watch CI). Use before any heavy build, test suite, image build or other job that loads a shared machine; when a command waits "in line" for a slot; when the person asks to li...
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Skill?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/fleetlayer-skill-76ea85c8)
---
name: fleetlayer-leases
description: Take a lease before heavy or shared work and release it after, with `fleetlayer lease` (Fleetlayer's leases plugin): a slot on a shared build server before a big compile or test run, a lock on one named thing (a Terraform component while you plan and apply it), or a claim the person approves once (a mail filter while you watch CI). Use before any heavy build, test suite, image build or other job that loads a shared machine; when a command waits "in line" for a slot; when the person asks to limit how many builds run at once; when a message says a lease started or ended; or to set up kinds of lease.
---
# Leases
A lease is a claim on something for a while: one of a build server's slots, or a claim the person approved. One
authority (a plugin on an always-on node) keeps them all, and `fleetlayer lease` talks to it from any machine.
## Take a slot before heavy work
Before a big compile, a full test run, an image build or anything else that loads a shared machine, take a slot of
its kind for exactly that command:
```sh
fleetlayer lease list # the kinds there are, who holds and who waits
fleetlayer lease list --kind docspring-dev --holder '*@laptop' --json # one kind's, one holder's (`*` wildcard)
fleetlayer lease run build-server --reason "full test run for the billing change" -- cargo test --workspace
fleetlayer lease run terraform --payload '{"component":"dns"}' --reason "apply the DNS change" -- terraform apply
```
A kind that locks one named thing at a time (`fleetlayer lease list` shows it "per" a field) takes that thing in
`--payload`, as JSON, on `lease run` as on `acquire`.
`lease run` waits its turn, runs the command, and releases the slot when the command ends, however it ends (an error,
Ctrl-C, a kill), passing its exit code through. It's the default for one-shot work: nothing to remember, and no slot
left held after it (a held, unused slot holds up everyone behind it). Use `acquire` and `release` only when the lease
must span several commands or outlive one:
```sh
out=$(fleetlayer --json lease acquire build-server --reason "release build and image" --wait) || exit 1
id=$(printf '%s\n' "$out" | tail -1 | jq -e 'select(.phase == "held") | .id') || exit 1
# … several heavy commands …
fleetlayer lease release "$id"
```
Check both: that `acquire` succeeded, and that the last line's `phase` is `held`. With `--wait --json` the first line is
the request in line (`"phase":"waiting"`), so if `acquire` fails after it, a bare `| tail -1 | jq .id` hands you the
ID of a lease you don't hold, and the pipe's status is jq's, not acquire's.
Never read a lease's ID from `acquire`'s words: take it from its standard output (or `--json`). You can release only
your own leases.
- `--wait` waits your turn, first come first served (a deploy with `--priority` goes ahead of everyone waiting; you
can only ask for that if the leases settings' `priority:` list names you, so don't), and says where you are in line. Without it, `acquire` fails at
once when every slot is taken and names who holds them. If the authority can't be reached for a moment, `--wait`
asks again by itself and gets its own request back, still in its place: don't start a second `acquire` beside it.
Ctrl-C while it waits withdraws the request.
- To follow a request from another process: `fleetlayer --json lease acquire … --wait` prints a first JSON line as
soon as it's in line (`{"id":14,"phase":"waiting","position":2,…}`), then the held lease. `fleetlayer lease wait 14`
waits for it elsewhere, and `fleetlayer lease release 14` withdraws it.
- Always release, even when the work failed. A lease you forget ends at its TTL (2h by default). If you're told
"Your … lease #N … ran into its TTL", it's gone: what it guarded may be someone else's now. If the work is still
going, take a new lease before going on, and next time pass a `--ttl` that covers it (up to the kind's max).
- Your lease is tied to your session: it ends if your session stops, or if you stay idle (or wait on the person)
past its idle limit (30m by default; `--idle` can ask for less, never more than the kind's). So don't end your turn with a lease held while a build runs in the
background: wait for the build in the foreground, or tie the lease to the build's process with `--pid <pid>`
(released when that process exits).
- For a build or a test run on a busy machine, use `lease run`, not a session-held `acquire`: the slot goes back the
moment the command ends. `lease.slow` names the leases held for a whole session while others wait.
- Scripts that take a slot themselves (Fleetlayer's `scripts/on-dev` does, through `scripts/fleetlayer-dev-slot`)
need nothing from you.
Don't take a slot by hand around them: with one slot, yours and theirs wait on each other. If one stops with
"couldn't take a build slot", the leases authority can't be reached: say so to your person, and
build without a slot (`FLEETLAYER_DEV_SLOT=none`) only if they agree.
- Some kinds start only while their machine has room (a laptop that builds while its person is away, a server that
stops taking work when it's strained). Then `acquire` without `--wait` says "no room to start it now: …", and
`--wait` waits for room as well as for a slot. If a message says there's no room for more work under a lease you
hold, finish the step you're on, release the lease, and don't start more work there; nothing is stopped for you.
- When another kind would do as well (`fleetlayer lease list` shows a laptop kind beside the build server), add
`--or <kind>`: with `--wait` you get whichever starts first. `fleetlayer lease show "$id"` says which kind you got,
so you know which machine to build on.
- A **pool** (`fleetlayer lease list` shows "Pool build: …") is used like a kind: `fleetlayer lease run build -- …`
takes any free slot on a member that's up, the cheapest tier first, at once (a box that's down is started for you
when the others stay full). Inside `lease run`, `$FLEETLAYER_LEASE_KIND` says which member you got: build on that
member's machine; `--exclude <member>` leaves out one you can't use. `scripts/on-dev` with a `pool` line in
`.dev-host` does this for you. A pool can go in `--or` too: `fleetlayer lease run my-kind --or build -- …` takes
your own kind if it's free, otherwise any member of the pool (one pool per request, never beside one of its members).
- Asking for a pool's member by name while it's down (`lease list` says "down since …"): a member nothing starts on
request is refused at once ("… is down since …: ask for its pool instead"), so ask for the pool. One with
`alert_wait_after` waits instead: its owner hears that you want it, starts the box and marks it up.
- `fleetlayer lease acquire` fails with "no leases authority found" when the fleet has none set up: carry on without
one, and don't set one up unless the person asks.
## A lock on one named thing
Some kinds are a lock per named thing (`per:` in their settings): one session at a time per Terraform component, say.
Name the thing in the payload; others holding different things don't wait for you, and someone holding the same one
puts you in that thing's line:
```sh
id=$(fleetlayer lease acquire terraform --reason "move the DNS records" --payload '{"component":"dns"}' --wait)
```
For several things at once, take one lease each in sorted order (so two sessions after the same two never each hold
one and wait for the other), and release them all when you're done.
A lock can run out under you: a long pause, a TTL you didn't notice. Each held lease has a fencing number (`fence`
in `fleetlayer lease show`, printed when it starts, `$FLEETLAYER_LEASE_FENCE` under `lease run`), higher than any
before it. Before a write the lock guards (an apply, a push), check it still holds, and stop if it doesn't:
```sh
fleetlayer lease check "$id" --fence "$fence" || exit 1 # exits 1 once the lease has ended or someone else has it
```
Where the thing you write can keep a number (a tag, a state file's field), store the fence with the write and refuse a
write with a lower one than stored: that also stops a write already on its way when the lease ended.
## Claims the person approves
Some kinds take a payload and need approval once per payload (a mail filter on an account):
```sh
fleetlayer lease acquire gmail-filter --reason "I'm fixing the build and watching CI myself" \
--payload '{"account":"work","query":"from:notifications@github.com subject:(\"Run failed\")"}'
```
It returns at once with the lease's ID while the person decides (`--wait` to wait here, or `fleetlayer lease wait
<id>` later), and you get a message when it starts. A payload the person approved before starts at once, for any
session. The service that owns the claim acts on it when it starts and undoes it when it ends; you just release it
when you're done.
## Other commands
```sh
fleetlayer lease show 14 # one lease, or how it ended
fleetlayer lease list --all # with every lease that ended in the last day
fleetlayer --json lease list # for programs
```
A machine you run (a rented build box you pause when it's idle): mark its kind down before you pause it, so no
lease starts there, and up once it answers again. Leases it holds run on.
```sh
fleetlayer lease kind down rented-build --reason "paused: idle for 30 minutes"
fleetlayer lease kind up rented-build
```
The access policy decides (write on `service:leases/kind/<kind>`); a refusal names the rule, and waiting for the
person's approval says so: run it again once they've approved. From a node other than the authority's it needs an
allow rule (the refusal says so): ask the person for one. Its `lease.queue` and `lease.idle` events on the
`capacity` channel (subject the kind) tell you when to bring it back and when it's idle; a `lease.queue` that stays
tripped comes again every 15 minutes (`reminder: true`). A tripped one is marked `severity: warning`, so with
nobody subscribed to its kind it goes to the fleet's trouble fallback, with its all-clear after it: whoever starts
the box should still subscribe to the kind (`fleetlayer subscribe capacity --subject <kind>`). Adding a kind for a box that has no server yet, give it
`start_down: "<reason>"` in leases.yaml, so it starts down instead of taking a build it can't run.
Only your own node may release your lease. If the authority can't be found automatically (several nodes share one),
name it with `--at <node>` or `$FLEETLAYER_LEASES`.
## Setting it up (when the person asks)
The kinds live in one settings file on the authority's machine (`~/.config/fleetlayer/leases.yaml`), read again
within 15 seconds of a change; check an edit with `fleetlayer-leases check`. The node setup, the kinds' fields,
approvals through the access policy, events for the service that acts on a lease, and the readings and status that
monitoring reads: https://fleetlayer.ai/docs/plugins/leases/