Repository navigation
fix(bin): refresh a remoteless pooled worktree onto its local default branch - #4394
matixacik-cell wants to merge 1 commit into
Conversation
… branch A local-only project has no remote, so fm-spawn's base refresh either failed its origin fetch (older homes) or skipped the refresh entirely and launched the pool slot from whatever commit it was last left at. Both left mode=local-only projects effectively undispatchable or stale. freshen_spawn_worktree_base now tells three shapes apart and names which one it hit in every refusal: - origin configured: unchanged fetch, set-head, and reset to origin/<default>; an unreachable or unusable origin still refuses. - no remote at all (`git remote` prints nothing): reset the clean pool slot to the local default branch (main, then master) with the same reset-then-verify guarantee; no resolvable default branch refuses. - remotes exist but none is origin: refuse rather than launching from a base the origin fetch never verified. The dirty-worktree refusal still runs first in every shape, so no uncommitted work is discarded on any path. Tests cover remoteless main and master refresh, a remoteless repository with no default branch, a non-origin remote, the dirty remoteless slot, and the unchanged unreachable-origin and healthy-origin paths. Claude-Session: https://claude.ai/code/session_017ZHa2WVWPpoHhbtbeaZaVD
|
Speaking as Kun's firstmate: First look on main What I inspected (diff vs main)
contract-class: restore — Attestation: MISSING (no Checks: first-time fork workflows approved this pass — CI VISION.md (each rule)
Security FYI (tip only, not waiting-captain): none material. Attestation missing is an author gate, not a captain security choice. Merge-eligible N. Waiting-author (attestation). Do not merge. No Firstmate flag. |
|
Closing: the project this fixed for us now has a remote, so we no longer need it. Feel free to pick the branch up if useful. |
Intent
Fix bin/fm-spawn.sh so a project with NO configured git remote can be dispatched. freshen_spawn_worktree_base() previously either failed its unconditional 'git fetch origin' (older homes) or, after #3885, skipped the refresh entirely for origin-less repos and launched the pool slot from whatever commit it was last left at. That made mode=local-only self-contradictory: local-only exists for projects with no remote, where the worker stops at a clean ready branch and firstmate lands it with bin/fm-merge-local.sh. Two registered projects (lead-finder, codeza-site-v2) were undispatchable. Required behaviour: (1) detect whether the repository has any configured remote at all using 'git -C remote' returning empty as the signal, not the name origin only; (2) with NO remote, skip the fetch/set-head/origin/ path entirely and refresh the pooled worktree against the LOCAL default branch resolved the same way default_branch() already falls back (main, then master), keeping every other guarantee: still refuse a dirty pooled worktree and never discard uncommitted work, still reset --hard to the resolved target so the slot starts clean, still verify HEAD equals the expected commit afterwards and refuse if not, and refuse with a clear message if no local default branch resolves; (3) a remote that IS configured but unreachable must behave exactly as before: still refuse with the existing 'could not fetch origin ... potentially stale base' message, never silently downgrading into launching from whatever is local; (4) error messages must say which case was hit so a reader can tell 'this repo has no remote' apart from 'your remote is unreachable'. Deliberate decision: a repository that has remotes but none named origin now refuses with a message naming those remotes, because the origin-based fetch cannot verify freshness against a remote it never contacts and the task forbids a silent downgrade to a local base; before this change that shape skipped the refresh and launched as-is. The origin path was extracted unchanged into freshen_spawn_worktree_base_from_origin and the new local path into freshen_spawn_worktree_base_from_local_default; the dirty-worktree refusal runs first on every path. The fm-spawn.sh header paragraph that owns the base-refresh rule was updated to describe the three shapes. Tests in tests/fm-spawn-pool-base-freshen.test.sh: the originless fixture now advances the local default branch past the pool base so the refresh is observable; new cases cover remoteless refresh onto main and onto master, a remoteless repository with no main or master refusing, a repository whose only remote is upstream refusing, and a dirty remoteless slot refusing without refresh or discard; the unreachable-origin and healthy-origin cases are unchanged; the two included-config boundary tests now assert the pool refreshed onto local main instead of asserting HEAD unchanged. Constraints: do NOT change bin/fm-merge-local.sh, bin/fm-backend.sh, or anything under projects/; scope is the freshen path in bin/fm-spawn.sh plus its colocated tests; follow firstmate-coding-guidelines (one sentence per line in prose, plain dash, no agent co-author on commits, shellcheck-clean via bin/fm-lint.sh, colocated tests). Pre-existing unrelated failures in tests/fm-secondmate-liveness.test.sh and tests/fm-muse-harness.test.sh reproduce identically on unchanged main in this environment and are out of scope.
What Changed
freshen_spawn_worktree_base()inbin/fm-spawn.shnow tells three repository shapes apart after the dirty-worktree refusal: an origin is fetched and reset to as before (extracted unchanged intofreshen_spawn_worktree_base_from_origin); a repository with no remote at all (git remoteprints nothing) skips the fetch and resets the pool slot to the local default branch (main, then master) via the newfreshen_spawn_worktree_base_from_local_default, verifying HEAD afterwards and refusing if no local default branch resolves; a repository whose remotes exist but include no origin now refuses with a message naming those remotes instead of launching as-is.bin/fm-spawn.shdocumenting the base-refresh rule was updated to describe all three shapes.tests/fm-spawn-pool-base-freshen.test.shadvances the originless fixture's local default branch past the pool base so the refresh is observable, and adds cases for remoteless refresh onto main and master, a remoteless repo with no main/master refusing, an upstream-only remote refusing, and a dirty remoteless slot refusing without refresh or discard; the two included-config boundary tests now assert the pool landed on local main. The pipeline Test stage ran this file in full on the target commit (22 cases pass) and confirmed it fails on the base commit.Risk Assessment
✅ Low: The change is confined to the freshen path and its colocated tests, satisfies every required behaviour in the intent (git remote emptiness as the signal, local main/master reset with dirty refusal first and HEAD verification, unchanged unreachable-origin refusal, distinguishable messages, non-origin remotes refusing by name), and the only findings are a vacuous test assertion and an optional dedup.
Testing
Ran the colocated freshen test suite on the target commit (all pass) and against the base commit (the new remoteless case fails there), then manually dispatched real fm-spawn.sh in --mode local-only across six repository shapes and captured a transcript showing the remoteless slot refreshes onto local main or master without fetching, while no-default, non-origin-remote, unreachable-origin, and dirty-slot cases each refuse with a message naming their case and leave HEAD and uncommitted work untouched. A broad 54-script changed-file sweep was started and stopped early with only passing results; the working tree is clean and temp checkouts were removed.
Evidence: Manual local-only dispatch transcript on target commit (six repository shapes)
== 1. No remote, default branch main, pool slot stale $ git -C pool remote -> '' pool HEAD before spawn -> da5e1ec6... local default tip -> 82906bf8... | spawned lf-main harness=codex kind=ship mode=local-only yolo=off ... exit=0 pool HEAD after spawn -> 82906bf8... pool FETCH_HEAD exists -> no pool has newer.txt -> yes == 3. No remote and no main or master | error: pooled worktree '.../pool' has no git remote and no local default branch (main or master); refusing to launch without a base to refresh from exit=1, HEAD unchanged, task record published -> no == 4. Remote named upstream, not origin | error: pooled worktree '.../pool' has remotes (upstream) but no origin to verify freshness against; refusing to launch from a potentially stale base exit=1, HEAD unchanged == 5. origin configured but unreachable | error: could not fetch origin for pooled worktree '.../pool'; refusing to launch from a potentially stale base exit=1, HEAD unchanged == 6. No remote, slot has uncommitted work | error: pooled worktree '.../pool' is not clean; refusing to discard uncommitted work while refreshing its base exit=1, HEAD unchanged, wip.txt still present -> do not lose meEvidence: Same manual scenarios on base commit b182d0f (remoteless slot launched stale, upstream-only launched as-is)
== 1. No remote, default branch main, pool slot stale pool HEAD before spawn -> a3c0134f... local default tip -> a9d6c32c... | spawned lf-main ... mode=local-only ... exit=0 pool HEAD after spawn -> a3c0134f... (still stale) pool has newer.txt -> no == 4. Remote named upstream, not origin | spawned lf-upstream ... mode=local-only ... exit=0 (launched without verifying freshness)Evidence: Colocated freshen test suite on target commit (FM_TEST_EVIDENCE=1)
Evidence: Colocated freshen test suite run against base commit (fails at the remoteless case)
Evidence: Manual scenario script used for the transcripts
/var/folders/sx/97t21t2d30xdp4yq61zj5mkm0000gn/T/no-mistakes-evidence/01M2EAW9WB4PB6NE8EQW15GJ01/changed-run.log) - Outcome:Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
tests/fm-spawn-pool-base-freshen.test.sh:263- The assertion[ ! -e "$POOL_DIR/.git/FETCH_HEAD" ]can never fail: the pool is a linked worktree, so$POOL_DIR/.gitis a gitdir pointer file and$POOL_DIR/.git/FETCH_HEADis not a real path. FETCH_HEAD for a linked worktree lives undergit -C "$POOL_DIR" rev-parse --git-path FETCH_HEAD. The behaviour is still covered by theassert_not_contains ... "could not fetch origin"check on the same case, so this only weakens the evidence rather than hiding a regression. Use--git-path FETCH_HEADif the fetch-free guarantee is meant to be asserted directly.bin/fm-spawn.sh:2686-freshen_spawn_worktree_base_from_local_defaultandfreshen_spawn_worktree_base_from_originrepeat the same reset-then-verify tail (rev-parse expected, reset --hard, rev-parse HEAD, compare, refuse). A small shared helper taking the target ref and a shape label for the messages would remove the duplication. The intent explicitly states the origin path was extracted unchanged, so this is a deliberate trade-off; noting it as a possible follow-up only.FM_TEST_EVIDENCE=1 bash tests/fm-spawn-pool-base-freshen.test.shon target 8318e4b (all 22 cases pass, including remoteless main/master refresh, no-default refusal, upstream-only refusal, dirty remoteless refusal, unreachable-origin and healthy-origin paths)Same test file run against agit archiveof base commit b182d0f: fails atnot ok - spawn left the remoteless pool on stale history instead of local mainManual end-to-end scriptmanual-local-only-dispatch.shdriving realbin/fm-spawn.sh <id> <project> --mode local-only --yolo offthrough the fixtures' fake terminal across six repository shapes: no remote + main, no remote + master, no remote + trunk only, upstream-only remote, unreachable origin, dirty remoteless slot; checked exit code, HEAD before/after, FETCH_HEAD absence, presence of the newer commit's file, task record publication, and preserved uncommitted fileSame manual script against the base commit for a before/after contrast (remoteless slot launched stale, upstream-only launched as-is)git diff --name-only b182d0f 8318e4bconfirms only bin/fm-spawn.sh and tests/fm-spawn-pool-base-freshen.test.sh changed;git log -1 --format=%Bshows no agent co-author trailerbin/fm-test-run.sh --changed --base b182d0fstarted (3 of 54 scripts completed, all passing) then stopped at the output deadline✅ **Document** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.