Repository navigation
feat(self-fix): worktree-based self-fix flow for firstmate's own tracked code - #451
Closed
chanjdaniel wants to merge 5 commits into
Closed
chanjdaniel wants to merge 5 commits into
chanjdaniel wants to merge 5 commits into
Conversation
…ect path (#1) * fix(spawn): wait for genuine isolated worktree, not just any non-project path The treehouse worktree wait loop was breaking on the first pane cwd that was not the project directory. Right after tmux new-window, the pane transiently reports the tmux server default (/home/danielc) before treehouse get runs, so the loop breaks immediately with WT=/home/danielc. The isolation guard then correctly refuses, aborting every spawn. Hoist the isolation invariant (real git worktree root, resolved toplevel equals itself, distinct from project checkout) into a reusable is_isolated_worktree() function and use it as the loop's break condition. This skips transient pre-chdir states and waits for the real worktree to appear. validate_spawn_worktree() now delegates to the same function as a redundant final assertion. * no-mistakes(test): make failing tests hermetic against ambient FM_HOME and system node * no-mistakes(document): mark herdr worktree-isolation symlink gap resolved in docs * no-mistakes(lint): fix SC2015 in fm-spawn is_isolated_worktree helper
…ked code (#2) * feat(self-fix): worktree-based self-fix flow so firstmate can ship its own fixes through the gate Add bin/fm-self-fix.sh, which creates an isolated git worktree of this repo on a fix branch (rooted outside any FM_HOME) and dispatches a crewmate into it via a new fm-spawn --worktree mode - so firstmate can fix its own tracked code through the no-mistakes gate without treehouse pooling and without moving the primary checkout off its default branch. - fm-spawn.sh: --worktree <path> skips treehouse get, uses the pre-created isolated worktree (same isolation assertion), starts the tmux window in it, and records selffix=1 in meta. All paths are byte-unchanged when the flag is absent. - fm-teardown.sh: selffix=1 tasks are cleaned with git worktree remove (after the unchanged landed-work safety check), not a treehouse return. Scoped to the tmux backend; other backends are a later follow-up. * no-mistakes(review): enforce tmux-only self-fix and skip fleet-sync on selffix teardown * no-mistakes(document): document worktree-based self-fix flow in scripts, AGENTS, architecture docs
bin/fm-self-fix.sh checked the brief at $FM_ROOT/data/$ID/brief.md, but firstmate's operational data lives under FM_HOME, which can differ from the repo root. Resolve FM_HOME/DATA the same way fm-spawn.sh and fm-brief.sh do, then check the brief there. Add regression test covering the FM_HOME-differs case and the missing-brief-diagnostic-message case.
chanjdaniel
force-pushed
the
fix/fm-selffix-brief-fmhome-b7
branch
from
July 11, 2026 03:08
c81cf71 to
ad6f077
Compare
Author
|
Closing - opened against the upstream parent by mistake; this work belongs only on our own fork (chanjdaniel/firstmate). Re-landing there. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Fix bin/fm-self-fix.sh brief-existence precheck to honor FM_HOME. When FM_HOME is set to a directory other than the repo root, firstmate's operational data (including briefs) lives under FM_HOME/data/, not FM_ROOT/data/. The precheck was checking FM_ROOT/data/ and false-refusing even when the brief existed at FM_HOME/data/. The fix resolves FM_HOME and DATA the same way fm-spawn.sh and fm-brief.sh do (FM_HOME="${FM_HOME:-${FM_ROOT_OVERRIDE:-$FM_ROOT}}", DATA="${FM_DATA_OVERRIDE:-$FM_HOME/data}"), then checks the brief at $DATA/$ID/brief.md and prints the resolved path in the error message. The scratch worktree root stays outside FM_HOME - unchanged behavior. A regression test at tests/fm-self-fix.test.sh covers the FM_HOME-differs case and the missing-brief-diagnostic-message case. Shellcheck clean on both changed files.
What Changed
bin/fm-self-fix.sh, which creates an isolated plaingit worktreeof the firstmate repo on afix/<id>branch rooted outside anyFM_HOMEand launches a crewmate into it viafm-spawn.sh --worktree, so the primary checkout never leaves its default branch while a shared-material fix still ships through the gate; the brief-existence precheck now resolvesFM_HOME/DATAthe same wayfm-spawn.shandfm-brief.shdo and reports the resolved$DATA/<id>/brief.mdpath on failure.fm-spawn.shto assert the resolved worktree is a genuine isolated worktree distinct from the primary checkout before launch, added the--worktreeself-fix path (recorded asselffix=1in meta), and taughtfm-teardown.shto remove a self-fix worktree withgit worktree remove.tests/fm-self-fix.test.shcovering theFM_HOME-differs and missing-brief-diagnostic cases (made hermetic via a worktree guard), extendedtests/lib.sh/tests/fm-gotmp.test.shto clear operational-home selector env vars, and updated AGENTS.md, CONTRIBUTING.md, and docs to document the self-fix flow andFM_SELFFIX_ROOT.Risk Assessment
✅ Low: Well-bounded change (a small FM_HOME-aware precheck, a --worktree spawn path, and matching teardown/test coverage); the prior hermeticity finding is fixed, and the one remaining issue is a defensive test-isolation gap, not a product-behavior risk.
Testing
The baseline suite (all tests/*.test.sh) already passed, and I ran the targeted
tests/fm-self-fix.test.sh(both cases green). For product-level evidence I built an end-to-end CLI transcript running the pre-fix script against the fixed one under an FM_HOME that differs from the repo root with the brief under$FM_HOME/data/: the old version false-refuses with "no brief at data/...", the fixed version finds the brief and advances past the precheck (stopping at the later worktree guard), and the missing-brief case now names the resolved FM_HOME path. This is a CLI/bin change with no UI surface, so the appropriate artifact is the command transcript rather than a screenshot. Worktree left clean.Evidence: fm-self-fix FM_HOME precheck before/after transcript
### BEFORE fix (v1b16a82): precheck read $FM_ROOT/data/ -> false refusal error: no brief at data/fix-typo-x7/brief.md (author it first) exit=1 ### AFTER fix (current): resolves $FM_HOME/data/ -> brief found, passes precheck error: worktree path already exists: .../selffix-scratch/fix-typo-x7 exit=1 ### Missing-brief diagnostic names the resolved FM_HOME path error: no brief at .../other-home/data/missing-b2/brief.md (author it first) exit=1Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
.agents/skills/afk/SKILL.md- branch carries 2 commit(s) that exist on your local main branch but were never pushed to origin/main; rebasing would bundle this unrelated work (147 file(s)) into the PR:Push main to origin, or rebase your branch onto origin/main, before gating.
tests/fm-self-fix.test.sh:33- tests/fm-self-fix.test.sh: test_brief_found_with_fmhome_set is not hermetic. With the brief present, fm-self-fix.sh passes the precheck and proceeds togit -C "$FM_ROOT" worktree add "$WT" -b fix/selffix-brief-a1 ...against the REAL repo ($ROOT), then execs fm-spawn.sh --backend tmux. So merely running this test creates a persistentfix/selffix-brief-a1branch plus a git worktree admin entry in the repo under review and launches a real tmux spawn as a side effect. The temp-dir cleanup (rm -rf) removes the worktree directory but not the branch or the git worktree registration, so it leaks state; a second run then fails at the branch-exists check (still with no 'no brief' text, so the assertion silently still passes). This runs in the pipeline's test step inside a worktree of this same repo, where the leaked branch/worktree/tmux window can interfere. The test should short-circuit before the worktree-add/exec (e.g. stub or intercept fm-spawn.sh, or assert the precheck outcome without reaching side effects) rather than exercising the full spawn.🔧 Fix: make self-fix FM_HOME test hermetic via worktree guard
1 warning still open:
tests/lib.sh:33- The new hermetic-isolation unset clears FM_HOME, FM_ROOT_OVERRIDE, FM_STATE_OVERRIDE, and FM_CONFIG_OVERRIDE, but omits FM_DATA_OVERRIDE (and FM_PROJECTS_OVERRIDE), which are also operational-home selectors read by the scripts under test. This directly undermines the fix's own regression test: fm-self-fix.sh resolves DATA="${FM_DATA_OVERRIDE:-$FM_HOME/data}", so both new tests in tests/fm-self-fix.test.sh assert on a path computed from FM_HOME only when FM_DATA_OVERRIDE is unset. If a live firstmate session (or CI env) exports FM_DATA_OVERRIDE, test_brief_found_with_fmhome_set reads the wrong data dir and its 'no brief' assertion fails, and test_brief_missing_prints_resolved_path could even find a real brief. The comment claims to 'Clear the operational-home selectors up front' but leaves the very selector the self-fix brief precheck keys on. Add FM_DATA_OVERRIDE (and FM_PROJECTS_OVERRIDE for consistency) to the unset list here and in tests/fm-gotmp.test.sh:18.✅ **Test** - passed
✅ No issues found.
command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"bash tests/fm-self-fix.test.sh- both cases pass (finds brief under FM_HOME; missing brief prints resolved FM_HOME path)E2E before/after transcript: ran pre-fix (git show 1b16a82:bin/fm-self-fix.sh) vs currentbin/fm-self-fix.shwith FM_HOME set to a separate ops-home and the brief authored at$FM_HOME/data/<id>/brief.mdVerified missing-brief diagnostic prints the resolved$FM_HOME/data/<id>/brief.mdpathgit status --porcelainafter cleanup - worktree clean, no transient files left behind✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.