Skip to content

feat(bin): add an opt-in no-mistakes home resolver for host reads - #7348

Merged
kunchenguid merged 1 commit into
kunchenguid:mainfrom
rchristensen:fm/fm-nm-home-resolver
Oct 20, 2026
Merged

kunchenguid merged 1 commit into
kunchenguid:mainfrom
rchristensen:fm/fm-nm-home-resolver

Conversation

@rchristensen

@rchristensen rchristensen commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Implement the accepted fix for #7309: an opt-in NM_HOME resolver for host-side no-mistakes reads when each workspace runs its own no-mistakes daemon.

Problem: every host-side no-mistakes read goes through fm_nm_bounded, fm_nm_run* and fm_nm_state_db in bin/fm-nm-run-lib.sh, which use the ambient NM_HOME or default to ~/.no-mistakes. When a task's run lives in a per-workspace NM_HOME, crew state sees no run for the task, pipeline spend cannot find it, and teardown never aborts a parked run. The home cannot be derived from the no-mistakes remote URL, because every workspace of a project shares one gate URL.

Accepted direction (maintainer triage on main 33503ab, contract class opt-in):

  • When NM_HOME is unset and a resolver command is configured, the read paths run it with the worktree path. If it prints a home, that NM_HOME is exported for that one call.
  • An explicit NM_HOME always wins. With nothing configured, behaviour is exactly as today.
  • Scope: host reads (axi status, runs, logs, daemon status, the state DB) and axi abort --run only. It never starts a daemon and never touches launch, account routing or config.yaml.
  • The resolver is site-provided; Firstmate only calls it.
  • The configuration shape (a config/ file or an environment variable) may be chosen in the PR, as long as it is documented and off by default.

What Changed

  • bin/fm-nm-run-lib.sh gets an opt-in resolver hook. When NM_HOME is unset and config/nm-home-resolver names an absolute executable, fm_nm_run_bounded and fm_nm_state_db call that executable with the worktree path, with a 5-second limit. The answer counts only if the executable prints exactly one line naming an existing absolute directory. That directory is then exported as NM_HOME for that one call.
  • The resolver only applies to host reads (the bare axi overview, axi status, axi logs, runs, daemon status, the state DB) and to axi abort --run <id>. Every other no-mistakes call keeps the ambient home. An explicit NM_HOME always wins. If the file is missing or the resolver fails, times out or prints anything unusable, behaviour is the same as before.
  • The new config file is documented in docs/configuration.md and in the operational-home-layout skill. New tests cover pipeline spend: finding a resolved workspace home, an explicit NM_HOME winning, bad resolver output falling back to the ambient home, and the command scope. A teardown test covers aborting a parked run that lives in a resolved workspace home.

Risk Assessment

✅ Low: The opt-in resolver is confined to the intended host reads and run-targeted abort, preserves explicit home precedence, and leaves unconfigured behavior unchanged.

Testing

Both targeted test files passed: fm-pipeline-spend and fm-teardown, including the new resolver tests. I then drove the change live with the real no-mistakes v1.84.0 CLI in a disposable lab. It had a firstmate lab home, a throwaway git project with its gate initialised in its own home (wsA), and a separate fake account home acting as the default ~/.no-mistakes. Reads through the resolver went to wsA. fm-crew-state went from unknown to done · source: run-step · run: 01LABRUNDONE. Pipeline spend went from source: unavailable to source: no-mistakes-state with the run attributed. axi abort --run went from "no run with that id" to the wsA daemon accepting the cancel request. An explicit NM_HOME won and the resolver was not called. An out-of-scope daemon stop stayed on the default home and wsA's daemon kept running. Every bad resolver answer fell back to the default home and created no directory. No read started a daemon. The abort fixture is a hand-inserted run row that no daemon was executing, so the cancel request was accepted but the run never reached a terminal state. The full teardown abort flow was not driven live, so that scenario is marked untested; the new teardown unit test covers it. The lab was removed afterwards, and the operator's own daemon (pid 198) was left untouched. There is no UI surface, so all evidence is CLI transcripts.

  • Live validation: ✅ go - 9 of 10 scenarios driven live against the product
Scenario Result Live Evidence
No config/nm-home-resolver: reads use the default home exactly as before (state DB is <HOME>/.no-mistakes/state.sqlite; wsA's run is not seen) ✅ pass live live-lib-resolver-transcript.txt S1
Resolver configured and NM_HOME unset: runs / daemon status / axi status / state DB read the workspace home, and the resolver gets the worktree path ✅ pass live live-lib-resolver-transcript.txt S2 (runs lists 01LABRUNDONE, daemon running pid of wsA, state DB <lab>/wsA/state.sqlite, resolver called with <lab>/wt)
Crew state finds the task's run in the workspace home only when the resolver is configured ✅ pass live live-scripts-resolver-transcript.txt: off -> 'state: unknown · source: none'; on -> 'state: done · source: run-step · run: 01LABRUNDONE'
Pipeline spend attributes the run in the workspace home only when the resolver is configured ✅ pass live live-scripts-resolver-transcript.txt: off -> source unavailable, runs []; on -> source no-mistakes-state, runs [01LABRUNDONE]
axi abort --run reaches the workspace home's daemon through the resolver ✅ pass live live-abort-run-transcript.txt: off -> 'no run with that id is recorded (no-op)'; on -> 'cancellation_requested: true' from the wsA daemon for 01LABRUNPARK
Teardown aborts a parked run in a resolved workspace home before removing the worker ⏸️ untested no The earlier payload did not establish a live result for this scenario; only tests/fm-teardown.test.sh covers it. Driving it live needs a real parked run, which means a full no-mistakes pipeline with a…
Adversarial: an explicit NM_HOME always wins and the resolver is not called ✅ pass live live-lib-resolver-transcript.txt S3: state DB <lab>/explicit/state.sqlite, resolver calls: 0
Adversarial: an out-of-scope call (daemon stop) is not redirected, so the workspace daemon survives ✅ pass live live-lib-resolver-transcript.txt S4: resolver calls 0; wsA daemon still running afterwards
Adversarial: a resolver that fails, prints a missing dir, a relative path or two lines, or a config naming a relative path, falls back to the default home and creates no directory ✅ pass live live-lib-resolver-transcript.txt S5: every case gives <HOME>/.no-mistakes/state.sqlite; 'no-such-home not created'
Adversarial: resolved host reads never start a daemon ✅ pass live live-no-daemon-start-transcript.txt: wsA daemon stopped, then axi / status / runs / daemon status / logs via the resolver; daemon still not running and 0 wsA daemon processes
Evidence: Live lib transcript: baseline, opt-in, explicit NM_HOME wins, scope, unusable answers

Source: Live lib transcript: baseline, opt-in, explicit NM_HOME wins, scope, unusable answers

=== S1 baseline: no config/nm-home-resolver -> ambient home (HOME=/tmp/fm-nmres.cOH7yU/acct) ===
$ bash -c . "$1/bin/fm-nm-run-lib.sh"; shift; "$@" _ ~/.no-mistakes/worktrees/91d79474e1a0/01M4ZPM0R4G8481B0ZZQWTEBTF fm_nm_run /tmp/fm-nmres.cOH7yU/wt 15 runs --limit 5
[rc=0]
$ bash -c . "$1/bin/fm-nm-run-lib.sh"; shift; "$@" _ ~/.no-mistakes/worktrees/91d79474e1a0/01M4ZPM0R4G8481B0ZZQWTEBTF fm_nm_run /tmp/fm-nmres.cOH7yU/wt 15 daemon status
  ○ daemon not running
[rc=0]
$ bash -c . "$1/bin/fm-nm-run-lib.sh"; shift; "$@" _ ~/.no-mistakes/worktrees/91d79474e1a0/01M4ZPM0R4G8481B0ZZQWTEBTF fm_nm_state_db /tmp/fm-nmres.cOH7yU/wt
/tmp/fm-nmres.cOH7yU/acct/.no-mistakes/state.sqlite
[rc=0]

=== S2 opt-in: config/nm-home-resolver -> /tmp/fm-nmres.cOH7yU/resolver ===
$ bash -c . "$1/bin/fm-nm-run-lib.sh"; shift; "$@" _ ~/.no-mistakes/worktrees/91d79474e1a0/01M4ZPM0R4G8481B0ZZQWTEBTF fm_nm_run /tmp/fm-nmres.cOH7yU/wt 15 runs --limit 5
  completed    fm/task              c91934c9  2026-10-15 12:03
[rc=0]
$ bash -c . "$1/bin/fm-nm-run-lib.sh"; shift; "$@" _ ~/.no-mistakes/worktrees/91d79474e1a0/01M4ZPM0R4G8481B0ZZQWTEBTF fm_nm_run /tmp/fm-nmres.cOH7yU/wt 15 daemon status
  ● daemon running (pid 2892189)
[rc=0]
$ bash -c . "$1/bin/fm-nm-run-lib.sh"; shift; "$@" _ ~/.no-mistakes/worktrees/91d79474e1a0/01M4ZPM0R4G8481B0ZZQWTEBTF fm_nm_run /tmp/fm-nmres.cOH7yU/wt 15 axi status --run 01LABRUNDONE
run:
  id: "01LABRUNDONE"
  branch: fm/task
  status: completed
  head: c91934c9
  head_sha: c91934c9804d25775e568011ba71b8aaaaca084f
  verification_plan: none
  findings: none
  steps[0]:
outcome: passed
[rc=0]
$ bash -c . "$1/bin/fm-nm-run-lib.sh"; shift; "$@" _ ~/.no-mistakes/worktrees/91d79474e1a0/01M4ZPM0R4G8481B0ZZQWTEBTF fm_nm_state_db /tmp/fm-nmres.cOH7yU/wt
/tmp/fm-nmres.cOH7yU/wsA/state.sqlite
[rc=0]
resolver was called with:
/tmp/fm-nmres.cOH7yU/wt

=== S3 explicit NM_HOME wins (NM_HOME=/tmp/fm-nmres.cOH7yU/explicit) ===
$ NM_HOME=/tmp/fm-nmres.cOH7yU/explicit fm_nm_run wt runs
[rc=0]
/tmp/fm-nmres.cOH7yU/explicit/state.sqlite
resolver calls: 0

=== S4 scope: out-of-scope 'daemon stop' keeps ambient home; wsA daemon must survive ===
$ bash -c . "$1/bin/fm-nm-run-lib.sh"; shift; "$@" _ ~/.no-mistakes/worktrees/91d79474e1a0/01M4ZPM0R4G8481B0ZZQWTEBTF fm_nm_run /tmp/fm-nmres.cOH7yU/wt 15 daemon stop
  ✓ daemon stopped
[rc=0]
resolver calls: 0
$ NM_HOME=/tmp/fm-nmres.cOH7yU/wsA no-mistakes daemon status
  ● daemon running (pid 2892189)

=== S5 unusable resolver answers fall back to ambient ===
--- resolver mode: fail
$ bash -c . "$1/bin/fm-nm-run-lib.sh"; shift; "$@" _ ~/.no-mistakes/worktrees/91d79474e1a0/01M4ZPM0R4G8481B0ZZQWTEBTF fm_nm_state_db /tmp/fm-nmres.cOH7yU/wt
/tmp/fm-nmres.cOH7yU/acct/.no-mistakes/state.sqlite
[rc=0]
no-such-home not created
--- resolver mode: nonexistent
$ bash -c . "$1/bin/fm-nm-run-lib.sh"; shift; "$@" _ ~/.no-mistakes/worktrees/91d79474e1a0/01M4ZPM0R4G8481B0ZZQWTEBTF fm_nm_state_db /tmp/fm-nmres.cOH7yU/wt
/tmp/fm-nmres.cOH7yU/acct/.no-mistakes/state.sqlite
[rc=0]
no-such-home not created
--- resolver mode: relative
$ bash -c . "$1/bin/fm-nm-run-lib.sh"; shift; "$@" _ ~/.no-mistakes/worktrees/91d79474e1a0/01M4ZPM0R4G8481B0ZZQWTEBTF fm_nm_state_db /tmp/fm-nmres.cOH7yU/wt
/tmp/fm-nmres.cOH7yU/acct/.no-mistakes/state.sqlite
[rc=0]
no-such-home not created
--- resolver mode: twolines
$ bash -c . "$1/bin/fm-nm-run-lib.sh"; shift; "$@" _ ~/.no-mistakes/worktrees/91d79474e1a0/01M4ZPM0R4G8481B0ZZQWTEBTF fm_nm_state_db /tmp/fm-nmres.cOH7yU/wt
/tmp/fm-nmres.cOH7yU/acct/.no-mistakes/state.sqlite
[rc=0]
no-such-home not created
--- config names a relative path
$ bash -c . "$1/bin/fm-nm-run-lib.sh"; shift; "$@" _ ~/.no-mistakes/worktrees/91d79474e1a0/01M4ZPM0R4G8481B0ZZQWTEBTF fm_nm_state_db /tmp/fm-nmres.cOH7yU/wt
/tmp/fm-nmres.cOH7yU/acct/.no-mistakes/state.sqlite
[rc=0]
Evidence: Driver script used for the live lib transcript

Source: Driver script used for the live lib transcript

#!/usr/bin/env bash
# usage: drive.sh <repo-root> <lab>
R=$1 L=$2 FMH=$L/fmhome
run() { echo "\$ $*"; env -u NM_HOME -u FM_CONFIG_OVERRIDE -u FM_STATE_OVERRIDE -u FM_DATA_OVERRIDE HOME=$L/acct FM_HOME=$FMH "$@" 2>&1; echo "[rc=$?]"; }
lib() { run bash -c '. "$1/bin/fm-nm-run-lib.sh"; shift; "$@"' _ "$R" "$@"; }
echo "=== S1 baseline: no config/nm-home-resolver -> ambient home (HOME=$L/acct) ==="
rm -f $FMH/config/nm-home-resolver
lib fm_nm_run $L/wt 15 runs --limit 5
lib fm_nm_run $L/wt 15 daemon status
lib fm_nm_state_db $L/wt
echo
echo "=== S2 opt-in: config/nm-home-resolver -> $L/resolver ==="
printf '%s\n' $L/resolver > $FMH/config/nm-home-resolver
: > $L/resolver-calls
lib fm_nm_run $L/wt 15 runs --limit 5
lib fm_nm_run $L/wt 15 daemon status
lib fm_nm_run $L/wt 15 axi status --run 01LABRUNDONE
lib fm_nm_state_db $L/wt
echo "resolver was called with:"; sort -u $L/resolver-calls
echo
echo "=== S3 explicit NM_HOME wins (NM_HOME=$L/explicit) ==="
mkdir -p $L/explicit; : > $L/resolver-calls
echo "\$ NM_HOME=$L/explicit fm_nm_run wt runs"; env -u FM_CONFIG_OVERRIDE HOME=$L/acct FM_HOME=$FMH NM_HOME=$L/explicit bash -c '. "$1/bin/fm-nm-run-lib.sh"; fm_nm_run "$2" 15 runs --limit 5; echo "[rc=$?]"; fm_nm_state_db "$2"' _ "$R" $L/wt 2>&1
echo "resolver calls: $(wc -l < $L/resolver-calls)"
echo
echo "=== S4 scope: out-of-scope 'daemon stop' keeps ambient home; wsA daemon must survive ==="
: > $L/resolver-calls
lib fm_nm_run $L/wt 15 daemon stop
echo "resolver calls: $(wc -l < $L/resolver-calls)"
echo "\$ NM_HOME=$L/wsA no-mistakes daemon status"; HOME=$L/acct NM_HOME=$L/wsA no-mistakes daemon status
echo
echo "=== S5 unusable resolver answers fall back to ambient ==="
for mode in fail nonexistent relative twolines; do
  case $mode in
    fail) body='exit 3' ;;
    nonexistent) body="echo $L/no-such-home" ;;
    relative) body='echo wsA' ;;
    twolines) body="printf '%s\n%s\n' $L/wsA $L/wsA" ;;
  esac
  printf '#!/usr/bin/env bash\n%s\n' "$body" > $L/bad-resolver; chmod +x $L/bad-resolver
  printf '%s\n' $L/bad-resolver > $FMH/config/nm-home-resolver
  echo "--- resolver mode: $mode"
  lib fm_nm_state_db $L/wt
  [ -e $L/no-such-home ] && echo "!! no-such-home was created" || echo "no-such-home not created"
done
printf 'relative-resolver\n' > $FMH/config/nm-home-resolver
echo "--- config names a relative path"; lib fm_nm_state_db $L/wt
printf '%s\n' $L/resolver > $FMH/config/nm-home-resolver
Evidence: Live fm-crew-state and fm-pipeline-spend, resolver off vs on

Source: Live fm-crew-state and fm-pipeline-spend, resolver off vs on

off: state: unknown · source: none ... | spend source: unavailable, runs [] on: state: done · source: run-step · run passed ... · run: 01LABRUNDONE | spend source: no-mistakes-state, runs [01LABRUNDONE]

=== config/nm-home-resolver: off ===
$ bin/fm-pipeline-spend.sh record labtask
recorded labtask s1792062215.1.abc
[rc=0]
ledger tail:
{"task": "labtask", "source": "unavailable", "runs": []}
$ FM_CREW_STATE_NO_FORGE=1 bin/fm-crew-state.sh labtask
state: unknown · source: none · backend unreachable (tmux endpoint state: unreadable)
[rc=0]

=== config/nm-home-resolver: on ===
$ bin/fm-pipeline-spend.sh record labtask
already recorded labtask s1792062215.1.abc
[rc=0]
ledger tail:
{"task": "labtask", "source": "unavailable", "runs": []}
$ FM_CREW_STATE_NO_FORGE=1 bin/fm-crew-state.sh labtask
state: done · source: run-step · run passed: PR state unknown (no PR identity) · run: 01LABRUNDONE
[rc=0]

=== config/nm-home-resolver: on, new task incarnation ===
$ bin/fm-pipeline-spend.sh record labtask
recorded labtask s1792064022.2.def
[rc=0]
ledger tail:
{"task":"labtask","spawn_gen":"s1792064022.2.def","recorded_at":"2026-10-15T12:03:42Z","source":"no-mistakes-state","reason":null,"repo":"/tmp/fm-nmres.cOH7yU/proj","branch":"fm/task","since":"2026-10-15T12:02:55Z","total":{"invocations":0,"exit":{},"duration_ms":0,"input_tokens":{"total":0,"unknown":0},"output_tokens":{"total":0,"unknown":0},"cache_read_tokens":{"total":0,"unknown":0},"cache_creation_tokens":{"total":0,"unknown":0}},"runs":[{"id":"01LABRUNDONE","status":"completed","created_at":"2026-10-15T12:03:02Z","invocations":0,"exit":{},"duration_ms":0,"input_tokens":{"total":0,"unknown":0},"output_tokens":{"total":0,"unknown":0},"cache_read_tokens":{"total":0,"unknown":0},"cache_creation_tokens":{"total":0,"unknown":0}}],"purposes":[]}
Evidence: Live axi abort --run, resolver off vs on

Source: Live axi abort --run, resolver off vs on

=== abort --run with resolver OFF (ambient home) ===
before: ('01LABRUNPARK', 'running')
aborted: false
run: "01LABRUNPARK"
detail: daemon not running and no run with that id is recorded (no-op)
[rc=0]
after: ('01LABRUNPARK', 'running')
=== abort --run with resolver ON ===
error: "cancellation was requested for run 01LABRUNPARK, but terminal quiescence is unconfirmed: the daemon reported no active run, but the exact run's durable state is still running"
cancellation_requested: true
terminal_confirmed: false
run: "01LABRUNPARK"
branch: fm/task
run_state:
  id: "01LABRUNPARK"
  branch: fm/task
  status: running
  head: c91934c9
  head_sha: c91934c9804d25775e568011ba71b8aaaaca084f
  verification_plan: none
  findings: none
  steps[0]:
help[3]: Run `no-mistakes axi status --run 01LABRUNPARK` to observe the run until it reports a terminal status,Re-run `no-mistakes axi abort` once the daemon is reachable; a repeated abort is an idempotent no-op,Do not treat the branch as released or recoverable until a terminal status is confirmed
[rc=1]
after: ('01LABRUNPARK', 'running')
Evidence: Live: resolved reads never start a daemon

Source: Live: resolved reads never start a daemon

=== resolved reads never start a daemon (fixture wsA daemon stopped first) ===
$ NM_HOME=/tmp/fm-nmres.cOH7yU/wsA no-mistakes daemon status
  ○ daemon not running
$ fm_nm_run wt axi
bin: /usr/local/share/mise/installs/github-kunchenguid-no-mistakes/1.84.0/no-mistakes
description: "Validate your code changes through the no-mistakes pipeline - automated code review, tests, lint, docs, push, PR, and CI - before they reach the configured push target. Use when the user asks to run no-mistakes, gate or ship or validate their changes, push safely, asks you to do a task and then validate it, or invokes /no-mistakes."
repo: /tmp/fm-nmres.cOH7yU/proj
current_branch: fm/task
$ fm_nm_run wt axi status
run:
  id: "01LABRUNPARK"
  branch: fm/task
  status: cancelled
$ fm_nm_run wt runs --limit 5
  cancelled    fm/task              c91934c9  2026-10-15 12:03
  completed    fm/task              c91934c9  2026-10-15 12:03
$ fm_nm_run wt daemon status
  ○ daemon not running
$ fm_nm_run wt axi logs --step review --run 01LABRUNDONE
step: review
run: "01LABRUNDONE"
log: "no log recorded for step \"review\" in this run"
after reads:
$ NM_HOME=/tmp/fm-nmres.cOH7yU/wsA no-mistakes daemon status
  ○ daemon not running
wsA daemon processes: 0
Evidence: tests/fm-pipeline-spend.test.sh output

Source: tests/fm-pipeline-spend.test.sh output

ok - known spend, including failed and cancelled invocations, is attributed to the task that ran it
ok - repeated review rounds in a resumed session are counted once
ok - absent spend reads as zero only when no run exists, and as unavailable when it cannot be read
ok - older state without delta columns counts only rounds it can prove
ok - record appends one line per task incarnation
ok - an absent opt-in flag bypasses task, pipeline, and ledger reads and writes
ok - the state database resolves under the account home when NM_HOME and HOME are unset
ok - a configured resolver supplies the no-mistakes home for reads when NM_HOME is unset
ok - an explicit NM_HOME always wins and the resolver is not called
ok - an absent or unusable resolver leaves every read on the ambient home
ok - the resolver applies to host reads and axi abort --run only
ok - missing tasks, secondmates, and unsafe ids are refused
rc=0
Evidence: tests/fm-teardown.test.sh output

Source: tests/fm-teardown.test.sh output

ok - a missing teardown startup source refuses before cleanup
ok - an unreadable teardown startup source refuses before cleanup
ok - a missing adapter sibling refuses before cleanup
ok - a forced descendant with a missing adapter sibling refuses before cleanup
ok - a forced secondmate with a missing own adapter sibling refuses before child cleanup
ok - present required sources still reach the ordinary teardown refusal
ok - local-only worktree with HEAD on a fork remote is torn down and the home summary is refreshed
ok - teardown closes its own backlog item before reporting success
ok - teardown closes a landed Gerrit task with its change URL as a note and a GitHub task with --pr
ok - teardown honors config/backlog-backend=manual and still finishes cleanly
ok - local-only worktree with truly unpushed work is refused (safety preserved)
ok - local-only worktree with work merged into local main is torn down (no regression)
ok - no-mistakes worktree with HEAD on origin is torn down (no regression)
ok - no-mistakes worktree with genuinely unlanded work is refused (safety preserved)
ok - local-only worktree with unpushed work is torn down under --force (escape hatch)
ok - fm-pr-check publishes the PR-ready line on a secondmate's parent channel once
ok - a secondmate home's teardown delivers the child's final line or refuses until it can
ok - teardown completes when an exact busy-state sidecar is already absent
ok - herdr teardown removes pane-owned escalation dedupe state
ok - herdr flat teardown refuses before returning the isolated copy under lock contention and the retry completes cleanly
ok - herdr flat teardown never erases records when pane presence is unparseable
ok - herdr flat teardown preflight refuses before every destructive change
ok - herdr teardown takes its lock in a per-account namespace another account cannot block, and still refuses a foreign-owned or wrong-mode one
ok - forced secondmate teardown preflights every Herdr child before cleanup mutation
ok - forced secondmate teardown holds every descendant lifecycle and metadata lock
ok - forced secondmate teardown retains Herdr child identity until exact pane disappearance
ok - forced teardown retains a nested secondmate home and its grandchild's Herdr identity when the grandchild close is unconfirmed
ok - herdr projection teardown retires its journal only after confirming the exact recorded pane is gone
ok - herdr projection teardown retains every record when post-close presence is unknown
ok - herdr projection teardown surfaces failed focus restoration without turning confirmed cleanup into a hard failure
ok - teardown retires the task's own watcher markers and orphaned presentation journal, leaving other tasks' markers alone
ok - teardown retains a presentation journal bound to a pane other than the closed endpoint
ok - teardown retires a v1 presentation journal once its token workspace is confirmed gone
ok - teardown retains a v1 presentation journal while its token workspace is still present
ok - teardown retains a v1 presentation journal when the workspace query is ambiguous
ok - squash-merged + deleted-branch worktree (PR merged) is torn down (the fix)
ok - squash-merged PR accepts a local HEAD that is an ancestor of the final PR head
ok - teardown discovers a merged PR by branch name and tears down when no pr= was ever recorded
ok - squash-merged PR accepts replayed unpushed local patches contained in the PR head
ok - merged PR does not allow teardown after a later local commit
ok - squash-merged task whose local branch followed the pipeline rebase is torn down
ok - teardown proves a Forgejo task landed from the merged pull request when the content check is inconclusive
ok - squash-merged same-path different content still refuses
ok - squash-merged rebased local still refuses a genuinely unlanded follow-up commit
ok - squash-merged stale local still refuses when the forge is unreachable
fm-contributions: data directory unavailable
contributions: observation not armed; coverage is unconfirmed
fm-contributions: data directory unavailable
contributions: observation not armed; coverage is unconfirmed
ok - fm-pr-check does not refresh PR head after HEAD moves
fm-contributions: data directory unavailable
contributions: observation not armed; coverage is unconfirmed
ok - fm-pr-check records the remote PR head when the local worktree lags
ok - worktree whose content already landed in the default branch is torn down (content fallback)
ok - the content-landed fallback checks a task's recorded base branch, not the default branch
ok - content fallback refreshes origin default before comparing trees
ok - dirty worktree is refused even when its committed work has landed (dirty always wins)
ok - untracked/no-mistakes: dirty refusal classifies leftovers and preserves work
ok - untracked/local-only: dirty refusal classifies leftovers and preserves work
ok - tracked/no-mistakes: dirty refusal classifies leftovers and preserves work
ok - tracked/local-only: dirty refusal classifies leftovers and preserves work
ok - mixed/no-mistakes: dirty refusal classifies leftovers and preserves work
ok - mixed/local-only: dirty refusal classifies leftovers and preserves work
ok - scout copy with a nested clone and a scratch file returns with no untracked entries
ok - ship copy with a nested clone is refused and its bytes stay
ok - a return that leaves residue names the lost slot and the remaining paths
ok - a dirty return is reported even when a later teardown step refuses
ok - a forced secondmate teardown returns a child scout copy with a nested clone clean
ok - a forced secondmate teardown warns about a dirty child return and still completes
ok - a return that leaves no readable copy reports the slot as unverified, not clean
ok - ignored files survive the scratch clean and plain scratch does not
ok - gh lookup error with content not in default refuses (fail-safe)
ok - a record predating spawn_gen refuses teardown until --legacy-record is passed
ok - a windowless leftover with no spawn_gen and no worktree tears down without --legacy-record
ok - a windowless leftover with no spawn_gen also tears down when --legacy-record is passed
ok - a windowless leftover still refuses while its worktree holds unlanded work
ok - a windowless record with a spawn_gen, a non-tmux backend or endpoint identity, no backlog validation, or ambiguous, foreign, or malformed identity still refuses
ok - a windowless leftover retries its retained legacy stamp without --legacy-record
ok - a landed legacy record with a dead endpoint tears down and logs its accepted incarnation
ok - --legacy-record never relaxes the unlanded-work refusal
ok - an endpoint that cannot be confidently read as dead refuses --legacy-record teardown
ok - --legacy-record teardown rolls its stamp back when the close marker write fails
ok - a legacy stamp a failed rollback left behind still faces the endpoint gate
ok - a corrupt spawn_gen is never accepted as a legacy record
ok - provably-stale worktree index.lock (old, no live holder) is cleared and teardown succeeds
ok - live-held worktree index.lock is never removed and teardown refuses
ok - lsof errors leave worktree index.lock in place and refuse teardown
ok - stale lock cleanup rechecks and refuses dirty worktree before return
ok - normal repo index.lock is resolved from the worktree and cleared when stale
ok - lock mtime read failures leave worktree index.lock in place and refuse teardown
ok - transient index.lock cleared after first failed return is retried successfully without force-remove
ok - persistent index.lock exhausts retries and refuses without force-removing the lock
ok - empty retry wait overrides use the default without aborting teardown
ok - fractional legacy retry wait remains supported without arithmetic
ok - teardown records the task's pipeline spend before removing its branch and record
ok - teardown skips all pipeline-spend recording when the home has not opted in
ok - teardown records unavailable pipeline spend for an owned ship task whose copy is gone
ok - a task's own parked no-mistakes run is aborted, not orphaned, before the worker is removed
ok - a parked run in a resolved workspace no-mistakes home is aborted before the worker is removed
ok - a run that lands on passed-with-override after abort is still recognized as terminal
ok - a run that lands on passed-with-skips after abort is still recognized as terminal
ok - a parked run the pipeline advanced past the task copy is still concluded from the runs ledger, not orphaned
ok - a ledger row for a different head never authorizes a parked-run abort
ok - a malformed ledger row never authorizes a parked-run abort
ok - an impossible ledger date never authorizes a parked-run abort
ok - a terminal status with a stale gate never reaches ledger cleanup
ok - an advanced head present locally aborts through the strict rule alone - the ledger fallback stays dormant
ok - an unresolvable active row with no same-branch anchor is never concluded (conservative refusal)
ok - an ancestor-only anchor never binds an advanced parked run to this task
ok - a terminal unfetched-head row is stale history and never concludes a run
ok - a terminal newest row anchored at this worktree's head never authorizes an abort
ok - a resolvable diverged newer same-branch row makes every older row stale history; no run is concluded
ok - consecutive unresolvable rows are ambiguous and never conclude a run
ok - a ledger-proven continuation is still left alone while the run is autonomously active
ok - teardown refuses before reap or removal when a task-owned run remains parked
ok - a different run cannot confirm the targeted abort
ok - empty post-abort status is not accepted as confirmation
ok - the CLI's exact run-not-found signal confirms completion
ok - a parked run on another branch is never aborted by this task's teardown (ownership is precise)
ok - a task-owned autonomous running step is left alone rather than aborted
ok - a leaked descendant process rooted under the task's worktree is reaped by teardown, not left surviving
ok - a leaked descendant process rooted under the task's per-task tasktmp is reaped by teardown too
ok - missing lsof falls back to reaping the tmux pane process group
ok - an erroring lsof scan refuses teardown and preserves the task
ok - a reused pid with a different start time is never force-killed
ok - an exec change preserves birth identity and the process is reaped
ok - a process spawned during grace is reaped on a later pass
ok - persistent leaked processes refuse teardown after bounded retries
ok - a process exiting during identity lookup does not block teardown
ok - the run abort and the leaked-process reap both complete before the destructive worktree return
rc=0

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.

  • Live validation: ✅ go - 9 of 10 scenarios driven live against the product
Scenario Result Live Evidence
No config/nm-home-resolver: reads use the default home exactly as before (state DB is <HOME>/.no-mistakes/state.sqlite; wsA's run is not seen) ✅ pass live live-lib-resolver-transcript.txt S1
Resolver configured and NM_HOME unset: runs / daemon status / axi status / state DB read the workspace home, and the resolver gets the worktree path ✅ pass live live-lib-resolver-transcript.txt S2 (runs lists 01LABRUNDONE, daemon running pid of wsA, state DB <lab>/wsA/state.sqlite, resolver called with <lab>/wt)
Crew state finds the task's run in the workspace home only when the resolver is configured ✅ pass live live-scripts-resolver-transcript.txt: off -> 'state: unknown · source: none'; on -> 'state: done · source: run-step · run: 01LABRUNDONE'
Pipeline spend attributes the run in the workspace home only when the resolver is configured ✅ pass live live-scripts-resolver-transcript.txt: off -> source unavailable, runs []; on -> source no-mistakes-state, runs [01LABRUNDONE]
axi abort --run reaches the workspace home's daemon through the resolver ✅ pass live live-abort-run-transcript.txt: off -> 'no run with that id is recorded (no-op)'; on -> 'cancellation_requested: true' from the wsA daemon for 01LABRUNPARK
Teardown aborts a parked run in a resolved workspace home before removing the worker ⏸️ untested no The earlier payload did not establish a live result for this scenario; only tests/fm-teardown.test.sh covers it. Driving it live needs a real parked run, which means a full no-mistakes pipeline with a…
Adversarial: an explicit NM_HOME always wins and the resolver is not called ✅ pass live live-lib-resolver-transcript.txt S3: state DB <lab>/explicit/state.sqlite, resolver calls: 0
Adversarial: an out-of-scope call (daemon stop) is not redirected, so the workspace daemon survives ✅ pass live live-lib-resolver-transcript.txt S4: resolver calls 0; wsA daemon still running afterwards
Adversarial: a resolver that fails, prints a missing dir, a relative path or two lines, or a config naming a relative path, falls back to the default home and creates no directory ✅ pass live live-lib-resolver-transcript.txt S5: every case gives <HOME>/.no-mistakes/state.sqlite; 'no-such-home not created'
Adversarial: resolved host reads never start a daemon ✅ pass live live-no-daemon-start-transcript.txt: wsA daemon stopped, then axi / status / runs / daemon status / logs via the resolver; daemon still not running and 0 wsA daemon processes
  • bash tests/fm-pipeline-spend.test.sh (includes the 4 new resolver tests)
  • bash tests/fm-teardown.test.sh (includes test_parked_run_in_a_resolved_workspace_home_is_aborted)
  • Live lab: no-mistakes init in a throwaway repo with NM_HOME=<lab>/wsA, run rows inserted into the real wsA state.sqlite, site resolver mapping <lab>/wt -> <lab>/wsA
  • Live: fm_nm_run &lt;wt&gt; runs|daemon status|axi status --run and fm_nm_state_db &lt;wt&gt;, with and without config/nm-home-resolver, using the real no-mistakes CLI (drive.sh)
  • Live: explicit NM_HOME=&lt;lab&gt;/explicit with the resolver configured; resolver call count recorded
  • Live: out-of-scope fm_nm_run &lt;wt&gt; daemon stop with the resolver configured; wsA daemon status checked afterwards
  • Live: resolver that fails (exit 3), prints a missing dir, prints a relative path, or prints two lines; config naming a relative path
  • Live: bin/fm-crew-state.sh labtask and bin/fm-pipeline-spend.sh record labtask against the lab FM_HOME, resolver off vs on
  • Live: fm_nm_run_bounded &lt;wt&gt; 30 axi abort --run 01LABRUNPARK, resolver off vs on, against the real wsA daemon
  • Live: wsA daemon stopped, then axi / axi status / runs / daemon status / axi logs run through the resolver; daemon status and process count checked afterwards
✅ **Document** - passed

✅ No issues found.

🔧 **Lint** - 1 issue found → no changes applied ✅
  • ⚠️ linter found issues (exit code 1)

🔧 No changes applied.
✅ Re-checked - no issues remain.

✅ **Push** - passed

✅ No issues found.

Fixes #7309

Sites that run one no-mistakes daemon per isolated workspace keep each
task's runs in a per-workspace NM_HOME that cannot be derived from the
shared gate remote, so crew state, pipeline spend, and teardown read the
wrong home.

When NM_HOME is unset and config/nm-home-resolver names a site-provided
executable, fm-nm-run-lib.sh now calls it with the task copy path and
exports the printed home for that one call. Only host reads (axi status,
the axi overview, axi logs, runs, daemon status, the state database) and
axi abort --run use it. An explicit NM_HOME always wins, and with no file
behaviour is unchanged.

Fixes kunchenguid#7309
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @rchristensen — tip 465c2c32 reviewed against main 9b1ada04 (5 files, +246/-5) for issue #7309.

Contract-class: opt-in (my own read). Unconfigured path is unchanged: with config/nm-home-resolver absent, or a non-absolute/non-executable first line, or a resolver that fails/times out/prints anything other than one existing absolute directory, every host read keeps ambient NM_HOME / ~/.no-mistakes. An explicit NM_HOME always wins. New surface is gated on a local gitignored config file naming a site-provided absolute executable, scoped to host reads and axi abort --run only.

VISION.md: one captain aligns; authority aligns (opt-in grant, never inferred); scripts own the resolver mechanics; restart aligns (no new durable obligation); delegation aligns; vendor-neutral; scope aligns (host no-mistakes reads only).

Security: no workflow/secret/network changes. Resolver runs only when configured, bounded to 5s, requires an existing absolute directory answer so a wrong path cannot plant a fresh home. Approved fork CI 38732359495 and no-mistakes 38734447822/38732359006.

Attestation: MATCH tip 465c2c32 (live go 9/10). CI just approved and is queued — when required checks are green this is auto-merge eligible as opt-in. One live scenario (teardown parked-run abort) remains portable-only; not a merge blocker given the adversarial live coverage.

@rchristensen

Copy link
Copy Markdown
Contributor Author

The 'Behavior portable serial 3' failure ('not ok - bootout did not stop the tracked worker' in tests/fm-remote-job-launchagent.test.sh) and the cancelled 'Behavior portable serial 2' shard look unrelated to this change: that test does not load bin/fm-nm-run-lib.sh or read NM_HOME, and it passes locally on this commit. Could a maintainer re-run those two jobs? Re-running from a fork needs repository admin rights.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @rchristensen — agreed, neither failure touches this diff. Behavior portable serial 2 hit the known 30-minute shard ceiling (#7255), and the serial 3 failure is the timing check right after the stub launchctl bootout in tests/fm-remote-job-launchagent.test.sh, which does not load bin/fm-nm-run-lib.sh. I re-ran the failed jobs of CI 38732359495 once. No new push since my last pass, so the opt-in verdict stands; when the required checks come back green this is on the auto-merge path.

@rchristensen

rchristensen commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Friendly ping on this one: it's the accepted opt-in from #7309 (per-workspace NM_HOME resolver for host reads and axi abort --run only), off by default with no behaviour change when unconfigured. It's the last upstream piece blocking our isolated no-mistakes rollout. Happy to rebase or whatever's needed to move this along

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks for the ping @rchristensen, and sorry this sat.

Nothing is needed from you — no rebase required (it is MERGEABLE against current main). Head 465c2c32 is unchanged; I re-read the diff and the verdict stands: contract-class: opt-in (with no config/nm-home-resolver, or an explicit NM_HOME, every no-mistakes read uses the ambient home exactly as before; the resolver only redirects host reads and axi abort --run). Closes #7309 verified from your body.

CI: the only red is Behavior portable serial 2, cancelled at the 30-minute job ceiling with every test that ran exiting 0 (tests/fm-supervision-host.test.sh alone took ~27 min) — the known #7255 ceiling, unrelated to this diff. Every other job, including the no-mistakes check, is green. I re-ran that job once more (attempt 4). If it comes back green this is on the auto-merge path; if the ceiling cancels it again, it goes to the captain as a land-despite-#7255 call rather than back to you.

@rchristensen

Copy link
Copy Markdown
Contributor Author

@kunchenguid are we on the auto-merge path? all looks green to me

@kunchenguid
kunchenguid merged commit bb57c8f into kunchenguid:main Oct 20, 2026
53 of 56 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @rchristensen — really appreciate you taking the time on this.