Leases
Build a factoryHold an external resource for a scope — the declaration, the outcome, the wait, and who owns the credential.
A lease is a declaration for something a scope must hold while it runs: an
issue claim, a branch, a prefix, a slot. A with acquires it before the scope's
first node and the platform releases it when the scope closes — on quiescence,
on abort and on an operator stop. That lifetime is the whole point: it is what a
container runner (a step's environment) and a plain port (a value) do not have.
A with names a lease or a credential provider. A lease is about holding a
resource; a credential provider opens a refreshable
endpoint instead. A runner and an ordinary adapter keep their own interfaces;
naming the capability subset separately is what makes the restriction clear.
type Claim = { number: int, url: text }
lease issue_claim(repo: text, label: text, number: int) -> ClaimOutcome
unit work:
in: { repo: text, label: text, number: int }
with held: issue_claim(repo: inputs.repo, label: inputs.label, number: inputs.number) wait 0
step build:
in: { issue: held.acquired.number }
What the scope binds: the lease outcome
The with name is not the adapter's value directly; it is the lease
outcome, a choice with two tags:
acquired— the resource was granted.unavailable— it was not, and the wait's facts say what happened.
unavailable always carries the platform's facts, in both lease shapes:
| field | type | meaning |
|---|---|---|
waited_ms |
int |
how long the platform waited |
attempts |
int |
how many acquisitions it tried |
since |
time |
when the wait began |
Reading held.acquired… is the lease's guard: under unavailable the path
is absent, so a node that depends on it simply does not fire. held is unavailable is the tag test for a when: or a binding guard.
Two result shapes
The declaration's result type picks the shape.
A payload lease declares any type that is not an outcome choice. The
platform builds the outcome, so a record's fields sit directly under acquired
(or a non-record value sits under value):
type Slot = { target: text }
lease deploy_slot(env: text) -> Slot
unit deploy:
with slot: deploy_slot(env: "prod")
step apply:
in: { target: slot.acquired.target }
out:
waited?: int = slot.unavailable.waited_ms
An outcome lease declares the choice itself, with exactly the tags
acquired and unavailable. The adapter supplies both variants, and the
platform merges its facts into unavailable: a field you declared is filled
(and must have the right type), a field you did not declare is added.
type ClaimOutcome = choice {
acquired { number: int, url: text }
unavailable { reason: text }
}
lease issue_claim(repo: text, label: text, number: int) -> ClaimOutcome
Here held.unavailable.reason is the adapter's word — "already claimed", "pull
request", a 404 — and held.unavailable.waited_ms is still the platform's. The
factory reads both without caring which shape the declaration used.
Waiting, and wait 0
If a lease cannot be granted now, the Run becomes waiting and the platform
retries. A deployment sets a default bound per lease; a with may override it:
with slot: deploy_slot(env: "prod") wait "2h"
wait accepts a duration string (30s, 15m, 2h, 1d, 1w, 1h30m) or an
integer number of seconds. When the bound passes, the scope settles with the
lease unavailable; it is not aborted, and the nodes that read acquired do
not fire.
wait 0 means one attempt, no parking. It is the shape a queue uses: try
the candidate once, then let the factory read unavailable and move to the next
one. A lease that is a singleton — one branch, one prefix — omits the clause (or
gives a long bound) and waits.
Who holds the credential
A lease call carries the resource's identity, never its credential. The call names what to lease; the adapter mints the deployment's credential when it acts — at acquire and again at release. A lease can outlive a token: a claim held through a build and a verification is released perhaps hours after it was acquired, so a token frozen in the request would be stale.
This is why the reference GitHub claim takes a repository, a label and an issue
number, and no token. The deployment's GitHub App supplies the installation
token, scoped to issues: write, separately for each act.
Release
The platform owns release. When the scope closes it releases every lease it
holds, last-acquired first; release is idempotent and a scope that settled
unavailable acquired nothing, so it releases nothing. There is no release
step: a factory that releases a claim by hand reintroduces the failure the
lease exists to prevent — a build that dies before its cleanup leaves the
resource held.
A refused lease is ordinary data, not an error. The factory's loop reads the
lost number and reason from unavailable and selects another candidate; an
exhausted queue settles no_work.
A worked factory lives at examples/lease/: it takes a local_slot payload
lease and a local_claim outcome lease, so it shows both shapes end to end.
Your factories will appear here. Create one and open it beside this guide.