Skip to content

feat(bin): support named base branches for pooled spawns - #2622

Closed
lakshyads05 wants to merge 13 commits into
kunchenguid:mainfrom
lakshyads:fm/fm-spawn-project-worktree-convention-v2
Closed

lakshyads05 wants to merge 13 commits into
kunchenguid:mainfrom
lakshyads:fm/fm-spawn-project-worktree-convention-v2

Conversation

@lakshyads05

@lakshyads05 lakshyads05 commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Give firstmate an additive --base-branch on fm-spawn.sh for existing pooled treehouse worktrees: freshen/reset to that named branch tip (origin/ if present, else the local branch; refuse if missing; no silent fallback to the remote default; refuse an unverifiable ref-specific fetch instead of treating it as remote absence). Record base_branch= in task meta only when the flag is set. --relaunch, --secondmate, and backend=orca refuse the flag. Do not change fm-teardown.sh, fm-control.sh, or validate_spawn_worktree. Do not add wtnew worktree provisioning, teardown, or process-reap behavior; that earlier design was cancelled and must not return.

For the eventual PR, do not change no-mistakes itself and do not use --skip pr. A no-mistakes ship must run the pipeline completely normally: push, PR against the repo default branch, CI monitored to green. After that first green, retarget the PR with raw gh pr edit <number> --base <branch> (installed gh-axi pr edit has no --base; keep gh-axi for every other GitHub operation), then wait and confirm CI is green again against the real target; do not trust the pre-retarget green. A direct-PR ship opens with gh-axi pr create --base . Document this exact sequence in fm-spawn.sh's header. Scaffold the matching worker-facing steps from fm-brief.sh --base-branch. When the flag is omitted, freshen, generated meta, and generated briefs stay identical to today.

Also accepted on the same change: optional --branch-name on fm-brief.sh so ship and scout scaffolds use that name everywhere the scaffold currently hardcodes fm/. Validate with git check-ref-format --branch. When omitted, generated briefs stay identical to today. Note other scripts that still reconstruct fm/. Shell-quote generated executable branch snippets.

This run's delivery job is to push the already-validated head through the gate to the recorded fork (https://github.com/lakshyads/firstmate.git) and let the PR step write a genuine no-mistakes ## Pipeline section (the marker "Updates from git push no-mistakes"). Update existing PR #2622 if that works, or open a fresh cross-repo PR from the fork; either is fine. Do not hand-stamp the signature. Do not merge.

Tests must exercise real executables and public behavior; never assert implementation source text.

What Changed

  • Added verified --base-branch freshening for pooled ship and scout worktrees, with metadata recording and refusal paths for unsupported or unverifiable cases.
  • Extended worker briefs with base-branch delivery steps and validated, shell-quoted custom --branch-name scaffolding.
  • Updated architecture documentation and executable regression coverage for the new spawn and brief behavior.

Risk Assessment

✅ Low: The requested behavior is implemented within the affected spawn and brief paths, with omitted-flag compatibility and relevant failure paths covered by reviewed executable tests.

Testing

Exercised real spawn and brief executables with isolated Git remotes and pooled worktrees: named-origin and local base selection, stale refresh, missing/unverifiable ref refusals, dirty-worktree preservation, incompatible mode refusals, metadata/brief contracts, quoted custom branches, and omitted-flag compatibility. The generated brief artifact shows the user-facing retarget-after-green sequence and custom branch command; all focused tests passed.

Evidence: Pooled-worktree base-branch E2E transcript

Source: Pooled-worktree base-branch E2E transcript

# 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/9_/lqnhn5_j6vz053wzxq2mk9rm0000gn/T//fm-spawn-pool-base-freshen.VkwbnK/current-base/pool
# observed base: HEAD=833579bd7be737afd98f9864bac22365f8c1ef4a origin/main=833579bd7be737afd98f9864bac22365f8c1ef4a 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/9_/lqnhn5_j6vz053wzxq2mk9rm0000gn/T//fm-spawn-pool-base-freshen.VkwbnK/direct-pr/pool
# observed scout spawn: spawned pool-scout-r3 harness=codex kind=scout window=firstmate:fm-pool-scout-r3 worktree=/var/folders/9_/lqnhn5_j6vz053wzxq2mk9rm0000gn/T//fm-spawn-pool-base-freshen.VkwbnK/scout/pool
ok - direct-PR ships and scouts both refresh stale pooled worktrees before launch
# observed dirty refusal: error: pooled worktree '/var/folders/9_/lqnhn5_j6vz053wzxq2mk9rm0000gn/T//fm-spawn-pool-base-freshen.VkwbnK/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/9_/lqnhn5_j6vz053wzxq2mk9rm0000gn/T//fm-spawn-pool-base-freshen.VkwbnK/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/9_/lqnhn5_j6vz053wzxq2mk9rm0000gn/T//fm-spawn-pool-base-freshen.VkwbnK/unreachable-origin/pool'; refusing to launch from a potentially stale base
ok - an unreachable origin refuses a potentially stale pooled worktree
ok - spawn --base-branch resets the pooled worktree to the named origin tip
ok - omitting --base-branch keeps default-branch freshen and does not record a PR target
ok - spawn --base-branch uses a local branch when origin lacks it
ok - a failed remote base fetch refuses instead of falling back to local
ok - a nonexistent --base-branch refuses without falling back to the default
ok - --relaunch, --secondmate, and backend=orca refuse --base-branch
ok - ship and scout base contracts refuse conflicting spawn flags
# all fm-spawn-pool-base-freshen tests passed
Evidence: Generated worker brief with base and branch contracts

Source: Generated worker brief with base and branch contracts

You are a crewmate: an autonomous worker agent managed by firstmate. Work on your own; do not wait for a human.

# Task
{TASK}

# Herdr lifecycle declaration - NOT ENABLED
**HARD SAFETY GATE:** this scaffold cannot inspect the task text that replaces `{TASK}` later.
If the task will start, stop, delete, restart, profile, or otherwise drive Herdr lifecycle behavior, stop and regenerate the brief with `--herdr-lab` before dispatch.
Do not add Herdr lifecycle commands to this unguarded brief by hand.

# Setup
You are in a disposable git worktree of firstmate, at a detached HEAD on `release/2026-q3`.

**Verify isolation before anything else.** Run `pwd -P` and `git rev-parse --show-toplevel`; both must resolve to the disposable task worktree you were launched in, such as a treehouse pool path or an Orca-managed worktree, not the primary checkout firstmate operates from.
The path check is authoritative: `git rev-parse --git-dir` and `git rev-parse --git-common-dir` can help inspect the repo, but they do not prove you are outside the primary checkout.
If the top-level path is the primary checkout or not the worktree you were launched in, STOP - do not branch or commit here - append `blocked: launched in primary checkout, not an isolated worktree` to the status file and stop.

1. First action: create your branch: `git checkout -b 'feature/worker-base-branch'`
2. Run `no-mistakes doctor`; if it reports the repo is not initialized here, run `no-mistakes init`.

# Rules
1. Never push to the default branch. Never merge a PR.
2. Stay inside this worktree; modify nothing outside it.
3. Use gh-axi for GitHub operations and chrome-devtools-axi for browser operations.
4. Report status by appending one line:
   `echo "{state}: {one short line}" >> '/var/folders/9_/lqnhn5_j6vz053wzxq2mk9rm0000gn/T/no-mistakes-evidence/01M0FEQVEPCJW32MTX8B1QR4S3/generated-brief-home/state/e2e-base-branch-demo.status'`
   States: working, needs-decision, blocked, paused, done, failed.
   Each append wakes firstmate, so report sparingly: only phase changes a supervisor
   would act on (setup done, bug reproduced, fix implemented, validation passed) and the
   needs-decision/blocked/paused/done/failed states. No step-by-step FYI progress lines;
   firstmate reads your pane for that.
   A mid-task `working:` line (including setup complete) is nonterminal: do not end the
   turn after it; continue the same stage until a defined `done:` gate under Definition of done.
   Use `paused: {why}` - distinct from `blocked:` - ONLY when you are deliberately idling on a
   known external wait you expect to clear on its own (an upstream release, a rate-limit reset,
   a scheduled window): firstmate then leaves your idle pane alone and rechecks it on a long
   cadence instead of treating it as a possible wedge. Use `blocked:` when you are stuck and need help.
5. If you hit the same obstacle twice, append `blocked: {why}` and stop; firstmate will help.
6. If a decision belongs above the implementation worker (product choices, destructive actions, ask-user findings),
   append `needs-decision: {summary of options}` and stop. Firstmate will apply the configured authority and reply with the decision.
   A decision or blocker you opened stays open until a `resolved` line carrying its exact key lands; a later `done:` or `working:` line never closes it, even when the answer is what started that work.
   Firstmate's reply normally writes that closing line at answer time; when a blocker or wait clears WITHOUT a firstmate reply, append `resolved: {how it cleared}` yourself (same `[key=<slug>]` if you opened it with one) as you resume.
7. Never stop, restart, or update the shared `no-mistakes` daemon - it is one instance serving
   every lane/home, so restarting it kills other lanes' in-flight pipeline runs. On ANY no-mistakes
   daemon error, append `blocked: {the daemon error}` and stop; only firstmate manages the daemon.

# Project memory
If `AGENTS.md` or `CLAUDE.md` already exists, or if this task produced durable project-intrinsic knowledge, run `/Users/lakshyadevsingh/.no-mistakes/worktrees/3980b3023422/01M0FEQVEPCJW32MTX8B1QR4S3/bin/fm-ensure-agents-md.sh .` in the worktree.
Record only project knowledge useful to almost every future session.
For anything the codebase already shows, prefer a pointer to the authoritative file, command, or doc over copying the detail.
If you touch a project `AGENTS.md` that lacks `## Maintaining this file`, add that short self-governance section from `/Users/lakshyadevsingh/.no-mistakes/worktrees/3980b3023422/01M0FEQVEPCJW32MTX8B1QR4S3/bin/fm-ensure-agents-md.sh` in the same pass.
Keep it proportionate: skip `AGENTS.md` edits for trivial tasks that produced no durable project knowledge.

# Definition of done
Delivery contract: mode=no-mistakes
The task is complete only when committed on your branch.
When you believe it is complete, append `done: {summary}` to the status file and stop.
Firstmate will then instruct you to run /no-mistakes to validate and ship a PR.

You drive no-mistakes by responding to its gates, not by implementing fixes.
Follow the guidance no-mistakes itself provides for the mechanics: it loads when you invoke /no-mistakes, and `no-mistakes axi run --help` plus the `help` lines in each `axi` response are authoritative and version-matched to the installed binary.
When starting no-mistakes, make `--intent` preserve all relevant content from this brief's `# Task` section plus every later accepted Firstmate requirement, clarification, constraint, exclusion, and supersession, carrying only each requirement's current accepted form; retain direct requirements instead of substituting a diff summary, and exclude generic operational, status, delivery, and other scaffold boilerplate unless it is task-specific.
Do not hand-edit, commit, or fix findings yourself while a run is active - the pipeline applies every fix.

Two firstmate-specific rules layer on top of that guidance:
- ask-user findings are never yours to answer: escalate to firstmate (rule 6) and stop.
  Firstmate applies the authority contract in its `AGENTS.md` and obtains any required captain decision.
  When the decision comes back, feed it to the gate with `no-mistakes axi respond` and let the pipeline apply it - do not route the question to "the user" or implement the fix yourself.
- Avoid `--yes`: it would silently bypass firstmate's authority check and any required captain escalation.

Run /no-mistakes completely normally: push, PR against the repo default branch, CI to green. Do not pass --skip pr and do not change no-mistakes PR-target settings.
After /no-mistakes reports CI green (the CI-ready return point - do not wait for it to keep monitoring in the background until merge), do not report done yet.
Retarget the open PR with `gh pr edit <number> --base 'release/2026-q3'` (the recorded base_branch value; bin/fm-spawn.sh owns this sequence).
Then poll `gh-axi pr checks <number>` until checks are green against that base (zero pending, zero failed). Do not trust the pre-retarget green, and do not treat "0 checks configured" as green unless that is this repo's trusted no-CI case.
Only then append `done: PR {url} checks green` and stop. You are finished.
Base branch contract: base_branch=release/2026-q3
Crew branch: branch=feature/worker-base-branch

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • ⚠️ bin/fm-spawn.sh:1699 - The new brief/spawn base agreement is enforced only for ship tasks. A scout brief scaffolded with --base-branch develop can be spawned with --scout --base-branch release; spawn resets the worktree to release while the worker-facing Setup still states develop. Emit the same machine-readable base contract for scouts and validate it before freshening, so the stated and actual analysis base cannot diverge.

🔧 Fix: Enforce named-base contracts for scout spawns
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • git diff --check 1cb900c28faf23fe23c9bb54e63f7c3b436ea096 d798af1b00fe9e138f07bf0f0012809ef263de5d
  • FM_TEST_EVIDENCE=1 bash tests/fm-spawn-pool-base-freshen.test.sh
  • bash tests/fm-brief.test.sh
  • FM_HOME=<evidence home> bin/fm-brief.sh e2e-base-branch-demo firstmate --mode no-mistakes --base-branch release/2026-q3 --branch-name feature/worker-base-branch
✅ **Document** - passed

✅ No issues found.

⚠️ **Lint** - 1 warning
  • ⚠️ linter found issues (exit code 127)
✅ **Push** - passed

✅ No issues found.

@lakshyads05

Copy link
Copy Markdown
Contributor Author

@kunchenguid This PR has been raised via the no-mistake pipeline. Still I see the check failing above

@lakshyads05
lakshyads05 force-pushed the fm/fm-spawn-project-worktree-convention-v2 branch from 2f81418 to d798af1 Compare August 20, 2026 11:37
@lakshyads05 lakshyads05 changed the title feat(spawn): add --base-branch for pooled freshen feat(bin): support named base branches for pooled spawns Aug 20, 2026
@lakshyads05

Copy link
Copy Markdown
Contributor Author

@kunchenguid please approve the workflows

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: Named bases are opt-in (--base-branch / --branch-name); omitting them keeps today's default-branch freshen, meta, and briefs. I reviewed the full diff (spawn freshen, brief contracts, refusal paths, colocated tests) with no security risk and approved fork CI. Waiting on green checks including no-mistakes. Open overlap on freshen_spawn_worktree_base with #2693, #2154, and #2486; head is also 4 commits behind main (including bin/fm-brief.sh). Not merge-eligible until CI is green and those overlaps close.

@greptile-apps

greptile-apps Bot commented Aug 22, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (17): Last reviewed commit: "fix(bin): bound relaunch after brief sen..." | Re-trigger Greptile

Comment thread bin/fm-brief.sh Resolved
@lakshyads05
lakshyads05 force-pushed the fm/fm-spawn-project-worktree-convention-v2 branch from 88615af to 456a15a Compare August 31, 2026 06:55
@lakshyads05

Copy link
Copy Markdown
Contributor Author

@kunchenguid please review

Comment thread bin/fm-brief.sh Resolved
Comment thread bin/fm-merge-local.sh Resolved
Comment thread bin/fm-brief.sh Resolved
Comment thread bin/fm-spawn.sh Resolved
Comment thread bin/fm-spawn.sh Resolved
Ordinary pooled freshen still tracks origin's default branch. When the
captain already cut a target branch, --base-branch resets the worktree
to that tip and records the PR target; --branch-name stops firstmate
from rewriting generated fm/<id> text by hand.
A local-only --branch-name brief finishes on that custom branch.
Merge-local now reads the recorded Crew branch line and keeps
fm/<id> only when that line is absent.
The generated contract is appended after free-form task text, so the
first matching line can be an earlier mention instead of the real name.
Local-only ships based on --base-branch were still delivered to the
repository default, which either refused the ready branch or landed
the named base on main.
An earlier Base branch line in replaceable task text was treated as
authoritative, so spawn could disagree with the generated brief and
local landing target.
Last-match parsing fixed task-text decoys, but a later progress note
could then override the generated Definition of done contract.
A task-authored heading could hide the generated contract section.
Read the last Definition of done before any relaunch progress note.
Stop whole-file fallback from reading relaunch progress notes when a
contract line was never generated. When a Definition of done section
exists, only that region is authoritative; otherwise scan the brief
prefix before the fm-control relaunch marker. Add regression tests for
local-only --branch-name landing and conjured progress-note contracts.
The scaffold checks out the named base before `git checkout -b`, so equal
crew and base branch names always fail the worker's first setup action.
Refuse --base-branch when it equals the resolved crew branch,
including the default fm/<task-id>. Ignore a forged relaunch
marker that still sits before generated Setup, so task text
cannot hide the Definition of done.
Spawn reads only Definition of done, so a scout --base-branch
recorded in Setup was invisible and matching spawns were refused.
A lone worktree line in a progress note no longer moves the
contract scan past the real fm-control relaunch marker.
A progress note that copies Setup plus the worktree
line could move the generated-contract bound. End
ship and scout briefs with a scaffold line and treat
only a later relaunch marker as structural.
@lakshyads05
lakshyads05 force-pushed the fm/fm-spawn-project-worktree-convention-v2 branch from a727289 to 58d0079 Compare September 2, 2026 11:57
@lakshyads05

Copy link
Copy Markdown
Contributor Author

@kunchenguid please review

@lakshyads05

Copy link
Copy Markdown
Contributor Author

@kunchenguid please review and approve

@lakshyads05

Copy link
Copy Markdown
Contributor Author

Superseded by #4071, which rebases the named-base and crew-branch work onto current upstream.

Closing this PR in favor of that replacement.

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.

2 participants