Repository navigation
Conversation
|
Speaking as Kun's firstmate: thank you @rob-mur, this is a real bug with unusually strong live evidence. I checked the premise on latest main What I read in the diff: a fresh Herdr spawn takes a durable VISION: aligns. It makes a restart a non-event, keeps project changes in isolated copies, and holds up as a verified Herdr adapter that binds to Herdr's real restore semantics. Unlanded work is never torn down: the reused slot is never force-returned. contract-class: new-default. Opening the pane in the leased worktree restores a promise main already makes. But the same-id recovery that adopts the old leased slot, and the switch from a process lease to a durable lease on the default Herdr spawn path, are new unconfigured behavior. So this goes to the captain for the merge call, not auto-merge. Next step is on our side: CI just started on this head. If it comes back green, I'll pass this to the captain to decide whether to merge. Nothing is needed from you right now. |
A Herdr restart restores each pane's shell, and resumes its agent, in the cwd of the pane's top-level shell. Herdr ship and scout panes were opened in the project's primary checkout and entered their worktree through an interactive `treehouse get` subshell, so a restart resumed every worker in the primary checkout. A fresh Herdr task now leases its slot with `treehouse get --lease` before its pane exists and opens the pane in that worktree. A spawn that aborts before its record or launch returns the lease once no pane is left in the slot, and otherwise prints the return command. The presentation lab test now asserts the restored pane cwd is the worktree, and the verification record holds a real Claude restart before and after.
A fresh Herdr task now durably leases its slot, and that lease outlives the pane. A same-id spawn after a Herdr restart therefore leased a second slot and stranded the first one, still leased to the task, with its work. When the task's record names a Herdr pane that holds no agent and Treehouse still reports the recorded slot leased to this id with a matching slot claim, the recovery reuses that worktree untouched instead of leasing a new one. Abort cleanup keeps a slot the record names and returns one it does not. The presentation lab test asserts the reclaim reuses the leased worktree and that teardown leaves no slot leased to the task.
…ktree reuse probe
Covered: a fresh crewmate or scout opens its pane in its leased worktree, a same-identity recovery after a restart reuses that worktree, a relaunch whose pane is gone opens its new pane in the recorded worktree, and a secondmate opens in its own home. Not covered: a pane created before this change, including one a relaunch reuses in place, keeps its original cwd until it is re-created, and a restart resumes only the agents Herdr itself restores.
…in/fm-teardown.sh`. The "Behavior portable serial 1" failure (ci-1) is a flake outside this PR. The fix is unconfirmed on Herdr 0.7.4, the version CI runs. **ci-2, "Behavior tests (Herdr)", caused by this PR.** The step "projected teardown changed active workspace/tab from w3/w3:t1 to w8/w8:t2" failed. - **Cause:** this PR opens a fresh Herdr task pane in its leased worktree, so the pane's top-level shell now lives there. Teardown killed every process in the worktree (the reap, then `treehouse return --force`) before closing the pane. That killed the pane's shell, and Herdr removed the pane itself instead of through the focus-preserving close. On Herdr 0.7.4 that removal moves focus to the next workspace (upstream kunchenguid#1621). The close then found the pane gone and never restored focus. Herdr 0.9.5 has fixed that bug, so the test passes locally either way. - **Invariant:** a Herdr task pane must be closed through the focus-preserving, lock-held close before anything kills the processes in its worktree. That applies to both the reap and the return in teardown, for projected and flat panes. Spawn abort cleanup already returns its lease only after the pane close is confirmed. Secondmate panes are unchanged by this PR. - **Fix:** I moved the whole Herdr close block in `bin/fm-teardown.sh` ahead of the reap and return. It now runs after every landed-work refusal and before any destructive step, the same way the T3 kill already runs before its return. The block covers the journal check, the projected or flat close, journal retirement, and the confirmed-gone refusal. The rex and generic close chain stays where it was, and I updated the two comments about ordering. - **If the return then fails:** teardown exits and keeps every record. A rerun still works because the preflight accepts a pane that is already gone. **ci-1, "Behavior portable serial 1", not caused by this PR.** The failure is in `tests/fm-supervision-host.test.sh` ("noack: the host counted an unacknowledged wake handled"), which this PR doesn't touch. The same file fails in the same shard on main with different assertions: run 40437879779 ("latch: the second engine error did not hand the wake back") and run 40413622972 ("return-fail: the host did not hand the wake to main"). I made no change for it. **Verification, all on real Herdr 0.9.5 (only version installed):** - These pass with the fix: `fm-backend-herdr-presentation-e2e`, `fm-backend-herdr-launcher-workspace-e2e`, `fm-backend-herdr-workspace-per-home-e2e`, `fm-backend-autodetect-smoke`. - Two tests fail locally, but they fail the same way with the PR head's original `bin/fm-teardown.sh`. They are `fm-teardown-endpoint-safety.test.sh` ("teardown reported success after a close that failed") and `fm-teardown.test.sh` ("fixture never attempted publication"). Both cover tmux and archive fixtures, not Herdr, so my change didn't cause them. - The 0.7.4 focus failure could not be reproduced here. The next Herdr CI run is the first real check of the fix
…tree The base branch extended freshen_spawn_worktree_base with project and mode arguments; the Herdr lease call site added on this branch still passed two. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…e worktree return
1fc4594 to
cc2de91
Compare
[Medium impact] The PR appears safe to merge; no new actionable issue was found. Reviews (3) · Last reviewed commit: "no-mistakes(ci): ci-2 (Behavior tests (H..." · Reviewed by Greptile |
A fresh Herdr spawn leases its slot before inspecting it, and abort cleanup force-returns that lease. An inspection failure returned the generic refresh error, so the unchecked slot was handed back with --force. Report it distinctly and keep the lease, so only a slot proven clean goes back.
|
Speaking as Kun's firstmate: thanks @rob-mur. I read the new head
The attestation binds this head with test/document/lint completed, and live validation is 5 of 6. There are no workflow, credential or network changes, so I approved the fork runs for this head: CI VISION: aligns, unchanged. A restart becomes a non-event, the work stays in isolated copies, and unlanded work is never torn down (a slot it can't inspect stays leased). contract-class: new-default, unchanged, and a bit stronger now. Durable leases, same-id slot reuse, and now a reordered default Herdr teardown are new unconfigured behavior. The hard-killed-spawn trade-off from my last note still stands: a durable lease can outlive a killed spawn. Next step is on our side. If CI comes back green on this head, it goes to the captain as a merge-or-leave decision. Nothing is needed from you right now. |
…and is fixed; ci-1 (Behavior portable serial 6) was not, and has no change. ci-2: the step "fm-hibit-resume-r1 reclaim leased .../2/recovery-project instead of reusing its leased worktree .../1/..." failed. herdr_task_own_leased_worktree (bin/fm-spawn.sh) checked that the task's old slot was still leased to its id by running `treehouse status --json`. CI pins Treehouse 2.0.1 (bin/fm-install-treehouse.sh), and in that version `status` has no --json option, so the check always failed in CI and the recovery leased a second slot. It passed locally because Treehouse 3.1.4 has the option. - Invariant: a same-id restart recovery must recognise a slot still leased to its id, whichever Treehouse version is installed. - The only other place that read leases through `status --json` was the e2e test's check that teardown released every slot leased to the task. On 2.0.1 it got no output and so always passed without checking anything. - Fix: both places now read the pool's treehouse-state.json directly (`.worktrees[]` with `.leased == true` and `.lease_holder == id`). The 2.0.1 source and local 3.1.4 pools both store leases this way, and fm_treehouse_pool_slot already requires that file. - Files: bin/fm-spawn.sh (the lease check in herdr_task_own_leased_worktree) and tests/fm-backend-herdr-presentation-e2e.test.sh (the RESTART_HELD teardown check). ci-1: tests/fm-watcher-lock.test.sh failed ("recovery drain after forced arm interruption failed"). This PR's only change to the watcher code is comment lines in bin/fm-wake-lib.sh. Locally the test fails at a different step ("acquirer could not reclaim dead steal owner rc=8") both on this branch and on base commit 6613c3e, so the failure comes from timing or the environment, not from this change. Verification: - tests/fm-backend-herdr-presentation-e2e.test.sh passes in full on real Herdr 0.9.5 with Treehouse 3.1.4, including the restart-reuse and teardown-release checks. - The new jq query, run against a real pool state file, matches the correct lease holder and rejects any other. - Not run: Treehouse 2.0.1, because its prebuilt binary won't start on this NixOS host, and Herdr 0.7.4, which isn't installed. The 2.0.1 state-file format is confirmed only from its source, so the next Herdr CI run is the first real check of the fix
|
Speaking as Kun's firstmate: thanks @rob-mur, that's a good catch. CI's pinned Treehouse 2.0.1 has no Delta since CI: I approved the fork runs on |
|
Speaking as Kun's firstmate: thanks @rob-mur. The Treehouse 2.0.1 fix worked. Every lane passed on head Where it stands:
Because it changes a default, it's waiting on the captain's merge-or-leave decision, not on you. FYI: #7941 just landed and also touches |
|
Closing: #8052 now covers most of this change (durable treehouse leases at spawn, lease cleanup on abort and teardown). I will send the one remaining part, where a restarted worker reuses its own leased slot, separately if it is still needed. |
Intent
Make a patch so a Herdr server restart no longer resumes firstmate workers in the wrong folder, and open a PR for it upstream.
Context: after a Herdr restart, Herdr (0.9.5,
[session] resume_agents_on_restore, on by default) resumed every herdr-backed worker's agent session (claude --resume <id>) in the pane's savedcwd. For every ordinary spawn that saved cwd is the project's primary checkout (e.g.<home>/projects/aegis), not the worker's isolated worktree, so all restored workers ended up running in the primary checkout. Becauseprojects/sits inside the firstmate home, Claude also offered to import the home's ownAGENTS.md(an "Allow external CLAUDE.md file imports?" dialog), and the project's direnv reported.envrcblocked. Herdr'ssession.jsonshowed panes with"cwd": "<home>/projects/aegis"and anagent_sessionid belonging to the session recorded under the worktree path.We need to make sure that restarts in general don't lose these kinds of workers.
What Changed
treehouse get --lease --lease-holder <id>and opens its task pane in that worktree. Before, the pane opened in the project's primary checkout and ran an interactivetreehouse getinside it. Herdr restores a pane, and resumes its agent, in the pane's top-level shell cwd, so after this change a restart brings the worker back in its worktree.fm_backend_herdr_projection_cleanup_exactnow reports whether the task-pane close was confirmed, and abort cleanup uses that for the last check. If a pane may still be there, or the worktree is dirty or couldn't be inspected, the lease stays and the spawn prints thetreehouse return --forcecommand to run.🤖 Generated with Claude Code
Risk Assessment
Testing
I drove three checks. First, a real Claude crewmate through a real Herdr 0.9.5 lab-session restart with agent resume on: the pane's saved cwd, the restored pane's cwd and the resumed
claude --resumeprocess cwd were all the leased worktree, and teardown left no lease. Second, the real-Herdr presentation e2e passed in full; it covers restored-pane cwd, reusing the same-id leased worktree on reclaim, the opted-out tab's--cwd, lease return on abort cleanup, and no leftover leases after teardown. Third, the hermetic relaunch suite passed every case it could run on this host. That needed a temporary copy that callssleepfrom PATH instead of/bin/sleep(missing on NixOS) and skips the case that needspi, which is not installed. The guard for a slot whose status can't be read is covered only by that hermetic test, so it is marked untested here. I made no source changes, and all lab sessions, lab homes and temp files were removed.claude --resume) in its own worktree, not the project's primary checkoutpane getcwd and the resumed process cwd from /proc and process-info were all ~/.treehouse/demo-eb7512/1/demoEvidence: Real-Claude Herdr restart transcript (saved/restored pane cwd, resumed claude cwd, teardown leases)
Source: Real-Claude Herdr restart transcript (saved/restored pane cwd, resumed claude cwd, teardown leases)
Evidence: Script that drove the real-Claude restart check
Source: Script that drove the real-Claude restart check
Evidence: Real-Herdr lab presentation e2e output
Source: Real-Herdr lab presentation e2e output
Evidence: Hermetic relaunch suite output
Source: Hermetic relaunch suite output
Evidence: Key restart evidence
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-spawn.sh:5094- Commit 58696bd givesfreshen_spawn_worktree_basea separate exit code 3 for a worktree whosegit statuscannot run. The Herdr lease branch (bin/fm-spawn.sh:4765-4772) treats both 2 and 3 as 'keep the lease', following its own comment that only a slot proven clean may be force-returned. The T3 sibling branch, which also leases durably, still checks only[ "$?" -eq 2 ]. With exit 3 it leavesT3CODE_LEASED=1, so abort cleanup runstreehouse return --forceon a worktree whose state was never inspected. The old code had the same outcome through exit 1, so this is not a regression. It is the one remaining caller where the invariant this commit introduced does not hold. Fix: handle the code the same way as the Herdr branch, for examplecase $? in 2|3) T3CODE_LEASED=0; echo ...;; esac.tests/fm-control-relaunch.test.sh:511- This host can't run tests/fm-control-relaunch.test.sh as written. It calls/bin/sleep(line 511, older than this change), which NixOS doesn't have, and its Pi relaunch case needspi, which isn't installed. I ran a temporary copy that callssleepfrom PATH and skips the Pi case; every other case passed. This has nothing to do with this change.claude --resume) in its own worktree, not the project's primary checkoutpane getcwd and the resumed process cwd from /proc and process-info were all ~/.treehouse/demo-eb7512/1/demoenv -u NO_MISTAKES_GATE HERDR_LAB_HELPER=bin/fm-herdr-lab.sh bash tests/fm-backend-herdr-presentation-e2e.test.sh(real Herdr 0.9.5, isolated fm-lab-* session, 25/25 ok, about 5.6 min)Live real-Claude restart: a lab home made withbin/fm-lab-home.sh create; a lab session frombin/fm-herdr-lab.sh name/provisionusing a HERDR_CONFIG_PATH copy withresume_agents_on_restore = true;bin/fm-spawn.sh democwd <lab>/projects/demo --mode local-only --yolo off --harness claude --backend herdr; thenfm-herdr-lab.sh stop+provision, readingpane get,pane process-info, session.json and /proc/<pid>/cwd; thenbin/fm-teardown.sh democwd --forceandtreehouse status --jsonlease check; the lab was torn down afterwardstests/fm-control-relaunch.test.shfrom a temporary copy (deleted afterwards) that callssleepfrom PATH instead of/bin/sleepand skips the Pi-only case, sincepiis not installed; every case passed, including the new 'fresh spawn keeps a leased slot it could not inspect'✅ **Document** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.