Skip to content

PathLease

A PathLease claims paths of a repository for a piece of work: the paths the work changes and the paths it depends on.

Several agents working in one repository collide when their changes touch the same files, or when one changes what another relies on. A PathLease says up front what a piece of work touches. kslip compares the leases of a repository, lets work on separate paths proceed freely, and orders or holds back work whose paths conflict.

apiVersion: kslip.dev/v1alpha1
kind: PathLease
metadata:
name: cart-totals
namespace: team-a
spec:
repository: github.com/acme/checkout
writes:
- internal/cart/**
- api/cart.proto
reads:
- internal/pricing/**
mode: Ordered
holder: change-142/task-3
leaseDurationSeconds: 3600
Terminal window
$ kubectl get pathleases --namespace team-a
NAME REPOSITORY HOLDER MODE PHASE MERGE AGE
cart-totals github.com/acme/checkout change-142/task-3 Ordered Held True 4m
cart-rounding github.com/acme/checkout change-143/task-1 Ordered Held False 3m
go-upgrade github.com/acme/checkout change-144/task-1 Exclusive Pending False 1m

A lease is a claim on repository paths. Git access remains available outside the lease. The holder starts work when the lease is held and merges when the lease is ready to merge. Builders are responsible for working within their declared paths.

Field Description
repository The repository, as a host, optional port and path without a scheme. Leases are compared only with leases of the same namespace that name the same repository, written the same way.
writes The paths the work changes. One to 64 patterns.
reads The paths the work depends on without changing them. Up to 64 patterns.
mode Ordered, the default, or Exclusive. Described under Modes.
holder Identifies the work that holds the lease, in whatever form its owner uses.
leaseDurationSeconds How long the lease lasts without being renewed. Defaults to 3600.
renewTime When the holder last renewed the lease.

Only renewTime and leaseDurationSeconds can change after a lease is created. Work that turns out to touch other paths takes another lease, which takes its place after the leases that exist.

A pattern is a path relative to the root of the repository, with segments separated by slashes.

In a pattern Stands for
A segment that is exactly ** Any number of segments, including none.
* in any other segment Any run of characters within the segment, including none.
Any other character Itself.
Pattern Describes
internal/cart/** internal/cart and everything under it.
api/*.proto The .proto files directly in api.
**/go.mod Every go.mod, at any depth.
docs/guide.md That one file.

A pattern describes paths whether or not they exist, so a lease on internal/cart/** covers files the work creates.

Two leases conflict when a path is described by:

  • the writes of both, or
  • the writes of one and the reads of the other.

Two leases that only read a path do not conflict.

Declaring reads catches the conflicts that changed lines alone do not show. Work that changes a function’s signature and work that adds a caller of that function touch different files, and still break each other.

The controller gives each lease a position at the end of its repository’s queue when it first reports the lease as Pending or Held. When several leases are waiting for their first decision, it takes them by creation time and then by name. A lease keeps its position when it is renewed or moves from Pending to Held.

The mode decides what happens between two leases that conflict.

Earlier lease Later lease The later lease
Ordered Ordered Is held at once. Its work proceeds, and merges after the earlier lease’s work.
Exclusive either Waits until the earlier lease is deleted or expires.
either Exclusive Waits until the earlier lease is deleted or expires.

Ordered suits most work: both pieces proceed at the same time, and the later one rebases onto the earlier one’s result before it merges. Exclusive suits paths where a rebase is costly or meaningless, such as generated code, schema migrations and lock files.

Field Description
queuePosition The lease’s fixed place in the repository queue. Smaller positions go first.
phase Pending, Held or Expired.
waitingFor The earlier leases this lease waits for. The lease is Pending while there are any.
mergeAfter The earlier leases whose work merges before this lease’s.
conditions Held and MergeReady.

Held is True while the work may proceed. MergeReady is True while the lease is held and no earlier lease it conflicts with remains, so the work may merge.

Condition Reason Status Meaning
Held Held True No earlier lease keeps this one waiting.
Held WaitingForEarlierLeases False Earlier conflicting leases keep this one waiting.
Held Expired False The lease was not renewed in time.
MergeReady NoEarlierConflicts True No earlier conflicting lease remains.
MergeReady EarlierLeasesMergeFirst False The work of earlier conflicting leases merges first.
MergeReady NotHeld False The lease is not held.
MergeReady Expired False The lease was not renewed in time.

A holder uses a lease in five steps:

  1. Create the lease with the paths the work touches.
  2. Wait until Held is True, then start the work.
  3. Renew the lease while the work runs, by setting spec.renewTime to the present time before leaseDurationSeconds have passed since the last renewal.
  4. Wait until MergeReady is True, then merge. If earlier work merged in the meantime, rebase onto it first.
  5. Delete the lease.

Deleting a lease releases it. Leases that waited for it are held, and leases that merged after it move up.

A lease that is not renewed within leaseDurationSeconds expires. An expired lease takes no further part: other leases neither wait for it nor merge after it. This keeps work that has stopped from blocking everything behind it.

Expiry is final. Renewing an expired lease does not revive it, because leases admitted since may conflict with it. A holder whose lease expired takes another lease.

Reason Type Published when
Held Normal The lease becomes held.
Waiting Normal The lease starts waiting for earlier leases.
Expired Warning The lease expires.

The lease architecture explains how kslip decides.