Skip to content

fix: parse decision verbs before status metadata tags - #2280

Merged
kunchenguid merged 3 commits into
mainfrom
fm/fm-remote-reply-decision-closer-fix-r1
Aug 12, 2026
Merged

kunchenguid merged 3 commits into
mainfrom
fm/fm-remote-reply-decision-closer-fix-r1

Conversation

@kunchenguid

Copy link
Copy Markdown
Owner

Intent

Bug fix in firstmate shared tracked material: the open-decisions fold mis-parses a remote-secondmate reply status line, so fm-send --resolve-key cannot close it. Root cause: status_line_verb() in bin/fm-classify-lib.sh only strips a leading [key=...] tag before the colon when isolating the verb word. A remote secondmate reply routinely prepends a [corr=...] correlation tag ahead of (or instead of) [key=...] - e.g. 'needs-decision [corr=d448ea86afa4bf67] [key=loan-installment-cadence-amount]: ...' - which the old parser did not strip, so the returned verb was contaminated ('needs-decision [corr=...]') and the fold's verb match silently failed to recognize the line as a decision at all, causing fm-send --resolve-key to wrongly refuse with 'no open decision with that key'. Fix: generalize status_line_verb to strip EVERY [name=value] tag before the colon (not just [key=...]) so the leading word returned is the bare verb (needs-decision/blocked/resolved/etc), regardless of how many bracketed tags precede the colon or their order. This is a fix to the ONE owner of this parser; no other place in the codebase duplicates single-tag-only stripping (_fm_key_before_colon, _fm_key_at_note_head, and _fm_decision_key already use substring/wildcard matching for [key=...] and are unaffected). Deliberately excluded: no remote-only send retry, no special remote closer path, no remote-vs-local branching - the shared parser is fixed so local and remote fold identically (transport-only difference principle). Required regression tests (added, all passing): tests/fm-classify-decision-key.test.sh gained cases driving the real status_line_verb/status_open_decisions functions for (1) a [corr=...] tag before [key=...] opening and closing under the stated key, (2) a corr-only tag opening under the 'default' key exactly like a bare needs-decision line, (3) a key-only tag (no corr) still opening correctly - no regression, and (4) blocked/resolved verbs parsing correctly regardless of bracket-tag order. tests/fm-send-resolve-key.test.sh gained an end-to-end test reproducing the exact reported remote-reply line and asserting fm-send --resolve-key now succeeds and closes it (previously it refused). All new tests were verified to fail against the pre-fix parser and pass after the fix. This is pure shell parser logic, not harness-dependent, so the portable tests/ regression suite is sufficient and no live-harness guard is needed. Delivery: mode=no-mistakes, yolo OFF - the captain (not this agent) must approve any ask-user finding and make the final merge decision. Note for the PR body: this touches the running open-decisions/supervision parsing surface, so fleet homes need a self-update after merge to pick up the fix.

What Changed

  • Strip all [name=value] metadata tags from status verbs, allowing correlation-tagged decisions to open and close correctly.
  • Bump the open-decisions fold version so existing cursors rebuild under the corrected parsing semantics.
  • Add regression coverage for tagged decision folding and fm-send --resolve-key; fleet homes should self-update after merge.

Risk Assessment

✅ Low: The shared parser fix is narrowly scoped, required behavioral regressions are covered, and the fold-version bump correctly invalidates stale persisted cursors.

Testing

Inspected the target diff, ran the three focused parser/send/cursor regression scripts, and reproduced the reported remote reply flow end-to-end: the corr-tagged decision surfaced, fm-send --resolve-key crossed the remote transport and exited successfully, appended the resolution locally, and disappeared from the open-decisions output.

Evidence: End-to-end remote corr-tag resolve-key CLI transcript
$ fm-wake-drain.sh  # before answering
OPEN DECISIONS (still open, folded from the durable status logs - not just the latest line):
rsm [key=loan-installment-cadence-amount] needs-decision: pick the cadence
OPEN DECISIONS: close one by answering it: bin/fm-send.sh <task> --resolve-key <key> '<answer>'

$ fm-send.sh rsm --resolve-key loan-installment-cadence-amount monthly
exit=0

$ remote transport invocation
-o ForwardAgent=no -o ClearAllForwardings=yes -o SendEnv=-* -o ServerAliveInterval=15 -o ServerAliveCountMax=3 -- remote-mac fm-remote-entrypoint.sh 1 L3JlbW90ZS9yb290 L3JlbW90ZS9ob21l Zm0tcmVtb3RlLXNlY29uZG1hdGUtY29udHJvbC5zaABzZW5kAHJzbQBbZm0tZnJvbS1maXJzdG1hdGVd4oGjY29ycj1lNWY2MjQ2YzBkMzZhMGYzIG1vbnRobHkA

$ persisted status ledger
needs-decision [corr=d448ea86afa4bf67] [key=loan-installment-cadence-amount]: pick the cadence
resolved [key=loan-installment-cadence-amount]: answered: monthly

$ fm-wake-drain.sh  # after answering
(no open decisions)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • 🚨 bin/fm-classify-lib.sh:189 - Changing status_line_verb changes fold semantics, but FM_OPEN_DECISIONS_FOLD_VERSION remains 3 at line 444. After upgrading, an existing v3 cursor already positioned past a corr-tagged decision is trusted with an empty open set, so incremental OPEN DECISIONS scans never reprocess or surface that decision. Bump the fold version and add a regression covering migration from a pre-fix cursor.

🔧 Fix: Invalidate stale decision cursors after parser fix
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-classify-decision-key.test.sh
  • bash tests/fm-send-resolve-key.test.sh
  • bash tests/fm-wake-drain-open-decisions-cursor.test.sh
  • Manual remote-secondmate fixture using real bin/fm-wake-drain.sh and bin/fm-send.sh rsm --resolve-key loan-installment-cadence-amount monthly with a stubbed SSH transport
  • Validated the evidence transcript contains the initially open keyed decision, successful exit, remote transport invocation, persisted resolution, and no remaining open decision
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…verb

status_line_verb only stripped a leading "[key=...]" token before the
colon, so a remote secondmate reply's leading "[corr=...]" correlation
tag stayed glued onto the returned verb word ("needs-decision
[corr=...]" instead of "needs-decision"). The open-decisions fold's
verb match then silently failed to recognize the line at all, so
fm-send --resolve-key refused to close a decision that was plainly
open on the status line.

Generalize the parser to strip every "[name=value]" tag before the
colon, in any order and count, so local and remote replies fold
identically.
@kunchenguid
kunchenguid merged commit b91016f into main Aug 12, 2026
13 checks passed
@kunchenguid
kunchenguid deleted the fm/fm-remote-reply-decision-closer-fix-r1 branch August 12, 2026 20:50
spirispark added a commit to spirispark/firstmate that referenced this pull request Aug 13, 2026