Skip to content

The workstream lease

The lease is a file named .lease in a workstream’s folder. While it exists, a run is working in that workstream. Each run takes the lease of its own workstream before it writes any artifact there, and gives it back when it finishes. A run that only adds items to the backlog takes no lease.

The lease holds one key: value line per key, in this order:

  • session: a random token, written once.
  • acquired: the time the lease was taken, written once.
  • heartbeat: the time of the latest refresh.
  • stage: the stage the run begins next, or upkeep once only the end-of-run bookkeeping remains.
  • artefact: the ID of the artifact that stage works on.
  • task, task_title and task_started: the number, title and start time of the task now running. Only the refresh before a child task or a task with no children sets them, and every other refresh writes them empty.
  • note: one line on progress inside the stage.

Times are ISO 8601 in UTC. A lease held by a run in this repository:

session: b954b247-bc89-4695-a1f3-c28a14234c9e
acquired: 2026-10-30T05:01:21.679Z
heartbeat: 2026-10-30T05:15:34.080Z
stage: execute-tasks
artefact: TL-39-m8dnlo
task: 3.4
task_title: Write the task and run-safety pages
task_started: 2026-10-30T05:15:34.053Z
note: parent task 3 of 6, subtask 3.4

Acquire. Once the workstream folder exists, FlowCharge creates .lease with an exclusive create, which fails only if a lease already exists. It keeps the session token for the rest of the run.

Contention. If a lease already exists, its age runs from its heartbeat, or from acquired when it has none. Under 60 minutes, the run halts and reports the holding session and the lease’s age, without waiting or retrying. At 60 minutes or older, the lease is stale: the run deletes it, retries the create once, and goes on.

Refresh. The run rewrites the lease right after it acquires it, after every stage, when execution starts, and before each child task or task with no children. It writes a temporary file in the same folder and renames it into place, so a reader never sees a half-written lease. If the file is missing or no longer holds this run’s token, the run no longer holds the workstream and halts.

Release. At the end of a run, and when a run halts, FlowCharge deletes .lease, but only if its session line still matches this run’s token. Otherwise another run has taken the workstream over, and the lease stays.

Stale leases. The generator reports a lease more than 60 minutes old as stale, and never deletes it.

Lease files are kept out of git. See What Core keeps out of git.

Checked against FlowCharge Core v0.6.0.