Skip to content

fix(spawn): support launches from remoteless projects - #2154

Closed
dchangchang wants to merge 2 commits into
kunchenguid:mainfrom
dchangchang:fm/fm-spawn-remoteless-origin
Closed

dchangchang wants to merge 2 commits into
kunchenguid:mainfrom
dchangchang:fm/fm-spawn-remoteless-origin

Conversation

@dchangchang

Copy link
Copy Markdown

Intent

Fix a spawn regression that blocks every crewmate and scout launch into a project with no origin remote. This is urgent: it currently blocks all work on two of the three registered projects, both gated by a hard 2026-08-22 deadline.

The defect: commit fc5f164 ("fix(spawn): refresh pooled worktrees from origin before launch") added freshen_spawn_worktree_base() to bin/fm-spawn.sh, called for every spawn that is not a relaunch and not a secondmate, so it covers ship and scout launches on every backend. Its first action is git -C "$worktree" fetch --quiet origin. A repository with no origin remote cannot satisfy that, so the spawn dies with "fatal: 'origin' does not appear to be a git repository" followed by "error: could not fetch origin for pooled worktree ''; refusing to launch from a potentially stale base". Reproducible with any remoteless repo: projects/tacos-draft-dashboard and projects/fantasy-football-draft both have zero remotes, while projects/smarttail has one and spawns fine.

The requested fix: the guard's premise is staleness relative to origin, and that premise is vacuous when there is no origin, so the refresh should be skipped for a remoteless repo. Every existing refusal for a repo that DOES have an origin it cannot reach must stay intact - that case is genuinely unsafe and is exactly what fc5f164 was written to prevent. The distinction is "no origin is configured" versus "origin is configured and the fetch failed", and only the first is safe to skip. The configured remote must be detected explicitly rather than inferred from the fetch failure, because a network error and a missing remote must not collapse into the same branch. Whether the skip is silent or prints a one-line notice was an explicitly delegated decision, to be made deliberately with the reason stated in the commit message. A pooled worktree of a remoteless repo still needs its base to be a clean, current default branch from the local repository, so the rest of the launch path must still leave it in the intended state and the cleanliness check must not be silently dropped along with the fetch.

Decisions made while implementing, which a reviewer reading only the diff would not know:

  • Detection reads the configured remote list (git remote, matched exactly against origin) BEFORE any fetch, so the branch is chosen from configuration and never from a failed fetch. A failure of git remote itself refuses rather than silently taking the remoteless path.
  • The remoteless path deliberately skips ONLY the origin-dependent steps (the two fetches and remote set-head). It still resolves the default branch through the existing shared default_branch helper, still refuses a worktree with uncommitted work, still resets to the default branch tip, and still verifies the resulting HEAD. Its reset target is the local refs/heads/<default> instead of origin/<default>, which is the local-repository equivalent of the same clean, current base - not a weakening of the guard into a no-op.
  • The skip WARNS on stderr rather than staying silent. This was the delegated call: the launch is safe, but the stronger remote-freshness guarantee did not apply to it, and a guard that quietly weakens itself is hard to notice later. One stderr line per affected spawn keeps that visible without touching the success path. The rationale is recorded in the commit message as required. The wording ("has no origin remote") is deliberately distinct from the unreachable-origin refusal wording, and a regression test asserts the unreachable case never emits it.
  • Deliberately NOT reverted: fc5f164 also added local origins to previously remoteless fixtures in tests/lib.sh, tests/fm-tangle-guard.test.sh, and tests/fm-gate-refuse.test.sh. Those now exercise the origin path on purpose and were left alone.

Repo rules that apply: this is firstmate's own shared tracked material, so the firstmate-coding-guidelines skill was loaded and followed - one sentence per line in prose, plain dash rather than the em dash character, shellcheck-clean bin/ scripts, colocated tests under tests/ extending the existing script rather than a new runner, the one-owner rule (the script header owns exact mechanics while docs/architecture.md owns the boundary statement), and never adding an agent name as a commit co-author.

Verification required and performed: a regression test was mandatory, not optional, covering both halves of the distinction - (1) a remoteless repo spawns instead of refusing, and (2) a repo with an origin that cannot be fetched still refuses with the existing message. tests/fm-spawn-pool-base-freshen.test.sh was extended with a remoteless fixture whose LOCAL default branch is advanced past the pool base, covering a ship launch, a scout launch, the disclosure line, and a dirty remoteless pool that must still be refused without discarding uncommitted work; the pre-existing unreachable-origin test additionally asserts the refusal never reports a missing remote. Each new assertion was proven able to go red by breaking the code on purpose (forcing the origin path unconditionally, removing the warning, inferring the skip from a failed fetch, dropping the clean-worktree check along with the fetch, and returning early without the local reset), and each break was reverted. bin/fm-lint.sh (shellcheck 0.11.0) and bin/fm-doc-audience-check.sh are clean, and the changed-file selection through bin/fm-test-run.sh exited 0.

Acceptance criteria: bin/fm-spawn.sh launches a ship or scout task into a remoteless project; every pre-existing refusal for a reachable-origin repo is preserved, including an origin that is configured but unfetchable; regression tests cover both cases and were each proven able to fail; shellcheck is clean on every script touched.

What Changed

  • Skip only origin-dependent freshness checks for projects without an origin remote, while refreshing from the local default branch and preserving clean-worktree and verification guards.
  • Preserve existing refusal behavior for configured but unreachable origins, with distinct warning and error messages.
  • Document the remoteless-project boundary and add regression coverage for ship, scout, dirty-worktree, and unreachable-origin cases.

Risk Assessment

✅ Low: The change explicitly distinguishes a missing origin from an unreachable configured origin, preserves the existing refusal and cleanliness checks, and keeps the local default-branch reset and verification on the remoteless path.

Testing

The focused regression test passed, covering remoteless ship/scout launches, local default refresh, warning disclosure, dirty-worktree refusal, and preserved unreachable-origin refusal. No source or test files were changed.

Evidence: Spawn regression evidence

Focused regression transcript shows successful ship/scout launches for remoteless repos, local-default HEAD alignment, dirty-pool preservation, and refusal for unreachable origin.

# observed spawn: spawned pool-current-base-r1 harness=codex kind=ship mode=no-mistakes yolo=off window=firstmate:fm-pool-current-base-r1 worktree=/var/folders/yz/tvv5c7_n0yqdw9bmvyyknvwc0000gn/T//fm-spawn-pool-base-freshen.2XueT5/current-base/pool
# observed base: HEAD=8fac3c00f1c90fec881ee558f00f292b9deff748 origin/main=8fac3c00f1c90fec881ee558f00f292b9deff748 advanced-main=must survive a newly spawned branch
ok - a stale pooled worktree refreshes to current origin/main before a crew branch is created
ok - a stale pooled worktree resolves and refreshes a non-main default branch
# observed direct-pr spawn: spawned pool-direct-pr-r3 harness=codex kind=ship mode=direct-PR yolo=off window=firstmate:fm-pool-direct-pr-r3 worktree=/var/folders/yz/tvv5c7_n0yqdw9bmvyyknvwc0000gn/T//fm-spawn-pool-base-freshen.2XueT5/direct-pr/pool
# observed scout spawn: spawned pool-scout-r3 harness=codex kind=scout window=firstmate:fm-pool-scout-r3 worktree=/var/folders/yz/tvv5c7_n0yqdw9bmvyyknvwc0000gn/T//fm-spawn-pool-base-freshen.2XueT5/scout/pool
ok - direct-PR ships and scouts both refresh stale pooled worktrees before launch
# observed dirty refusal: error: pooled worktree '/var/folders/yz/tvv5c7_n0yqdw9bmvyyknvwc0000gn/T//fm-spawn-pool-base-freshen.2XueT5/dirty-refusal/pool' is not clean; refusing to discard uncommitted work while refreshing its base; preserved=keep this local work
ok - a dirty pooled worktree is refused without discarding its local work
# observed unresolved-default refusal: error: could not resolve origin's current default branch for pooled worktree '/var/folders/yz/tvv5c7_n0yqdw9bmvyyknvwc0000gn/T//fm-spawn-pool-base-freshen.2XueT5/unresolved-default/pool'; refusing to launch from a potentially stale base
ok - an unresolved remote default branch refuses the pooled worktree
# observed unreachable-origin refusal: error: could not fetch origin for pooled worktree '/var/folders/yz/tvv5c7_n0yqdw9bmvyyknvwc0000gn/T//fm-spawn-pool-base-freshen.2XueT5/unreachable-origin/pool'; refusing to launch from a potentially stale base
ok - an unreachable origin refuses a potentially stale pooled worktree
# observed remoteless spawn: spawned pool-remoteless-scout-r6 harness=codex kind=scout window=firstmate:fm-pool-remoteless-scout-r6 worktree=/var/folders/yz/tvv5c7_n0yqdw9bmvyyknvwc0000gn/T//fm-spawn-pool-base-freshen.2XueT5/remoteless/pool
# observed remoteless base: HEAD=2fddf81df8d2ef5dd5c7e73b1d25bdb9e884b686 local-main=2fddf81df8d2ef5dd5c7e73b1d25bdb9e884b686
ok - a project with no origin remote launches ships and scouts from its local default branch
ok - a remoteless project still refuses a dirty pooled worktree without discarding its work
# all fm-spawn-pool-base-freshen tests passed

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.

  • FM_TEST_EVIDENCE=1 bash tests/fm-spawn-pool-base-freshen.test.sh using a temporary process-identity fixture
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Daniel Chang added 2 commits August 10, 2026 22:01
fc5f164 made every fresh ship and scout refresh its pooled worktree from
origin before launch. Its first action is `git fetch origin`, which a
repository with no origin remote can never satisfy, so the guard refused
every spawn into a remoteless project rather than only stale ones.

The guard's premise is staleness relative to origin, and that premise is
vacuous with no origin configured. freshen_spawn_worktree_base now reads
the configured remote list first and takes the origin path only when a
remote named origin exists. A configured origin that cannot be fetched
still refuses exactly as before: the branch is decided from configuration,
never from a failed fetch, so a network error and a missing remote cannot
collapse into the same case.

The remoteless path skips only the origin-dependent steps. It still
resolves the default branch, still refuses a worktree with uncommitted
work, still resets to that branch's tip, and still verifies the result, so
a remoteless launch gets the same clean, current base from the local
repository.

The skip warns rather than staying silent. The launch is safe, but the
stronger remote-freshness guarantee did not apply to it, and a guard that
quietly weakens itself is exactly the kind of change that is hard to notice
later - one line on stderr per affected spawn keeps that visible without
touching the success path.

Regression coverage extends tests/fm-spawn-pool-base-freshen.test.sh with
a remoteless fixture whose local default branch is advanced past the pool
base, covering a ship launch, a scout launch, the disclosure line, and a
dirty remoteless pool that must still be refused without discarding work.
The unreachable-origin test now also asserts that refusal never reports a
missing remote.

Each new assertion was proven able to fail by breaking the code on
purpose: forcing the origin path unconditionally, removing the warning,
inferring the skip from a failed fetch, dropping the clean-worktree check
along with the fetch, and returning early without the local reset. Each
break reddened the intended assertion and was reverted.

@jkartiwa jkartiwa left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independently reached the same diagnosis today and arrived at the same required fix shape before finding this PR, so this is a confirming second pair of eyes rather than a first read.

The self-contradiction is worth stating plainly for anyone triaging priority: firstmate's own project-management skill instructs a remoteless project into existence ("create a local Git repository under its unused projects/<name> path, add the registry entry, and make no GitHub call", and it may not add a remote without the captain's word), and since fc5f164 the spawn path then refuses to launch a worker into exactly that project. One documented path produces what another rejects. Every neighbouring code path already handles the same situation benignly and by name - fm-fleet-sync.sh and fm-ff-lib.sh both emit "skipped: no origin remote", and fm-teardown.sh:27 calls it "the common case where there is no remote at all". This guard was the only one that did not.

Two properties of this implementation are the ones that matter, and both are easy to lose in a shorter diff:

  1. The skip is decided from the configured remote list, before any fetch. A missing remote and an unreachable remote must not collapse into one branch, because only the first is safe to skip. Inferring the skip from a failed fetch would silently convert the exact stale-base risk fc5f164 was written to prevent into a no-op, and it would do so precisely when the network is unreliable. Reading git remote up front is the correct discriminator, and refusing when git remote itself fails is the right call on the residual case.

  2. The remoteless path keeps the reset, the clean-worktree refusal, and the HEAD verification. This is the part most at risk of being dropped. Because these worktrees are pooled and reused, the hard reset is not merely a freshness step - it is what prevents a previous task's state from leaking into the next one, and the cleanliness check is what stops uncommitted work being discarded. An implementation that returns early on a missing remote would skip all three and trade a launch failure for a silent isolation regression, which is the worse defect of the two. Retargeting the reset at local refs/heads/<default> keeps the guarantee intact rather than weakening it.

The delegated call to warn on stderr rather than skip silently also looks right: the launch is safe, but a weaker guarantee applied, and a guard that quietly narrows itself is hard to notice later. Keeping that wording distinct from the unreachable-origin refusal, and asserting in a test that the unreachable case never emits it, is a good touch.

Test coverage looks sufficient to me on the axis that matters - both halves of the missing/unreachable distinction, plus the dirty remoteless pool - and proving each new assertion can go red before trusting it is the right standard for a guard whose failure mode is silence.

One observation rather than a change request: the urgency framing here is real but understates the reach slightly. A fleet whose remoteless project happens to be cloned from a local path will not see this bug at all, because the clone manufactures an origin the original never had. That masks the regression for some operators while blocking others entirely, which is worth knowing when judging how widely it has actually bitten.

No changes requested. This is the shape the fix should take.

@dchangchang dchangchang reopened this Aug 21, 2026

@kunchenguid kunchenguid left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Speaking as Kun's firstmate:

VISION verdict: align. Remoteless local projects are already a supported shape; spawn was the one path that still demanded origin.

Class: corrective. Design: detect missing origin from git remote before any fetch; skip only origin-dependent steps; still require a clean worktree; reset to local refs/heads/<default>; warn on stderr. That is reset-to-local-default, not skip-freshen.

Open overlap, so do not merge:

  • #2486 still OPEN: skip-freshen. Early return after the clean check, no local reset, notice that the base was not freshened.
  • #2693 still OPEN: reset-to-local-default plus a HEAD-symref fallback when neither main nor master exists.

This PR is closer to #2693 than to #2486. Pick one remoteless spawn design; do not land two.

CI was fully green including no-mistakes on 2026-08-11. New first-time-fork pending runs exist on the same SHA; approving those. Not merge-eligible while overlapping PRs stay open. Not a captain-flag.

This was referenced Aug 21, 2026
@devin-ai-integration

Copy link
Copy Markdown

Closed as superseded — this work already landed on main via #2486.

— Kun's Firstmate

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.

3 participants