Skip to content

fix(bin): lease each crew spawn's treehouse slot until teardown - #2760

Closed
Lifferado wants to merge 3 commits into
kunchenguid:mainfrom
Lifferado:fm/wt-slot-t5
Closed

Lifferado wants to merge 3 commits into
kunchenguid:mainfrom
Lifferado:fm/wt-slot-t5

Conversation

@Lifferado

Copy link
Copy Markdown

Fixes #2754.

Problem

fm-spawn asked the pane's shell to run an interactive treehouse get, which holds its pool slot only while processes still run inside it. A parked worker whose occupant processes went quiet left its recorded worktree= pointing at a slot the pool considered free, so the next spawn on the same project received the same path - two concurrently-live tasks sharing one worktree, with task B doing its whole job inside task A's copy.

Fix

  • fm-spawn acquires the slot itself with durable treehouse get --lease --lease-holder <task-id> (the idiom bin/fm-home-seed.sh already uses; bootstrap already gates fleet-wide on lease support), so the lease survives process death until teardown's treehouse return --force releases it.
  • The pane is sent into that exact leased path with a top-level cd, and spawn settles only after two consecutive pane reads agree on the leased physical path.
  • An abort between lease acquisition and task-record publication releases the lease through the existing spawn_abort_cleanup EXIT-trap idiom, so failed spawns cannot strand slots; after publication the recorded task owns the slot through teardown.
  • New regression suite tests/fm-spawn-worktree-lease.test.sh proves two live tasks cannot share a slot (verified failing on pre-fix code), that an allocator refusal stops the spawn fail-closed, and that an aborted spawn releases its lease. Existing spawn suites' inert exit-0 treehouse stubs were updated via a shared fm_fake_treehouse_lease helper; the new suite is mapped into the backend-dispatch family.
  • docs/cmux-backend.md and docs/zellij-backend.md pane-cwd lines updated to describe the top-level cd flow.

Validation

Pipeline run 01M0K7B0BRTY30D1E3HG93432J passed intent, rebase, review, test, document, and lint; its two review fixes are included. The push step alone failed because the ambient credential (Lifferado) lacks push access to the upstream repo, so this branch is pushed from the fork and this PR opened per supervisor instruction. Review auto-fix findings addressed: missing lease stub in tests/fm-secondmate-harness.test.sh's real-spawn fixture; lease-disarm window closed by moving the disarm immediately after record publication.

An interactive in-pane `treehouse get` holds its slot only while
processes run inside it, so a parked worker whose occupant processes
went quiet could see its recorded worktree handed to the next spawn on
the same project - two concurrently-live tasks sharing one slot
(kunchenguid#2754). Spawn now acquires the pool slot itself with
`treehouse get --lease --lease-holder <task-id>`, whose durable lease
survives process death until teardown's `treehouse return --force`
releases it, sends the pane into that exact leased path, and settles
only when the pane reads there twice consecutively. An abort between
lease and task-record publication releases the lease through the
existing abort-cleanup trap so failed spawns cannot strand slots.
@greptile-apps

greptile-apps Bot commented Aug 21, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (2): Last reviewed commit: "fix(test): answer lease-shaped treehouse..." | Re-trigger Greptile

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

VISION: aligned. This is a scripted isolation fix for a real parked-worker failure mode, not a new captain-facing surface and not inferred consent. It deepens the "restart is a non-event" rule (the lease survives process death) and fail-closes when the allocator refuses. A ready-for-pr issue is not a merge vote; VISION, CI, and default-behavior still apply. Class: corrective (default spawn path, bugfix).

Security: none.

Overlap / do not land together:

CI: first-time fork workflows approved after diff review (CI run 32536015279, Require no-mistakes 32536015277). Greptile is green. no-mistakes is still pending and is blocking. HEAD is 2 behind main, mergeable.

Waiting on CI — not on the author, not on the captain. Coordinator must sequence around the holds above even if CI goes green.

Merge-eligible: NO. Captain-flag NOW: NO.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Corrective lease for #2754: treehouse get --lease --lease-holder so a parked worker cannot free a slot another live task then receives. Aligns (isolated copies; scripts own the allocator; fail-closed on refusal).

Not merge-eligible. Require no-mistakes FAILED on this HEAD. CI still in progress. File-level overlap with #2770 on fm-spawn.sh and with spawn-freshen #2622/#2693/#2154 on spawn/freshen tests (this PR is lease, not freshen). Distinct from held teardown pair #2637/#2692.

Waiting on the author for a green no-mistakes raise — not waiting on the captain.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Correction on CI: after approving the first-time fork workflows, Require no-mistakes failed. The check did not find Updates from git push no-mistakes / a no-mistakes-pipeline-attestation:v1 block in the PR body. The description names pipeline run 01M0K7B0BRTY30D1E3HG93432J and says the push step lacked upstream access, but that is not a substitute for the attestation this repo's check requires (no-mistakes >= 1.46.0).

Portable CI is still in flight. no-mistakes is blocking regardless.

Waiting on the author to re-deliver through git push no-mistakes so the body carries structured attestation — not waiting on the captain. Overlap holds from the previous comment still apply. Merge-eligible remains NO.

…tation abort fixture

The post-create abort fixture armed worktree-validation refusals by making
its treehouse stub answer a bare interactive `get` with silence while the
wrapped pane reported a non-worktree cwd. fm-spawn now executes
`get --lease --lease-holder <task-id>` itself (kunchenguid#2754), so the silent answer
aborted each spawn at an empty acquisition instead of at the armed
"did not yield an isolated worktree" validation. Answer `--lease` with the
same bogus cwd the fake pane reports and intercept best-effort lease
returns, keeping the fixture's post-create abort semantics intact.
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Re-review of NEW HEAD b5bea4983fed. Corrective lease for ready-for-pr #2754: treehouse get --lease --lease-holder so a parked worker cannot free a slot another live task then receives. A ready-for-pr issue is not a merge vote.

VISION (per rule):

  • One captain, one interface — aligns. No new captain-facing surface; allocator refusal is a named fail-closed error.
  • Authority is explicit — aligns. Isolation bugfix on the existing spawn path, not a new grant.
  • Scripts own the mechanics — aligns. The allocator is a scripted treehouse lease; spawn no longer asks the pane's shell to hold the slot by occupancy.
  • A restart is a non-event — aligns. The lease survives process death until teardown's treehouse return --force.
  • Delegation with a spine — aligns. Isolated copies; an unleased slot refuses launch.
  • The fleet outlives any vendor — aligns. Treehouse remains the worktree provider; Orca still skips the lease.
  • Scope — aligns. Command-layer isolation, not workshop validation.

Security: no.

Overlap / do not land together:

CI: first-time fork workflows re-approved on this HEAD after diff review (CI 32564007475, Require no-mistakes 32564007596). Greptile is green. Portable CI has not finished. The PR body still has no Updates from git push no-mistakes / no-mistakes-pipeline-attestation:v1 block (pipeline run 01M0K7B0BRTY30D1E3HG93432J is not a substitute). no-mistakes is blocking.

Ahead 3, behind 5, mergeable, mergeStateStatus UNSTABLE.

Waiting on the author for a green no-mistakes raise whose body attestation matches this HEAD — not waiting on the captain. Coordinator must sequence around the holds even if CI later goes green.

Merge-eligible: NO. Captain-flag NOW: NO.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Newer HEAD b5bea4983fed for #2754. Still corrective (lease until teardown). Require no-mistakes is still FAILED. Do not land with held pair #2637/#2692 or with #2770 (same fm-spawn.sh).

Waiting on the author for a green no-mistakes raise — not waiting on the captain.

@Lifferado

Copy link
Copy Markdown
Author

Crew verdict on the #2754 fix (fm/wt-slot-t5 @ b5bea49)

Primary defect and fix. fm-spawn asked the pane shell to run an interactive treehouse get, whose slot protection lasts only while processes run inside it. A parked worker whose occupant processes went quiet left its recorded worktree= pointing at a slot the pool considered free, so a later spawn on the same project received the identical path — two concurrently-live tasks sharing one worktree (#2754). This branch fixes that: fm-spawn acquires the slot itself via durable treehouse get --lease --lease-holder <task-id> (the idiom bin/fm-home-seed.sh already uses; bootstrap gates fleet-wide on lease support), sends the pane into the exact leased path with a top-level cd, settles only after two consecutive pane reads agree on the leased physical path, and releases the lease through the existing spawn_abort_cleanup EXIT trap when a spawn aborts between lease acquisition and task-record publication.

Validation. Pipeline run 01M0K7B0BRTY30D1E3HG93432J passed intent, rebase, review, test, document, and lint; only its push step failed, on credential scope (hence this fork-raised PR). New regression suite tests/fm-spawn-worktree-lease.test.sh proves two concurrently-live tasks cannot share a slot and is verified failing on pre-fix code. Latest CI: 12 of 13 behavior checks green.

Residual known failure — confirmed not flake. Behavior tests (Herdr) fails in the concurrent post-create abort fixtures of tests/fm-backend-herdr-presentation-e2e.test.sh: after the armed worktree-validation refusal, each task's projected pane is already gone (pane_not_found) when its own cleanup verifies it, so cleanup refuses ("could not verify the exact pane") and the serialized create→close audit loses its close events ("interleaved outside the presentation lock"). Reproduced identically locally and on a quiet CI runner (run 32564007475). Ruled out so far: the new cd dispatch itself (raw-Herdr probes keep panes alive through cd, seeded-prune, and concurrent gets). Not yet root-caused: which actor removes the projected workspaces before their own serialized close once spawn acquires slots by durable lease. Commit b5bea49 already restores the fixture's armed-stub contract for lease-shaped acquires, which fixed the original assertion progression; the deeper residual layer remains open.

Repo-policy check. "PR must be raised via no-mistakes" failing is expected here: the shared no-mistakes daemon could not push from this environment (upstream credential scope), so the branch was pushed from a fork per operator instruction; every pre-push pipeline step passed.

Recommendation: fix-forward. Hold merge until the residual edge is root-caused and fixed on this branch. Leading suspects are Herdr's emptying-close/husk machinery interacting with pre-launch validation aborts, or a fixture contract that needs deliberate re-specification for the lease era; both are bounded follow-up work, and the underlying #2754 race is a real data-integrity hazard worth landing promptly once green. Alternatives, in order of fallback: park this PR while the residual is investigated separately, or document-and-land with the required Herdr job knowingly red — which we do not recommend. Happy to drive the fix-forward round on this same branch on your word.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Re-review of THIS HEAD b5bea4983fed after Lifferado's 11:41Z note. Corrective lease for ready-for-pr #2754: treehouse get --lease --lease-holder so a parked worker cannot free a slot another live task then receives. A ready-for-pr issue is not a merge vote.

VISION (per rule):

  • One captain, one interface — aligns. No new captain-facing surface; allocator refusal is a named fail-closed error.
  • Authority is explicit — aligns. Isolation bugfix on the existing spawn path, not a new grant.
  • Scripts own the mechanics — aligns. The allocator is a scripted treehouse lease; spawn no longer asks the pane's shell to hold the slot by occupancy.
  • A restart is a non-event — aligns. The lease survives process death until teardown's treehouse return --force.
  • Delegation with a spine — aligns. Isolated copies; an unleased slot refuses launch.
  • The fleet outlives any vendor — aligns. Treehouse remains the worktree provider; Orca still skips the lease.
  • Scope — aligns. Command-layer isolation, not workshop validation.

Security: none.

Overlap / do not land together:

CI: Require no-mistakes FAILED (run 32564007596). No structured no-mistakes-pipeline-attestation:v1 in the body; pipeline run 01M0K7B0BRTY30D1E3HG93432J is not a substitute. Behavior tests (Herdr) FAILED (CI 32564007475) on the concurrent post-create abort fixtures in tests/fm-backend-herdr-presentation-e2e.test.sh (author reproduced; not flake). First-time fork workflows were already approved on this HEAD. Greptile is not a merge gate.

Ahead 3, behind 6, mergeable, mergeStateStatus UNSTABLE.

Not merge-eligible. Waiting on the author for a green no-mistakes raise whose body attestation matches this HEAD and for Herdr CI green — not waiting on the captain. Coordinator must still sequence around the holds even if CI later goes green.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

This PR is the help for #1924 (and already claims #2754). Field reports on #1924 (jjaguirr 2026-08-07; angelescala 2026-08-08 parked ship + scout on herdr/codex) are the same hole: ordinary treehouse get without --lease --lease-holder hands over and resets an idle or parked worker's slot before any firstmate guard can object.

Please add Fixes #1924 to the PR body so the earlier report closes with this landing. No competing spawn-lease PR should open.

@tiago-peixoto

Copy link
Copy Markdown
Contributor

Current-main acquisition remains bare treehouse get at bin/fm-spawn.sh:2532; detecting lease support does not acquire one. We support coordinating the persistent-ownership correction here, following the maintainer's direction to help this PR rather than opening a competing lease implementation. The recorded copy already governs relaunch and should remain authoritative.

Our September 4 dispatch from a linked supervisor home also recorded the primary repository directory while the worker was actually isolated; freshening reset the primary to the same head, with no observed content loss. That distinct guard defect is now documented in #3741 so it is not silently bundled into the lease change. We can supply bounded acquisition/relaunch regression work here once coordinated with the author and the maintainer's existing sequencing constraints.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Re-review of THIS HEAD b5bea4983fed for ready-for-pr #2754 (and field reports on #1924). Main tip 8f7b79c77c21 still acquires with bare treehouse get (no --lease --lease-holder), so this hole is not fixed on main. A ready-for-pr issue is not a merge vote.

VISION (per rule):

  • One captain, one interface — aligns. No new captain-facing surface; allocator refusal is a named fail-closed error.
  • Authority is explicit — aligns. Isolation bug fix on the existing spawn path, not a new grant.
  • Scripts own the mechanics — aligns. Durable treehouse lease is scripted; spawn no longer asks the pane shell to hold the slot by occupancy.
  • A restart is a non-event — aligns. The lease survives process death until teardown's treehouse return --force.
  • Delegation with a spine — aligns. Isolated copies; an unleased slot refuses launch.
  • The fleet outlives any vendor — aligns. Treehouse remains the worktree provider; Orca still skips the lease.
  • Scope — aligns. Command-layer isolation, not workshop validation.

Contract-class: restore (corrective default spawn path: promised isolation fixed).

Security: none.

CI / gates on this HEAD:

  • Merge state: CONFLICTING / DIRTY (not auto-merge-ready; will not resolve conflicts here).
  • Require no-mistakes: FAILED — PR body has no structured no-mistakes-pipeline-attestation:v1 / matching head_sha (pipeline run id alone is not a substitute). Attestation: MISSING.
  • Behavior tests (Herdr): FAILED (author-reproduced concurrent post-create abort fixtures; not treated as flake).
  • Portable / lint / Greptile: previously green on this HEAD; Greptile is not a merge gate.
  • First-time fork workflows were already approved on this HEAD in prior triage.

Stale check (today 2026-09-04): last author activity is Lifferado's 2026-08-22 comment/push window (~13 days). Not yet 14 days — do not close stale. Becomes eligible for the 14-day rule on 2026-09-05 if still waiting on the contributor.

Not merge-eligible. Do not rebase (not otherwise auto-merge-ready). Overlap still applies with other open bin/fm-spawn.sh work; coordinator must sequence.

Waiting on the author — not on the captain:

  1. Re-deliver through git push no-mistakes so the body carries structured attestation whose head_sha MATCHes this (or a new) HEAD.
  2. Resolve merge conflicts against current main.
  3. Clear Herdr CI (or a new HEAD that does).
  4. Prefer adding Fixes #1924 to the body so the earlier field report closes with this landing.
    A contributor offered bounded help on this PR (2026-09-04); coordination stays with the author.

Captain-flag NOW: NO. Firstmate FYI: none.

@tiago-peixoto

Copy link
Copy Markdown
Contributor

Raising upstream what we have been carrying locally, and doing it on this thread rather than in a new one: the maintainer asked here on 2026-08-26 that this PR carry Fixes #1924 and that no competing spawn-lease pull request open, so this is the right home for it. Not an approval, and not a request for a re-review.

The gap, verified on today's main rather than asserted

On main at a27646c4, bin/fm-spawn.sh sends the pane an interactive treehouse get and then claims the pool slot with its own owner-claim helper. The file contains no --lease or --lease-holder anywhere, so nothing reserves the copy and occupancy is still inferred from what is running inside it.

The installed allocator already provides the reservation. treehouse get --help (v2.3.0) documents --lease and --lease-holder, and states that a leased worktree "is never handed out by a later get and never removed by prune, even with no process running inside it, until you release it with 'treehouse return '".

So the reservation this PR adds is not new machinery, it is an existing tool capability upstream does not currently use. That is this PR's own thesis, independently confirmed against current main and the installed tool.

Evidence we can add

A terminal pane restore moved live workers' shells out of their copies at once, and whole pools then reported their live copies as available together. Reported on #1924 on 2026-09-10.

It matters here because it shows the failure does not need a parked or idle worker: occupancy inferred from a process working directory fails for reasons unrelated to parking, and the copy is in continuous use the whole time.

A case worth a word in the refusal path this PR adds

This PR makes an allocator refusal stop the spawn rather than proceed, which we think is the right outcome. One case makes that refusal more common than parking does: a pool directory can hold worktrees registered from more than one base repository. treehouse status lists every registered tree, while get hands out only a tree belonging to the invoking repository, so a pool can be at its cap for the invoking repository while still appearing to have free trees.

The refusal text is then the operator's only signal, and a message about worktrees being in use or dirty reads as a transient condition when it is structural. Observed here while a pool was shared that way.

What we run

Our public fork carries this behaviour as tiago-peixoto/firstmate@c87eef1f, leasing the copy for the task lifetime. Offered as evidence that the shape holds up in daily use, not as a competing implementation and not as a suggestion to change this branch.

If bounded acquisition or refusal regression coverage would be useful to you, we can supply it.

@Lifferado Lifferado closed this Sep 21, 2026
tiago-peixoto added a commit to tiago-peixoto/firstmate that referenced this pull request Sep 25, 2026
A process-bound `treehouse get` hold lapses when no process remains in
the copy, so a later `get` could be handed a live task's recorded
worktree while that task was merely idle between turns. Its next
relaunch, teardown, or worktree read then pointed at someone else's work.

Fresh ship and scout Treehouse spawns now acquire the copy with
`treehouse get --lease --lease-holder <task-id>` from the spawning
project instead of opening a process-bound subshell in the pane. A
leased worktree is never handed out by a later `get` and never removed by
prune, even with no process running inside it, until `treehouse return` -
and teardown returns it only after the landed-work test passes.

After acquiring, spawn refuses a copy that another live task in this home
or any locally registered home already records, including pre-lease tasks
whose hold has lapsed; a relaunch of the same task reuses the copy its own
record names. The pane is then seated with a top-level `cd` into the
leased path and polled until two consecutive reads agree on it. The
pool-slot ownership claim is kept alongside the lease, because that
marker is what teardown reads to leave a reassigned slot untouched.
Upstream spawn fixtures are taught the lease so tests added after this
patch keep passing.

Fork patch. Tracks kunchenguid#2754, kunchenguid#1924 and kunchenguid#947 (all
open); the upstream PR that carried this design, kunchenguid#2760, was closed by
its own author on 2026-09-21, not declined by the maintainer.
tiago-peixoto added a commit to tiago-peixoto/firstmate that referenced this pull request Oct 17, 2026
A process-bound `treehouse get` hold lapses when no process remains in
the copy, so a later `get` could be handed a live task's recorded
worktree while that task was merely idle between turns. Its next
relaunch, teardown, or worktree read then pointed at someone else's work.

Fresh ship and scout Treehouse spawns now acquire the copy with
`treehouse get --lease --lease-holder <task-id>` from the spawning
project instead of opening a process-bound subshell in the pane. A
leased worktree is never handed out by a later `get` and never removed by
prune, even with no process running inside it, until `treehouse return` -
and teardown returns it only after the landed-work test passes.

After acquiring, spawn refuses a copy that another live task in this home
or any locally registered home already records, including pre-lease tasks
whose hold has lapsed; a relaunch of the same task reuses the copy its own
record names. The pane is then seated with a top-level `cd` into the
leased path and polled until two consecutive reads agree on it. The
pool-slot ownership claim is kept alongside the lease, because that
marker is what teardown reads to leave a reassigned slot untouched.
Upstream spawn fixtures are taught the lease so tests added after this
patch keep passing.

The occupancy walk reuses upstream's fm_local_firstmate_state_dirs, the
same local-home set teardown reads, and a spawn that aborts before any
lease was armed skips the lease return.

Fork patch. Tracks kunchenguid#2754, kunchenguid#1924 and kunchenguid#947 (all
open); the upstream PR that carried this design, kunchenguid#2760, was closed by
its own author on 2026-09-21, not declined by the maintainer.
tiago-peixoto added a commit to tiago-peixoto/firstmate that referenced this pull request Oct 17, 2026
A process-bound `treehouse get` hold lapses when no process remains in
the copy, so a later `get` could be handed a live task's recorded
worktree while that task was merely idle between turns. Its next
relaunch, teardown, or worktree read then pointed at someone else's work.

Fresh ship and scout Treehouse spawns now acquire the copy with
`treehouse get --lease --lease-holder <task-id>` from the spawning
project instead of opening a process-bound subshell in the pane. A
leased worktree is never handed out by a later `get` and never removed by
prune, even with no process running inside it, until `treehouse return` -
and teardown returns it only after the landed-work test passes.

After acquiring, spawn refuses a copy that another live task in this home
or any locally registered home already records, including pre-lease tasks
whose hold has lapsed; a relaunch of the same task reuses the copy its own
record names. The pane is then seated with a top-level `cd` into the
leased path and polled until two consecutive reads agree on it. The
pool-slot ownership claim is kept alongside the lease, because that
marker is what teardown reads to leave a reassigned slot untouched.
Upstream spawn fixtures are taught the lease so tests added after this
patch keep passing.

The occupancy walk reuses upstream's fm_local_firstmate_state_dirs, the
same local-home set teardown reads, and a spawn that aborts before any
lease was armed skips the lease return.

Fork patch. Tracks kunchenguid#2754, kunchenguid#1924 and kunchenguid#947 (all
open); the upstream PR that carried this design, kunchenguid#2760, was closed by
its own author on 2026-09-21, not declined by the maintainer.
tiago-peixoto added a commit to tiago-peixoto/firstmate that referenced this pull request Nov 18, 2026
…t-PR branch PRs (#120)

* fix(bin): treat a declared wait as a standing declaration, not the log's last event

`state/<id>.status` is an append-only event log, and every declared-wait
gate read it last-event-wins. A worker that appended `paused: <external
wait>` kept its wedge-alarm suppression only until the next line landed,
from anyone: its own armed background reporter, a pipeline step notice, a
firstmate note. That line became the newest event, current state flipped
away from the declaration, the possible-wedge ladder restarted from zero,
and nothing reported that the suppression had been voided.

`status_standing_wait_line` in `bin/fm-classify-lib.sh` folds the log the
way keyed decisions are already folded: a `paused:` or `captain-held:` line
declares the wait, and only a line the worker writes to say its situation
changed - `done`, `needs-decision`, `blocked`, `failed`, `resolved`, or a
replacing declaration - retracts it. `working:`, `note:` and free-text
prose leave it standing. A `resolved` line retracts a pause only when it
carries the pause's own phase key, where a keyless line is its own phase
distinct from a stated `[key=default]`, matching upstream's
`status_declared_wait_line`; a captain hold is retracted by any `resolved`
line because the hold waits on firstmate's answer. Every declared-wait
gate reads that fold: `fm-crew-state.sh`, `fm-watch.sh`,
`fm-supervise-daemon.sh`, and `fm-push-transition-lib.sh`'s Herdr fast
path. The re-surface throttle is scoped to the declaration line rather
than the status-log signature. The daemon's captain-relevance and terminal
reads, and the watcher's wedge wait evidence, keep upstream's
`status_declared_wait_line` read.

Fork patch F6. Tracks kunchenguid#2713 (open); upstream PR
kunchenguid#4811 proposes a narrower cadence fix for the same
issue. Rebuilt on upstream a8572f6, whose 5587 introduced
`status_declared_wait_line` at these gates; each conflicting gate keeps
the standing fold on top of upstream's surrounding change.

Upstream issue: kunchenguid#2713 (open)
Upstream PR: kunchenguid#4811 (open)
(cherry picked from commit 4bfc53c)

* feat(spawn): lease Treehouse copies for the task lifetime

A process-bound `treehouse get` hold lapses when no process remains in
the copy, so a later `get` could be handed a live task's recorded
worktree while that task was merely idle between turns. Its next
relaunch, teardown, or worktree read then pointed at someone else's work.

Fresh ship and scout Treehouse spawns now acquire the copy with
`treehouse get --lease --lease-holder <task-id>` from the spawning
project instead of opening a process-bound subshell in the pane. A
leased worktree is never handed out by a later `get` and never removed by
prune, even with no process running inside it, until `treehouse return` -
and teardown returns it only after the landed-work test passes.

After acquiring, spawn refuses a copy that another live task in this home
or any locally registered home already records, including pre-lease tasks
whose hold has lapsed; a relaunch of the same task reuses the copy its own
record names. The pane is then seated with a top-level `cd` into the
leased path and polled until two consecutive reads agree on it. The
pool-slot ownership claim is kept alongside the lease, because that
marker is what teardown reads to leave a reassigned slot untouched.
Upstream spawn fixtures are taught the lease so tests added after this
patch keep passing.

The occupancy walk reuses upstream's fm_local_firstmate_state_dirs, the
same local-home set teardown reads, and a spawn that aborts before any
lease was armed skips the lease return.

Fork patch. Tracks kunchenguid#2754, kunchenguid#1924 and kunchenguid#947 (all
open); the upstream PR that carried this design, kunchenguid#2760, was closed by
its own author on 2026-09-21, not declined by the maintainer.

Upstream issue: kunchenguid#2754 (open); also kunchenguid#1924 and kunchenguid#947 (open)
Upstream PR: kunchenguid#2760 (closed unmerged by its author; the open issues above still track the defect)
(cherry picked from commit eacfbf4)

* fix(bin): lease a secondmate's worktree from its own clone (#64)

* fix(bin): lease a secondmate's worktree from its own clone

Treehouse names a pool by directory name and origin URL, not by clone
path, so a secondmate home's clone of a project shares the pool of the
main home's clone of the same origin. A spawn from the secondmate home
was handed a copy linked to the main home's clone, and Claude trust
pre-registration refused it ("is not a worktree of project"), so no
claude worker could start there.

Acquisition now holds such a copy leased while it retries, so Treehouse
cannot hand it out again and creates a copy from the spawning clone,
then returns the held copies. The trust refusal is unchanged for fresh
spawns. A relaunch of a task already recorded in another clone's copy
of the same origin registers trust against that clone, so existing work
can move to claude; an unrelated repository's copy is still refused.

Refs kunchenguid#4348

* test(pi): stop a killed fork from deleting the dead-lock fixture

The free-or-dead-lock case made its dead pid with `sleep 30 &` followed
at once by `kill`. A TERM that reaches the forked child before it drops
the suite's TERM trap runs fm_test_cleanup there, and the child shares
the suite's cleanup registry, so it deleted the fixture root while the
test kept running. CI saw the second extension load fail with
ERR_MODULE_NOT_FOUND. A child that exits on its own yields a dead pid
without sending any signal.

Upstream issue: kunchenguid#4348 (open)
Fork PR: #64
(cherry picked from commit 8cef12e)

* fix(bin): refresh the watcher beacon between slow poll phases (#65)

* fix(bin): refresh the watcher beacon between slow poll phases

A round of checks can outlast the liveness grace while the watcher is
still moving, so a live watcher is reported dead.
kunchenguid#5408

* fix(bin): treat a beacon generation change as the next poll

Mid-cycle liveness touches moved the beacon mtime during a slow round, so a cycle wait reaped the watcher before wedge classification.

Upstream issue: kunchenguid#5408 (open)
Fork PR: #65
Includes the wedge-suite fixture correction from fork PR #100 (fork commit 44a9daa), which reads a completed watcher poll from the beacon's generation rather than its modification time, because this carry refreshes that time between slow phases.
(cherry picked from commit c01eae6)

* fix(bin): carry the machine-capacity rule in every ship and scout brief (#76)

* fix(bin): carry the machine-capacity rule in every ship and scout brief

Ship and scout briefs said nothing about the heavy-run slots that every
Firstmate home on a machine shares, so each home hand-wrote its own copy
of the rule. One copy named a slot by a bare suffix, which two lanes
resolved to two different paths: each held a genuine lock and both ran
heavy suites at once.

fm-brief.sh now emits one "# Machine capacity" section in ship and scout
briefs. It spells each of this home's slot paths in full, in claim order,
states the 1-minute load bar, and sends every claim through the new
bin/fm-heavy-slot.sh. The helper claims a slot by one atomic mkdir of its
full path, records the task and a pid that lives for the whole heavy
command, and releases only the task's own slot. The slot list and load
bar come from config/heavy-suite-slots and config/heavy-suite-load.

* fix(bin): leave a project's own slot-claiming suite script unwrapped

A project on this server runs its full suite through its own script,
which claims a heavy slot by itself. Wrapped in fm-heavy-slot.sh as the
brief directed, that script would wait on the slot its own wrapper
already holds. The capacity rule now tells the worker to run such a
script as the project says instead.

Upstream issue: kunchenguid#4453 (open; a full-check limit for parallel workers on one machine)
Upstream PR for the same job: kunchenguid#7614 (closed unmerged; superseded)
Fork PR: #76
(cherry picked from commit d6d65e4)

Current successor: kunchenguid#8006 (open).

* fix(bin): serve heavy-slot waiters in arrival order and show live holders (#77)

Heavy-slot admission was bare mkdir contention, so a home whose tasks
released and retook a slot faster than another home polled could keep
it indefinitely. A waiter could not tell that starvation from honest
queuing behind working holders either: the owner pid was its only
liveness evidence, and a suite's short-lived processes leave any one pid
dead while the suite still works.

fm-heavy-slot.sh now refreshes the owner file's time while the command
runs, so its age shows a working holder even between a suite's
processes. Waiters keep a refreshed ticket in a queue beside the slots,
and a free slot goes to the longest live waiter that may use it. The new
status subcommand reads each slot as working, between commands, idle, or
stale, and the brief escalates only a holder not shown to be working.

Upstream issue: kunchenguid#4453 (open)
Upstream PR for the same job: kunchenguid#7614 (closed unmerged; superseded)
Fork PR: #77
(cherry picked from commit 27b3cc2)

Current successor: kunchenguid#8006 (open).

* fix(bin): let firstmate clear an abandoned heavy slot only on positive evidence (#78)

* test(heavy-slot): end fake suites when a failed test removes their directory

Two fake suites in tests/fm-heavy-slot.test.sh wait for a "go" file that
only the passing path creates. When a test failed first, the test root was
removed but the suite kept polling for a file that could no longer appear,
so it ran until someone killed it and held any pipe on the test's output
open. Each loop now also ends once its case directory is gone.

* fix(bin): let firstmate clear an abandoned heavy slot only on positive evidence

Nothing could tell an abandoned heavy slot from one whose suite still ran.
The owner pid is the launcher's, and a wrapper killed outright leaves its
suite running under other pids, so a sweep keyed on a dead pid would clear
a live slot and start a second suite beside it. Slots on this machine also
came in older shapes, plain files and bare-pid owner lines, that status
lumped together as unreadable.

fm-heavy-slot.sh run now exports FM_HEAVY_SLOT_HELD=<slot>:<task> into the
heavy command, so every process the suite starts carries the claim's mark.
The new clear subcommand is for firstmate only and removes one slot only
when the record is past its bound, no recorded pid is alive, no live
process carries the mark, and no no-mistakes pipeline step runs. It checks
the record's age last, so a slot claimed again during the scans is left
alone. Status now names plain-file claims and legacy owner lines, and the
brief tells workers that only firstmate clears a slot.

* fix(bin): refuse to clear a heavy slot the helper did not mark

clear derived a claim's mark from its owner line, so a claim written by
hand in that shape, or one with no pid at all, looked as if no process
carried its mark and cleared on age alone. All three slots live on this
machine today are hand-made claims, and one records no pid, so a suite
running under it would have been invisible to every check.

Every claim fm-heavy-slot.sh makes now holds a mark file, and run exports
that file's line as the mark. clear trusts only that file; any other claim
is refused unless firstmate passes --owner-ended after confirming the
owning task has ended, and the recorded-pid, pipeline-step, and age checks
still apply.

Upstream issue: kunchenguid#4453 (open)
Upstream PR for the same job: kunchenguid#7614 (closed unmerged; superseded)
Fork PR: #78
(cherry picked from commit 9430517)

Current successor: kunchenguid#8006 (open).

On macOS, clear refuses occupied slots even with --owner-ended because ps can hide a live process environment. The protected-process regression fails before this guard and passes afterward. Ordinary claim, run, and owner release are unchanged.

* fix(bin): relaunch a gone herdr worker into its own presentation space (#79)

When fm-control relaunch re-created a worker whose Herdr pane was gone,
fm-spawn always used the flat per-home container. A second mate runs
fm-control from its own pane, so the replacement tab landed inside the
second mate's own workspace instead of a presentation space of its own.

The rebind now follows the fresh-spawn placement rules in the recorded
session: the projected create moves into spawn_herdr_projection_create,
shared by both paths. A journal whose token workspace is positively gone
is retired first; a space that is still present or unreadable is left
untouched and the replacement falls back flat with a warning. A projected
replacement also gets the projection's abort cleanup.

tests/fm-control-relaunch.test.sh reproduces the defect against a
stateful stand-in Herdr. tests/fm-control-herdr-relaunch-space-e2e.test.sh
checks the same placement against real Herdr where a default session
exists, and skips elsewhere.

Upstream PR: kunchenguid#6700 (closed unmerged by its author; re-create a rebound herdr endpoint in its own presentation space)
Upstream issue: kunchenguid#5356 (open)
Fork PR: #79
Includes the Herdr fixture correction from fork PR #100 (fork commit 42f55e0): the inert opencode stand-in answers upstream's --version probe.
(cherry picked from commit 38b19bf)

* fix(bin): tell the no-mistakes validation handoff from the finished report (#86)

A no-mistakes worker was told to append done at commit time and again when
its pull request was green, so one status line could not say which event it
reported, and the handoff sentence did not name who starts the validation run.

The handoff line now opens with the fixed words 'ready for validation, not
pushed', and the instructions say that firstmate sends the /no-mistakes
instruction and the worker starts the run only then. A secondmate home no
longer publishes that handoff to its parent as finished work.

A bare done: {summary} from a worker launched on older instructions stays an
ungated handoff, as before.

Refs kunchenguid#7251

Upstream issue: kunchenguid#7251 (open)
Fork PR: #86
(cherry picked from commit 1e01205)

* fix: match Pi Codex quota accounts by recorded sign-in source (#92)

Upstream issue: kunchenguid#7483 (open)
Fork PR: #92
(cherry picked from commit 5b55c4a)

* fix(bin): read a green PR waiting on a merge as held, not finished (#75)

* fix(bin): read a green PR waiting on a merge as held, not finished

A secondmate home summary counted every in-flight child that
fm-crew-state.sh reads as done as terminal_in_flight. A no-mistakes ship
whose run passed reads done while its PR is still open and waiting on a
maintainer, so Bearings reported those homes as having unreconciled
books and the parent queued a reconcile request for each of them.

A done child whose run-step reading shows its PR still open is now a
child-state hold. Merged, closed, unknown, and status-log done readings
still count as terminal_in_flight, so a finished task that was never
cleaned up still reads as a mismatch.

* ci: expect the added Bearings regression test in the stock Bash count

The stock macOS Bash job pins the number of Bearings tests it must see.
The parked-PR regression test makes that 61.

Upstream PR: kunchenguid#7493 (open; same job), also kunchenguid#6565 (open)
Upstream issue: kunchenguid#3941 (open; related)
Fork PR: #75
(cherry picked from commit 5876427)

* fix(bin): require a handoff or disposition receipt to acknowledge a review with findings (#109)

Upstream issue: kunchenguid#8046

* fix(bin): keep a correlated reply distinct from the child's completion (#110)

Upstream issue: kunchenguid#8047

* fix(status): validate status event writes (#111)

Upstream issue: kunchenguid#8048

* fix(bin): refresh the watcher beacon between pane-scan windows (#113)

One pane scan reads every recorded window in turn. A pane seen stable for
the first time costs a current-state read, which can spend its whole
no-mistakes bound, so many windows together outlast the beacon grace while
the watcher is still working. The arm then refuses a live watcher with
"lock held by live pid ... but heartbeat is stale".

Refresh the beacon at the start of each window, as the check loop already
does between checks. One window whose reads hang past the grace still reads
stale.

Upstream issue: kunchenguid#8095

* feat(bin): deliver verified document snapshots with secondmate --doc reports (#114)

Capture document bytes before publishing a report and bind the report to their digest.
Verify remote bytes before making the snapshot available to the parent.
Preserve upstream interrupt cleanup for remote download temporary files.

Upstream PR: kunchenguid#8243
Fork PR: #114

* fix(bin): reuse unchanged pending-reply decisions within a tick (#115)

Reuse one decision fold while task status identity, contents, kind, and classification settings remain unchanged within a tick. Invalidate the cached verdict on changed evidence and keep calls outside a tick uncached.

Upstream PR: kunchenguid#8241

Fork PR: #115

* fix(bin): preserve Claude worker local settings during spawn and relaunch (#119)

* fix: preserve Claude worker settings during spawn and relaunch

* no-mistakes(test): Seed Claude worker settings from the primary clone

* no-mistakes(document): Document that local Claude settings seed workers

* fix(contributions): wake on an unanswered inline comment from an app bot

A GitHub App reviewer such as CodeRabbit posts inline findings as a Bot
account with no repository association, so the observer dropped them unless a
home listed the bot. Admit such an inline comment while its thread has no later
reply from the contribution author, and key it without the edit time so the
bot rewriting its own comment does not wake again.

* fix(pr-health): record a direct-PR ship's branch PR when no ready line names it

A direct-PR worker that reports readiness in other words, or only through a
paused merge wait, leaves no done line that a PR registration path reads, so the
task never records pr= and never arms a merge poll. The monitor already finds
the open PR on each live task copy's branch; record it through fm-pr-check.sh
for a direct-PR ship that has none. Other modes open their PR before the work
is ready, so they keep relying on their ready report.

Document both this and the app-bot inline comment admission in the
configuration reference, the script index and the ship-landing skill.

* fix(pr-health): never re-arm a merge poll on a PR whose merge was reported

After a merge the watcher retires the poll but keeps pr=, and the contribution
record can stay non-final for a pass, so branch registration skipped a PR the
merge poll already reported, as fm-pr-check.sh scan does. Also correct the
registration-scan section, which said pr= could only come from a manual run.

* ci: trigger checks after Actions were re-enabled on the fork

* no-mistakes(document): docs: state full direct-PR registration rule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fm-spawn/treehouse: pool assigned the same worktree slot to two concurrently-live tasks

3 participants