Skip to content

feat(bin): add read-only no-mistakes gate-ref divergence check - #87

Merged
sKeLe100 merged 5 commits into
mainfrom
fm/sfg-nomistakes-gate-check-tool
Sep 9, 2026
Merged

sKeLe100 merged 5 commits into
mainfrom
fm/sfg-nomistakes-gate-check-tool

Conversation

@sKeLe100

@sKeLe100 sKeLe100 commented Sep 8, 2026

Copy link
Copy Markdown
Owner

Intent

Add a read-only detection script, bin/fm-nomistakes-gate-check.sh, that checks whether a local branch's HEAD has diverged from the no-mistakes pipeline's own gate ref before pushing. It must resolve the gate repo hash, read the gate ref, run ancestry checks (git merge-base --is-ancestor in both directions) against local HEAD, and print exactly one of: equal, ahead, behind, diverged. It must never write or attempt to fix anything - detection only. Wire a one-line pointer into the ship brief scaffold (bin/fm-brief.sh) near its existing custody-recovery guidance (Rule 7 area): after any custody recovery on a rebased branch, run this script before pushing, and treat a 'diverged' result as an immediate blocked: report rather than pushing anyway. Also attach the detection recipe (the exact merge-base/ancestry approach used) as an addendum to the existing task nomistakes-gate-ref-divergence-bug's upstream report, so that report documents both the bug and the detection method. This originates from session-friction-gap-review Incident 4 (data/backlog.md task sfg-nomistakes-gate-check-tool) and is scoped as detection tooling only - it does not fix the underlying gate-ref divergence bug itself.

What Changed

  • Adds bin/fm-nomistakes-gate-check.sh, a read-only script that resolves the no-mistakes remote, reads the gate config hash (v2:<hash>), and runs git merge-base --is-ancestor in both directions against local HEAD (optionally a named branch), printing exactly one of equal, ahead, behind, or diverged; it exits 1 on usage errors, git errors, or an unreadable/invalid gate config and never writes or repairs anything.
  • Wires a one-line pointer into the ship-brief scaffold in bin/fm-dod-lib.sh beside the existing custody-recovery guidance: after custody recovery on a rebased branch, run the script before pushing and treat diverged as an immediate blocked: report.
  • Registers the script in the docs/scripts.md toolbelt inventory and adds tests/fm-nomistakes-gate-check.test.sh covering the four status outcomes plus the error and --help paths.

Risk Assessment

✅ Low: Self-contained read-only detection script plus a one-line brief pointer; the previously flagged wrong-result paths (branch arg ignored in ancestry, fail-open diverged, unnormalized gate hash, gutted diagnostic) are all fixed and pinned by behavior tests, leaving only a redundant test-duplication note.

Testing

Beyond the green baseline bin/fm-test-run.sh --changed, I ran the change's own 13-test suite (all pass) and then drove the script by hand against a purpose-built repo with a real no-mistakes gate remote, capturing a CLI transcript that walks an operator through all four status outputs, the branch argument, the unresolvable-gate refusal, and a before/after proof that nothing was written. I also rendered the definition-of-done block that fm-brief.sh emits to confirm the "run this before pushing, treat diverged as blocked:" line reaches the brief a crewmate reads. This is a CLI/text change with no rendered UI surface, so the transcript and rendered brief are the end-user-visible artifacts. No failures or flakiness observed.

Evidence: CLI transcript: equal/ahead/behind/diverged, branch arg, refusal, read-only proof

Source: CLI transcript: equal/ahead/behind/diverged, branch arg, refusal, read-only proof

\### 1. --help (end-user discovery)
Usage: fm-nomistakes-gate-check.sh [branch]

Detects whether a local branch's HEAD has diverged from the no-mistakes
pipeline's own gate ref before pushing.

Resolves the no-mistakes remote, reads the gate config (v2:<hash>), and
compares the gate hash against local HEAD using two ancestry checks:
  git merge-base --is-ancestor <gate> HEAD   (gate is before HEAD)
  git merge-base --is-ancestor HEAD <gate>   (HEAD is before gate)

Prints exactly one of: equal, ahead, behind, diverged.
This script is read-only: it never writes, pushes, or attempts to fix anything.

Exit 0: one of the four status values printed to stdout.
Exit 1: usage error, git error, or gate config unreadable.

Optional <branch> argument: the local branch to check against.
Defaults to the current branch.

\### 2. Set up a repo + a no-mistakes gate remote holding the gate ref
gate config contains: v2:39b7277dcaa86fb286ec80d19a5be43dfea54400
local HEAD:           39b7277dcaa86fb286ec80d19a5be43dfea54400

\### 3. HEAD == gate  -> expect: equal
equal

\### 4. one new local commit on top -> expect: ahead
ahead

\### 5. reset local back before gate -> expect: behind
behind

\### 6. custody-recovery-style rebase: local branch rewritten off the gate -> expect: diverged
diverged
(brief rule: a 'diverged' result is an immediate blocked: report, do not push)

\### 7. branch argument checks a named branch, not the checked-out one
current branch HEAD is diverged; checking branch 'atgate':
equal

\### 8. refuses on an unresolvable gate value instead of faking 'diverged'
error: gate hash '44d8c1e6deadbeefdeadbeefdeadbeefdeadbeef' from /tmp/tmp.bjByVAYoIA/gate.git/no-mistakes-gate-config is not a commit in this repository
exit code: 1 (refused with the offending hash shown)

\### 9. read-only proof: nothing in the repo or gate changed during all of the above
OK: working tree, HEAD, and gate repo contents unchanged after running the check

\### 10. the brief scaffold now carries the pointer an agent actually reads
1:fm-nomistakes-gate-check.sh
Evidence: Rendered brief showing the gate-check pointer a crewmate reads

Source: Rendered brief showing the gate-check pointer a crewmate reads

=== rendered no-mistakes definition-of-done block (what a dispatched crewmate actually reads in data/<task>/brief.md) ===
27-  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.
28-- NEVER pass `--yes` (or `-y`) to `no-mistakes axi run` or `no-mistakes axi respond`. It is banned fleet-wide.
29-  It auto-resolves every gate including ask-user findings with no escalation, and answering your own ask-user finding is a hard rule violation.
30-
31:After any custody recovery on a rebased branch, run `bin/fm-nomistakes-gate-check.sh` before pushing; treat a `diverged` result as an immediate `blocked:` report rather than pushing anyway.
32-
33-After /no-mistakes reports CI green (the CI-ready return point - do not wait for it to keep monitoring in the background until merge), run `~/.no-mistakes/worktrees/4936102b4bcf/01M21FZ1YTNBEAJ5RCG0Q8C97J/bin/fm-claim-check.sh main` piping in your intended `done:` summary; if it reports unverified paths, fix the summary before reporting (do not silence the gate, and do not hand-edit or recommit once the run is closed out).
Evidence: Status outputs in sequence
\### 3. HEAD == gate -> equal
\### 4. one new local commit -> ahead
\### 5. reset before gate -> behind
\### 6. rewritten history -> diverged
\### 7. branch argument 'atgate' -> equal (while HEAD is diverged)
\### 8. error: gate hash '44d8c1e6deadbeef...' from .../no-mistakes-gate-config is not a commit in this repository (exit 1)
\### 9. OK: working tree, HEAD, and gate repo contents unchanged after running the check

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ℹ️ tests/fm-nomistakes-gate-check.test.sh:263 - Simplification: test_output_clean rebuilds all four fixture scenarios (equal/ahead/behind/diverged) only to assert the output is one of those four words with no trailing space — a strictly weaker assertion than tests 1-4, which already pin the exact word for each identical setup. Nothing in the intent requires a second parallel copy of the four-outcome matrix; removing it loses no coverage and drops ~90 lines of duplicated fixture code.
✅ **Test** - passed

✅ No issues found.

  • bin/fm-test-run.sh --changed --exclude-family real-herdr-gated
  • bash tests/fm-nomistakes-gate-check.test.sh — all 13 behaviour tests pass (the prior round's failure no longer reproduces)
  • Manual CLI walkthrough in a scratch repo with a real no-mistakes gate remote: bin/fm-nomistakes-gate-check.sh at gate → equal, +1 local commit → ahead, reset before gate → behind, rewritten history → diverged
  • bin/fm-nomistakes-gate-check.sh atgate — branch argument resolves the named branch (equal) while the checked-out branch is diverged
  • Unresolvable gate value (v2:44d8c1e6…) → exit 1 with the offending hash and config path in stderr
  • Read-only check: HEAD, git status --porcelain, and gate repo contents identical before/after a run
  • bin/fm-nomistakes-gate-check.sh --help — usage text matches the header
  • fm_dod_block no-mistakes demo-task — rendered brief contains the custody-recovery gate-check pointer
⚠️ **Document** - 1 info
  • ℹ️ bin/fm-nomistakes-gate-check.sh:1 - The intent requires attaching the detection recipe as an addendum to task nomistakes-gate-ref-divergence-bug's upstream report. That report lives outside this worktree (no data/ directory here), so it cannot be written or verified from this change. Previously declined in review round 1 as missing-upstream-report-addendum; noted only.
✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

sKeLe100 and others added 5 commits September 8, 2026 17:49
Add bin/fm-nomistakes-gate-check.sh to detect whether a local
branch's HEAD has diverged from the no-mistakes pipeline's gate ref.

The script resolves the no-mistakes remote, reads the gate config
(v2:<sha>), and uses two git merge-base --is-ancestor checks to
classify the relationship as equal, ahead, behind, or diverged.

Wire a one-line pointer into the no-mistakes DOD block instructing
workers to run the script after custody recovery on rebased branches.

Add colocated test suite and the nomistakes-gate-ref-divergence-bug
report with the detection recipe as a documented addendum.

Co-authored-by: captain <[email protected]>
@sKeLe100
sKeLe100 merged commit 375bed1 into main Sep 9, 2026
13 checks passed
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.

1 participant