Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a1427a0
feat(adapter): add opt-in treehouse-worktree adapter for pooled workt…
Dematom1 Nov 12, 2026
5f882e3
no-mistakes(review): Clarify worktree expiry and verify CI installati…
Dematom1 Nov 12, 2026
e32a9a3
no-mistakes(review): Block lease renewal during outside-lock cleanup
Dematom1 Nov 12, 2026
6b19129
no-mistakes(review): Guard worktree returns against active writers
Dematom1 Nov 12, 2026
8b1f288
no-mistakes(review): Document return race limits and assert CI commands
Dematom1 Nov 15, 2026
5c2d47f
no-mistakes(review): Reject malformed treehouse status evidence
Dematom1 Nov 15, 2026
2fef156
feat(adapter): integrate treehouse-worktree with main's lease lifecycle
Dematom1 Nov 15, 2026
0dfce09
no-mistakes(review): Reject malformed treehouse lease claim fields
Dematom1 Nov 15, 2026
6b7872b
no-mistakes(review): Match worktree identity on keyed retries
Dematom1 Nov 15, 2026
ca13c86
no-mistakes(review): Resolve canonical worktree identity before retries
Dematom1 Nov 15, 2026
78c63ee
no-mistakes(review): Document all consumer contract refusal reasons
Dematom1 Nov 15, 2026
e318349
no-mistakes(review): Keep process checks during forced worktree discard
Dematom1 Nov 15, 2026
cb119c3
no-mistakes(review): Verify treehouse claim path identity
Dematom1 Nov 15, 2026
bd4a202
no-mistakes(document): Correct adapter documentation and pass lint ch…
Dematom1 Nov 15, 2026
71838af
no-mistakes(ci): Updated only the four AXI output snapshots for recon…
Dematom1 Nov 15, 2026
d97c3f0
no-mistakes(ci): Invariant: every public help mode must match its sta…
Dematom1 Nov 15, 2026
b45f8c9
no-mistakes(ci): Updated 14 stale CLI output baselines (AXI help acro…
Dematom1 Nov 16, 2026
d61d0ef
fix(adapter): address treehouse-worktree review threads
Dematom1 Nov 16, 2026
0f80d6b
no-mistakes(document): Update worktree lease documentation
Dematom1 Nov 16, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .claude/skills/lease-job-safety/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Run `git diff 11e1da46ff0c479a5027661622dbda459350d755 -- internal/lease interna
- The same model covers `internal/remote/agent.go:Serve` and `internal/remote/ssh.go:Run`. Ready follows version validation, child output cannot create a result frame, delivered stdin EOF cancels the remote context, and a received result is authoritative during transport teardown.
- `internal/owner/registry.go:Registry.Check` and `internal/owner/reference.go:ProcessIdentity` supply Alive, Dead, and Unknown evidence. `internal/config/config.go:Config.Available` supplies a common capacity after owner room. The models assume these observations and parsed positive requests are valid. `internal/lease/formal_test.go` and `internal/cli/formal_test.go` and existing tests execute the real functions at these boundaries.
- `releaseLease`'s pending-lease branch (`internal/lease/pending.go:settlePending`) is not modeled: it binds a single unclaimed match before Destroy, forgets the lease without Destroy only when discovery succeeds and finds no match at all, and retains it when discovery fails, several resources match, or any match is under another lease. `Manager.Reclaim` acts only on Dead owners and reuses `releaseLease`. `internal/lease/pending_test.go` executes these paths; no model or mutant covers them.
- Adapters that set `Definition.CleanupOutsideLock` (only `treehouse-worktree`) are released by `internal/lease/manager.go:Manager.releaseOutsideLock` (from `Release`, `Sweep`, and `Reclaim`): Destroy runs between two locked transactions, and the record is forgotten only if its `ResourceRef` is unchanged. `Lease.tla` models release as one step and does not describe this path. Sweep eligibility is still decided under the lock. `internal/lease/cleanup_test.go` and `TestIntegrationTreehouseWorktree` cover it, not the model.
- `internal/cli/cli.go` and `internal/adapter/{kind,k3d,compose}` provide command routing and Destroy semantics. External adapter implementations are not proved. `releaseLease` trusts a successful Destroy.

Move the source baseline forward only after confirming that these abstractions still describe the code and rerunning every check. Use `/maintain-formal-verification-skill` after changes that did not recheck this record.
Expand Down
2 changes: 2 additions & 0 deletions .claude/skills/verify/features/adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ A user creates an attributed stack or throwaway Kubernetes cluster, uses the ser

Run `dibs create --adapter compose --file <compose.yaml>`, `dibs create --adapter kind`, or `dibs create --adapter k3d`, with a live `--owner` and positive `--ttl`. Inspect via `dibs ps`, Docker, HTTP, and `kubectl`; release via `dibs release <id> --confirm`.

The opt-in `treehouse-worktree` adapter is not driven by `verify.py`. `just integration` drives it through `TestIntegrationTreehouseWorktree` with real treehouse and git in a disposable repository and pool; see [Adapters](../../../../docs/adapters.md#treehouse-worktree).

## Driving it with verify.py

Preconditions: Docker, Compose, kind, k3d, and kubectl all pass the skill's doctor checks. Images and package registries must be reachable.
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ jobs:
k3d version
docker info
docker compose version
- name: Install pinned treehouse for real worktree adapter integration
run: |
go install github.com/kunchenguid/treehouse/v3@v3.1.5
echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"
"$(go env GOPATH)/bin/treehouse" --version
- name: Verify demo Compose HTTP and Ready kind/k3d nodes
run: .claude/skills/verify/verify.py adapters --evidence "$RUNNER_TEMP/verify/adapters"
- name: Real kind, k3d, and Compose adapter integration
Expand Down
4 changes: 3 additions & 1 deletion ADDING-AN-ADAPTER.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
Start with an issue and agree on scope and validation under [CONTRIBUTING.md](CONTRIBUTING.md). New built-ins must meet the [vision](VISION.md). This guide describes the current internal interface, not a public extension API.

1. Add `internal/adapter/<name>` with a private implementation and a `New` constructor that returns `adapter.Definition`. Use [kind](internal/adapter/kind/kind.go) as an example.
2. Implement `Create` and `Destroy` against `adapter.Target`. `Create` runs only after the lease is durable. `Destroy` must tolerate partial creation and already-absent resources. Keep absence verification inside `Destroy`; an error retains the cleanup record.
2. Implement `Create` and `Destroy` against `adapter.Target`. `Create` runs only after the lease is durable and returns the identity to record; return `Target.Ref` unchanged unless creation learns something, such as an allocator token, which must still pass `Validate`. `Destroy` must tolerate partial creation and already-absent resources. Keep absence verification inside `Destroy`; an error retains the cleanup record.
3. Bundle preparation, stored-reference validation, file policy, and environment projection in the definition. Preparation captures cleanup scope and private snapshots before creation. Validation must work without the source file or an engine call. Do not read or write the lease ledger.
4. Add one ordinary import and constructor entry in [`cli.newAdapters`](internal/cli/adapters.go). Do not use `init`, blank imports, or another operational allowlist. The CLI derives create choices from the registry.
5. Retain exact command, environment, snapshot, survivor, and tool-failure tests. Add real isolated integration coverage that fails when prerequisites are missing. Run `just check`, `just integration`, `just ssh-integration`, and the published verification flows.

An optional built-in sets `Definition.OptIn` to its setting and enables `CreateAllowed` only when that setting is on, while staying registered so recorded leases remain readable. Set `CleanupOutsideLock` only when `Destroy` is conditional and idempotent, because concurrent destroys of the same lease can then run. Set `VerifiesAdoption` when `Prepare` verifies an existing resource and its duplicates against `PrepareRequest.Leased` without Docker discovery.

An adapter can optionally provide `Definition.Discover` for read-only inventory.
Discovery reports Docker evidence without creating or deleting resources. For
adoption, `PrepareRequest.Existing` carries the verified resource identity with
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Read `VISION.md` first; it is the accept/resist test for every change.
## Rules for changes

- Dibs owns only the lease lifecycle and its guarantees; task-runner, repo-agent-runtime, secrets, and network-policy features are out of scope.
- New resource types and liveness sources go through the Adapter and Owner contracts; dibs ships one as a built-in, off until an opt-in setting enables it, only when it is widely used and CI-testable and was proposed as an issue first; anything dibs does not ship stays an exec file or plugin.
- New resource types and liveness sources go through the Adapter and Owner contracts; dibs ships one as a built-in, off until an opt-in setting enables it, only when it is widely used or dogfooded by the maintainers' own fleet, is CI-testable, and was proposed as an issue first; anything dibs does not ship stays an exec file or plugin.
- Every adapter or owner must pass the conformance kit; every call runs under a timeout, and extensions never write dibs state.
- Record cleanup intent before creating a resource, and forget a lease only after destroy and verify-gone succeed.
- Never reclaim a resource that is not under a lease (adoption is an explicit `adopt`), never reclaim on unknown liveness alone (expiry still reclaims), and never act on another machine's leases.
Expand Down
114 changes: 111 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,111 @@ Pane shells and treehouse subshells are ordinary shells found by PID. This
adapter does not drive tmux, herdr, or rex. A terminal lease that closes a pane
hangs up its shell, and the shell lease then finds its shell gone.

## Lease a pooled worktree

The `treehouse-worktree` adapter leases one slot of a
[treehouse](https://github.com/kunchenguid/treehouse) worktree pool. Treehouse
keeps allocation, reset, and its own durable lease token. Dibs adds the owner,
expiry, and reclaim that treehouse leases do not have. Without lease policies,
an expired worktree lease becomes eligible for reclamation like every lease, and
the next `dibs sweep --confirm` returns its slot, so renew it with `dibs extend`
before expiry. To keep a live owner's slot past expiry, pass
`--protect-live-owner` (see [live-owner protection](#protect-a-live-owners-lease)), or
turn on lease policies, whose built-in `treehouse-worktree` row is owner-bound.
With the consumer contract on, `--key` makes `create` and `adopt` retries return
the same lease. It needs treehouse 3.1.5 or newer and git 2.31 or newer on `PATH`.

The adapter is off by default. Turn it on per machine with
`"treehouse_worktree_adapter": true` in the user config, or with
`DIBS_TREEHOUSE_WORKTREE=1`. The variable overrides the config either way, so
`DIBS_TREEHOUSE_WORKTREE=0` turns a config opt-in off. Project files cannot
enable it. While it is off, `create --adapter treehouse-worktree` and
`adopt treehouse-worktree` fail with code 2 and name the setting. Leases that
are already recorded still list, release, and sweep.

```sh
export DIBS_TREEHOUSE_WORKTREE=1
dibs --axi create --adapter treehouse-worktree --repo ~/src/app \
--owner "pid:$WORKER_PID" --ttl 8h --landed-exclude-remote gate
# lease.path is the slot; ps --full records carry resource.path too
dibs --axi extend <id> --ttl 8h
dibs --axi release <id> --confirm # returns the slot only if its work landed
```

`create` saves the lease first, then runs
`treehouse get --lease --json --lease-holder dibs:<id>` in the repository's main
checkout, then records the slot path and treehouse `lease_id` on the lease.
`--repo` defaults to the current directory. A `TREEHOUSE_ROOT` that is set at
create time is pinned and passed as `--root` to every later call. Otherwise,
later calls clear `TREEHOUSE_ROOT`. If dibs stops after treehouse allocates a
slot but before it records the token, release finds the slot by its unique
`dibs:<id>` holder.

To lease a slot that treehouse already leased durably (from
`treehouse get --lease` or `treehouse lease <name>`), adopt it by path and token:

```sh
dibs --axi adopt treehouse-worktree /path/to/slot --lease-id <treehouse lease_id> \
--owner "pid:$WORKER_PID" --ttl 8h
```

Adoption requires that exact token on that exact slot. It refuses a slot that
another dibs lease already owns, and a slot that only a process reservation
holds (a plain `treehouse get`).

Release and sweep return the slot with
`treehouse return <path> --if-lease-id <token>` (plus `--if-lease-holder` for
slots that dibs allocated). A stale lease therefore never resets a slot that has
been handed to someone else since. Before return, dibs requires detected slot
processes to exit and refuses unlanded work, keeping the lease. Unlanded work is:

- uncommitted changes, including untracked files
(`git status --porcelain --untracked-files=all`)
- commits that no remote-tracking ref contains
(`git log HEAD --not --remotes`)

Treehouse detects processes by cwd inside the slot, so processes whose cwd is
elsewhere are not covered. Dibs rechecks the claim, process list, and HEAD
immediately before return. Callers should stop their writers before release.
Sweep and `reclaim` act only on leases whose owner is dead or whose lease ended.

There is a narrow limit: dibs's final check and `treehouse return` are separate
processes. A process that starts in the slot and creates a commit between them
can have that commit reset away. A commit on a named branch remains reachable in
the shared repository; a detached-HEAD commit is reachable only from the reflog.
Uncommitted edits in that interval are still caught because return without
`--force` refuses a dirty tree. Full closure needs an atomic return-if-clean in
treehouse; see [treehouse issue 216](https://github.com/kunchenguid/treehouse/issues/216).

A blocked release exits 1. The AXI and JSON error carries a `blockers` object
with up to ten `uncommitted` paths, up to ten `unpushed` commit IDs, the
`uncommitted_count` and `unpushed_count` totals, and the `processes` (`pid`,
`name`) that must exit first. With the consumer contract on, a blocked `release`
or `reclaim` carries the same `blockers`, reports `reason: unlanded_work`, and
exits 3. A blocked sweep lists the same reason under `failures`. Pass `--landed-exclude-remote NAME` (repeatable) on
`create` or `adopt` for remotes whose refs do not count as landed, such as a
local validation mirror. The lease records the list, so sweep applies the same
policy later. Only an explicit `dibs release <id> --confirm --discard-unlanded`
returns a slot that holds unlanded work, with `treehouse return --force`. It
skips only the unlanded-work check; it never terminates processes in the slot.
Stop them first. Use it only after you prove that the work landed some other
way, such as a squash-merged pull request. Sweep never discards work.

Verify-gone means the claim is gone: no slot carries the token (or the pending
holder), and the pinned slot is either listed without it or deleted. The slot
itself goes back to the pool. Treehouse stops processes that are still running
inside the slot when it returns it. Never also run `treehouse return` on a slot
that dibs owns. Release the lease instead.

Slot returns can take seconds. Release, sweep, and `reclaim` run this adapter's
cleanup without the host-wide state lock, so renewals of other leases do not
wait behind it. Dibs marks the lease first, and `extend` refuses a marked lease
(`cleanup_in_progress`) until a release or sweep finishes the cleanup. A refusal
for unlanded work or running processes touches nothing, so it removes the mark
again and the owner can keep renewing. Dibs then
forgets the lease under the lock only if its recorded identity did not change in
the meantime.

## Run a local job

```sh
Expand Down Expand Up @@ -598,7 +703,8 @@ outage reads as owner death.
(`status: renewed`). After expiry it reattaches the same lease (`status:
reattached`) only when the adapter proves the pinned resource is still present.
For kind, k3d, and Compose, the cluster or project must still be visible in the
pinned Docker context, at the pinned endpoint for adopted resources. A renew
pinned Docker context, at the pinned endpoint for adopted resources. For
`treehouse-worktree`, the pool must still carry the lease's treehouse token. A renew
never creates a lease. A refusal for one of these reasons exits 3, leaves the
lease unchanged, and names the `reason` in AXI and JSON output; any other
refusal, such as a lease on another machine, exits 1 as for any lease:
Expand Down Expand Up @@ -646,6 +752,7 @@ Built-in rows apply when the table is on:
| `shell` | `hybrid` | `8h` | - | - | `30m` | `false` |
| `kind`, `k3d`, `compose` | `time` | `4h` | `2h` | `24h` | - | - |
| `none` | `time` | `8h` | - | - | - | - |
| `treehouse-worktree` | `owner` | `8h` | - | - | - | - |

Job deadlines come from job classes, and a `process` row is refused. A row you
configure replaces the built-in row with the same key; omitted fields are off.
Expand Down Expand Up @@ -686,10 +793,11 @@ without one), the condition that fired, when the next condition ends
| Command | Behavior |
| --- | --- |
| `dibs` | Live home view with executable path, description, lease count, and hints |
| `dibs create` or `dibs up` | Create a lease, optionally with `--adapter kind`, `k3d`, or `compose`; with the consumer contract, `--pending` records it before you build the resource and `--key` makes retries idempotent |
| `dibs create` or `dibs up` | Create a lease, optionally with `--adapter kind`, `k3d`, `compose`, or the opt-in `treehouse-worktree` (`--repo`, `--landed-exclude-remote`); with the consumer contract, `--pending` records it before you build the resource and `--key` makes retries idempotent |
| `dibs adopt <type> <name> --owner KIND:ID --ttl D` | Lease an existing kind, k3d, or Compose resource after verifying existence |
| `dibs adopt <type> <handle> --pending ID` | Consumer contract: register the resource you built for a pending lease |
| `dibs adopt shell <pid> --owner KIND:ID` | Lease a running shell and its helpers by PID and start time (`shell_adapter`) |
| `dibs adopt treehouse-worktree <path> --lease-id ID --owner KIND:ID --ttl D` | Lease a durably leased treehouse slot after verifying its token (`treehouse_worktree_adapter`) |
| `dibs reconcile [ID] [--confirm]` | Consumer contract: find and bind resources built for pending leases after a crash |
| `dibs reclaim ID [--confirm]` | Consumer contract: reclaim one lease only when its owner is proven dead |
| `dibs explain ID` | Consumer contract: owner liveness, expiry, and whether sweep or reclaim would act, and why |
Expand All @@ -698,7 +806,7 @@ without one), the condition that fired, when the next condition ends
| `dibs env <id>` | Print a shell-safe kubeconfig export for a kind or k3d lease |
| `dibs setup hooks [--remove]` | Install or remove managed agent integrations |
| `dibs extend <id> --ttl D` | Renew an unexpired lease with a live owner; a protected lease may also reattach after expiry |
| `dibs release <id>` or `down` | Preview cleanup; `--confirm` performs it |
| `dibs release <id>` or `down` | Preview cleanup; `--confirm` performs it; `--discard-unlanded` lets a confirmed worktree release discard unlanded work |
| `dibs sweep` | Preview reclaim of dead-owner or expired leases; `--confirm` performs it |
| `dibs job [--machine NAME] [flags] -- <cmd...>` | FIFO machine-budget admission, deadline, and child exit-code passthrough |
| `dibs machine install <name> --file <binary>` | Version-checked SSH agent installation or upgrade |
Expand Down
2 changes: 1 addition & 1 deletion VISION.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Existing behavior changes only through a manual review by the maintainer.
Opt-in, non-breaking changes merge once the automated review process approves them.
Opt-in capabilities in vision include a resident sweeper, deadline-bounded backfill, owner preemption of lower-class jobs, cgroup or container enforcement of reservations, Kubernetes namespaces as machines through API calls, worktree sync into a per-lease remote directory, and interactive remote jobs.
Every guarantee holds without any of them: dibs stays one Go binary that works per command, with sweep from a host timer or a caller and an SSH agent that lives exactly as long as its session.
A resource type is built in only when it is widely used and has a real integration test in CI, on a self-hosted runner where hosted runners cannot run it; everything else is exec or a plugin, and a new built-in starts as an issue.
A resource type is built in only when it is widely used, or dogfooded by the maintainers' own fleet, and has a real integration test in CI, on a self-hosted runner where hosted runners cannot run it; everything else is exec or a plugin, and a new built-in starts as an issue.
Tart macOS VMs are an in-vision built-in, tested in CI on a self-hosted runner.
The state schema is versioned with migrations, the CLI, AXI, and exit-code contracts are stable, releases follow semver, and removals follow a published deprecation policy.
`dibs job` exits with the child's code, 124 on deadline, 75 when no slot frees within the wait, 76 when SSH transport fails, 143 when preempted, and dibs's own 1 and 2 only when no child started.
Expand Down
Loading
Loading