Skip to content

fix(bin): keep a stated default-key retraction from cancelling a keyless wait - #5587

Merged
kunchenguid merged 4 commits into
kunchenguid:mainfrom
tiago-peixoto:fm/upstream-4762
Sep 25, 2026
Merged

kunchenguid merged 4 commits into
kunchenguid:mainfrom
tiago-peixoto:fm/upstream-4762

Conversation

@tiago-peixoto

@tiago-peixoto tiago-peixoto commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Fixes #4762.
Implement ready-for-pr issue #4762: a keyless retraction into the shared default decision bucket can cancel an unrelated live wait.

Decision keys fall back to default when no token is present. Closed issue 2109 stopped rewriting a malformed stated key to default; keyless lines still use that bucket. The generated brief's keyless forms (paused: {why}, needs-decision: {summary}) therefore share default. A resolved [key=default] from a foreign producer retracts any standing keyless wait. One sequence: unkeyed needs-decision then unkeyed paused; answering with --resolve-key default cancels the wait that is still live. A retraction from a foreign producer must not cancel a live declaration by landing in the shared default bucket. A worker's own documented keyless self-retraction should still work. A correctly waiting worker re-enters the wedge ladder because an unrelated default-key resolution cleared its wait.

What Changed

  • The keyed activity fold in bin/fm-classify-lib.sh now treats a keyless line as its own phase, separate from an explicit [key=default] line. A foreign resolved: [key=default] no longer closes a standing keyless paused: wait. A worker's own keyless retraction still closes it. The phase is still printed as default on output.
  • A new helper, status_declared_wait_line, returns the line holding a crew in a declared wait. If the latest event is a resolved line, it walks back past resolved lines to the nearest other event. It keeps that event as the wait when it is a pause and none of those resolved lines share its phase key. The read is bounded to the tail window and widens to the whole file only when that window holds nothing but resolved events. status_current_line falls back to it before the latest event.
  • fm-supervise-daemon.sh, fm-watch.sh, and fm-push-transition-lib.sh now use this helper instead of last_status_line when they decide pause or captain-held state. An unrelated default-key resolution therefore no longer puts a correctly waiting crew back on the wedge ladder. docs/architecture.md is updated to match, and regression tests cover the fold, the daemon, and watcher triage.

Risk Assessment

✅ Low: Supervisor pause classification only changes when the latest event is a resolved line. In that case the bounded backward scan keeps a pause standing unless the resolved line shares the pause's phase key. Every converted call site reads the returned line only for pause or captain-held checks. The behaviour tests cover the reported sequence and the worker's own retraction at the snapshot fold, the daemon and the watcher.

Testing

I sent a real fm-send --resolve-key default answer into a real tmux pane on a private socket, in a throwaway home. On base, the resolved line it appends made the supervisors' declared-wait read return "no wait". On the fix, the keyless pause still stands. A 13-case matrix of status logs confirmed the guard in both directions: - Foreign-key, default-key and stacked answers, and pauses buried past the event window, keep the wait (about 0.5s for the worst 1500-line case, 40ms for the common one). - Keyless self-retraction, same-key retraction, working/done lines, captain-held followed by a resolved line, and a stated [key=default] pause still retract it. The targeted classify and daemon suites passed. The new fm-watch wedge-ladder test and its two neighbours passed. I also ran the new fm-watch test against base: it fails there with exactly the reported wedge escalation. The full fm-watch-triage suite ran past my 15-minute cap, with no failures before it stopped, so I ran the relevant tests by name. fm-crew-state could only report "unknown" from the bare shell pane, so crew-state's status-log fallback was checked through status_current_line instead. I did not use a Herdr lab: the change is backend-agnostic status classification, and the tmux backend exercised the real answer path. The fm-watch wedge-ladder and daemon stale-classifier scenarios were covered only by tests over stubbed or sourced components, so they are recorded as untested live.

  • Live validation: ✅ go - 5 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Firstmate answers a keyless needs-decision with fm-send --resolve-key default while the worker is in a keyless paused wait; the supervisors still see the declared wait ✅ pass live resolve-key-default-vs-keyless-pause.txt: on base the declared-wait line is the resolved line and there is no wait; on the fix it is 'paused: waiting on the vendor release' and the wait stands
A waiting lane that gets a default-key answer is not put on the fm-watch wedge ladder ⏸️ untested no The prior payload did not establish a live result: it was covered only by FM_TEST_ONLY=test_wedge_threshold_keeps_a_wait_past_a_default_key_answer, which drives fm-watch.sh over a stubbed backend (pas…
Adversarial: a resolved line for an unrelated key ([key=legal]), stacked foreign answers, or a default answer to a stated-key pause does not cancel the wait ✅ pass live declared-wait-matrix.txt rows B, C, F: WAIT on the fix, no-wait on base
The worker's own keyless resolved line, a same-key resolved line, a later working or done line, and a stated default pause answered with the default key still retract the wait ✅ pass live declared-wait-matrix.txt rows D, E, G, I, M: no-wait on the fix
Captain-held behavior is unchanged: a later resolved line still retracts a captain-held declaration ✅ pass live declared-wait-matrix.txt row H, plus the fm-daemon.test.sh captain-held cases
A long log where the pause sits past the 200-line window under foreign answers still reports the wait, at bounded cost ✅ pass live declared-wait-matrix.txt rows K (WAIT, about 480ms, worst case with 250 stacked answers) and L (WAIT, 40ms, common case)
The daemon's stale classifier keeps a foreign-answered pause on the pause cadence ⏸️ untested no The prior payload did not establish a live result: it was covered only by tests/fm-daemon.test.sh test_stale_pause_survives_a_foreign_resolved_line, which sources the daemon and calls classify_stale o…
Evidence: Real fm-send --resolve-key default into a tmux pane: base loses the wait, fix keeps it

Source: Real fm-send --resolve-key default into a tmux pane: base loses the wait, fix keeps it

=== [base-b42d4fa] status log before answer
needs-decision: which color
paused: waiting on the vendor release
=== [base-b42d4fa] fm-send t1 --resolve-key default 'blue'
●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
fm-send: doorbell not typed because the agent in sess:fm-t1 has exited; the steer is durably recorded at /tmp/fm4762-0XX3/home/state/t1.inbox/001.msg for recovery (stuck-crewmate-recovery), and the watcher will not re-ring a dead pane
rc=0
=== [base-b42d4fa] status log after answer
needs-decision: which color
paused: waiting on the vendor release
resolved [key=default] [at=1790292453]: answered: blue
=== [base-b42d4fa] fm-crew-state.sh t1
state: unknown · source: pane · harness state unavailable (unknown missing)
=== [base-b42d4fa] declared-wait read used by the supervisors
line: resolved [key=default] [at=1790292453]: answered: blue
DECLARED WAIT: no (wedge ladder applies)

=== [fix-46faffa] status log before answer
needs-decision: which color
paused: waiting on the vendor release
=== [fix-46faffa] fm-send t1 --resolve-key default 'blue'
●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
fm-send: doorbell not typed because the agent in sess:fm-t1 has exited; the steer is durably recorded at /tmp/fm4762-gIEV/home/state/t1.inbox/001.msg for recovery (stuck-crewmate-recovery), and the watcher will not re-ring a dead pane
rc=0
=== [fix-46faffa] status log after answer
needs-decision: which color
paused: waiting on the vendor release
resolved [key=default] [at=1790292454]: answered: blue
=== [fix-46faffa] fm-crew-state.sh t1
state: unknown · source: pane · harness state unavailable (unknown missing)
=== [fix-46faffa] declared-wait read used by the supervisors
line: paused: waiting on the vendor release
DECLARED WAIT: yes
Evidence: Declared-wait matrix, base vs fix, including adversarial and long-log cases

Source: Declared-wait matrix, base vs fix, including adversarial and long-log cases

\### base b42d4fa
A keyless ND, keyless pause, resolved[key=default]         expect=WAIT    got=no-wait cur=resolved [key=default]: answered: blue
B keyless pause, resolved[key=legal] (foreign key)         expect=WAIT    got=no-wait cur=resolved [key=legal]: counsel answered
C keyless pause, two foreign resolves stacked              expect=WAIT    got=no-wait cur=resolved [key=default]: y
D keyless pause, worker keyless resolved (self-retract)    expect=no-wait got=no-wait cur=resolved: the vendor shipped
E paused[key=vendor], resolved[key=vendor]                 expect=no-wait got=no-wait cur=resolved [key=vendor]: shipped
F paused[key=vendor], resolved[key=default]                expect=WAIT    got=no-wait cur=resolved [key=default]: answered
G keyless pause, working line, resolved[key=default]       expect=no-wait got=no-wait cur=resolved [key=default]: answered
H captain-held, then resolved[key=default]                 expect=no-wait got=no-wait cur=resolved [key=default]: answered
I keyless pause then done                                  expect=no-wait got=no-wait cur=done: finished
J keyless pause is latest (unchanged)                      expect=WAIT    got=WAIT    cur=needs-decision [key=default]: x
K 1500-line log, pause buried under 250 foreign resolves   expect=WAIT    got=no-wait (25ms)
L 1500-line log, pause + one default answer (poll cost)    expect=WAIT    got=no-wait (20ms)

\### fix 46faffa
A keyless ND, keyless pause, resolved[key=default]         expect=WAIT    got=WAIT    cur=paused: waiting on vendor
B keyless pause, resolved[key=legal] (foreign key)         expect=WAIT    got=WAIT    cur=paused: waiting on vendor
C keyless pause, two foreign resolves stacked              expect=WAIT    got=WAIT    cur=paused: waiting on vendor
D keyless pause, worker keyless resolved (self-retract)    expect=no-wait got=no-wait cur=resolved: the vendor shipped
E paused[key=vendor], resolved[key=vendor]                 expect=no-wait got=no-wait cur=resolved [key=vendor]: shipped
F paused[key=vendor], resolved[key=default]                expect=WAIT    got=WAIT    cur=paused [key=vendor]: waiting
G keyless pause, working line, resolved[key=default]       expect=no-wait got=no-wait cur=resolved [key=default]: answered
H captain-held, then resolved[key=default]                 expect=no-wait got=no-wait cur=resolved [key=default]: answered
I keyless pause then done                                  expect=no-wait got=no-wait cur=done: finished
J keyless pause is latest (unchanged)                      expect=WAIT    got=WAIT    cur=needs-decision [key=default]: x
K 1500-line log, pause buried under 250 foreign resolves   expect=WAIT    got=WAIT    (478ms)
L 1500-line log, pause + one default answer (poll cost)    expect=WAIT    got=WAIT    (40ms)
M stated default pause + default resolve: no-wait (expected)
Evidence: Targeted test transcripts, including the new watcher test failing on base

Source: Targeted test transcripts, including the new watcher test failing on base

== fm-classify-decision-key
ok - status_key_closing_verb reports the last real transition, in either key position
ok - per-key reads retain resolutions without subprocess work growing with unrelated history
ok - overridden resolve and durable-transfer verbs still close keys behind unrelated history
ok - per-key filtering retains ship/scout terminals, reopenings, and secondmate blockers
ok - prose without a colon cannot impersonate a ship or scout terminal declaration
ok - a stated default retraction closes its decision and leaves an unrelated keyless wait standing
ok - a declared wait outlives answers for other keys beyond the event window, and its own resolved line retracts it
ok - only a colon-bearing or keyed line is a decision transition in the fold
rc=0
== fm-daemon
ok - pane_is_busy: omitted backend defaults to tmux for Grok's isolated fallback
ok - pane_input_pending: dispatches through fm_backend_composer_state for backend=herdr
ok - inject_msg: herdr busy-guard defers before ever attempting a submit
ok - inject_msg: herdr composer-guard defers before ever attempting a submit
ok - inject_msg: herdr pane-gone check defers before any busy/composer/submit call
ok - inject_msg: dispatches busy-guard/composer-guard/submit through the herdr backend and succeeds on a confirmed empty composer
ok - inject_msg: defers on a dead-shell/unreadable composer (unknown), never typing the escalation into a shell
ok - inject_msg: unrecognized composer states defer by default
rc=0
== fm-watch-triage
ok - the production default busy-turn-age bound is 3600s (5min under does not wedge, 66min over does)
ok - a busy pane under a declared pause is rechecked on the long cadence, and lifting the pause restores the wedge escalation
ok - away mode hands a busy declared pause to the daemon as a plain stale, and lifting the declaration restores the wedge escalation
ok - away mode wakes the daemon once per declaration for a busy pane whose footer ticks on every capture
ok - a not-provably-working non-terminal stale is surfaced immediately (never left to wait out the timer)
ok - a declared pause is absorbed on first sight, then re-surfaced as a recheck past the threshold, never wedge-escalated
ok - exited declared-pause and captain-held panes use bounded pause cadence while a live decision gate still surfaces once
ok - absorbed paused and captain-held replacements each start their own re-surface cadence
rc=124
== fm-watch-triage (FM_TEST_ONLY, real fm-watch.sh over a fake backend)
ok - a default-key answer leaves a keyless wait standing, while the worker's own keyless resolved line retracts it
rc=0 (test_wedge_threshold_keeps_a_wait_past_a_default_key_answer)
ok - a declared wait is not wedge-escalated by a working verdict, while an elapsed declaration and an undeclared lane both keep the unchanged ladder
rc=0 (test_wedge_threshold_defers_to_a_declared_wait_under_a_working_verdict)
ok - a captain-held lane is rechecked as a hold on the captain, never as an external wait, and never at all while the captain is away
rc=0 (test_wedge_threshold_recheck_names_the_captain_for_a_held_lane)
== base b42d4fa + new watcher test
not ok - a default-key answer put a waiting lane on the wedge ladder at threshold 1: stale: test:fm-wedge (idle 2s, possible wedge, escalation 1)
rc=1

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.

  • Live validation: ✅ go - 5 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Firstmate answers a keyless needs-decision with fm-send --resolve-key default while the worker is in a keyless paused wait; the supervisors still see the declared wait ✅ pass live resolve-key-default-vs-keyless-pause.txt: on base the declared-wait line is the resolved line and there is no wait; on the fix it is 'paused: waiting on the vendor release' and the wait stands
A waiting lane that gets a default-key answer is not put on the fm-watch wedge ladder ⏸️ untested no The prior payload did not establish a live result: it was covered only by FM_TEST_ONLY=test_wedge_threshold_keeps_a_wait_past_a_default_key_answer, which drives fm-watch.sh over a stubbed backend (pas…
Adversarial: a resolved line for an unrelated key ([key=legal]), stacked foreign answers, or a default answer to a stated-key pause does not cancel the wait ✅ pass live declared-wait-matrix.txt rows B, C, F: WAIT on the fix, no-wait on base
The worker's own keyless resolved line, a same-key resolved line, a later working or done line, and a stated default pause answered with the default key still retract the wait ✅ pass live declared-wait-matrix.txt rows D, E, G, I, M: no-wait on the fix
Captain-held behavior is unchanged: a later resolved line still retracts a captain-held declaration ✅ pass live declared-wait-matrix.txt row H, plus the fm-daemon.test.sh captain-held cases
A long log where the pause sits past the 200-line window under foreign answers still reports the wait, at bounded cost ✅ pass live declared-wait-matrix.txt rows K (WAIT, about 480ms, worst case with 250 stacked answers) and L (WAIT, 40ms, common case)
The daemon's stale classifier keeps a foreign-answered pause on the pause cadence ⏸️ untested no The prior payload did not establish a live result: it was covered only by tests/fm-daemon.test.sh test_stale_pause_survives_a_foreign_resolved_line, which sources the daemon and calls classify_stale o…
  • Ran the real bin/fm-send.sh t1 --resolve-key default "blue" against a real tmux pane on a private TMUX_TMPDIR socket, in a throwaway FM_HOME with FM_GATE_REFUSE_BYPASS=1 (the repo test harness's bypass). Then read status_declared_wait_line/last_status_line and fm-crew-state.sh, on base b42d4fa and on the fix 46faffa.
  • Ran a matrix of status logs (A-M) through bin/fm-classify-lib.sh, reading the supervisors' declared-wait line and status_current_line, on base and on the fix. It covers foreign-key and default-key answers, stacked foreign answers, keyless self-retraction, same-key keyed retraction, working/done retraction, captain-held retraction, stated [key=default] pause retraction, and 1500-line logs past the 200-line event window, with timing.
  • bash tests/fm-classify-decision-key.test.sh (passed)
  • bash tests/fm-daemon.test.sh (passed, includes the new test_stale_pause_survives_a_foreign_resolved_line)
  • FM_TEST_ONLY=test_wedge_threshold_keeps_a_wait_past_a_default_key_answer bash tests/fm-watch-triage.test.sh plus the two neighbouring wedge-threshold tests (all passed; they drive the real fm-watch.sh over a fake backend)
  • Ran the new watcher test against the base b42d4fa tree: it fails with 'possible wedge, escalation 1', which is the reported bug
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…wait

A resolved line that names the shared default decision bucket was closing the keyless live wait that only prints as that same key. Keyless self-retraction still closes the keyless wait.
@tiago-peixoto tiago-peixoto changed the title fix(bin): keep a stated default-key resolution from cancelling a keyless wait fix(bin): keep a stated default-key retraction from cancelling a keyless wait Sep 24, 2026
@kunchenguid
kunchenguid merged commit c6e816f into kunchenguid:main Sep 25, 2026
21 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

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

contract-class: restore — existing keyless wait shared the public default bucket with stated [key=default]; foreign --resolve-key default cancelled an unrelated live keyless pause. Tip separates keyless phase from stated default in the activity fold and keeps declared-wait reads standing past foreign-key resolutions. No new default-on surface. Closes #4762 (Fixes verified).

VISION: Interface honesty — aligns (wait not falsely cleared). Authority — aligns (keyed close still works; no inferred widen). Scripts — aligns. Restart — aligns. Spine/vendor/scope — align.

Attestation: MATCH. CI/NM: SUCCESS. Firstmate flag: no.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Correction: squash merge landed at c6e816ffadcc62e7d98f60b8483eda8dc3acc527 (prior stamp placeholder). Outcome unchanged: merged restore closing #4762.

kunchenguid pushed a commit to tiago-peixoto/firstmate that referenced this pull request Sep 25, 2026
…kunchenguid#5599/kunchenguid#5544

Keep unrecognized status-prefix eventing from kunchenguid#5588 inside main's
shared _fm_status_line_is_event helper, and keep both the unrecognized-
prefix latest-event sentence and the declared-wait foreign-key sentence
in docs/architecture.md.
mituso89 pushed a commit to mituso89/firstmate that referenced this pull request Sep 26, 2026
…ess wait (kunchenguid#5587)

* fix(bin): keep a stated default retraction from cancelling a keyless wait

A resolved line that names the shared default decision bucket was closing the keyless live wait that only prints as that same key. Keyless self-retraction still closes the keyless wait.

* no-mistakes(review): Keep declared waits standing past foreign-key resolved lines

* no-mistakes(review): Bound declared-wait read and share one decision-key parser

* no-mistakes(document): Document supervisors' key-aware declared-wait read
mehulbhagwani pushed a commit to mehulbhagwani/firstmate that referenced this pull request Sep 26, 2026
…ess wait (kunchenguid#5587)

* fix(bin): keep a stated default retraction from cancelling a keyless wait

A resolved line that names the shared default decision bucket was closing the keyless live wait that only prints as that same key. Keyless self-retraction still closes the keyless wait.

* no-mistakes(review): Keep declared waits standing past foreign-key resolved lines

* no-mistakes(review): Bound declared-wait read and share one decision-key parser

* no-mistakes(document): Document supervisors' key-aware declared-wait read
mehulbhagwani pushed a commit to mehulbhagwani/firstmate that referenced this pull request Sep 26, 2026
…ess wait (kunchenguid#5587)

* fix(bin): keep a stated default retraction from cancelling a keyless wait

A resolved line that names the shared default decision bucket was closing the keyless live wait that only prints as that same key. Keyless self-retraction still closes the keyless wait.

* no-mistakes(review): Keep declared waits standing past foreign-key resolved lines

* no-mistakes(review): Bound declared-wait read and share one decision-key parser

* no-mistakes(document): Document supervisors' key-aware declared-wait read
ashkonmousavi added a commit to ashkonmousavi/firstmate that referenced this pull request Sep 26, 2026