Skip to content

fix(bin): confirm a ship done's named head on origin when no tracking ref holds it - #20

Merged
max-metaplanet merged 3 commits into
mainfrom
fm/dod-fetch-refspec
Oct 2, 2026
Merged

max-metaplanet merged 3 commits into
mainfrom
fm/dod-fetch-refspec

Conversation

@max-metaplanet

Copy link
Copy Markdown
Owner

Intent

Stop the ship done named-head gate from pushing workers into editing a project clone's shared git configuration.

Observed twice in one day on one project: pooled worktrees share the primary clone's .git/config, and that clone's remote.origin.fetch is narrowed to the main branch only.
The named-head check in bin/fm-dod-lib.sh accepts a head only when a local remote-tracking ref such as origin/fm/<id> contains it, so a correctly pushed head reads as "unreachable outside the worker copy".
Workers cleared that refusal with git config --add remote.origin.fetch +refs/heads/fm/<id>:refs/remotes/origin/fm/<id>, which writes into the shared configuration.
Once that branch is deleted after merge, every later worktree creation from the clone fails with couldn't find remote ref refs/heads/fm/<id>, and no new worker can start.

Wanted behaviour: the named-head check confirms the head on the remote or forge directly, for example with git ls-remote origin or the forge API that fm_dod_recorded_pr_on_forge already partly uses, without needing a local tracking ref.
The refusal text tells workers never to change remote.origin.fetch, and names a one-off git fetch origin <branch>:refs/remotes/origin/<branch> if they need a ref.
A regression test covers the narrowed-refspec case.

What Changed

  • The ship done named-head gate in bin/fm-dod-lib.sh no longer needs a local remote-tracking ref. If neither the worker copy nor the project clone has a remote-tracking ref containing the head, the new fm_dod_named_head_on_origin makes one bounded, read-only git ls-remote origin call with GIT_TERMINAL_PROMPT=0. It accepts the head only when origin advertises a ref that points exactly at that SHA. If origin can't be read, the gate still refuses. local-only mode never reads the remote. As a result, a correctly pushed head now passes in a pooled worktree whose shared clone has remote.origin.fetch narrowed to the default branch.
  • The refusal text now tells the worker to push the commit and report again. It also says never to change remote.origin.fetch, and if a local ref is needed, to fetch it once with git fetch origin <branch>:refs/remotes/origin/<branch>.
  • New setting FM_DOD_ORIGIN_READ_SECONDS (default 5) bounds the origin read; it is documented in docs/configuration.md. tests/fm-dod-lib.test.sh adds regression tests for these cases:
    • a pushed head is accepted with a narrowed fetch refspec
    • an unpushed head is still refused
    • ref names containing shell syntax are not executed
    • an unreadable origin keeps the refusal
    • a stalled origin read is bounded
    • local-only mode does not read origin

🤖 Generated with Claude Code

Risk Assessment

✅ Low: The change adds a single read-only git ls-remote with a 5s bound, used only as a fallback after the local-ref checks fail and never for local-only. Any read failure keeps the refusal. Both round-1 fixes are confirmed in the code: the containment walk is gone and the bound is now 5s. The narrowed-refspec regression test runs the real gate end-to-end and checks that the shared clone's config and refs stay unchanged.

Testing

I ran the real fm-pr-check.sh CLI against throwaway git setups: a bare origin, a clone whose fetch refspec only covers main, and a pooled worktree. On the base commit a correctly pushed head was refused as "unreachable outside the worker copy", which reproduces the reported bug; on the change it was accepted and the PR was armed. In every case the shared clone's config and refs stayed byte-identical. After the branch was deleted on origin, a fresh fetch and worktree creation from the clone still worked. An unpushed head, an origin that can't be read and a stalled origin are all still refused, with the new guidance about remote.origin.fetch and the one-off fetch. The stalled read gave up in about 5s, inside the snapshot's 10s bound. Local-only mode still passes without contacting the remote. The targeted fm-dod-lib test file passes, and its new narrowed-refspec test fails against the base library. No Herdr lab was needed because the gate never touches panes.

  • Live validation: ✅ go - 6 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Worker pushes fm/<id> from a pooled worktree whose clone only fetches main, then registers the PR: the gate accepts (base refused it) ✅ pass live narrowed-refspec-pushed-before-after.txt: base exit 1 'unreachable outside the worker copy'; change exit 0 'armed: state/t1.check.sh', pr= recorded
The gate leaves the shared clone's .git/config and refs untouched whether it accepts or refuses ✅ pass live 'shared clone config+refs: UNCHANGED' in both artifact files for every case
After merge deletes the branch on origin, a new pooled worktree can still be created from the clone ✅ pass live narrowed-refspec-pushed-before-after.txt: 'new worktree created OK'
Adversarial: a HEAD origin never received is still refused, and the refusal says never change remote.origin.fetch and gives the one-off git fetch ✅ pass live refusal-and-boundary-cases.txt case=unpushed
Adversarial: an origin that can't be read, or that stalls, refuses rather than accepting, and the read gives up within the bound (~5s, under the 10s snapshot bound) ✅ pass live refusal-and-boundary-cases.txt case=unreadable (1s) and case=stalled (6s total CLI time)
Local-only mode keeps the project-heads rule and never contacts a stalled remote ✅ pass live refusal-and-boundary-cases.txt case=localonly: exit 0 in 2s while the origin ssh transport hangs
A regression test covers the narrowed-refspec case and fails against the old gate ⏸️ untested no The prior payload backed this only with a unit test run (tests/fm-dod-lib.test.sh), not a live drive of the product, so it did not establish a live result. The live CLI drives in the scenarios above c…
Evidence: Narrowed refspec: base refuses the pushed head, change accepts it, clone unchanged, later worktree creation works

Source: Narrowed refspec: base refuses the pushed head, change accepts it, clone unchanged, later worktree creation works

===== BASE (e73254a) case=pushed
--- layout: project remote.origin.fetch = +refs/heads/main:refs/remotes/origin/main
--- worktree tracking refs: refs/remotes/origin/HEAD refs/remotes/origin/main 
--- origin advertises: fm/t1=2bbab69 main=95785f8 
--- worker HEAD: 2bbab69
--- $ fm-pr-check.sh t1 https://github.com/o/r/pull/1   (exit 1, 2s)
    ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    ●  WATCHER DOWN - SUPERVISION IS OFF
    ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
    ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
    ●  This is a supervision warning only; the guarded operation WILL still run.
    ●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
    ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    error: named head 2bbab6993a9f878ec94f318b89c2994b18651637 is unreachable outside the worker copy
--- elapsed: 1s
--- shared clone config+refs: UNCHANGED
ROOT=/tmp/fmdod/run.vNzw

===== CHANGE (eaad160) case=pushed
--- layout: project remote.origin.fetch = +refs/heads/main:refs/remotes/origin/main
--- worktree tracking refs: refs/remotes/origin/HEAD refs/remotes/origin/main 
--- origin advertises: fm/t1=e537756 main=019171f 
--- worker HEAD: e537756
--- $ fm-pr-check.sh t1 https://github.com/o/r/pull/1   (exit 0, 3s)
    ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    ●  WATCHER DOWN - SUPERVISION IS OFF
    ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
    ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
    ●  This is a supervision warning only; the guarded operation WILL still run.
    ●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
    ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    fm-contributions: data directory unavailable
    armed: state/t1.check.sh
--- elapsed: 2s
--- shared clone config+refs: UNCHANGED
--- meta pr= recorded: pr=https://github.com/o/r/pull/1
--- simulate merge: delete fm/t1 on origin, then create a new pooled worktree from the clone
    new worktree created OK (fetch + worktree add succeeded)
ROOT=/tmp/fmdod/run.2ufn
Evidence: Refusal and boundary cases (unpushed, unreadable, stalled ~5s, local-only)

Source: Refusal and boundary cases (unpushed, unreadable, stalled ~5s, local-only)

===== CHANGE (eaad160) case=unpushed
--- layout: project remote.origin.fetch = +refs/heads/main:refs/remotes/origin/main
--- worktree tracking refs: refs/remotes/origin/HEAD refs/remotes/origin/main 
--- origin advertises: fm/t1=aab6c23 main=5332664 
--- worker HEAD: 99f83e4
--- $ fm-pr-check.sh t1 https://github.com/o/r/pull/1   (exit 1, 2s)
    error: named head 99f83e4d9be85a85d5173ff90092dabbd26a698b is unreachable outside the worker copy: no ref either copy holds carries it and origin does not advertise it, or origin could not be read - push that commit and report again; never change remote.origin.fetch, which rewrites the clone configuration every pooled worktree shares and breaks later worktree creation once the branch is deleted, and if you need a local ref fetch it once with `git fetch origin <branch>:refs/remotes/origin/<branch>`
--- elapsed: 1s
--- shared clone config+refs: UNCHANGED
ROOT=/tmp/fmdod/run.9QZK

===== CHANGE (eaad160) case=unreadable
--- layout: project remote.origin.fetch = +refs/heads/main:refs/remotes/origin/main
--- worktree tracking refs: refs/remotes/origin/HEAD refs/remotes/origin/main 
--- origin advertises: fm/t1=2818dcc main=86dbcbd 
--- worker HEAD: 2818dcc
--- $ fm-pr-check.sh t1 https://github.com/o/r/pull/1   (exit 1, 2s)
    error: named head 2818dcc1d9615fda5a53b4f8f81c4fc07fc654e7 is unreachable outside the worker copy: no ref either copy holds carries it and origin does not advertise it, or origin could not be read - push that commit and report again; never change remote.origin.fetch, which rewrites the clone configuration every pooled worktree shares and breaks later worktree creation once the branch is deleted, and if you need a local ref fetch it once with `git fetch origin <branch>:refs/remotes/origin/<branch>`
--- elapsed: 1s
--- shared clone config+refs: UNCHANGED
ROOT=/tmp/fmdod/run.Q5Gd

===== CHANGE (eaad160) case=stalled
--- layout: project remote.origin.fetch = +refs/heads/main:refs/remotes/origin/main
--- worktree tracking refs: refs/remotes/origin/HEAD refs/remotes/origin/main 
--- origin advertises: main=20ddb14 
--- worker HEAD: afb2af6
--- $ fm-pr-check.sh t1 https://github.com/o/r/pull/1   (exit 1, 7s)
    error: named head afb2af64ac598e0a01e1122297baaae62d705c7e is unreachable outside the worker copy: no ref either copy holds carries it and origin does not advertise it, or origin could not be read - push that commit and report again; never change remote.origin.fetch, which rewrites the clone configuration every pooled worktree shares and breaks later worktree creation once the branch is deleted, and if you need a local ref fetch it once with `git fetch origin <branch>:refs/remotes/origin/<branch>`
--- elapsed: 6s
--- shared clone config+refs: UNCHANGED
ROOT=/tmp/fmdod/run.rrva

===== CHANGE (eaad160) case=localonly
--- layout: project remote.origin.fetch = +refs/heads/main:refs/remotes/origin/main
--- worktree tracking refs: refs/remotes/origin/HEAD refs/remotes/origin/main 
--- origin advertises: main=e37544d 
--- worker HEAD: 30016ba
--- $ fm-pr-check.sh t1 https://github.com/o/r/pull/1   (exit 0, 2s)
    fm-contributions: data directory unavailable
    armed: state/t1.check.sh
--- elapsed: 2s
--- shared clone config+refs: UNCHANGED
--- meta pr= recorded: pr=https://github.com/o/r/pull/1
ROOT=/tmp/fmdod/run.nBSO
Evidence: fm-dod-lib targeted test run

Source: fm-dod-lib targeted test run

ok - standalone local-only done: requires the named head in the project clone
ok - non-done lines are not gated
ok - a direct-PR PR on the fork's parent repository is refused
ok - a direct-PR PR on the fork's own origin is accepted
ok - a plain clone's direct-PR PR is bound to its own origin
ok - a wrong-repository PR is refused before the recorded-PR path
ok - a direct-PR origin through an SSH alias accepts its own PR only
ok - the origin binding covers direct-PR forge origins only
ok - a pushed head is accepted through a narrowed remote.origin.fetch
ok - a head origin never received is still refused, with safe-ref guidance
ok - a hostile remote ref name is read as data, not run
ok - an origin that cannot be read keeps the refusal rather than accepting
ok - a stalled origin read is cut off by the gate's bound
ok - local-only keeps its project-heads rule and reads no remote
all fm-dod-lib tests passed
Evidence: New regression test fails against base library

Source: New regression test fails against base library

not ok - a head pushed to origin was refused because the clone's fetch refspec is narrowed

not ok - a head pushed to origin was refused because the clone's fetch refspec is narrowed

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 2 issues found → auto-fixed ✅
  • ⚠️ bin/fm-dod-lib.sh:112 - The new FM_DOD_ORIGIN_READ_SECONDS defaults to 10s. That equals FM_SNAPSHOT_CREW_STATE_TIMEOUT (10s), the bound bin/fm-fleet-snapshot.sh:326 puts around the whole fm-crew-state.sh call, and the gate makes this call on every heartbeat. Concrete sequence: a ship crew reports done: PR &lt;url&gt; checks green in a clone with a narrowed remote.origin.fetch, and origin is stalled (offline laptop, hung ssh). fm_dod_named_head_on_origin then uses the full 10s. Any prior work in crew-state, such as the bounded fm_dod_recorded_pr_on_forge read, pushes the total past 10s. The snapshot kills the child and shows the crew as state unknown instead of the old quick blocked: named head ... unreachable. Fix: lower the default (for example to 5s, matching crew-state's other forge fallback) so the gate's worst case fits inside its callers' bounds.
  • ⚠️ bin/fm-dod-lib.sh:718 - Unrequired component: the fallback containment walk (cat-file over every advertised tip, then rev-list $sha --not $held). The intent asks the gate to confirm the head on the remote directly. In the reported narrowed-refspec case the worker pushed fm/&lt;id&gt; at HEAD, so the exact-tip match at line 715 is enough. The walk only helps when HEAD sits behind an advertised tip this copy already holds. That extends the old tracking-ref containment rule to remote refs, which the intent does not require. A latent defect also lives inside it. $held goes in as command-line arguments, and on a large GitHub repo the advertised refs/pull/*/head tips of merged PRs are mostly held locally. That can mean tens of thousands of SHAs, which can exceed ARG_MAX, so rev-list fails and the gate refuses (it fails closed). The smallest honest remedy is to remove the walk and keep only the exact advertised-tip match. If the author wants to keep it, feed the revs through rev-list --stdin instead of argv.

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 6 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Worker pushes fm/<id> from a pooled worktree whose clone only fetches main, then registers the PR: the gate accepts (base refused it) ✅ pass live narrowed-refspec-pushed-before-after.txt: base exit 1 'unreachable outside the worker copy'; change exit 0 'armed: state/t1.check.sh', pr= recorded
The gate leaves the shared clone's .git/config and refs untouched whether it accepts or refuses ✅ pass live 'shared clone config+refs: UNCHANGED' in both artifact files for every case
After merge deletes the branch on origin, a new pooled worktree can still be created from the clone ✅ pass live narrowed-refspec-pushed-before-after.txt: 'new worktree created OK'
Adversarial: a HEAD origin never received is still refused, and the refusal says never change remote.origin.fetch and gives the one-off git fetch ✅ pass live refusal-and-boundary-cases.txt case=unpushed
Adversarial: an origin that can't be read, or that stalls, refuses rather than accepting, and the read gives up within the bound (~5s, under the 10s snapshot bound) ✅ pass live refusal-and-boundary-cases.txt case=unreadable (1s) and case=stalled (6s total CLI time)
Local-only mode keeps the project-heads rule and never contacts a stalled remote ✅ pass live refusal-and-boundary-cases.txt case=localonly: exit 0 in 2s while the origin ssh transport hangs
A regression test covers the narrowed-refspec case and fails against the old gate ⏸️ untested no The prior payload backed this only with a unit test run (tests/fm-dod-lib.test.sh), not a live drive of the product, so it did not establish a live result. The live CLI drives in the scenarios above c…
  • bin/fm-pr-check.sh t1 https://github.com/o/r/pull/1, driven live at base e73254a and at eaad160. Setup: a real bare origin, a project clone with remote.origin.fetch=+refs/heads/main:refs/remotes/origin/main, and a pooled worktree on fm/t1 that had been pushed.
  • Same live drive for an unpushed HEAD, an origin URL that can't be read, a stalled ssh origin (GIT_SSH_COMMAND that sleeps 120s) and local-only mode.
  • Before/after hash of the shared clone's .git/config plus all its refs, taken in every case.
  • After acceptance, deleted fm/t1 on origin, then ran git fetch and git worktree add from the clone.
  • bash tests/fm-dod-lib.test.sh (targeted, all passed)
  • Ran the new tests/fm-dod-lib.test.sh against the base e73254a library: the narrowed-refspec test fails there.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…cking ref

A pooled worktree shares its clone's .git/config. When that clone's
remote.origin.fetch is narrowed to the default branch, pushing a task
branch never creates origin/fm/<id>, so the named-head gate read a
correctly pushed head as existing only in the worker copy. Workers
cleared the refusal with `git config --add remote.origin.fetch ...`,
which outlives the task: once the branch is deleted after merge, every
later worktree creation fails with `couldn't find remote ref`.

The gate now asks the remote. fm_dod_named_head_on_origin makes one
bounded `git ls-remote origin` and accepts when a ref is advertised at
that commit, or when an advertised tip this copy already holds contains
it. It writes no configuration, fetches no objects and creates no ref.
A remote that cannot be read keeps the refusal rather than accepting,
and local-only keeps its project-heads rule with no remote read.

The refusal now names the shared-configuration hazard and the one-off
`git fetch origin <branch>:refs/remotes/origin/<branch>` instead of
leaving workers to find the refspec edit themselves.
@max-metaplanet
max-metaplanet merged commit 68c5c0c into main Oct 2, 2026
21 checks passed
max-metaplanet added a commit that referenced this pull request Oct 6, 2026
… ref holds it (#20)

* fix(bin): confirm a ship done's named head on origin, not a local tracking ref

A pooled worktree shares its clone's .git/config. When that clone's
remote.origin.fetch is narrowed to the default branch, pushing a task
branch never creates origin/fm/<id>, so the named-head gate read a
correctly pushed head as existing only in the worker copy. Workers
cleared the refusal with `git config --add remote.origin.fetch ...`,
which outlives the task: once the branch is deleted after merge, every
later worktree creation fails with `couldn't find remote ref`.

The gate now asks the remote. fm_dod_named_head_on_origin makes one
bounded `git ls-remote origin` and accepts when a ref is advertised at
that commit, or when an advertised tip this copy already holds contains
it. It writes no configuration, fetches no objects and creates no ref.
A remote that cannot be read keeps the refusal rather than accepting,
and local-only keeps its project-heads rule with no remote read.

The refusal now names the shared-configuration hazard and the one-off
`git fetch origin <branch>:refs/remotes/origin/<branch>` instead of
leaving workers to find the refspec edit themselves.

* no-mistakes(review): Drop origin containment walk and shorten origin read bound

* no-mistakes(document): Document FM_DOD_ORIGIN_READ_SECONDS origin-read bound
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.

1 participant