Skip to content

fix(bin): honor decision keys after the verb colon - #2202

Merged
kunchenguid merged 1 commit into
mainfrom
fm/fm-status-key-colon-parse-fix-r1
Aug 11, 2026
Merged

kunchenguid merged 1 commit into
mainfrom
fm/fm-status-key-colon-parse-fix-r1

Conversation

@kunchenguid

Copy link
Copy Markdown
Owner

Intent

Fix firstmate GitHub issue #2109: status decision keys silently collapse to 'default' when the [key=X] token follows the verb colon. The open-decisions key parser in bin/fm-classify-lib.sh (status_open_decisions and its incremental cursor-backed variant status_open_decisions_incremental) only recognized a key in the documented position 'needs-decision [key=X]: ...' (token before the verb colon). A worker writing 'needs-decision: [key=X] ...' (token after the colon) had its stated key silently parsed as 'default' - a shared bucket - so two open decisions on one task collapsed into one record, an answer could close the wrong record, and bin/fm-send.sh --resolve-key X refused with 'no open decision or blocker with that key'. Observed live on independent claude and codex tasks, so the misplaced-colon shape is common worker output. Chosen behavior, per the issue's stated preference: accept ': [key=]' as an EQUIVALENT form - extract the stated key correctly regardless of its position relative to the verb colon (silently rewriting a stated key to 'default' is the unsafe option and must end). Requirements carried from the task: (1) both status_open_decisions AND status_open_decisions_incremental must agree - the fix goes through the shared single-owner key extractor (_fm_decision_key) feeding the one fold rule (_fm_decision_fold_line) so the incremental cursor path cannot diverge from the full fold, and FM_OPEN_DECISIONS_FOLD_VERSION is bumped (2->3) so persisted cursors folded under the old interpretation are discarded and rebuilt from byte 0 as that constant's contract requires; (2) the same position-robust extraction applies symmetrically to 'resolved [key=X]:' / 'blocked [key=X]:' (and captain-held and the activities fold) so an answer closes the right record from either position; (3) a genuinely keyless line keeps its meaning - bare 'needs-decision:' with no [key=...] still folds to 'default'. Deliberate scoping decisions: only a complete [key=] token at the HEAD of the note (immediately after the first colon, ignoring leading whitespace) states a key - a token deeper inside the note is prose, so a summary merely mentioning '[key=x]' cannot open or close that decision; when both positions carry a token the documented before-colon position wins and the note-head token stays note text; a consumed note-head token is stripped from the note so both positions yield byte-identical fold records (this also keeps the reserved-key namespace vocabulary check in _fm_decision_key_transition_allowed working symmetrically); a stated-but-malformed slug (charset violation in a complete token) is rejected in both positions exactly like the pre-existing before-colon behavior - the folds skip the line - never silently rewritten to 'default'. The documented before-colon form remains the canonical taught form (briefs and fm-send still write it); the note-head form is parser tolerance. Regression tests are required to be behavioral through the real functions, never source-text asserts: new tests/fm-classify-decision-key.test.sh sources the real lib and covers the documented before-colon form -> X, the colon-first form -> X (the fixed case), bare keyless -> default (unchanged, open and close), resolved/blocked symmetry in both positions including cross-position open/close, two colon-form decisions staying distinct and independently closable, mid-note prose mentions not hijacking keys, malformed stated keys rejected in both positions, and the incremental path matching the full fold on the same input including across appends; it is registered in bin/fm-test-run.sh's pure-contract-unit family. One end-to-end case was also added to tests/fm-send-resolve-key.test.sh pinning the exact reported symptom: a colon-first open is listed under its stated key and fm-send --resolve-key answers and closes it. Acceptance criteria: no silent collapse of a stated key; bin/fm-lint.sh clean (it covers bin/.sh and tests/.sh); minimal focused diff (bin/fm-classify-lib.sh, bin/fm-test-run.sh family registration, the two test files). Delivery: this no-mistakes run must reach a PR with genuinely green CI; yolo is OFF - the captain merges, no self-merge.

What Changed

  • Accept complete [key=<slug>] tokens immediately after the verb colon while preserving the canonical before-colon form and keyless default behavior.
  • Keep key extraction consistent across full and incremental decision folds, reject malformed stated keys, and bump the persisted fold version to rebuild stale cursors.
  • Add behavioral unit and end-to-end coverage for position-tolerant opening, closing, and fm-send --resolve-key handling.

Risk Assessment

✅ Low: The focused shared-parser change satisfies the stated invariants, keeps full and incremental folds aligned, bumps persisted fold state, and adds behavioral regression coverage without a substantiated source defect.

Testing

After inspecting the focused diff and clean worktree baseline, targeted parser, fm-send, and cursor-rebuild tests passed; manual checks confirmed captain-held/activity symmetry and an end-to-end colon-first decision was listed under its stated key, answered successfully, persisted as resolved, and disappeared from OPEN DECISIONS. CLI transcript evidence was captured; no visual screenshot was applicable.

Evidence: Colon-first keyed decision listed, resolved through fm-send, and closed
=== Worker status (colon-first key) ===
needs-decision: [key=seam-max-bound] cap the seam at 4 or 8
=== Firstmate OPEN DECISIONS before answer ===
OPEN DECISIONS (still open, folded from the durable status logs - not just the latest line):
t2109 [key=seam-max-bound] needs-decision: cap the seam at 4 or 8
OPEN DECISIONS: close one by answering it: bin/fm-send.sh <task> --resolve-key <key> '<answer>'
=== Captain answers with fm-send --resolve-key seam-max-bound ===
exit=0
delivered-to-worker=cap it at 4
=== Persisted status ledger after answer ===
needs-decision: [key=seam-max-bound] cap the seam at 4 or 8
resolved [key=seam-max-bound]: answered: cap it at 4
=== Firstmate OPEN DECISIONS after answer ===
(none)

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.

  • bash tests/fm-classify-decision-key.test.sh
  • bash tests/fm-send-resolve-key.test.sh
  • bin/fm-test-run.sh tests/fm-classify-decision-key.test.sh tests/fm-send-resolve-key.test.sh
  • bash tests/fm-wake-drain-open-decisions-cursor.test.sh
  • Manual fold checks exercised colon-first captain-held, activity open/close symmetry, and canonical before-colon precedence when both positions contain keys.
  • Manual end-to-end fixture ran bin/fm-wake-drain.sh, then bin/fm-send.sh t2109 --resolve-key seam-max-bound &#39;cap it at 4&#39;, and drained again.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

The open-decisions fold only recognized a [key=<slug>] token between the
verb and the colon (needs-decision [key=x]: note). The common worker
shape with the colon first (needs-decision: [key=x] note) silently
folded its stated key into the shared "default" bucket, so two open
decisions could collapse into one record and fm-send --resolve-key <x>
refused to close the decision it plainly named.

A complete token at the head of the note is now an equivalent stated-key
position for every keyed verb, shared by the whole-file and incremental
folds through the one _fm_decision_key owner. The documented
before-colon position wins when both are present, a token deeper in the
note stays prose, a bare keyless line still folds to "default", and a
stated-but-malformed slug is rejected rather than rewritten to
"default". A consumed note-head token is stripped from the note so both
positions yield identical records, and the incremental fold version is
bumped so persisted cursors folded under the old interpretation are
rebuilt from the authoritative log.

Fixes #2109
@kunchenguid
kunchenguid merged commit 614fae6 into main Aug 11, 2026
13 checks passed
@kunchenguid
kunchenguid deleted the fm/fm-status-key-colon-parse-fix-r1 branch August 11, 2026 22:38
abhi-sama added a commit to abhi-sama/firstmate that referenced this pull request Aug 12, 2026
…y livelock fix) (#9)

* docs: add project vision (kunchenguid#1997)

* docs: add firstmate vision

* no-mistakes(test): Classify VISION.md as public product documentation

* no-mistakes(document): Restore approved one-file vision diff

* no-mistakes: apply CI fixes

* fix(spawn): force regular Pi TUI for crews (kunchenguid#2005)

* fix(spawn): force regular Pi TUI for crews

* no-mistakes(document): Documented Pi regular TUI launch mode

* fix(cmux): classify borderless Claude composers (kunchenguid#2029)

* fix(cmux): classify borderless Claude composer

* no-mistakes(review): Normalize cmux NBSP prompts across locales

* no-mistakes(document): Document cmux borderless Claude composer classification

* docs(stow): generalize read-before-write in the public stow skill (kunchenguid#2091)

The public installer-facing stow skill scoped its classify-then-replace
discipline to TODO/BACKLOG items only, so findings routed to a memory file
had no stated rule against a blind append or a wholesale overwrite.

Step 6 now classifies every finding against the destination's current
contents as new, duplicate, superseding, or obsolete, and states the
considered replacement each classification implies. The outcomes follow the
tiered-memory contract already in the file: an obsolete entry is refreshed,
archived, or replaced in a way that preserves its fact, a duplicate folds
into the entry that already carries it, and a superseded body worth keeping
leaves through step 7's existing exits rather than a second recovery
mechanism.

* fix: resurface durable supervision work after re-arm (kunchenguid#2065)

* fix(watcher): resurface durable work after downtime

* no-mistakes(review): Make watcher rearm recovery durable and cursor-safe

* no-mistakes(review): Persist safe recovery markers across migration lock recovery

* no-mistakes(review): Retain stale lock when recovery marker publication fails

* no-mistakes(review): Preserve delivery-gap recovery and quarantine malformed markers

* no-mistakes(review): Serialize recovery consumption and report acknowledgment failures

* no-mistakes(review): Centralize recovery publication before clearing watcher evidence

* no-mistakes(review): Guarantee recovery evidence across queue and lock handoffs

* no-mistakes(review): Publish recovery evidence before durable wake commits

* no-mistakes(review): Replace recovery marker Perl dependency with Node

* no-mistakes(review): Keep interrupted wakes durable until handling acknowledgment

* no-mistakes(review): Add post-handling durable wake acknowledgements

* no-mistakes(review): Enforce post-handling acknowledgement across recovery and AFK return

* no-mistakes(review): Bind wake acknowledgements to recovery generations

* no-mistakes(review): Align wake regressions with generation-bound acknowledgements

* no-mistakes(document): Document durable re-arm recovery semantics

* no-mistakes(lint): Resolve ShellCheck warnings in recovery and watcher tests

* no-mistakes: apply CI fixes

* test(watcher): assert post-handling wake replay

* no-mistakes(review): Prevent successor loops and adopt legacy wake generations

* no-mistakes(review): Rearm durable wakes without recursive successor recovery

* no-mistakes(review): Align recovery tests with handling marker state

* no-mistakes(review): Delay handling transition until successor launch is established

* no-mistakes(review): Confirm wake handling only after successful prompt delivery

* no-mistakes(review): Acknowledge AFK wakes only after evidence publication

* no-mistakes(review): Prevent AFK wake loss before post-handling acknowledgement

* no-mistakes(document): Document durable wake acknowledgement semantics

* no-mistakes(lint): Suppress false positive for recovery action output

* no-mistakes: apply CI fixes

* no-mistakes: apply CI fixes

* ci: measure Herdr automation on Windows runners (kunchenguid#2100)

* ci: add Windows Herdr automation spike

* ci: run Windows spike on its pull request

* fix: wait for Windows Herdr command output

* fix: run ANSI probe in pane shell

* ci: keep Windows Herdr spike manually triggered

* docs: clarify Windows Herdr spike verdict

* feat(ahoy): guide captains through open decisions (kunchenguid#2099)

* Add guided ahoy decision flow

* no-mistakes(document): Document guided Ahoy decision flow

* fix(stow): enforce startup-memory budget decisions (kunchenguid#2110)

* Harden stow memory budget policy

* Refine internal stow offload policy

* no-mistakes(review): Enforce shared-budget decisions and autonomous offload

* fix(spawn): refresh pooled worktrees from origin before launch (kunchenguid#2116)

* fix(spawn): refresh pooled worktree base

* no-mistakes(document): Document spawn base-freshness invariant

* no-mistakes: apply CI fixes

* fix(composer): unify safe classification across backends (kunchenguid#2102)

* refactor(composer): one shape owner behind thin capture adapters, whole matrix fixed

Consolidate every composer shape - bordered boxes (all families, geometry,
titled bottom borders), bare agent-glyph rows and their wrap regions,
opencode's left bar, and pi's identity-gated separator pair - into
fm_composer_classify_screen in bin/fm-composer-lib.sh. Adapters now
contribute only a capture and a declarative capability descriptor
(styled/cursor/identity/rows); capability differences change how confidently
a shape is judged, never what the shapes are, so a new harness shape is
teachable in exactly one place.

Correctness fixes landed as part of the consolidation (audit
data/fm-composer-consolidation-audit-s1):
- locale-safe Unicode-space normalization in the shared owner (closes the
  fleet-wide half of kunchenguid#1988; cmux's local byte-exact NBSP case deleted;
  naming converges with PR kunchenguid#1995's normalization primitive)
- muse's bare glyph joins the shared set, unbreaking muse on herdr/cmux/orca
- orca learns the borderless bare shape, drops its backward-paged composer
  window, and can no longer classify a stale startup banner as the composer
- tmux tolerates a titled bottom border, unbreaking grok steering
- the left-bar shape makes opencode readable on every backend
- zellij gets a real classifier through dump-screen --ansi, replacing the
  content-diff submit heuristic that could confirm an undelivered message
  and close a --resolve-key decision (the fleet's only false positive)
- fm-spawn's kimi launch-readiness regex (the fourth shape copy) now routes
  through the shared classifier

The strict blank-row posture applies fleet-wide (captain decision
blank-row-injection-posture): no positive container proof = unknown = defer,
replacing tmux's permissive blank-cursor-row rule. Away-mode injection was
re-validated end to end on real tmux (defer on partial input and unproven
rows, clean delivery with swallowed-Enter retry into proven-empty
composers). The tmux submit core gains a baseline-idle turn-started
conversion so pi steering stays confirmed while its working screen hides
the composer; busy conversion without that baseline remains forbidden.

Plain-capture backends now degrade a glyph row carrying trailing text to
unknown instead of a false pending, per the approved capability rule.

Portable regressions pin the full byte-capture matrix from the audit under
a UTF-8 locale and LC_ALL=C, the strict-vs-permissive divergence, and
deliberate signal separation; the opt-in live guard
(tests/fm-composer-matrix-live-e2e.test.sh) verified every installed
harness against the real classifier, recorded in
docs/verification/runtime-backends.md.

* no-mistakes(review): Fix Pi glyph ambiguity and complete profile matrix

* no-mistakes(review): Preserve bare verdict when Pi identity probe is absent

* no-mistakes(review): Harden composer structure and titled-border geometry

* no-mistakes(review): Require proven idle baseline and strict Zellij guard

* no-mistakes(review): Reject box bottom borders as composer input rows

* no-mistakes(review): Prove Zellij probe typing before classifier retries

* no-mistakes(review): Preserve Pi identity uncertainty and scan full left-bar drafts

* no-mistakes(review): Verify Zellij text lands before submitting

* no-mistakes(review): Scope Zellij typing verification to selected composer content

* no-mistakes(review): Verify Zellij pastes through composer-scoped content deltas

* no-mistakes(review): Prove wrapped bare Zellij pastes through composer extraction

* no-mistakes(review): Invalidate stale cursorless composers below dead shell prompts

* no-mistakes(review): Handle shell prompt placeholders in composer extraction

* no-mistakes(review): Classify cursorless bare continuation regions safely

* no-mistakes(review): Reject stale cursorless containers below live activity

* no-mistakes(review): Preserve prompt glyphs in wrapped Zellij pastes

* no-mistakes(review): Reject live shell rows during composer extraction

* no-mistakes(review): Preserve wrapped glyph continuations through submit retries

* no-mistakes(review): Scope idle placeholders to proven positions

* no-mistakes(review): Restore boxed placeholders and live prompt reanchoring

* no-mistakes(review): Fix Zellij placeholder and wrapped glyph paste proof

* no-mistakes(document): Align composer architecture documentation

* no-mistakes(lint): Fix ShellCheck warnings in composer refactor

* no-mistakes: apply CI fixes

* docs(verification): record the trusted-checkout live matrix rerun

The pipeline's isolated gate worktree is untrusted, so claude, grok, and
muse stopped at first-launch trust dialogs there (the guard refuses to
confirm them by design). This rerun from the trusted checkout at the final
validated head verified all six installed harnesses, the strict blank-row
deferral, and the hardened zellij false-positive probe live.

* no-mistakes(document): Align composer verification evidence

* no-mistakes: apply CI fixes

* no-mistakes(review): Restore proven box bottom-cursor classification

* no-mistakes(review): Preserve styled placeholder-like drafts as pending

* no-mistakes(document): Align composer safety and Zellij delivery documentation

* no-mistakes: apply CI fixes

* docs(verification): refresh the live matrix with the final-head trusted rerun

The post-validation rerun from the trusted checkout verified all six
installed harnesses at the branch's final head, including Claude 2.1.227
(auto-updated since the audit's captures) and Grok, which the untrusted
gate worktree could not verify past their first-launch trust dialogs.

* fix(spawn): gate Pi TUI mode by CLI capability (kunchenguid#2117)

* fix(spawn): gate Pi regular TUI flag by capability

* no-mistakes(review): Document conditional Pi TUI capability detection

* no-mistakes(review): Pin Pi probing and launch to one executable

* no-mistakes(review): Preserve literal pinned Pi paths and update documentation

* no-mistakes(review): Defer pinned Pi path insertion until final substitution

* no-mistakes(document): Document version-safe Pi launch probing

* no-mistakes: apply CI fixes

* no-mistakes: apply CI fixes

* docs(vision): elevate experience, pain narrative, and distro virtues (kunchenguid#2147)

* docs(vision): elevate experience, pain narrative, and distro virtues

Fold the captain's public vision framing into VISION.md: peace of mind as a
primary goal, multi-session context-switch pain as the problem one interface
solves, clone-and-run setup ease, self-evolution including community, and
explicit harness/backend orthogonality. Reconcile experience-as-garnish into
experience-as-purpose and update aligns/resists accordingly.

* docs(vision): state the experience goal positively

Drop the negative "not a smart workflow / useful tool / impressive technology"
pretext. Lead straight into the positive experience north star.

* feat(bin): reconcile inactive terminal crew outcomes (kunchenguid#2167)

* fix: reconcile inactive terminal outcomes

* fix: stream secondmate summary inputs

* no-mistakes(review): Fix reconciliation locking and request delivery retries

* no-mistakes(review): Prevent retries after unknown request delivery

* no-mistakes(document): Clarify inactive reconciliation cadence and receipts

* no-mistakes(lint): Quote terminal status arguments in reconciliation tests

* refactor: simplify inactive outcome reconciliation

* no-mistakes(review): Bound inactive reconciliation scans with durable progress

* no-mistakes(review): Bound reconciliation and deduplicate recovery notices

* no-mistakes(document): Document inactive outcome reconciliation contracts

* no-mistakes(review): Reject relative local secondmate parent routes

* no-mistakes(review): Key terminal receipts by spawn incarnation

* no-mistakes(review): Stabilize legacy receipts and lock reconciliation snapshots

* no-mistakes(review): Fail closed on invalid secondmate identity markers

* no-mistakes(document): Document durable inactive-outcome reconciliation

* no-mistakes: apply CI fixes

* no-mistakes: apply CI fixes

* no-mistakes: apply CI fixes

* ci: raise Herdr test timeout (kunchenguid#2191)

* fix: refresh stale Pi instructions after compaction (kunchenguid#2163)

* fix(session-start): refresh drifted instructions on stale rebuilds

* test(session-start): prove Pi instruction refresh end to end

* no-mistakes(review): Fix stale instruction refresh and baseline integrity

* no-mistakes(review): Preserve true-start baselines across Pi continuations

* no-mistakes(review): Correct Pi continuation classification and live expectation

* no-mistakes(review): Correct Pi continuation coverage documentation

* no-mistakes(review): Fix read-only refresh and exact Pi session restores

* no-mistakes(review): Classify Pi create-if-missing sessions correctly

* no-mistakes(review): Classify named Pi sessions using immutable headers

* no-mistakes(review): Correct Codex interactive coverage diagnostic

* no-mistakes(document): Document immutable Pi compaction instruction refresh

* no-mistakes(document): Correct Pi refresh documentation and validation claims

* feat: add deterministic condition-to-action watcher (kunchenguid#2200)

* feat(bin): add deterministic condition->action watch adapter on the process-event channel

Register a (condition, action) pair once with bin/fm-procevent-when.sh and the
existing process-to-event runner polls the condition tokenlessly, fires the
action at most once on a stable true, and wakes firstmate exactly once with the
captured outcome - instead of burning an agent turn per re-check.

The pair is stored privately under state/when/ and hash-bound by a trust record
the same way fm-check-register.sh binds a custom check, so a mutated spec is
refused without executing anything. A durable exclusive fired marker claimed
before the action makes restarts and re-polls unable to double-fire; every
failure path (mutated spec, condition error past budget, expired deadline,
failed action, uncaptured earlier fire) ends in a terminal captured outcome
that wakes firstmate rather than a silent retry. Eligibility stays a firstmate
judgment: only exact, safe, reversible actions may be bound, and judgment-
needing or destructive actions keep the wake-and-decide flow.

* no-mistakes(review): Harden when watcher concurrency, deadlines, timeouts, and output

* no-mistakes(test): Bind watcher actions to registered executable bytes

* no-mistakes(document): Correct condition-action watcher documentation

* no-mistakes(document): Clarify outcome wake re-announcement

* no-mistakes: apply CI fixes

* fix(bin): honor a decision key stated after the verb colon (kunchenguid#2202)

The open-decisions fold only recognized a [key=<slug>] token between the
verb and the colon (needs-decision [key=x]: note). The common worker
shape with the colon first (needs-decision: [key=x] note) silently
folded its stated key into the shared "default" bucket, so two open
decisions could collapse into one record and fm-send --resolve-key <x>
refused to close the decision it plainly named.

A complete token at the head of the note is now an equivalent stated-key
position for every keyed verb, shared by the whole-file and incremental
folds through the one _fm_decision_key owner. The documented
before-colon position wins when both are present, a token deeper in the
note stays prose, a bare keyless line still folds to "default", and a
stated-but-malformed slug is rejected rather than rewritten to
"default". A consumed note-head token is stripped from the note so both
positions yield identical records, and the incremental fold version is
bumped so persisted cursors folded under the old interpretation are
rebuilt from the authoritative log.

Fixes kunchenguid#2109

* fix(bin): prevent watcher recovery acknowledgement livelock (kunchenguid#2212)

* fix(bin): keep a recovery acknowledgement valid across republication

A watcher cycle that opened and closed while the model handled its drained
wakes minted a fresh recovery generation, which invalidated the exact
acknowledgement the drain had just printed. That acknowledgement then consumed
nothing, so the marker stayed pending and every later arm spent its whole cycle
re-announcing the same recovery instead of supervising - a livelock the home
could not leave on its own.

A downtime publication now reuses the generation of an outstanding handling
episode, so a close during the handling window cannot orphan the printed
acknowledgement. The acknowledgement itself separates its two facts: queue-row
consumption is bound to the monotonic --ack-through sequence and always
happens, while only retiring the episode is bound to --recovery-generation. A
generation that moved on is a non-fatal result that names its own remedy
instead of a refusal that consumes nothing.

* no-mistakes(review): Preserve recovery generations and consume stale acknowledgements safely

* no-mistakes(document): Document sequence-bound recovery acknowledgements

* feat(fmx-respond): consume Relay conversation chains (kunchenguid#2206)

* feat(fmx-respond): consume in_reply_to_chain conversation context

The relay's poll payload can carry in_reply_to_chain, an oldest-first
transcript of the surrounding conversation, but the mention-handling
procedure only ever read the immediate in_reply_to parent, so referents
like "this" in a standalone mention stayed unresolvable even when
context was delivered.

Teach fmx-respond to read the chain when present (optional and
backward-compatible: often absent today, kind label not required),
resolve referents against the whole transcript, and extend the
untrusted-content framing to every chain entry including the upcoming
kind=history entries. Document the field's wire shape in
docs/configuration.md as the firstmate-side owner.

* no-mistakes(document): Document Relay chain context ownership

---------

Co-authored-by: Kun Chen <[email protected]>
Co-authored-by: Roelof Blom <[email protected]>
spirispark added a commit to spirispark/firstmate that referenced this pull request Aug 13, 2026