Repository navigation
fix(bin): fold decision keys written after the status colon - #3
Merged
Merged
Conversation
A worker that appends "needs-decision: [key=slug] ..." had its record
folded under "default": the key extractor only ever read the text before
the first colon, so a token in the note position was never seen. The
OPEN DECISIONS listing still advertised the slug, and fm-send
--resolve-key <slug> then refused it, leaving the answerer to guess.
Accept the token in either position and fold both under the same key,
strip a consumed note-position token so every consumer reads the same
note text, and route both positions through one slug validator. A
malformed token before the colon still voids the line; after the colon
the same bytes are ordinary prose and keep the "default" key.
The brief scaffold was the half that drifted: its rule 6 showed a bare
"needs-decision: {summary}" and mentioned [key=<slug>] only in passing
on the resolved line, never stating where the token goes when opening
one. It now states the canonical position explicitly.
Regression coverage drives the real fm-send and fm-wake-drain
executables over note-position, canonical, multi-key, and
already-resolved records.
digbycampbell
marked this pull request as draft
August 12, 2026 14:05
digbycampbell
marked this pull request as ready for review
August 12, 2026 22:58
This was referenced Aug 16, 2026
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 a defect where worker decision markers were recorded under the wrong key, so answering an escalation with 'fm-send.sh --resolve-key ' was rejected.
OBSERVED DEFECT (repeatedly, 2026-08-11 and 2026-08-12): a crewmate appends a status line such as 'needs-decision: [key=palette-review-gate] no-mistakes review parked with 2 ask-user findings'. status_open_decisions in bin/fm-classify-lib.sh folded that record under the key 'default' rather than 'palette-review-gate'. The OPEN DECISIONS listing therefore printed a key that 'bin/fm-send.sh --resolve-key palette-review-gate' then refused with 'no open decision or blocker with that key'; only '--resolve-key default' worked. Firstmate had to guess before every keyed answer. It cost three failed sends on one escalation and recurred on at least four tasks across two days. Clearing state/..open-decisions-cursor did not help, confirming the parse rather than the cursor fold.
ROOT CAUSE, reproduced before changing anything: _fm_decision_key read only , the text BEFORE the first colon. A '[key=...]' token written after the state prefix lands in the note and is never seen, so the line keeps the 'default' key. Proven with a before/after run of the real status_open_decisions against the HEAD version of the library and the fixed one.
REQUIRED SHAPE OF THE FIX (from the task): the brief scaffold and the classify library are two halves of one contract, so whichever is wrong must be fixed so they match, and if the scaffold's documented shape is the odd one out, say so rather than quietly changing worker instructions.
DIAGNOSIS AND DELIBERATE DECISIONS:
REGRESSION COVERAGE (required by the task, covering multi-key and already-resolved cases): tests/fm-send-resolve-key.test.sh gains test_note_position_key_folds_under_its_slug, which extends the existing file rather than adding a new runner and drives the REAL fm-send.sh and fm-wake-drain.sh executables over stubbed transports, never asserting implementation source bytes. It asserts that note-position records list under their own slugs, that a canonical-position record still works alongside them, that a note-position 'resolved: [key=...]' line closes its own decision, that the key token is not left duplicated inside the listed note, that --resolve-key is now ACCEPTED, that the historical wrong guess --resolve-key default is now refused before anything is sent, and that answering one key leaves the other records untouched.
VERIFICATION ALREADY DONE: 8 affected suites green with zero failures (fm-brief, fm-crew-state, fm-decision-hold-lifecycle, fm-fleet-snapshot-view, fm-pending-reply, both fm-wake-drain-open-decisions suites, fm-send-resolve-key). ShellCheck is not installed on this host so bin/fm-lint.sh could not run locally and CI is relied on for lint parity.
CONSTRAINTS: this is firstmate's own shared tracked material, so firstmate-coding-guidelines applies - one sentence per line in tracked Markdown, plain dashes not em dashes, shellcheck-clean shell, contracts stated once with cross-references rather than restatements, and no agent name as a commit co-author. Delivery is this repo's own no-mistakes pipeline and PR path. The PR must remain a DRAFT: the captain previews and merges queued PRs one at a time and firstmate owns the readiness queue, so it must not be marked ready for review.
What Changed
_fm_decision_keyinbin/fm-classify-lib.shnow accepts a[key=<slug>]token either between the verb and the colon (canonical) or as the first token of the note, so a line likeneeds-decision: [key=palette-review-gate] ...folds under its own slug instead ofdefault; both positions route through a new single_fm_decision_key_leadingslug validator, andstatus_line_notestrips a consumed note-position token so every consumer reads the same note text. A malformed token before the colon still voids the line, while after the colon it is left as prose - documented in the library header - andFM_OPEN_DECISIONS_FOLD_VERSIONbumps to 3 so existing cursors refold.bin/fm-brief.shnow states the canonical key position explicitly (needs-decision [key=<slug>]: {summary}/blocked [key=<slug>]: {why}), which the scaffold previously only mentioned for theresolvedline.tests/fm-send-resolve-key.test.shgainstest_note_position_key_folds_under_its_slug, driving the realfm-send.shandfm-wake-drain.shover stubbed transports to assert note-position records list under their own slugs alongside a canonical-position record, that a note-positionresolved:line closes its own decision, that the token is not duplicated in the listed note, that--resolve-key <slug>is accepted while--resolve-key defaultis refused, and that answering one key leaves the others untouched.Risk Assessment
✅ Low: The parser change is small, backward-compatible (malformed and mid-note tokens still fall back to "default"), routes both positions through one slug validator, the reserved-namespace vocabulary check still holds under the new note stripping, the fold version is now bumped to 3 so persisted cursors refold, and the new test drives the real fm-send/fm-wake-drain executables rather than asserting source text.
Testing
Reproduced the reported defect end to end before touching anything: with the base library, the crewmate line
needs-decision: [key=palette-review-gate] ...listed with the token stuck inside the note and--resolve-key palette-review-gatefailed with "no open decision or blocker with that key" while--resolve-key defaultsucceeded. On the target commit the same transcript flips: the listing advertises[key=palette-review-gate], the keyed answer is delivered and appendsresolved [key=palette-review-gate]:, and--resolve-key defaultis now refused before any send. The new regression test in tests/fm-send-resolve-key.test.sh fails on the base library and passes on the fix, and all eight affected suites are green. This is a CLI/text surface with no rendered UI, so evidence is the CLI transcript plus the generated brief excerpt rather than a screenshot. Transientdata/t-demo/from the brief run was removed; the worktree is clean.Evidence: Before/after CLI transcript: OPEN DECISIONS listing and fm-send.sh --resolve-key
BEFORE (base 566d737) listing: palette needs-decision: [key=palette-review-gate] no-mistakes review parked with 2 ask-user findings fm-send.sh palette --resolve-key palette-review-gate -> exit=1 "no open decision or blocker with that key ... nothing was sent" fm-send.sh palette --resolve-key default -> exit=0, appends "resolved [key=default]: answered: guessing" AFTER (target 68afa0d) listing: palette [key=palette-review-gate] needs-decision: no-mistakes review parked with 2 ask-user findings fm-send.sh palette --resolve-key palette-review-gate -> exit=0, typed to the worker: "fix both findings, then continue", appends "resolved [key=palette-review-gate]: answered: fix both findings, then continue", OPEN DECISIONS now empty fm-send.sh palette --resolve-key default -> exit=1, refused before anything is sentEvidence: Generated crewmate brief, rule 6 (bin/fm-brief.sh output)
41: When more than one decision or blocker can be open at once, name yours: write the key between the state and the colon, asneeds-decision [key=<slug>]: {summary}orblocked [key=<slug>]: {why}.Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-classify-lib.sh:418- FM_OPEN_DECISIONS_FOLD_VERSION is still 2 even though this commit changes the fold semantics (_fm_decision_key / status_line_note now derive a different key and note for note-position lines). The persisted cursor at state/.<id>.open-decisions-cursor is only invalidated and refolded from offset 0 when the version differs, so every task that already has a cursor keeps its pre-fix records: 'needs-decision: [key=palette-review-gate] ...' stays folded under key 'default' with the token still embedded in the note, and fm-send.sh --resolve-key palette-review-gate keeps failing with 'no open decision or blocker with that key' until the worker appends a fresh line. That is exactly the observed defect for the in-flight escalations the intent cites. Bumping the constant to 3 makes the existing status history re-fold under the corrected parser.🔧 Fix: bump open-decisions fold version so cursors refold
2 infos still open:
tests/fm-send-resolve-key.test.sh:170- The assertiongrep -F '[key=default]' && fail "a note-position key was folded as default"can never fail: bin/fm-wake-drain.sh:56 only appends[key=$key]when the key is NOT default, so a record folded underdefaultprints with no key token at all. The regression is caught by the positive[key=palette-review-gate]greps above it, but this line reads as a guard and provides none. To actually assert the old behavior is gone, match the listing line for the record (e.g. that the line carrying "review parked with 2 findings" contains a[key=token) rather than searching for the string[key=default].bin/fm-classify-lib.sh:209- status_line_note strips a well-formed leading[key=...]unconditionally, including when the key already came from the canonical pre-colon position. Verified:needs-decision [key=a]: [key=b] textyields key=a and note="text" - the[key=b]bytes are silently dropped from the note even though they were never used as a key, while the header documents that a[key=...]appearing mid-note is left as prose. Harmless in practice (no writer emits that shape) and the current behavior is arguably the friendlier one, but the documented rule and the code diverge for this one input.✅ **Test** - passed
✅ No issues found.
bash tests/fm-send-resolve-key.test.sh(11 tests green, including the newtest_note_position_key_folds_under_its_slug)Regression proof: restoredbin/fm-classify-lib.shfrom base 566d737 and re-ran the same suite - the new test fails (the open listing should carry [key=palette-review-gate]), passes on 68afa0dbash tests/fm-brief.test.sh,tests/fm-crew-state.test.sh,tests/fm-decision-hold-lifecycle.test.sh,tests/fm-fleet-snapshot-view.test.sh,tests/fm-pending-reply.test.sh,tests/fm-wake-drain-open-decisions.test.sh,tests/fm-wake-drain-open-decisions-cursor.test.sh- all greenManual end-to-end CLI transcript with the exact reported status line, driving the realbin/fm-wake-drain.shandbin/fm-send.shover a stubbed tmux transport, run against the base library and the fixed onebash bin/fm-brief.sh t-demo firstmate --mode no-mistakesand inspected rule 6 of the generated brief✅ **Document** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.