Skip to content

fix(bin): name a consumed branch grant instead of a wiring bug - #7969

Merged
kunchenguid merged 2 commits into
kunchenguid:mainfrom
c6aw:fm/report-upstream-fm-branch-snapshot-msg
Oct 30, 2026
Merged

kunchenguid merged 2 commits into
kunchenguid:mainfrom
c6aw:fm/report-upstream-fm-branch-snapshot-msg

Conversation

@c6aw

@c6aw c6aw commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Every 'no branch-eligible row snapshot' refusal in this home was the supervision branch re-running its own successful, silent acknowledgement; the first acknowledgement had already removed the rows file, and nothing was lost. bin/fm-wake-drain.sh treats a missing rows file with a live owner as a wiring bug and says so. Wanted upstream: a message-only fix with one test: when the owner record is live but the rows file is gone, say the grant was already consumed, not that wiring is broken.

What Changed

  • bin/fm-wake-drain.sh: require_branch_eligible_rows still refuses when the branch-eligible snapshot is missing or empty. If the rows file is gone (not even a dangling symlink) and the branch owner record still matches, it now says the branch's grant was already consumed by its acknowledgement and must not be acknowledged again. Every other case keeps the old "no branch-eligible row snapshot" error. The exit status is the same, and the comment above the function now covers both cases.
  • tests/fm-wake-queue.test.sh: a new test activates a branch owner, publishes a grant, drains and acknowledges once, and then acknowledges again. It checks that the repeat acknowledgement still fails, that its error says "already consumed", and that it does not blame wiring.
  • docs/watcher-continuity.md: the refusal paragraph now separates a grant already consumed (live owner) from a real wiring bug.

Risk Assessment

✅ Low: Only the message changes: every path that refused before still refuses with exit 1. The new wording appears only when the rows file is missing and the owner record still matches a live process, which is exactly the state a full branch acknowledgement leaves behind, because write_rows_file_locked removes the emptied rows file and keeps the owner file.

Testing

I ran the real wake-drain and wake-grant CLIs against throwaway state directories. A repeat branch ack or drain with a live owner now gets the new "grant was already consumed" message and still exits 1. A dead owner, no owner record, an empty rows file and a dangling symlink all keep the generic refusal. Three repeat refusals left every state file byte-identical. The base commit gave the old generic message in the same scenario, and the new regression test passes. No UI surface is involved, so the evidence is CLI transcripts. One note: the "state dir changed" line in transcript.txt is noise from my own script listing the parent directory. The byte-level check in state-check.txt replaces it.

  • Live validation: ✅ go - 7 of 7 scenarios driven live against the product
Scenario Result Live Evidence
A branch repeats its acknowledgement after its first ack consumed the grant: refused with exit 1 and told the grant was already consumed, with no blame on wiring ✅ pass live transcript.txt S1/S4 (new message, exit 1); base-transcript.txt shows the old generic message for the same steps
The first branch drain and ack still succeed and remove the rows file ✅ pass live transcript.txt S1/S4: drain exit 0, ack exit 0, rows file no longer present
A repeat plain branch drain (no ack) with a live owner and the rows file gone gets the consumed-grant message ✅ pass live transcript.txt S2
Repeat refusals change no state, and the row that was never granted is still left for the main actor ✅ pass live state-check.txt: three repeat acks each exit 1, all state files byte-identical, main drain returns seq 2
Adversarial: owner process dead and rows file gone gives the generic refusal, not the consumed-grant message ✅ pass live transcript.txt S3
Adversarial: no owner record at all (run outside the handoff) gives the generic refusal ✅ pass live transcript.txt S5
Adversarial: live owner but the rows file is empty, or is a dangling symlink, gives the generic refusal ✅ pass live transcript.txt S6 and S6b
Evidence: Live CLI transcript of all scenarios (new code)

Source: Live CLI transcript of all scenarios (new code)

== S1/S4: first branch drain + ack succeed, repeat ack names consumed grant
1793310582	1	signal	task-a.status	signal: task-a
[drain exit 0]
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 1925646.1793310582.Vq8ery
$ env FM_STATE_OVERRIDE=/tmp/tmp.J2w045dGrZ/state FM_SUPERVISION_ACTOR=branch ~/.no-mistakes/worktrees/<repo-id>/01M64T5QWRTRAZ2FD4W6NAX3B4/bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 1925646.1793310582.Vq8ery
[exit 0]
rows file present after first ack? no
$ env FM_STATE_OVERRIDE=/tmp/tmp.J2w045dGrZ/state FM_SUPERVISION_ACTOR=branch ~/.no-mistakes/worktrees/<repo-id>/01M64T5QWRTRAZ2FD4W6NAX3B4/bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 1925646.1793310582.Vq8ery
wake drain: this branch's grant was already consumed by its acknowledgement; nothing is left to drain or acknowledge, so do not acknowledge again
[exit 1]
== S2: repeat plain branch drain with live owner, rows gone
$ env FM_STATE_OVERRIDE=/tmp/tmp.J2w045dGrZ/state FM_SUPERVISION_ACTOR=branch ~/.no-mistakes/worktrees/<repo-id>/01M64T5QWRTRAZ2FD4W6NAX3B4/bin/fm-wake-drain.sh
wake drain: this branch's grant was already consumed by its acknowledgement; nothing is left to drain or acknowledge, so do not acknowledge again
[exit 1]
state dir changed:
3c3
< drwx------ 3 <user> <user> 100 Oct 29 16:49 ..
---
> drwx------ 3 <user> <user> 120 Oct 29 16:49 ..
== S3: owner dead, rows gone -> generic refusal
$ env FM_STATE_OVERRIDE=/tmp/tmp.J2w045dGrZ/state FM_SUPERVISION_ACTOR=branch ~/.no-mistakes/worktrees/<repo-id>/01M64T5QWRTRAZ2FD4W6NAX3B4/bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 1925646.1793310582.Vq8ery
wake drain: no branch-eligible row snapshot at /tmp/tmp.J2w045dGrZ/state/.branch-eligible-rows; refusing to guess what this actor may consume
[exit 1]
== S5: no owner record at all (outside handoff) -> generic refusal
$ env FM_STATE_OVERRIDE=/tmp/tmp.J2w045dGrZ/state2 FM_SUPERVISION_ACTOR=branch ~/.no-mistakes/worktrees/<repo-id>/01M64T5QWRTRAZ2FD4W6NAX3B4/bin/fm-wake-drain.sh
wake drain: no branch-eligible row snapshot at /tmp/tmp.J2w045dGrZ/state2/.branch-eligible-rows; refusing to guess what this actor may consume
[exit 1]
== S6: live owner, rows file exists but empty -> generic refusal
$ env FM_STATE_OVERRIDE=/tmp/tmp.J2w045dGrZ/state2 FM_SUPERVISION_ACTOR=branch ~/.no-mistakes/worktrees/<repo-id>/01M64T5QWRTRAZ2FD4W6NAX3B4/bin/fm-wake-drain.sh
wake drain: no branch-eligible row snapshot at /tmp/tmp.J2w045dGrZ/state2/.branch-eligible-rows; refusing to guess what this actor may consume
[exit 1]
== S6b: live owner, rows path is a dangling symlink -> generic refusal
$ env FM_STATE_OVERRIDE=/tmp/tmp.J2w045dGrZ/state2 FM_SUPERVISION_ACTOR=branch ~/.no-mistakes/worktrees/<repo-id>/01M64T5QWRTRAZ2FD4W6NAX3B4/bin/fm-wake-drain.sh
wake drain: no branch-eligible row snapshot at /tmp/tmp.J2w045dGrZ/state2/.branch-eligible-rows; refusing to guess what this actor may consume
[exit 1]
Evidence: Base-commit transcript showing the old generic message on a repeat ack

Source: Base-commit transcript showing the old generic message on a repeat ack

== S1/S4: first branch drain + ack succeed, repeat ack names consumed grant
1793310599	1	signal	task-a.status	signal: task-a
[drain exit 0]
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 1950099.1793310599.FvbPCu
$ env FM_STATE_OVERRIDE=/tmp/tmp.K9bJ0XSrr8/state FM_SUPERVISION_ACTOR=branch /tmp/tmp.ZO0ebrptdt/bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 1950099.1793310599.FvbPCu
[exit 0]
rows file present after first ack? no
$ env FM_STATE_OVERRIDE=/tmp/tmp.K9bJ0XSrr8/state FM_SUPERVISION_ACTOR=branch /tmp/tmp.ZO0ebrptdt/bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 1950099.1793310599.FvbPCu
wake drain: no branch-eligible row snapshot at /tmp/tmp.K9bJ0XSrr8/state/.branch-eligible-rows; refusing to guess what this actor may consume
[exit 1]
== S2: repeat plain branch drain with live owner, rows gone
$ env FM_STATE_OVERRIDE=/tmp/tmp.K9bJ0XSrr8/state FM_SUPERVISION_ACTOR=branch /tmp/tmp.ZO0ebrptdt/bin/fm-wake-drain.sh
Evidence: State files byte-identical across repeat refusals; un-granted row still available to main

Source: State files byte-identical across repeat refusals; un-granted row still available to main

first ack exit 0
repeat ack 1 exit 1
repeat ack 2 exit 1
repeat ack 3 exit 1
every state file byte-identical across repeat refusals
main drain still sees the un-granted row (seq 2):
2	signal	task-b.status	signal: task-b
Evidence: Targeted regression test output

Source: Targeted regression test output

ok - a branch-actor drain with no eligible-row snapshot refuses loudly instead of draining nothing
ok - a repeat branch acknowledgement after its own ack consumed the grant says the grant was already consumed
Evidence: Driver scripts

Source: Driver scripts

#!/usr/bin/env bash
# Drives bin/fm-wake-drain.sh against a disposable state dir.
set -u
R=$1; T=$(mktemp -d); S="$T/state"; mkdir -p "$S"
DRAIN="$R/bin/fm-wake-drain.sh"; GRANT="$R/bin/fm-wake-grant.sh"
app(){ FM_STATE_OVERRIDE="$S" bash -c '. "$1"; fm_wake_append "$2" "$3" "$4"' _ "$R/bin/fm-wake-lib.sh" "$@"; }
run(){ echo "\$ $*"; "$@"; echo "[exit $?]"; }
sleep 600 & OWNER=$!
echo "== S1/S4: first branch drain + ack succeed, repeat ack names consumed grant"
app signal task-a.status "signal: task-a"
FM_STATE_OVERRIDE="$S" "$GRANT" activate "$OWNER" g1
FM_STATE_OVERRIDE="$S" "$GRANT" publish g1 1
FM_STATE_OVERRIDE="$S" FM_SUPERVISION_ACTOR=branch "$DRAIN" 2>"$T/e"; echo "[drain exit $?]"; cat "$T/e"
seq=$(sed -n 's/^WAKE_ACK_REQUIRED:.*--ack-through \([0-9]*\) --recovery-generation .*/\1/p' "$T/e")
gen=$(sed -n 's/^WAKE_ACK_REQUIRED:.*--recovery-generation \([A-Za-z0-9._-]*\)$/\1/p' "$T/e")
run env FM_STATE_OVERRIDE="$S" FM_SUPERVISION_ACTOR=branch "$DRAIN" --ack-through "$seq" --recovery-generation "$gen"
echo "rows file present after first ack? $( [ -e "$S/.branch-eligible-rows" ] && echo yes || echo no )"
ls -la "$S" > "$T/before"
run env FM_STATE_OVERRIDE="$S" FM_SUPERVISION_ACTOR=branch "$DRAIN" --ack-through "$seq" --recovery-generation "$gen"
echo "== S2: repeat plain branch drain with live owner, rows gone"
run env FM_STATE_OVERRIDE="$S" FM_SUPERVISION_ACTOR=branch "$DRAIN"
ls -la "$S" > "$T/after"; diff <(awk '{print $NF,$5}' "$T/before") <(awk '{print $NF,$5}' "$T/after") >/dev/null && echo "state dir unchanged by refusals: yes" || { echo "state dir changed:"; diff "$T/before" "$T/after"; }
echo "== S3: owner dead, rows gone -> generic refusal"
kill "$OWNER"; wait "$OWNER" 2>/dev/null
run env FM_STATE_OVERRIDE="$S" FM_SUPERVISION_ACTOR=branch "$DRAIN" --ack-through "$seq" --recovery-generation "$gen"
echo "== S5: no owner record at all (outside handoff) -> generic refusal"
S2="$T/state2"; mkdir -p "$S2"; app2(){ :; }
FM_STATE_OVERRIDE="$S2" bash -c '. "$1"; fm_wake_append signal k "p"' _ "$R/bin/fm-wake-lib.sh"
run env FM_STATE_OVERRIDE="$S2" FM_SUPERVISION_ACTOR=branch "$DRAIN"
echo "== S6: live owner, rows file exists but empty -> generic refusal"
sleep 600 & O2=$!
FM_STATE_OVERRIDE="$S2" "$GRANT" activate "$O2" g2
: > "$S2/.branch-eligible-rows"
run env FM_STATE_OVERRIDE="$S2" FM_SUPERVISION_ACTOR=branch "$DRAIN"
echo "== S6b: live owner, rows path is a dangling symlink -> generic refusal"
rm -f "$S2/.branch-eligible-rows"; ln -s "$T/nowhere" "$S2/.branch-eligible-rows"
run env FM_STATE_OVERRIDE="$S2" FM_SUPERVISION_ACTOR=branch "$DRAIN"
FM_STATE_OVERRIDE="$S2" "$GRANT" deactivate "$O2" g2; kill "$O2"; wait "$O2" 2>/dev/null
rm -rf "$T"

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ℹ️ tests/fm-wake-queue.test.sh:1966 - The negative assertion grep -q &#34;wiring&#34; can never fail: neither the old refusal text ('no branch-eligible row snapshot ... refusing to guess what this actor may consume') nor the new one contains the word 'wiring'. The test still fails before the fix and passes after it, because of the 'already consumed' check, so this extra assertion adds nothing. If a negative check is wanted, it should look for the old message's text ('no branch-eligible row snapshot').
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 7 of 7 scenarios driven live against the product
Scenario Result Live Evidence
A branch repeats its acknowledgement after its first ack consumed the grant: refused with exit 1 and told the grant was already consumed, with no blame on wiring ✅ pass live transcript.txt S1/S4 (new message, exit 1); base-transcript.txt shows the old generic message for the same steps
The first branch drain and ack still succeed and remove the rows file ✅ pass live transcript.txt S1/S4: drain exit 0, ack exit 0, rows file no longer present
A repeat plain branch drain (no ack) with a live owner and the rows file gone gets the consumed-grant message ✅ pass live transcript.txt S2
Repeat refusals change no state, and the row that was never granted is still left for the main actor ✅ pass live state-check.txt: three repeat acks each exit 1, all state files byte-identical, main drain returns seq 2
Adversarial: owner process dead and rows file gone gives the generic refusal, not the consumed-grant message ✅ pass live transcript.txt S3
Adversarial: no owner record at all (run outside the handoff) gives the generic refusal ✅ pass live transcript.txt S5
Adversarial: live owner but the rows file is empty, or is a dangling symlink, gives the generic refusal ✅ pass live transcript.txt S6 and S6b
  • ~/.no-mistakes/evidence/01M64T5QWRTRAZ2FD4W6NAX3B4/drive.sh &lt;worktree&gt;: ran the real fm-wake-grant.sh and fm-wake-drain.sh on a throwaway state directory. Covered: first drain and ack, a repeat ack, a repeat plain drain, a dead owner, no owner record, an empty rows file, and a dangling rows symlink.
  • state-check.sh &lt;worktree&gt;: hashed every state file before and after three repeat acks, then checked that the main actor still drains the row that was never granted.
  • Ran drive.sh against the base commit b936f040 in a temporary detached worktree (removed afterwards) to confirm the old message.
  • test_branch_actor_without_eligible_snapshot_refuses and test_branch_repeat_ack_after_consumed_grant_names_the_consumed_grant from tests/fm-wake-queue.test.sh, run alone with a temporary runner that was then deleted.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

c6aw and others added 2 commits October 29, 2026 16:48
When a supervision branch's own acknowledgement consumes every granted
row, the drain removes the branch-eligible row snapshot while the owner
record stays live. A repeat drain or acknowledgement in the same turn then
refused with a message implying a broken handoff. Say instead that the
grant was already consumed; the refusal and its exit status are unchanged.
@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge; the new message preserves the existing refusal behavior.

Reviews (1) · Last reviewed commit: "no-mistakes(document): Document consumed..." · Reviewed by Greptile

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @c6aw. This is a small, careful fix, and the field note in the intent made the cause easy to verify.

Review: I read the tip 8ac93bef against main b936f040. require_branch_eligible_rows still refuses with exit 1 in every case it refused before. Only the message changes, and only when the rows file is truly absent (not a dangling symlink) and fm_wake_branch_owner_matches confirms a live owner. That helper is read-only, and that state is exactly what a full branch ack leaves behind. A dead owner, no owner, an empty file or a dangling symlink all keep the generic refusal. The new fm-wake-queue test checks that a repeat ack still fails, says "already consumed", and doesn't blame wiring. The docs match. There are no workflow, network or credential changes.

Gates: coverage guard, repo invariants and the no-mistakes check pass. The attestation binds 8ac93bef with every step completed. Greptile is 5/5 with no open threads. Live CLI evidence is posted (7/7, including adversarial cases and byte-identical state after repeat refusals).

Next: the only thing left is the Full suite check. It runs for outside PRs only after we add the full-ci label. That's on us, and nothing here is waiting on you. If it passes on this head and stays clean, this can go in as a restore.

VISION: aligns with every rule. The interface stays honest: a consumed grant no longer gets reported as a wiring bug, which was noise that sent the first mate looking for a fault that wasn't there. The refusal path is unchanged and still fails loudly. A script owns the distinction, with no new surface, layer or default. It's vendor-neutral and in scope.
contract-class: restore. The default refusal holds exactly as before (same cases, same exit), and its diagnosis now matches what the drain actually did. There's no new path or default-on surface.

@kunchenguid kunchenguid added the full-ci Maintainer go-ahead: run the full CI suite on this outside pull request label Oct 30, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @c6aw. I re-checked every gate on head 8ac93bef against main 05196e30. Nothing has changed since my last note, so I've added the full-ci label and the full suite is now running (40992021376). Nothing is needed from you. If it passes, I'll merge this as a restore.

@kunchenguid
kunchenguid merged commit c0aa730 into kunchenguid:main Oct 30, 2026
31 of 32 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

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

trillium added a commit to trillium/firstmate that referenced this pull request Oct 30, 2026
…m commits on the branch (e.g. kunchenguid#7906, kunchenguid#7969, kunchenguid#7939) that don't fit this repo's base c12c102. The base's `fm-spawn.sh` already requires a backlog item to record its repo, and the upstream tests don't set one. That caused the failures across spawn, hooks and project capacity, plus lint and Full suite. I reset the working tree to c12c102 and re-applied only the herdr diff, so the staged change is now just `bin/backends/herdr.sh`, `docs/herdr-backend.md` and `tests/fm-backend-herdr.test.sh`. `fm-backend-herdr` and `fm-ci-workflow` pass locally. `fm-project-capacity` still fails on the base too, so it is not caused by this PR. I did not re-run the other failing shards or the lint jobs locally. Nothing is committed or pushed; the pipeline must commit this tree and push, because the branch history still contains the upstream commits
kesslerio pushed a commit to kesslerio/firstmate that referenced this pull request Oct 31, 2026
…enguid#7969)

* fix(bin): name a consumed branch grant instead of a wiring bug

When a supervision branch's own acknowledgement consumes every granted
row, the drain removes the branch-eligible row snapshot while the owner
record stays live. A repeat drain or acknowledgement in the same turn then
refused with a message implying a broken handoff. Say instead that the
grant was already consumed; the refusal and its exit status are unchanged.

* no-mistakes(document): Document consumed-grant refusal in watcher continuity doc

---------

Co-authored-by: c-c6aw <[email protected]>
nathanjgaul-agile added a commit to nathanjgaul-agile/firstmate that referenced this pull request Nov 2, 2026