Skip to content

fix(bin): start pooled worktrees from the newer of origin and the primary checkout - #3812

Closed
mikeastwoody wants to merge 2 commits into
kunchenguid:mainfrom
mikeastwoody:fm/fm-treehouse-base-obsoleta
Closed

mikeastwoody wants to merge 2 commits into
kunchenguid:mainfrom
mikeastwoody:fm/fm-treehouse-base-obsoleta

Conversation

@mikeastwoody

@mikeastwoody mikeastwoody commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A treehouse pool slot is refreshed by resetting it to origin/. On a local-only project that ref is frozen at the last push while the primary checkout's default branch keeps landing work through fm-merge-local.sh, so every fresh task started hundreds of commits behind (measured 400 to 854 commits on one project) and one worker built and installed a stale app from that base. The fix: a fresh slot starts from whichever of origin's tip and that same branch in the primary checkout contains the other; a delivery that opens a pull request keeps origin's tip and is told how far ahead the primary is; diverged candidates keep origin's tip and say so; the refresh reports the exact number of commits the slot was behind; fm-review-diff.sh anchors the captain's review on the same base rule; fm-dod-lib.sh is the single owner of which modes open a pull request. An unclean slot is never touched, nothing is fetched to resolve the base, relaunch keeps its base, and a scout keeps working from the base it needs.

What Changed

  • bin/fm-spawn.sh no longer always resets a fresh pooled task worktree to origin/<default>. A local-only ship or a scout now starts from the same branch in the primary checkout when that branch contains origin's tip. Both commits are read from the local object store, so nothing is fetched. A no-mistakes or direct-PR ship still starts from origin's tip, and a note says how many commits the primary carries that origin lacks. If the two have diverged, the worktree starts from origin's tip with a note, and no spawn is refused. After the refresh, it reports exactly how many commits the worktree was behind. Unclean worktrees are still refused, and relaunch still skips the refresh.
  • bin/fm-review-diff.sh now anchors the review on the branch the task delivers to. Pull-request modes compare against origin/<default>. Local-only ships and scouts compare against whichever of the local <default> and origin/<default> meets the branch later. On a local-only project this stops the review from listing commits already landed on the local branch as the task's own. It prints a note when the local <default> already contains the branch, or when the two merge bases are unrelated.
  • bin/fm-dod-lib.sh adds fm_delivery_opens_pull_request, now the one place that says which modes open a pull request. Both scripts use it. The header comments, docs/architecture.md and docs/scripts.md describe the new rule. New tests cover the spawn base choice, the review anchor, and a relaunch keeping its base after the primary checkout moves ahead.

Risk Assessment

✅ Low: I traced every branch of the base rule and found no case in intended use that gives a wrong result. At spawn, a slot starts from origin's tip or, only for local-only ships and scouts, from the primary's default branch when that branch strictly contains origin's tip; pull-request and diverged cases keep origin's tip and print a note. The review anchors on the later of the two merge bases with the branch, which lands on the spawn base in every converged, diverged, rebased and stale-primary case. Unclean slots are refused before anything is reset, no new network access is added, relaunch never refreshes the base, and the one behavior change that could be questioned (starting from origin's tip when the candidates have diverged) was explicitly approved by the captain.

Testing

I drove 15 scenarios live in a sandbox: disposable firstmate homes and projects, a separate tmux server and per-case treehouse pool roots. FM_GATE_REFUSE_BYPASS=1 was set, the documented exemption for runs against a throwaway fleet. The agent was a sleep stand-in. The spawn and review scripts ran against real git state; for key cases the base-commit scripts ran too, reproducing the original bug (a slot 12 commits behind, a review listing 6–11 foreign landed files) and showing the fix. Every scenario passed. Two scenarios needed commits or uncommitted files injected between treehouse get and the refresh: the exact-count note and the unclean-slot refusal. Treehouse 2.3.0 hands out slots already at the newer tip and will not recycle a dirty slot. Of the existing tests, I ran only the two focused files for this change, not the full suite; both passed. This is CLI-only, so the evidence is a transcript, not screenshots. The sandbox tmux server, its stand-in processes and the temp directories were removed afterwards; the worktree is unchanged.

  • Live validation: ✅ go - 15 of 15 scenarios driven live against the product
Scenario Result Live Evidence
A local-only ship on a project whose primary main has 12 unpushed fm-merge-local landings starts from the primary's tip, not the frozen origin (the old code planted it 12 commits behind) ✅ pass live Transcript section s1: base code slot HEAD=544331b, 12 behind, landed-12.txt missing; new code slot HEAD=b91dc58 = primary main, landed-12.txt present
A scout on a local-only project starts from the primary's landed tip ✅ pass live Transcript section s2 (s2-scout): slot HEAD=1e09e03 = primary main, not origin/main
A no-mistakes or direct-PR ship keeps origin's tip and is told how many unpushed commits the primary carries ✅ pass live Transcript section s2 (s3-nomistakes, s3-directpr): slot == origin/main; note 'carries 9 commits origin/main does not, but mode=... opens a pull request against origin'
Diverged primary and origin (unpushed landings plus a forge-only merge) still launch a local-only ship and a scout from origin's tip, with a note counting both sides ✅ pass live Transcript section s4: exit=0 for both; slot == origin/main with forge-only-1.txt and without landed-1.txt; note 'have diverged: that branch carries 3 commits origin lacks and lacks 1 commit origin ha…
A PR ship whose origin is 4 forge merges ahead of a stale primary starts from origin's tip ✅ pass live Transcript section s4 (s5 origin ahead): slot HEAD=cb8d10c = origin/main, primary main=ff9a3b9
The refresh reports the exact number of commits the slot was behind when history moves after treehouse hands out the slot ✅ pass live Transcript section s6: 'was 3 commits behind main in the primary checkout; refreshed to e8234bb' (local-only); 'was 4 commits behind origin/main; refreshed to ed82784' (no-mistakes)
Adversarial: an unclean slot (diverged history, primary ahead) is refused without discarding the uncommitted work or moving its base, and is not reported as a divergence ✅ pass live Transcript section s8: exit=1 with 'is not clean; refusing to discard uncommitted work'; uncommitted.txt kept; HEAD unchanged; no meta published; no 'diverged' text
Relaunching a task after the primary lands 5 more commits keeps the task's branch, commit and work ✅ pass live Transcript section s9b: relaunch exit=0; HEAD 544c288 on fm/relaunch-live unchanged; task-change.txt present; after-5.txt not pulled in
Captain review of a local-only task shows only the task's own work, not the landed commits a frozen origin would attribute to it ✅ pass live Transcript section s10: base code 'diff base: origin/main' with 6 landed files plus task-change.txt; new code 'diff base: main' with task-change.txt only
Review after the mandated rebase onto main plus 2 further landings still shows only the task's change ✅ pass live Transcript section s11a: base code shows 12 files; new code 'diff base: main' with 1 file
Review of a pull-request delivery anchors on origin/main ✅ pass live Transcript section s11b: 'diff base: origin/main' with task-change.txt only
Review of a diverged local-only task starts from the same commit the spawn planted the slot on ✅ pass live Transcript section s11c: 'diff base: origin/main'; spawn base 5117cd3 = merge-base(origin/main, branch); only task-change.txt
Review of a scout on a local-only project shows only the scout's change ✅ pass live Transcript section s11d: base code shows 9 landed files plus task-change.txt; new code 'diff base: main' with 1 file
Review of a task already fast-forwarded into main comes back empty and says why (documented header behavior) ✅ pass live Transcript section s12: 'note: main already contains fm/scoutlive, so there is nothing left to review against it' / 'no changes vs main'
Resolving the base issues no extra fetch: the primary's commit is read from the local object store ✅ pass live Transcript section s13 (GIT_TRACE): new and base code issue the same two pre-existing 'git fetch --quiet origin' calls and nothing else
Evidence: Live CLI transcript: spawn base rule and review anchor, new vs base code (all scenarios)

Source: Live CLI transcript: spawn base rule and review anchor, new vs base code (all scenarios)

# Live transcript: pooled worktree base rule + review anchor (branch fm/fm-treehouse-base-obsoleta, target b31a4fa3)
# Date: 2026-09-14. Driven against the REAL bin/fm-spawn.sh and bin/fm-review-diff.sh from this worktree.
# "base code" rows run the same scripts extracted from the base commit b182d0f9 (git archive) for contrast.
#
# Sandbox (nothing touches a real fleet):
# - a separate tmux 3.7b server on its own socket (tmux -L fmlive-nm), which fm-spawn drives through TMUX=
# - real treehouse v2.3.0 running `treehouse get` in that pane, pool rooted per case with TREEHOUSE_ROOT
# - throwaway FM_HOME / state / data / config / HOME per case; a throwaway project with a bare file:// origin
# - "local-only landings" = commits on the primary checkout's main that were never pushed (what fm-merge-local.sh leaves)
# - the agent is a stand-in: raw launch command 'sleep 3600', or a pane-PATH 'codex' that execs sleep (relaunch case)
# - FM_GATE_REFUSE_BYPASS=1 + FM_SPAWN_NO_GUARD=1, the documented sandbox exemptions the test helpers use
# Filtered from spawn output: the sandbox brief's "no delivery contract line" warning and the standing-posture notice.
# Filtered from review output: the sandbox's stale-watcher supervision banner (fm-guard.sh), unrelated to this change.

################ s1 ################
=== [base code] local-only ship; primary main has 12 fm-merge-local landings origin never received ===
primary main=85187cd  origin/main=544331b  unpushed=12
$ bin/fm-spawn.sh tregua-base <project> --mode local-only --yolo off 'sleep 3600'
spawned tregua-base harness=sleep kind=ship mode=local-only yolo=off window=firstmate:fm-tregua-base worktree=/private/tmp/fm-nm-live.NEXO33/s1-base/pool-root/.treehouse/project-0a1d1c/1/project
exit=0
slot HEAD=544331b  commits behind primary main=12  has landed-12.txt: NO

=== [new code] local-only ship; primary main has 12 fm-merge-local landings origin never received ===
primary main=b91dc58  origin/main=36f600e  unpushed=12
$ bin/fm-spawn.sh tregua-new <project> --mode local-only --yolo off 'sleep 3600'
spawned tregua-new harness=sleep kind=ship mode=local-only yolo=off window=firstmate:fm-tregua-new worktree=/private/tmp/fm-nm-live.NEXO33/s1-new/pool-root/.treehouse/project-2e6174/1/project
exit=0
slot HEAD=b91dc58  commits behind primary main=0  has landed-12.txt: yes

################ s2 ################
=== s2-scout ===
primary main=1e09e03  origin/main=bf72eaf  unpushed=9
$ bin/fm-spawn.sh scoutlive <project> --scout sleep 3600
spawned scoutlive harness=sleep kind=scout window=firstmate:fm-scoutlive worktree=/private/tmp/fm-nm-live.NEXO33/s2-scout/pool-root/.treehouse/project-e669f0/1/project
exit=0
slot HEAD=1e09e03  == origin/main? no  == primary main? yes

=== s3-nomistakes ===
primary main=214cf27  origin/main=bc6c15c  unpushed=9
$ bin/fm-spawn.sh nmlive <project> --mode no-mistakes --yolo off sleep 3600
note: pooled worktree '/private/tmp/fm-nm-live.NEXO33/s3-nomistakes/pool-root/.treehouse/project-c4f425/1/project': main in the primary checkout carries 9 commits origin/main does not, but mode=no-mistakes opens a pull request against origin; starting from origin's tip so those unpushed commits cannot ride along inside it
spawned nmlive harness=sleep kind=ship mode=no-mistakes yolo=off window=firstmate:fm-nmlive worktree=/private/tmp/fm-nm-live.NEXO33/s3-nomistakes/pool-root/.treehouse/project-c4f425/1/project
exit=0
slot HEAD=bc6c15c  == origin/main? yes  == primary main? no

=== s3-directpr ===
primary main=5ba1b59  origin/main=6d9bac5  unpushed=9
$ bin/fm-spawn.sh prlive <project> --mode direct-PR --yolo off sleep 3600
note: pooled worktree '/private/tmp/fm-nm-live.NEXO33/s3-directpr/pool-root/.treehouse/project-b13f59/1/project': main in the primary checkout carries 9 commits origin/main does not, but mode=direct-PR opens a pull request against origin; starting from origin's tip so those unpushed commits cannot ride along inside it
spawned prlive harness=sleep kind=ship mode=direct-PR yolo=off window=firstmate:fm-prlive worktree=/private/tmp/fm-nm-live.NEXO33/s3-directpr/pool-root/.treehouse/project-b13f59/1/project
exit=0
slot HEAD=6d9bac5  == origin/main? yes  == primary main? no

################ s4 ################
=== s4 diverged / local-only: primary main has 3 unpushed landings, origin received 1 forge-only merge ===
$ bin/fm-spawn.sh div-local-only <project> --mode local-only --yolo off 'sleep 3600'
note: pooled worktree '/private/tmp/fm-nm-live.NEXO33/s4-diverged-local-only/pool-root/.treehouse/project-ac3d8a/1/project': main in the primary checkout and origin/main have diverged: that branch carries 3 commits origin lacks and lacks 1 commit origin has, so neither contains the other; starting from origin's tip, which carries nothing that branch has landed since they parted
spawned div-local-only harness=sleep kind=ship mode=local-only yolo=off window=firstmate:fm-div-local-only worktree=/private/tmp/fm-nm-live.NEXO33/s4-diverged-local-only/pool-root/.treehouse/project-ac3d8a/1/project
exit=0
slot HEAD=5117cd3  origin/main=5117cd3  primary main=5063e14  slot==origin? yes  has forge-only-1.txt: yes  has landed-1.txt: no

=== s4 diverged / scout: primary main has 3 unpushed landings, origin received 1 forge-only merge ===
$ bin/fm-spawn.sh div-scout <project> --scout 'sleep 3600'
note: pooled worktree '/private/tmp/fm-nm-live.NEXO33/s4-diverged-scout/pool-root/.treehouse/project-5f2fec/1/project': main in the primary checkout and origin/main have diverged: that branch carries 3 commits origin lacks and lacks 1 commit origin has, so neither contains the other; starting from origin's tip, which carries nothing that branch has landed since they parted
spawned div-scout harness=sleep kind=scout window=firstmate:fm-div-scout worktree=/private/tmp/fm-nm-live.NEXO33/s4-diverged-scout/pool-root/.treehouse/project-5f2fec/1/project
exit=0
slot HEAD=963438a  origin/main=963438a  primary main=1e742c1  slot==origin? yes  has forge-only-1.txt: yes  has landed-1.txt: no

=== s5 origin ahead: origin received 4 forge merges the primary checkout never pulled ===
primary main=ff9a3b9  (origin tip not yet fetched by the primary)
$ bin/fm-spawn.sh origin-ahead <project> --mode no-mistakes --yolo off 'sleep 3600'
spawned origin-ahead harness=sleep kind=ship mode=no-mistakes yolo=off window=firstmate:fm-origin-ahead worktree=/private/tmp/fm-nm-live.NEXO33/s5-origin-ahead/pool-root/.treehouse/project-e55428/1/project
exit=0
slot HEAD=cb8d10c  origin/main=cb8d10c  primary main=ff9a3b9  slot==origin? yes  has forge-only-1.txt: yes  has landed-1.txt: no

################ s6 ################
=== s6a local-only ship: 3 more fm-merge-local landings arrive after treehouse hands out the slot ===
$ bin/fm-spawn.sh late-local <project> --mode local-only --yolo off 'sleep 3600'
note: pooled worktree '/private/tmp/fm-nm-live.NEXO33/s6-late-local/pool-root/.treehouse/project-1bae02/1/project' was 3 commits behind main in the primary checkout; refreshed to e8234bb
spawned late-local harness=sleep kind=ship mode=local-only yolo=off window=firstmate:fm-late-local worktree=/private/tmp/fm-nm-live.NEXO33/s6-late-local/pool-root/.treehouse/project-1bae02/1/project
exit=0
[race] land of 3 commit(s) happened after treehouse handed out the slot
slot HEAD=e8234bb  primary main=e8234bb  origin/main=91b0f2a  has late-landing-3.txt: yes

=== s6b no-mistakes ship: origin receives 4 forge merges after treehouse hands out the slot ===
$ bin/fm-spawn.sh late-forge <project> --mode no-mistakes --yolo off 'sleep 3600'
note: pooled worktree '/private/tmp/fm-nm-live.NEXO33/s6-late-forge/pool-root/.treehouse/project-15b6ec/1/project' was 4 commits behind origin/main; refreshed to ed82784
spawned late-forge harness=sleep kind=ship mode=no-mistakes yolo=off window=firstmate:fm-late-forge worktree=/private/tmp/fm-nm-live.NEXO33/s6-late-forge/pool-root/.treehouse/project-15b6ec/1/project
exit=0
[race] push of 4 commit(s) happened after treehouse handed out the slot
slot HEAD=ed82784  origin/main=ed82784  has forge-after-4.txt: yes

################ s8 ################
=== s8 unclean slot: uncommitted work in the slot, primary 4 landings ahead, origin diverged by 1 forge-only merge ===
$ bin/fm-spawn.sh dirty-race <project> --mode local-only --yolo off 'sleep 3600'
error: pooled worktree '/private/tmp/fm-nm-live.NEXO33/s8-dirty-race/pool-root/.treehouse/project-d97ca9/1/project' is not clean; refusing to discard uncommitted work while refreshing its base
exit=1
[race] wrote uncommitted.txt into /tmp/fm-nm-live.NEXO33/s8-dirty-race/pool-root/.treehouse/project-d97ca9/1/project before the refresh; HEAD then=ea4fcdf
after refusal: slot HEAD=ea4fcdf  uncommitted.txt: work the captain has not committed  meta published: no

################ s9b ################
=== s9 relaunch: local-only ship on a project whose primary main is 6 landings ahead of a frozen origin ===
$ bin/fm-spawn.sh relaunch-live <project> --mode local-only --yolo off   (harness from config/crew-harness: codex; the pane's codex is a stand-in that sleeps)
spawned relaunch-live harness=codex kind=ship mode=local-only yolo=off window=firstmate:fm-relaunch-live worktree=/private/tmp/fm-nm-live.NEXO33/s9-relaunch/pool-root/.treehouse/project-2c736d/1/project
exit=0
spawn base: slot HEAD=e80a8e5 primary main=e80a8e5
task committed work on fm/relaunch-live (544c288); primary then landed 5 more (main=d1f04be); agent stopped (pane foreground: bash)
$ bin/fm-spawn.sh relaunch-live --relaunch
spawned relaunch-live harness=codex kind=ship mode=local-only yolo=off window=firstmate:fm-relaunch-live worktree=/private/tmp/fm-nm-live.NEXO33/s9-relaunch/pool-root/.treehouse/project-2c736d/1/project
exit=0
after relaunch: slot HEAD=544c288 on fm/relaunch-live; HEAD unchanged: yes; task-change.txt present: yes; primary's later after-5.txt pulled in: no; pane foreground: codex

################ s10 ################
=== s10 review of local-only task relaunch-live: branch = spawn base + 1 task commit; primary main has since landed 5 more; origin frozen 6 commits behind the spawn base ===
--- [base code] $ bin/fm-review-diff.sh relaunch-live --stat
diff base: origin/main
 landed-1.txt    | 1 +
 landed-2.txt    | 1 +
 landed-3.txt    | 1 +
 landed-4.txt    | 1 +
 landed-5.txt    | 1 +
 landed-6.txt    | 1 +
 task-change.txt | 1 +
 7 files changed, 7 insertions(+)
exit=0
--- [new code] $ bin/fm-review-diff.sh relaunch-live --stat
diff base: main
 task-change.txt | 1 +
 1 file changed, 1 insertion(+)
exit=0

################ s11 ################
=== s11a mandated rebase then another landing: relaunch-live rebases onto main (M1), then main lands 2 more (M2) before review ===
branch=887ab32 main=f168a04 origin/main=2322389
--- [base code] $ bin/fm-review-diff.sh relaunch-live --stat
diff base: origin/main
 after-1.txt     | 1 +
 after-2.txt     | 1 +
 after-3.txt     | 1 +
 after-4.txt     | 1 +
 after-5.txt     | 1 +
 landed-1.txt    | 1 +
 landed-2.txt    | 1 +
 landed-3.txt    | 1 +
 landed-4.txt    | 1 +
 landed-5.txt    | 1 +
 landed-6.txt    | 1 +
 task-change.txt | 1 +
 12 files changed, 12 insertions(+)
exit=0
--- [new code] $ bin/fm-review-diff.sh relaunch-live --stat
diff base: main
 task-change.txt | 1 +
 1 file changed, 1 insertion(+)
exit=0

=== s11b review of no-mistakes (PR) task nmlive: spawned on origin's tip; primary main carries 9 unpushed commits ===
--- [new code] $ bin/fm-review-diff.sh nmlive --stat
diff base: origin/main
 task-change.txt | 1 +
 1 file changed, 1 insertion(+)
exit=0

=== s11c review of diverged local-only task div-local-only: spawned on origin's tip (forge-only merge), primary main carries 3 diverged landings ===
--- [base code] $ bin/fm-review-diff.sh div-local-only --stat
diff base: origin/main
 task-change.txt | 1 +
 1 file changed, 1 insertion(+)
exit=0
--- [new code] $ bin/fm-review-diff.sh div-local-only --stat
diff base: origin/main
 task-change.txt | 1 +
 1 file changed, 1 insertion(+)
exit=0
spawn base = 5117cd3; review starts from merge-base(main, branch)=9e782d0 merge-base(origin/main, branch)=5117cd3

=== s11d review of scout scoutlive on a local-only project (primary 9 ahead of frozen origin) ===
--- [base code] $ bin/fm-review-diff.sh scoutlive --stat
diff base: origin/main
 landed-1.txt    | 1 +
 landed-2.txt    | 1 +
 landed-3.txt    | 1 +
 landed-4.txt    | 1 +
 landed-5.txt    | 1 +
 landed-6.txt    | 1 +
 landed-7.txt    | 1 +
 landed-8.txt    | 1 +
 landed-9.txt    | 1 +
 task-change.txt | 1 +
 10 files changed, 10 insertions(+)
exit=0
--- [new code] $ bin/fm-review-diff.sh scoutlive --stat
diff base: main
 task-change.txt | 1 +
 1 file changed, 1 insertion(+)
exit=0

################ s12 ################
=== s12 the task has already landed: primary main fast-forwarded onto fm/scoutlive (what fm-merge-local.sh does) ===
main=2ce1803 fm/scoutlive=2ce1803
--- [new code] $ bin/fm-review-diff.sh scoutlive --stat
note: main already contains fm/scoutlive, so there is nothing left to review against it
diff base: main
no changes vs main
exit=0

################ s13 ################
=== s13 [base code] local-only ship with GIT_TRACE on fm-spawn: which git fetches does resolving the base issue? (primary 7 ahead of frozen origin) ===
spawned trace-base harness=sleep kind=ship mode=local-only yolo=off window=firstmate:fm-trace-base worktree=/private/tmp/fm-nm-live.NEXO33/s13-trace-base/pool-root/.treehouse/project-451480/1/project
exit=0
git fetch / ls-remote / remote-network commands issued by fm-spawn:
   1 trace: run_command: unset GIT_DIR GIT_PREFIX; GIT_PROTOCOL=version=2 'git-upload-pack '\\''/tmp/fm-nm-live.NEXO33/s13-trace-base/origin.git'\\'''
   1 trace: run_command: git rev-list --objects --stdin --not --exclude-hidden=fetch --all --quiet --alternate-refs
   1 trace: run_command: unset GIT_DIR GIT_PREFIX; GIT_PROTOCOL=version=2 'git-upload-pack '\\''/tmp/fm-nm-live.NEXO33/s13-trace-base/origin.git'\\'''
   1 trace: run_command: unset GIT_DIR GIT_PREFIX; GIT_PROTOCOL=version=2 'git-upload-pack '\\''/tmp/fm-nm-live.NEXO33/s13-trace-base/origin.git'\\'''
   1 trace: run_command: git rev-list --objects --stdin --not --exclude-hidden=fetch --all --quiet --alternate-refs
   1 trace: built-in: git fetch --quiet origin
   1 trace: built-in: git fetch --quiet origin +refs/heads/main:refs/remotes/origin/main
slot HEAD=bd297e9  primary main=5d84479  origin/main=bd297e9

=== s13 [new code] local-only ship with GIT_TRACE on fm-spawn: which git fetches does resolving the base issue? (primary 7 ahead of frozen origin) ===
spawned trace-new harness=sleep kind=ship mode=local-only yolo=off window=firstmate:fm-trace-new worktree=/private/tmp/fm-nm-live.NEXO33/s13-trace-new/pool-root/.treehouse/project-ec35a9/1/project
exit=0
git fetch / ls-remote / remote-network commands issued by fm-spawn:
   1 trace: run_command: unset GIT_DIR GIT_PREFIX; GIT_PROTOCOL=version=2 'git-upload-pack '\\''/tmp/fm-nm-live.NEXO33/s13-trace-new/origin.git'\\'''
   1 trace: run_command: git rev-list --objects --stdin --not --exclude-hidden=fetch --all --quiet --alternate-refs
   1 trace: run_command: unset GIT_DIR GIT_PREFIX; GIT_PROTOCOL=version=2 'git-upload-pack '\\''/tmp/fm-nm-live.NEXO33/s13-trace-new/origin.git'\\'''
   1 trace: run_command: unset GIT_DIR GIT_PREFIX; GIT_PROTOCOL=version=2 'git-upload-pack '\\''/tmp/fm-nm-live.NEXO33/s13-trace-new/origin.git'\\'''
   1 trace: run_command: git rev-list --objects --stdin --not --exclude-hidden=fetch --all --quiet --alternate-refs
   1 trace: built-in: git fetch --quiet origin
   1 trace: built-in: git fetch --quiet origin +refs/heads/main:refs/remotes/origin/main
slot HEAD=bbc991a  primary main=bbc991a  origin/main=87e4efd
Evidence: Reproduction vs fix: local-only spawn with 12 unpushed landings
[base code] $ bin/fm-spawn.sh tregua-base <project> --mode local-only --yolo off
exit=0
slot HEAD=544331b commits behind primary main=12 has landed-12.txt: NO

[new code] $ bin/fm-spawn.sh tregua-new <project> --mode local-only --yolo off
exit=0
slot HEAD=b91dc58 commits behind primary main=0 has landed-12.txt: yes
Evidence: PR delivery keeps origin, diverged history falls back to origin, exact refresh count
note: pooled worktree '.../1/project': main in the primary checkout carries 9 commits origin/main does not, but mode=no-mistakes opens a pull request against origin; starting from origin's tip so those unpushed commits cannot ride along inside it
note: pooled worktree '.../1/project': main in the primary checkout and origin/main have diverged: that branch carries 3 commits origin lacks and lacks 1 commit origin has, so neither contains the other; starting from origin's tip, which carries nothing that branch has landed since they parted
note: pooled worktree '.../1/project' was 3 commits behind main in the primary checkout; refreshed to e8234bb
note: pooled worktree '.../1/project' was 4 commits behind origin/main; refreshed to ed82784
error: pooled worktree '.../1/project' is not clean; refusing to discard uncommitted work while refreshing its base (uncommitted.txt kept, HEAD unchanged)
Evidence: Review anchor after a rebase plus a further landing: base vs new code
[base code] $ bin/fm-review-diff.sh relaunch-live --stat
diff base: origin/main
... 11 landed files from other tasks ...
task-change.txt | 1 +
12 files changed, 12 insertions(+)

[new code] $ bin/fm-review-diff.sh relaunch-live --stat
diff base: main
task-change.txt | 1 +
1 file changed, 1 insertion(+)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 15 of 15 scenarios driven live against the product
Scenario Result Live Evidence
A local-only ship on a project whose primary main has 12 unpushed fm-merge-local landings starts from the primary's tip, not the frozen origin (the old code planted it 12 commits behind) ✅ pass live Transcript section s1: base code slot HEAD=544331b, 12 behind, landed-12.txt missing; new code slot HEAD=b91dc58 = primary main, landed-12.txt present
A scout on a local-only project starts from the primary's landed tip ✅ pass live Transcript section s2 (s2-scout): slot HEAD=1e09e03 = primary main, not origin/main
A no-mistakes or direct-PR ship keeps origin's tip and is told how many unpushed commits the primary carries ✅ pass live Transcript section s2 (s3-nomistakes, s3-directpr): slot == origin/main; note 'carries 9 commits origin/main does not, but mode=... opens a pull request against origin'
Diverged primary and origin (unpushed landings plus a forge-only merge) still launch a local-only ship and a scout from origin's tip, with a note counting both sides ✅ pass live Transcript section s4: exit=0 for both; slot == origin/main with forge-only-1.txt and without landed-1.txt; note 'have diverged: that branch carries 3 commits origin lacks and lacks 1 commit origin ha…
A PR ship whose origin is 4 forge merges ahead of a stale primary starts from origin's tip ✅ pass live Transcript section s4 (s5 origin ahead): slot HEAD=cb8d10c = origin/main, primary main=ff9a3b9
The refresh reports the exact number of commits the slot was behind when history moves after treehouse hands out the slot ✅ pass live Transcript section s6: 'was 3 commits behind main in the primary checkout; refreshed to e8234bb' (local-only); 'was 4 commits behind origin/main; refreshed to ed82784' (no-mistakes)
Adversarial: an unclean slot (diverged history, primary ahead) is refused without discarding the uncommitted work or moving its base, and is not reported as a divergence ✅ pass live Transcript section s8: exit=1 with 'is not clean; refusing to discard uncommitted work'; uncommitted.txt kept; HEAD unchanged; no meta published; no 'diverged' text
Relaunching a task after the primary lands 5 more commits keeps the task's branch, commit and work ✅ pass live Transcript section s9b: relaunch exit=0; HEAD 544c288 on fm/relaunch-live unchanged; task-change.txt present; after-5.txt not pulled in
Captain review of a local-only task shows only the task's own work, not the landed commits a frozen origin would attribute to it ✅ pass live Transcript section s10: base code 'diff base: origin/main' with 6 landed files plus task-change.txt; new code 'diff base: main' with task-change.txt only
Review after the mandated rebase onto main plus 2 further landings still shows only the task's change ✅ pass live Transcript section s11a: base code shows 12 files; new code 'diff base: main' with 1 file
Review of a pull-request delivery anchors on origin/main ✅ pass live Transcript section s11b: 'diff base: origin/main' with task-change.txt only
Review of a diverged local-only task starts from the same commit the spawn planted the slot on ✅ pass live Transcript section s11c: 'diff base: origin/main'; spawn base 5117cd3 = merge-base(origin/main, branch); only task-change.txt
Review of a scout on a local-only project shows only the scout's change ✅ pass live Transcript section s11d: base code shows 9 landed files plus task-change.txt; new code 'diff base: main' with 1 file
Review of a task already fast-forwarded into main comes back empty and says why (documented header behavior) ✅ pass live Transcript section s12: 'note: main already contains fm/scoutlive, so there is nothing left to review against it' / 'no changes vs main'
Resolving the base issues no extra fetch: the primary's commit is read from the local object store ✅ pass live Transcript section s13 (GIT_TRACE): new and base code issue the same two pre-existing 'git fetch --quiet origin' calls and nothing else
  • Real bin/fm-spawn.sh &lt;id&gt; &lt;project&gt; --mode local-only --yolo off &#39;sleep 3600&#39;: real tmux (tmux -L fmlive-nm) and real treehouse get; primary main 12 commits ahead of a frozen origin. Run once with the new code and once with the base-commit code from git archive b182d0f9
  • Real bin/fm-spawn.sh &lt;id&gt; &lt;project&gt; --scout &#39;sleep 3600&#39; on a local-only project, primary 9 commits ahead
  • Real bin/fm-spawn.sh &lt;id&gt; &lt;project&gt; --mode no-mistakes|direct-PR --yolo off &#39;sleep 3600&#39;, primary 9 commits ahead of origin
  • Real bin/fm-spawn.sh local-only and scout on diverged history (3 unpushed landings plus 1 forge-only push)
  • Real bin/fm-spawn.sh --mode no-mistakes with origin 4 forge merges ahead of a stale primary
  • Real bin/fm-spawn.sh, local-only and no-mistakes, with 3 landings / 4 pushes made after treehouse get entered the slot and before the refresh, to trigger the exact-count note
  • Real bin/fm-spawn.sh --mode local-only with uncommitted work written into the slot before the refresh, on diverged history with the primary ahead (adversarial)
  • Real bin/fm-spawn.sh &lt;id&gt; --relaunch after the task committed work and the primary landed 5 more commits (codex stand-in in the pane PATH)
  • Real bin/fm-review-diff.sh &lt;id&gt; --stat, new vs base code: local-only task after later landings; after a rebase onto main plus 2 more landings; scout on a local-only project; diverged local-only task; no-mistakes task; task already fast-forwarded into main
  • GIT_TRACE on real bin/fm-spawn.sh, new vs base code, listing every fetch issued while resolving the base
  • bash tests/fm-spawn-pool-base-freshen.test.sh (focused suite for this change, exit 0)
  • bash tests/fm-review-diff.test.sh (focused suite for this change, exit 0)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (2): Last reviewed commit: "no-mistakes(document): document fm-dod-l..." | Re-trigger Greptile

@mikeastwoody
mikeastwoody force-pushed the fm/fm-treehouse-base-obsoleta branch from 40111d3 to 680edd1 Compare September 5, 2026 23:03
…ary checkout

freshen_spawn_worktree_base reset every fresh pool slot to origin/<default>.
A local-only project lands work on the primary checkout's default branch
through fm-merge-local.sh and never pushes, so that ref is frozen at the
last push and every fresh task started hundreds of commits behind the work
already landed: measured between 400 and 854 commits on one project, and one
worker built and installed a stale app from that base before catching up.

The slot now starts from the base its delivery lands on. origin/<default>
stays the default; the primary checkout's <default> replaces it only when it
strictly contains origin's tip and the task lands locally (a local-only ship
or a scout). A no-mistakes or direct-PR ship keeps origin's tip, because its
pull request targets origin and unpushed local commits would ride along
inside it, and is told how many commits the primary carries that origin
lacks. Diverged candidates keep origin's tip and say so instead of refusing,
since the only remedy a refusal leaves is reconciling the primary checkout by
hand, which firstmate must not do. The refresh reports the exact number of
commits the slot was behind. Every chosen base contains origin's tip, so the
reset discards nothing the origin-only rule kept, and the uncommitted-work
refusal is unchanged and still precedes it. Relaunch still never touches the
base a task already has.

fm-dod-lib.sh gains fm_delivery_opens_pull_request as the single owner of
which delivery modes open a pull request, so the spawn does not restate the
mode list.
fm-review-diff.sh compared every remote-backed project against
origin/<default>. Once a local-only task is planted on the primary's default
branch, that anchor shows every locally landed commit as the task's own work
in the captain's review. Anchor on the branch the task delivers to instead,
with the same rule the spawn applies: origin/<default> for a pull-request
delivery (read from fm-dod-lib.sh's one owner), otherwise whichever of the
local <default> and origin/<default> meets the branch later, taking the
candidate whose merge base with the branch descends from the other's. That
follows a local-only branch through the rebase its definition of done
mandates, keeps a stale local default from dragging origin's newer history
into the review, and decides diverged default branches by where the task was
actually planted. A landed branch and two unrelated merge bases are reported
on stderr rather than passed silently.

The spawn suite now drives both scripts over one repository state per
delivery and requires the review's starting commit to be the slot's spawn
base.
@mikeastwoody
mikeastwoody force-pushed the fm/fm-treehouse-base-obsoleta branch from 680edd1 to b31a4fa Compare September 14, 2026 06:20
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

First look on HEAD b31a4fa36d1aad3125ebf24bf97d2cef97db877b. MERGEABLE/UNSTABLE. Fork CI + NM approved this pass after safe file-list review (no .github/workflows changes): CI 34813022472 (in_progress), Require no-mistakes 34813022515 FAIL. Attestation MISMATCH (body binds 40111d35992a7f066a8495516529b612d1f4ad0c; tip is two commits later: review-diff anchor + suite).

Contract-class: new-default. Always-on rewrite of freshen_spawn_worktree_base / resolve_spawn_worktree_base on every fresh ship/scout pool slot: unconfigured path no longer always resets to origin/<default>; local-only/scout may plant on the primary checkout's tip when it strictly contains origin. PR deliveries keep origin. That replaces the previously specified origin-only freshen rule (script header + tests previously asserted origin tip). Also always-on: promote guard + review-diff anchor via new fm_delivery_opens_pull_request. A VISION/incident motive does not turn replacing the specified default path into restore.

VISION.md per-rule

  • One captain, one interface: aligns — fewer surprise stale installs; captain sees fresher landed work.
  • Authority is explicit and never inferred: does not align (default) — changes unconfigured spawn base selection without an opt-in gate.
  • Scripts own the mechanics, agents own the judgment: aligns — deterministic ancestry / mode ownership in scripts + tests.
  • A restart is a non-event: aligns — base= recorded; relaunch still untouched (tests).
  • Delegation with a spine: aligns — delivery mode owns PR-vs-local base; refuse/withhold paths named.
  • The fleet outlives any vendor: neutral.
  • Scope: aligns — command-layer spawn/review mechanics, not workshop.

Security FYI: none material (git ancestry + reset of clean pooled slots; uncommitted-work gate unchanged). Pipeline review left open infos (promote missing-WT note, ff-lib weight, residual instruction wording) — tip hygiene, not a merge-gate while attestation/NM are red.

Merge-eligible N — attestation MISMATCH, NM FAIL, class new-default (no auto-merge). outcome=waiting-author. Firstmate-flag=no (not otherwise-ready). Please rebind the no-mistakes attestation to the tip SHA (and clear NM). Do not merge; do not rebase from here.

@mikeastwoody mikeastwoody changed the title fix(bin): base task worktrees on the newer of origin and the primary checkout fix(bin): start pooled worktrees from the newer of origin and the primary checkout Sep 14, 2026
@mikeastwoody

Copy link
Copy Markdown
Contributor Author

Thanks for the pass — the contract-class call is right, and useful.

I went and checked tests/fm-spawn-pool-base-freshen.test.sh at the base commit:
twelve assertions that a fresh pooled slot resets to origin/<default>. That is a
specified, covered rule and this change replaces it, so new-default is the honest
classification. Calling it a restore would have been wrong.

That makes the gate question yours rather than mine, and I would rather you set its
default than guess at it. The tradeoff, with what we measured: on a local-only
project, fresh slots started 400, 407, 418, and later 822, 826, 830, 848 and 854
commits behind, and one of those built and installed a stale app on a device. It
happened again today on an unrelated task — 102 commits, a month-old base. Off by
default, that stays live for anyone who never turns the gate on. On by default, it
is the same new default you flagged, just nameable and switchable. I am happy to
implement whichever you pick, including off-by-default with a follow-up migration.

Two status updates, since the tree moved right after your pass:

  • The body now binds b31a4fa36d1aad3125ebf24bf97d2cef97db877b, which is the tip —
    the pipeline's pr step republished it just after your read.
  • CI 34813022472 has since completed success.

And one small ask. The remaining red Require no-mistakes is run 34813022515,
which evaluated the old binding 40111d35. Three re-runs against the current body
are waiting in action_required — 34817990947, 34818029769, 34819067214 —
because fork PRs need a maintainer to approve the workflow run. Whenever one of you
has a moment to approve one, the check can evaluate the current attestation.

Not merging and not rebasing, as asked.

Housekeeping, so the body churn makes sense: I replaced the opening section, which
was a verbatim task brief, with a plain technical problem statement, and my first
attempt at that edit mangled the check-mark characters. Both are fixed, and the
attestation block stayed byte-identical through both edits.

@mikeastwoody

Copy link
Copy Markdown
Contributor Author

Superseded by #7352, which reworks this as an opt-in per the new-default triage above: a home creates config/spawn-base-primary-checkout to start fresh local-only ships and scouts from the primary checkout's default branch, while publishing modes stay anchored on origin/<default>. Closing in favor of it.

kunchenguid pushed a commit that referenced this pull request Oct 28, 2026
… work (#7352)

* feat(bin): add opt-in config/spawn-base-primary-checkout for local landings

A fresh pooled task worktree is reset to origin/<default>. A local-only
project lands work on the primary checkout's default branch through
fm-merge-local.sh and never pushes, so that ref stays frozen at the last
push and every fresh task starts behind work already landed, loading the
project's instruction files from the stale tree. The always-on fix proposed
in #3812 replaced the specified origin-only refresh for every home; this
rework keeps that rule as the default and moves the new base behind an
explicit, default-off presence flag, following the existing config/<flag>
pattern.

With config/spawn-base-primary-checkout present:
- fm-spawn.sh starts a fresh local-only ship, or a scout without
  --base-branch, from the primary checkout's <default> when it strictly
  contains origin's tip. Publishing modes and named base branches keep
  origin's tip, because that work is delivered against origin. A diverged
  primary keeps origin's tip and prints a note counting both sides. The
  commit is read from the local object store, so nothing extra is fetched,
  and the clean-slot refusal still runs first.
- fm-review-diff.sh anchors a remote-backed task without base_branch= on the
  branch it delivers to: publishing modes stay on origin/<default>, while a
  local-only ship or a scout is compared against whichever of the local
  <default> and origin/<default> meets the branch later, so the review shows
  the task's own work instead of every locally landed commit.
- fm-promote.sh tells a scout promoted to a publishing mode to return to
  origin's default branch, because in this home the scout may have started
  from the primary checkout's branch, whose unpushed commits would otherwise
  be published with the work.

fm-dod-lib.sh gains fm_mode_publishes as the one predicate those three
readers share. Without the flag every path is unchanged: the spawn resets
to origin's tip, the review anchors on origin/<default>, and promotion keeps
its wording; the existing tests run unmodified. Treehouse 3 (verified on
3.1.3) already hands a slot out at whichever of the local and remote default
branch is further ahead, so with the flag the refresh keeps that slot where
Treehouse put it for a local landing instead of rewinding it, and a project
without origin is untouched as before.

Supersedes #3812.

* no-mistakes(document): Drop change-relative wording from spawn-base config docs

* no-mistakes(ci): The Greptile Review check failed on two review findings, not on a broken build or test. I fixed both as the user directed, and the tests and lint pass. ci-1 (bin/fm-promote.sh): promotion must name origin's default branch only when spawn could actually have started the scout from the primary checkout. Spawn does that only when the project has an origin remote and is recorded on the task. Before this fix, the opt-in flag alone made promotion to no-mistakes or direct-PR say "copy of origin's default branch...", even on a project with no origin. - The new wording now also requires a recorded project (`[ -n "$PROMOTE_PROJECT" ]`) whose `git remote get-url origin` succeeds. That is the same check bin/fm-review-diff.sh already makes. The empty-project guard is needed because `git -C ""` would run in the current directory. Otherwise the existing "default-branch base" wording stays. - The three places that read the flag now agree: spawn, review-diff and promote. - I updated the header and inline comments in fm-promote.sh, and the promote line in docs/configuration.md, to say this applies only to a project with an origin remote. - Test: `test_promote_names_origin_for_a_publishing_mode_in_an_opted_in_home` in tests/fm-task-delivery.test.sh now records a real `project=` with a registry entry, and covers flag on/off × origin/none × direct-PR/no-mistakes/local-only. Only flag on + origin + a publishing mode gets the new wording. The named-base case is unchanged. - Before the fix, the test fails with "not ok - flag on, remote none, direct-PR: the promotion changed the default-branch wording". With the fix, it passes. ci-2 (tests/fm-spawn-pool-base-freshen.test.sh): with the flag set, both publishing modes must start from origin's tip and print no divergence note. - The opted-in spawn test now covers no-mistakes as well as direct-PR, local-only and scout. - The expectations no longer single out direct-PR. Both publishing modes now expect origin's tip, no "note: pooled worktree", and a review anchored at the slot's start, in the leading, diverged and trailing cases. Verification: - `bash tests/fm-task-delivery.test.sh`: exit 0. - `bash tests/fm-spawn-pool-base-freshen.test.sh`: exit 0. - `bin/fm-lint.sh` on the three changed shell files: exit 0 (ShellCheck 0.11.0, pinned, with extended analysis)
trillium added a commit to trillium/firstmate that referenced this pull request Nov 3, 2026