Repository navigation
fix: adopt a verified Herdr pool lease before relaunch stops the agent - #64
Merged
Merged
Conversation
A relaunch now checks the recorded pool reservation before it records a checkpoint or stops the running agent, so a refusal leaves that agent and its record in place. When the pool entry is leased by this task on the recorded copy, relaunch records that lease id and holder and continues.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Found 2026-11-09 on pv-cash-toggle-payments-u1: fm-control relaunch refused with "recorded copy has no verifiable pool reservation; reconcile its ownership before relaunch" (bin/fm-treehouse-slot-lib.sh spawn_treehouse_reservation_preflight). The Herdr spawn path had taken the pool lease with treehouse get --lease --lease-holder (pool entry leased=true, lease_holder=task id, lease_id set) but wrote no treehouse_lease_id/treehouse_lease_holder into state/.meta. The relaunch preflight only accepts a meta with those fields or a fully unleased legacy entry, so it refuses the Herdr-native lease that fm_treehouse_task_holds_pool_lease already recognises. The first relaunch attempt stopped the Codex agent before refusing, leaving no agent running. Workaround used: append the verified pool lease_id and holder to the meta, then relaunch. Fix idea: in the relaunch preflight, accept fm_treehouse_task_holds_pool_lease and adopt its lease_id, or have the Herdr spawn record treehouse_lease_* in the meta; and run the preflight before stopping the old agent. PR 53 (fm-main-ci-red-fix-m1) restored durable leases for new spawns, so copies spawned before it still lack treehouse_lease_* and the preflight still stops the agent before refusing.
q2102 a
What Changed
fm-control relaunchnow runs the Treehouse reservation check (spawn_treehouse_reservation_preflight) after the checkpoint and before it copies the task record, writes the journal or note, or stops the old agent. If the check refuses, the agent keeps running and the task record is unchanged.treehouse_lease_*fields when the pool entry for the recorded copy is leased by this task and its lease id and holder can be read. This is the lease that Herdr-native spawns created. After the exclusivity check passes, the check writes thattreehouse_lease_id/treehouse_lease_holderinto the task record. It writes a temp copy and renames it into place, using the newfm_treehouse_record_adopt_pool_lease. Every other reservation it can't verify is still refused, and it also refuses if the lease can't be recorded.docs/agent-control.md(adds a new "Verify the pool reservation" relaunch step and the test coverage) and the ownership-contract comments inbin/fm-wake-lib.shandbin/fm-control.sh. Added cases totests/fm-control-relaunch.test.shfor a refusal that happens before the agent stops and for adopting a Herdr-native lease.🤖 Generated with Claude Code
Risk Assessment
✅ Low: The change is narrow and matches the intent. fm-control now runs the same reservation preflight that fm-spawn uses, and it runs it before anything durable is written or the agent stops. A Herdr-native lease is adopted only after verifying the holder, the slot claim and that no other record names the copy. The adopted fields go through preserve_relaunch_meta and are re-verified by fm-spawn under the project lock. Behavioral tests cover the refusal and adoption paths.
Testing
I drove three live scenarios on a disposable Herdr 0.9.0 lab session with a real Treehouse 2.3.0 pool and a real Claude worker started by fm-spawn. In each one I removed the lease fields from the task record to recreate a copy spawned before PR 53. First, with the pool lease held by the task id,
fm-control relaunchexited 0: the record gained the lease id and holder from the pool, the pool entry was unchanged, and a new Claude came up idle in the same pane. Second, with the lease held by a different holder, relaunch refused and left Claude running idle, the record byte-identical, and no relaunch checkpoint. Third, the same adoption setup on the base commit reproduced the incident: Claude was stopped, the relaunch refused, and no agent was left running. My first adoption attempt failed only because I relaunched about 1s after Claude started, before its state could be read; after adding a wait for idle, the rerun passed. The targetedtests/fm-control-relaunch.test.shsuite passed, including the two new tests. All lab sessions, pools and temp homes were torn down, and the worktree is clean.Evidence: Live driver script (Herdr lab + real treehouse + fm-spawn + fm-control relaunch)
Source: Live driver script (Herdr lab + real treehouse + fm-spawn + fm-control relaunch)
Evidence: Live: Herdr-native pool lease adopted, relaunch succeeds
Source: Live: Herdr-native pool lease adopted, relaunch succeeds
pool entry before relaunch: {"leased":true,"lease_id":"569e2642...","lease_holder":"lease-adopt"} relaunched lease-adopt harness=claude ... backend=herdr fm-control exit=0 agent on pane after relaunch: claude state=idle meta: treehouse_lease_id=569e264219ebb594847822774a48ac0b treehouse_lease_holder=lease-adoptEvidence: Live adversarial: lease held by another holder refuses before stopping the agent
Source: Live adversarial: lease held by another holder refuses before stopping the agent
REFUSED: task lease-foreign's recorded copy has no verifiable pool reservation; reconcile its ownership before relaunch fm-control exit=1 agent on pane after relaunch: claude state=idle meta unchanged vs before: yes relaunch checkpoint present: noEvidence: Live base-commit reproduction of the incident (agent stopped, then refused)
Source: Live base-commit reproduction of the incident (agent stopped, then refused)
REFUSED: task lease-adopt's recorded copy has no verifiable pool reservation; reconcile its ownership before relaunch error: lease-adopt's agent was stopped but the replacement did not launch; no agent is runningEvidence: First adoption attempt: relaunched before Claude's state was readable (setup timing)
Source: First adoption attempt: relaunched before Claude's state was readable (setup timing)
Evidence: Targeted suite tests/fm-control-relaunch.test.sh output
Source: Targeted suite tests/fm-control-relaunch.test.sh output
Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-treehouse-slot-lib.sh:470- In the adoption branch,fm_treehouse_task_holds_pool_lease "$RELAUNCH_WT" "$ID"is redundant. Thefm_treehouse_lease_readcall right after it already requires leased==true, destroying!=true and a non-empty, tab/newline-free lease_id and lease_holder, and the following[ "$FM_TREEHOUSE_LEASE_HOLDER" = "$ID" ]checks the holder. The first call is a strict subset of those checks and costs one extra pool-state read and jq pass. Dropping it would not change behavior. It is optional to keep it as documentation that this is the contract fm-wake-lib.sh recognises.✅ **Test** - passed
✅ No issues found.
bin/fm-herdr-lab.sh provision/teardownwith a named fm-lab-relaunch-* session, a disposable FM_HOME made bybin/fm-lab-home.sh create, a disposable git project with a bare origin, and an isolatedTREEHOUSE_ROOTpoolbin/fm-spawn.sh lease-adopt <project> --harness claude --backend herdr --mode local-only --yolo off(real treehouse lease, real claude in a Herdr pane), then lease fields stripped from the meta and the pool entry's lease_holder set to the task id, thenbin/fm-control.sh lease-adopt relaunch --note ...Adversarial: same setup, but the pool lease is held by a holder that is not the task id, thenbin/fm-control.sh lease-foreign relaunch --note ...Base-commit reproduction: the same adoption driver run againstgit archive 4cdc3a7(pre-fix code)bash tests/fm-control-relaunch.test.sh(the targeted suite containing the two new tests)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.