Skip to content

fix(classify): 无 key 的 open 行被后续终态行取代后不再列出 - #43

Merged
onyx-space merged 5 commits into
mainfrom
fm/fm-open-decisions-keeps-superseded-keyless
Oct 4, 2026
Merged

onyx-space merged 5 commits into
mainfrom
fm/fm-open-decisions-keeps-superseded-keyless

Conversation

@onyx-space

@onyx-space onyx-space commented Oct 2, 2026 •

Copy link
Copy Markdown
Owner

摘要

bin/fm-wake-drain.sh 每轮打印的 OPEN DECISIONS 折叠,把一条早已完成的待决项一直挂在清单上:state/retired-repo-cleanup-x1.status 第 42 行是一条无 key 的 blocked: dsh-search,它落在折叠的共享 default 槽里;第 43 行的 resolved [key=dsh-search-cleanup-approval] 只关掉第 41 行那条 keyed 记录,第 44 行的 paused: 终态行又不被折叠认作结束。于是每轮 drain 都出现一个不存在的待决项。

本次只改这一处折叠语义:同一份 status 日志里,无 key 的 blocked:/needs-decision 行之后出现终态行即视为已被取代,不再进 open 集。keyed 决定的配对与关闭语义未动。

改动

  • _fm_decision_fold_line:落在 *) 分支的终态判定(status_is_terminal_verb 的 done/failed,或 FM_CLASSIFY_PAUSED_VERB 的 paused,即 status_is_paused)命中时,丢弃共享的 default 记录。keyed 开局的行在更早的分支就返回,永不进入这条规则。
  • _fm_status_open_decision_origins 与 _fm_span_scan_fold_line:open 集里不再持有 default 时同步丢弃它的 origin,span-scan 的折叠触发词也加上终态与 paused,两个分类器保持一致。
  • FM_OPEN_DECISIONS_FOLD_VERSION 5 → 7、FM_CLASSIFY_SPAN_SCAN_VERSION 2 → 3,落盘游标按新语义从字节 0 重建;测试里另补了一条针对版本号的回归钉(旧版本号的 span-scan 游标必须被拒、并从首行重建)。
  • docs/architecture.md 一句话同步;测试在既有家族内扩写(decision-key、span-scan、pending-reply、wake-drain、captain-hold lifecycle、watch-triage)。

本 PR 的三条记录

① 本地定向证据(逐个文件实跑)

被触及的测试文件在本地逐个跑过(分支 rebase 到当前 main 后的 4d3ee908,同一计数口径),全部退出码 0、无 not ok:

测试文件 退出码 ok not ok
tests/fm-classify-decision-key.test.sh 0 16 0
tests/fm-classify-span-scan.test.sh 0 17 0
tests/fm-wake-drain-open-decisions.test.sh 0 10 0
tests/fm-wake-drain-open-decisions-cursor.test.sh 0 8 0
tests/fm-pending-reply.test.sh 0 42 0
tests/fm-captain-hold-lifecycle.test.sh 0 53 0
tests/fm-watch-triage.test.sh 0 118 0

② 为什么早先那次 CI 是红的

本 PR 上一次 CI(run 36981325080)的三条红 shard 跑在旧底座上:那次 run 在 #45 合并之前,而 #45 修的正是它们红的原因(CI 里 pi 未钉版本导致漂移,以及 pi 1.0.0 的 stock 调用头与 Calm off 不一致)。同一次检查里的 PR must be raised via no-mistakes 则是闸门本身——手开的 PR 过不了这条。本分支已更新到当前 main(f42a979b)并由 no-mistakes 管线重新出品,该闸门与那三条 shard 都在新底座上重判。

③ 验证口径

  • 本地:上表逐文件退出码 0;
  • 管线:本次 run 01M42APR2848K68GRK0D6WY7S5 的 review/test/document/lint/push/pr 各步完成,test 步完整跑通(未走 skip);
  • CI:本次 push 触发的检查已全绿。
English

Intent

一个反复出现的监督噪声缺陷(firstmate 自己身上的):bin/fm-wake-drain.sh 每轮的 OPEN DECISIONS 折叠会把 retired-repo-cleanup-x1 的 blocked: dsh-search 那一行每轮重新列出来,而那件事早已完成。它收不掉的原因:那一行没有 key,而 bin/fm-send.sh --resolve-key 只能收有 key 的记录(默认槽的 key 是 default,但 drain 的清单不显示它)。实测证据(h 机,2026-10-02):state/retired-repo-cleanup-x1.status 里,第 41 行是 needs-decision [key=dsh-search-cleanup-approval],第 42 行是 blocked: dsh-search(无 key),第 43 行是 resolved [key=dsh-search-cleanup-approval](只关掉第 41 行那条 keyed 记录),第 44 行是 paused: dsh-search 清理完成(终态行,但折叠不因此丢掉第 42 行),于是每轮 drain 都出现一个不存在的待决项。边界:只修这一处折叠语义 —— 同一份 status 日志里,无 key 的 blocked/needs-decision 行之后出现任何终态行(done/paused/failed)即视为已被取代,不再进 open 集;不要重写分类器、不要改 keyed 决定的配对与关闭语义。终态词复用本仓既有的 status_is_terminal_verb(done|failed)加 FM_CLASSIFY_PAUSED_VERB 的 paused,不另写表;span-scan 分类器与 status_open_decisions 保持一致并 bump FM_CLASSIFY_SPAN_SCAN_VERSION,让落盘的 partial-scan 游标重建。

What Changed

  • The status fold now drops a keyless needs-decision/blocked record once a later line in the same log is a terminal verb (done/failed, via status_is_terminal_verb) or a declared paused; only the shared default record is dropped, so keyed decisions keep their existing resolve/captain-held close semantics.
  • The span-scan classifier applies the same supersede rule and bumps FM_CLASSIFY_SPAN_SCAN_VERSION (2 to 3); the open-decisions fold version advances to 7 (version 6 added the done/paused supersede, 7 extends it to failed) so persisted partial-scan and fold cursors rebuild from the span's first line.
  • Origin maps drop the default key when the open set no longer holds it, and tests cover the supersede rule, legacy pending-reply escalation closure under a terminal reply, and both cursor migrations.

Risk Assessment

✅ Low: 该变更紧贴单条 fold 规则,在 whole-file、incremental、origin-map 和 span-scan 各消费者之间保持一致,使过期的持久化 cursors 失效,并由行为级回归测试覆盖;此前提出的分歧已解决。

Testing

I derived the product surface from the intent: bin/fm-wake-drain.sh's OPEN DECISIONS section, backed by fm-classify-lib.sh's status_open_decisions fold, the incremental cursor fold, and the watch/daemon span-scan classifier. Driving the real drain over the exact reported log (keyed decision, keyless blocked, keyed resolved, then paused:) now prints nothing; the base build printed default blocked: dsh-search ..., and the base span scan reported that line (rc 0) while the target returns rc 1 with no record, so the fold and the classifier agree. Guards were exercised live: a keyless blocker with no later terminal line still lists, a later unrelated done: never clears a still-open keyed decision, a fresh keyless decision raised after a terminal line lists again, and the configured FM_CLASSIFY_PAUSED_VERB (not a hardcoded paused) defines the supersede vocabulary. done: and failed: both supersede. I also confirmed a persisted partial span-scan cursor written under the previous scanner version is discarded and rebuilt rather than trusted as live; since no test pinned that version-bump requirement, I added one focused regression test to tests/fm-classify-span-scan.test.sh (drives status_span_first_actionable and asserts rc=1, empty record, and no leftover cursor). Targeted suites for the drain, cursor, decision-key, span-scan, pending-reply, and the two changed fixture cases all pass. The full 52-case captain-hold and 116-case watch-triage files were not run to completion; only their changed cases were run, in isolation, because the intent is targeted validation. Evidence: live transcripts, a base-vs-head comparison, suite logs, and the pause-verb check are in the evidence directory. Overall the change satisfies the intent with no failures.

  • Live validation: ✅ go - 8 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Run the drain over the exact reported log (keyed decision, keyless blocked, keyed resolved, then paused) and see no OPEN DECISIONS section for the finished blocker ✅ pass live live-drain-scenarios.out Scenario 1; before-after.txt (base prints default blocked, head prints nothing)
Guard: a keyless blocker with only later routine appends and no terminal line is still listed by the drain ✅ pass live live-drain-scenarios.out Scenario 2 (OPEN DECISIONS printed? YES)
Guard: a later unrelated done: line does not clear a still-open keyed decision, which the drain still lists ✅ pass live live-drain-scenarios.out Scenario 3 (task1 [key=api-shape] needs-decision: pick REST or RPC)
A keyless needs-decision or blocked line is superseded by either done: or failed: and stops being listed ✅ pass live live-drain-scenarios.out Scenario 4 (both cases: no OPEN DECISIONS; failed event still appears in the outcome backstop)
Adversarial: a fresh keyless decision raised after a terminal line is a new decision and lists again ✅ pass live live-drain-scenarios.out Scenario 5 (task1 blocked: the forge went down again)
The watch/daemon span scan agrees with the whole-file fold: the reported sequence is non-actionable (rc 1, no record) and a keyed decision is still actionable ✅ pass live live-drain-scenarios.out Scenario 6 (real status_span_first_actionable + status_open_decisions)
A persisted partial span-scan cursor written under the previous scanner version is discarded and the span rebuilt, not trusted with a stale live keyless origin ✅ pass live before-after.txt cursor-migration section (base accepts the version-2 cursor and returns the blocker, head returns rc 1); targeted-suites.out span-scan run; new `test_pre-fix span-scan cursor is disca…
The supersede vocabulary follows the configured FM_CLASSIFY_PAUSED_VERB rather than a hardcoded paused ✅ pass live pause-verb-override.txt (FM_CLASSIFY_PAUSED_VERB=waiting retires on waiting: and not on paused:)
Evidence: Live drain + span-scan scenario transcript (reported sequence, guards, adversarial reopen, cursor migration)

Source: Live drain + span-scan scenario transcript (reported sequence, guards, adversarial reopen, cursor migration)

------------------------------------------------------------------------
Scenario 1: exact reported sequence (keyed decision, keyless blocked,
keyed resolved, task paused). Before the fix the drain listed the
keyless blocker on every wake.
------------------------------------------------------------------------

\### reported sequence
$ cat state/task1.status
    needs-decision [key=dsh-search-cleanup-approval]: approve the cleanup
    blocked: dsh-search - w unreachable, remote delete paused
    resolved [key=dsh-search-cleanup-approval]: approved, executed
    paused: dsh-search cleanup complete
$ FM_STATE_OVERRIDE=state bin/fm-wake-drain.sh   (exit=0)
    (no output)
OPEN DECISIONS printed? no
------------------------------------------------------------------------
Scenario 2 (guard): the same keyless blocker with NO later terminal line
must still be listed - the rule is a supersede, not a blanket suppression.
------------------------------------------------------------------------

\### keyless blocker, no terminal line
$ cat state/task1.status
    blocked: waiting on the forge
    working: polling the forge
$ FM_STATE_OVERRIDE=state bin/fm-wake-drain.sh   (exit=0)
    | OPEN DECISIONS (still open, folded from the durable status logs - not just the latest line):
    | task1 blocked: waiting on the forge
    | OPEN DECISIONS: close one by answering it: bin/fm-send.sh <task> --resolve-key <key> '<answer>'
OPEN DECISIONS printed? YES
------------------------------------------------------------------------
Scenario 3 (guard): a later unrelated terminal line must NOT clear a KEYED
open decision - keyed pairing/closing semantics unchanged.
------------------------------------------------------------------------

\### keyed decision + unrelated done
$ cat state/task1.status
    needs-decision [key=api-shape]: pick REST or RPC
    done: unrelated later milestone
$ FM_STATE_OVERRIDE=state bin/fm-wake-drain.sh   (exit=0)
    | STATUS OUTCOME BACKSTOP (newest captain-facing task event has no covering branch outcome):
    | task1 done: unrelated later milestone
    | OPEN DECISIONS (still open, folded from the durable status logs - not just the latest line):
    | task1 [key=api-shape] needs-decision: pick REST or RPC
    | OPEN DECISIONS: close one by answering it: bin/fm-send.sh <task> --resolve-key <key> '<answer>'
OPEN DECISIONS printed? YES
------------------------------------------------------------------------
Scenario 4: keyless needs-decision (not only blocked) superseded by done,
and by failed - both terminal verbs shared with status_is_terminal_verb.
------------------------------------------------------------------------

\### keyless needs-decision + done
$ cat state/task1.status
    needs-decision: choose a release target
    done: shipped the release
$ FM_STATE_OVERRIDE=state bin/fm-wake-drain.sh   (exit=0)
    | STATUS OUTCOME BACKSTOP (newest captain-facing task event has no covering branch outcome):
    | task1 done: shipped the release
OPEN DECISIONS printed? no

\### keyless blocked + failed
$ cat state/task1.status
    blocked: waiting on the forge
    failed: the forge never came back
$ FM_STATE_OVERRIDE=state bin/fm-wake-drain.sh   (exit=0)
    | STATUS OUTCOME BACKSTOP (newest captain-facing task event has no covering branch outcome):
    | task1 failed: the forge never came back
OPEN DECISIONS printed? no
------------------------------------------------------------------------
Scenario 5 (adversarial): a fresh keyless decision raised AFTER a terminal
line is a NEW decision and must list again.
------------------------------------------------------------------------

\### keyless reopen after a pause
$ cat state/task1.status
    blocked: first wait
    paused: first wait cleared
    blocked: the forge went down again
$ FM_STATE_OVERRIDE=state bin/fm-wake-drain.sh   (exit=0)
    | OPEN DECISIONS (still open, folded from the durable status logs - not just the latest line):
    | task1 blocked: the forge went down again
    | OPEN DECISIONS: close one by answering it: bin/fm-send.sh <task> --resolve-key <key> '<answer>'
OPEN DECISIONS printed? YES
------------------------------------------------------------------------
Scenario 6: span-scan consistency (the watcher/daemon path). The bounded
span scan must agree with the whole-file fold on the reported sequence.
------------------------------------------------------------------------

$ _fm span scan on reported.status (start offset 0)
    rc=1  actionable_record=''
    whole-file fold lists=''

$ _fm span scan on keyed.status (start offset 0)
    rc=0  actionable_record=needs-decision\ \[key=api-shape\]:\ pick\ REST\ or\ RPC\ \;\ done:\ unrelated\ later\ milestone
    whole-file fold lists=$'api-shape\tneeds-decision\tpick REST or RPC'

Expected: reported -> rc=1 and no fold record; keyed -> rc=0 naming the
api-shape decision while the keyless default record stays retired.
------------------------------------------------------------------------
Scenario 7: persisted span-scan cursor migration. A cursor written under
the previous scanner version (2) must be discarded and the span rebuilt,
not trusted with a stale live keyless origin.
------------------------------------------------------------------------
$ pre-fix cursor:
    version=2
    ident=strong:64770:28864604:2026-10-04 10:14:43.357577999 +0800
    start=0
    size=94
    line=1
    nd=0
    ndp=0
    o	default	blocked	dsh-search - w unreachable, remote delete paused
    p	default	1
    e	D	default	1	blocked	blocked: dsh-search - w unreachable, remote delete paused
$ span scan with that pre-fix cursor present: rc=1 record=''
$ cursor after the scan (must be gone: the scan completed from a rebuild):
    (no cursor left)
Expected: rc=1, no actionable record - the version bump forced a rebuild
that saw the later pause supersede the keyless blocker.
------------------------------------------------------------------------
DONE
exit=0
Evidence: Before/after: base lists the stale keyless blocker and re-signals it via span scan; head does not

Source: Before/after: base lists the stale keyless blocker and re-signals it via span scan; head does not

Before/after evidence for fm/fm-open-decisions-keeps-superseded-keyless
Base commit: f42a979be28eedc63348ddbc8c57ed9d8961b7d7
Head (target): 4d3ee908307568a58877aa5d1f828d6846ac6386

Exact reported status log (h, 2026-10-02, retired-repo-cleanup-x1):
  needs-decision [key=dsh-search-cleanup-approval]: approve the cleanup
  blocked: dsh-search - w unreachable, remote delete paused
  resolved [key=dsh-search-cleanup-approval]: approved, executed
  paused: dsh-search cleanup complete

=== BASE lib: status_open_decisions (whole-file fold) ===
default	blocked	dsh-search - w unreachable, remote delete paused[rc=0]
=== BASE lib: status_span_first_actionable (watcher/daemon path) ===
blocked: dsh-search - w unreachable, remote delete paused[rc=0]

=== HEAD lib: status_open_decisions (whole-file fold) ===
[rc=0]
=== HEAD lib: status_span_first_actionable (watcher/daemon path) ===
[rc=1]

=== Span-scan persisted-cursor migration (FM_CLASSIFY_SPAN_SCAN_VERSION 2 -> 3) ===
Log: keyless blocked, later pause, then a routine append.
A version=2 partial cursor had already folded past the pause under the old
reading, so its open set still held the keyless default origin as live.

-- BASE lib (version 2, cursor accepted):
blocked: dsh-search - w unreachable, remote delete paused  [rc=0]
-- HEAD lib (version 3, cursor rejected and rebuilt):
  [rc=1]
Evidence: Targeted suite logs (drain, cursor, decision-key, span-scan, pending-reply, focused captain-hold/watch-triage)

Source: Targeted suite logs (drain, cursor, decision-key, span-scan, pending-reply, focused captain-hold/watch-triage)

Targeted validation suites for fm/fm-open-decisions-keeps-superseded-keyless
All runs use the real bin/fm-wake-drain.sh / bin/fm-classify-lib.sh from the
target worktree. Each block ends with exit=<rc>.

===== fm-wake-drain-open-decisions =====
ok - a needs-decision buried under later routine/other-key lines still reports as open
ok - a keyless blocker is re-listed only while no later terminal line supersedes it
ok - an over-long open decision is cut to its per-item budget with the shared truncation marker
ok - an explicit resolved [key=X] closes the keyed decision
ok - a later unrelated terminal line never clears an open decision
ok - a reserved decision key can only be opened or closed by its owning library
ok - no open decisions across the fleet prints nothing
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 54439.1791080001.ayGC72
ok - the open-decision section is fleet-wide, not scoped to this drain's own queued records
ok - a buried open decision surfaces even when the wake queue itself is empty
ok - the fleet-wide decision scan does not follow status symlinks
exit=0
===== fm-wake-drain-open-decisions-cursor =====
ok - a truncated/rewritten log falls back to a full re-fold instead of dropping or misreading the decision
ok - a same-size file rotation (new inode) is detected and falls back to a full re-fold
ok - a failed presentation read preserves status state for retry
ok - a cursor-cache read failure refolds decisions without replaying handled unread status
ok - a pre-fix cursor is rebuilt so a previously skipped corr-tagged decision surfaces
ok - an old fold cache is rebuilt once before same-version incremental reads resume
ok - a cursor from the pre-supersede fold version is rebuilt and drops the stale blocker
ok - a buried decision survives many growing drains with bounded read cost, and resolution durably clears it at bounded cost too
exit=0
===== fm-classify-decision-key =====
ok - a stated [key=X] opens X whether it precedes or follows the verb colon
ok - a keyless needs-decision still opens and closes the default key
ok - a resolution closes its decision regardless of either line's key position
ok - blocked [key=X] opens X in both key positions
ok - two colon-form keyed decisions never collapse into one shared bucket
ok - a [key=x] mentioned mid-note is prose, never an opened or closed key
ok - a malformed stated key is rejected in both positions, never folded as default
ok - status_line_verb strips every bracket tag before the colon, in any order, and recovers the bare verb
ok - a [corr=...] tag ahead of [key=...] no longer swallows the verb: opens and closes under the stated key
ok - a [corr=...] tag with no stated key opens under 'default', exactly like a bare needs-decision line
ok - a [key=x] tag alone (no corr tag) still opens x - no regression from the tag-stripping fix
ok - blocked/resolved parse their bare verb with any bracket-tag order preceding the colon
ok - the incremental fold matches the full fold across appends in both key positions
ok - a later terminal line supersedes a keyless open decision, and only that
ok - status_key_closing_verb separates resolution, durable transfer, and still-open
ok - status_key_closing_verb reports the last real transition, in either key position
exit=0
===== fm-classify-span-scan (fresh run after review) =====
syntax ok
ok - equivalence: bounded span scan equals the whole-file fold on every start offset
ok - equivalence: a mid-line span reports the live declarations the absolute-numbered fold dropped
ok - mid-line span: the live declaration is reported, the superseded one is not, and the fold is the side that dropped it
ok - a keyless decision retired by a later terminal line is not re-signalled by the span scan
ok - a pre-fix span-scan cursor is discarded and the span rebuilt under the supersede rule
ok - equivalence: a completed scan leaves no state that changes the next one
ok - equivalence: bounded span scan equals the whole-file fold on pseudo-random traffic
ok - teeth: the equivalence assertion detects a scan that skips its input
ok - bounded rounds: 8 rounds over 8283ms, slowest round 1254ms of a 1s budget
ok - resumption: an abandoned round resumes from its cursor and still reaches the full answer
ok - resumption: an untrustworthy cursor restarts safely instead of answering in part
ok - resumption: a cursor positioned past the log's lines restarts instead of answering empty
ok - resumption: a rejected cursor's records never leak into the answered span
ok - isolation: two callers keep separate span progress without restarting
ok - verdicts: a bounded deferral reports 4, a genuinely unreadable log still reports 2
ok - tail decision: resuming reaches a decision in the span's tail, and an unfinished round reports none of it
ok - out-parameters: a caller-named record and decision variable survive the scan's inner frames
ok - fm-classify-span-scan
exit=0

===== fm-pending-reply =====
===== fm-pending-reply =====
ok - concurrent escalation yields to a late correlated reply
ok - transport success cannot masquerade as reply success
ok - undelivered records remain immutable across scan paths
ok - delivery confirmation fallback reconciles durably
ok - delivery confirmation serializes with reconciliation
ok - unrelated events and stale correlation ids cannot resolve
ok - restart preserves expectation and exact parent destination
ok - wrong-home reports are detected but do not silently acknowledge
ok - direct unmarked captain input creates no expectation
ok - fm-send marked secondmate path creates pending and embeds corr
ok - status-pointed document resolves the expectation
ok - optional helper report resolves without being required for correctness
ok - backend busy/idle observation covers Pi/Claude paths without conversation scrape
ok - tmux and zellij unknown states use bounded capture fallback
ok - pending replies scope Kimi capture fallback by recorded harness
ok - tick skips terminal records and reuses target observations
ok - correlations are reused only for matching open task records
ok - tick end-to-end: miss -> one recovery -> escalate -> durable
ok - failed transport discards undelivered expectation only
ok - a remote repost waits for the reply channel and still fires on a real miss
ok - a mirrored correlated remote reply resolves without any repost
ok - same-basename self-home corr= is restated onto the parent channel and resolves
ok - same-basename reply resolves at the recovery failure boundary
ok - a child-file mate-home sighting is not copied and still escalates
ok - mechanical helper writes the parent channel from verb, corr, and note
ok - remote parent-replies.status is not classified as wrong-home
ok - local parent-replies.status remains wrong-home evidence
ok - an escalated correlation stays retryable only while undelivered
ok - the poll-path escalation close is bounded and never folds the whole status log
ok - all pending-reply tests passed
exit=0

===== fm-captain-hold-lifecycle: affected case run in isolation =====
(the full 52-case file was not run to completion; the changed fixture's case was)
ok - terminal single-owner stale status decisions do not block empty inventory
exit=0

===== fm-watch-triage: affected case run in isolation =====
ok - an actionable event is not hidden by later routine appends, and is named as itself
ok - watcher triage left no process behind: every process this case started was reaped
exit=0
Evidence: FM_CLASSIFY_PAUSED_VERB override defines the terminal-supersede vocabulary

Source: FM_CLASSIFY_PAUSED_VERB override defines the terminal-supersede vocabulary

FM_CLASSIFY_PAUSED_VERB reuse check (the terminal-supersede vocabulary is owner-defined)

Model: bin/fm-classify-lib.sh status_open_decisions

--- FM_CLASSIFY_PAUSED_VERB=waiting, log: blocked / waiting: ---
[rc=0]
expected: empty fold - the configured pause verb supersedes the keyless blocker

--- FM_CLASSIFY_PAUSED_VERB=waiting, log: blocked / paused: ---
default	blocked	waiting on the forge[rc=0]
expected: default blocked still listed - paused is not the configured pause verb
Evidence: Reproducible evidence driver script for the live drain/span-scan scenarios

Source: Reproducible evidence driver script for the live drain/span-scan scenarios

#!/usr/bin/env bash
# Live evidence driver for the keyless-supersede change.
# Drives the REAL bin/fm-wake-drain.sh (the product surface) and the REAL
# bin/fm-classify-lib.sh span-scan entry points over crafted status logs in an
# isolated state directory. Prints a transcript; the transcript is the artifact.
set -u

WT=~/.no-mistakes/worktrees/e7f71fdfbe8f/01M42APR2848K68GRK0D6WY7S5
EVID=~/.no-mistakes/evidence/01M42APR2848K68GRK0D6WY7S5
DRAIN="$WT/bin/fm-wake-drain.sh"

# shellcheck source=tests/wake-helpers.sh
. "$WT/tests/wake-helpers.sh"
TMP_ROOT="$EVID/live-state"
rm -rf "$TMP_ROOT"
mkdir -p "$TMP_ROOT"

hr() { printf '%s\n' "------------------------------------------------------------------------"; }

run_drain() {  # <case> <label>
  local case=$1 label=$2 dir state out rc
  dir=$(make_case "$case")
  state="$dir/state"
  out="$dir/drain.out"
  cp "$EVID/fixture.status" "$state/task1.status" 2>/dev/null || true
  FM_STATE_OVERRIDE="$state" "$DRAIN" > "$out" 2>"$dir/drain.err"
  rc=$?
  printf '\n### %s\n' "$label"
  printf '$ cat state/task1.status\n'
  sed 's/^/    /' "$state/task1.status"
  printf '$ FM_STATE_OVERRIDE=state bin/fm-wake-drain.sh   (exit=%s)\n' "$rc"
  if [ -s "$out" ]; then sed 's/^/    | /' "$out"; else printf '    (no output)\n'; fi
  printf 'OPEN DECISIONS printed? '
  if grep -qF 'OPEN DECISIONS' "$out"; then printf 'YES\n'; else printf 'no\n'; fi
}

hr
printf 'Scenario 1: exact reported sequence (keyed decision, keyless blocked,\n'
printf 'keyed resolved, task paused). Before the fix the drain listed the\n'
printf 'keyless blocker on every wake.\n'
hr
cat > "$EVID/fixture.status" <<'EOF'
needs-decision [key=dsh-search-cleanup-approval]: approve the cleanup
blocked: dsh-search - w unreachable, remote delete paused
resolved [key=dsh-search-cleanup-approval]: approved, executed
paused: dsh-search cleanup complete
EOF
run_drain s1-exact "reported sequence"

hr
printf 'Scenario 2 (guard): the same keyless blocker with NO later terminal line\n'
printf 'must still be listed - the rule is a supersede, not a blanket suppression.\n'
hr
cat > "$EVID/fixture.status" <<'EOF'
blocked: waiting on the forge
working: polling the forge
EOF
run_drain s2-still-open "keyless blocker, no terminal line"

hr
printf 'Scenario 3 (guard): a later unrelated terminal line must NOT clear a KEYED\n'
printf 'open decision - keyed pairing/closing semantics unchanged.\n'
hr
cat > "$EVID/fixture.status" <<'EOF'
needs-decision [key=api-shape]: pick REST or RPC
done: unrelated later milestone
EOF
run_drain s3-keyed-survives "keyed decision + unrelated done"

hr
printf 'Scenario 4: keyless needs-decision (not only blocked) superseded by done,\n'
printf 'and by failed - both terminal verbs shared with status_is_terminal_verb.\n'
hr
cat > "$EVID/fixture.status" <<'EOF'
needs-decision: choose a release target
done: shipped the release
EOF
run_drain s4a-keyless-nd-done "keyless needs-decision + done"
cat > "$EVID/fixture.status" <<'EOF'
blocked: waiting on the forge
failed: the forge never came back
EOF
run_drain s4b-keyless-blocked-failed "keyless blocked + failed"

hr
printf 'Scenario 5 (adversarial): a fresh keyless decision raised AFTER a terminal\n'
printf 'line is a NEW decision and must list again.\n'
hr
cat > "$EVID/fixture.status" <<'EOF'
blocked: first wait
paused: first wait cleared
blocked: the forge went down again
EOF
run_drain s5-reopen "keyless reopen after a pause"

hr
printf 'Scenario 6: span-scan consistency (the watcher/daemon path). The bounded\n'
printf 'span scan must agree with the whole-file fold on the reported sequence.\n'
hr
span_dir="$TMP_ROOT/span"
mkdir -p "$span_dir"
cat > "$span_dir/reported.status" <<'EOF'
needs-decision [key=dsh-search-cleanup-approval]: approve the cleanup
blocked: dsh-search - w unreachable, remote delete paused
resolved [key=dsh-search-cleanup-approval]: approved, executed
paused: dsh-search cleanup complete
EOF
cat > "$span_dir/keyed.status" <<'EOF'
needs-decision [key=api-shape]: pick REST or RPC
done: unrelated later milestone
EOF
for f in reported keyed; do
  rec=$(bash -c '. "$1"; status_span_first_actionable "$2"' _ "$WT/bin/fm-classify-lib.sh" "$span_dir/$f.status")
  rc=$?
  open=$(bash -c '. "$1"; status_open_decisions "$2"' _ "$WT/bin/fm-classify-lib.sh" "$span_dir/$f.status")
  printf '\n$ _fm span scan on %s.status (start offset 0)\n' "$f"
  printf '    rc=%s  actionable_record=%q\n' "$rc" "$rec"
  printf '    whole-file fold lists=%q\n' "$open"
done
printf '\nExpected: reported -> rc=1 and no fold record; keyed -> rc=0 naming the\n'
printf 'api-shape decision while the keyless default record stays retired.\n'

hr
printf 'Scenario 7: persisted span-scan cursor migration. A cursor written under\n'
printf 'the previous scanner version (2) must be discarded and the span rebuilt,\n'
printf 'not trusted with a stale live keyless origin.\n'
hr
mig_dir="$TMP_ROOT/migrate"
mkdir -p "$mig_dir"
cat > "$mig_dir/status.status" <<'EOF'
blocked: dsh-search - w unreachable, remote delete paused
paused: dsh-search cleanup complete
EOF
ident=$(bash -c '. "$1"; _fm_open_decisions_file_ident "$2"' _ "$WT/bin/fm-classify-lib.sh" "$mig_dir/status.status")
size=$(wc -c < "$mig_dir/status.status" | tr -d ' ')
cursor="$mig_dir/.status.span-scan-cursor.0"
{
  printf 'version=2\n'
  printf 'ident=%s\n' "$ident"
  printf 'start=0\n'
  printf 'size=%s\n' "$size"
  printf 'line=1\n'
  printf 'nd=0\n'
  printf 'ndp=0\n'
  printf 'o\tdefault\tblocked\t%s\n' 'dsh-search - w unreachable, remote delete paused'
  printf 'p\tdefault\t1\n'
  printf 'e\tD\tdefault\t1\tblocked\tblocked: dsh-search - w unreachable, remote delete paused\n'
} > "$cursor"
printf '$ pre-fix cursor:\n'
sed 's/^/    /' "$cursor"
rec=$(bash -c '. "$1"; status_span_first_actionable "$2" 0' _ "$WT/bin/fm-classify-lib.sh" "$mig_dir/status.status")
rc=$?
printf '$ span scan with that pre-fix cursor present: rc=%s record=%q\n' "$rc" "$rec"
printf '$ cursor after the scan (must be gone: the scan completed from a rebuild):\n'
if [ -e "$cursor" ]; then sed 's/^/    /' "$cursor"; else printf '    (no cursor left)\n'; fi
printf 'Expected: rc=1, no actionable record - the version bump forced a rebuild\n'
printf 'that saw the later pause supersede the keyless blocker.\n'

hr
printf 'DONE\n'

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 - 8 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Run the drain over the exact reported log (keyed decision, keyless blocked, keyed resolved, then paused) and see no OPEN DECISIONS section for the finished blocker ✅ pass live live-drain-scenarios.out Scenario 1; before-after.txt (base prints default blocked, head prints nothing)
Guard: a keyless blocker with only later routine appends and no terminal line is still listed by the drain ✅ pass live live-drain-scenarios.out Scenario 2 (OPEN DECISIONS printed? YES)
Guard: a later unrelated done: line does not clear a still-open keyed decision, which the drain still lists ✅ pass live live-drain-scenarios.out Scenario 3 (task1 [key=api-shape] needs-decision: pick REST or RPC)
A keyless needs-decision or blocked line is superseded by either done: or failed: and stops being listed ✅ pass live live-drain-scenarios.out Scenario 4 (both cases: no OPEN DECISIONS; failed event still appears in the outcome backstop)
Adversarial: a fresh keyless decision raised after a terminal line is a new decision and lists again ✅ pass live live-drain-scenarios.out Scenario 5 (task1 blocked: the forge went down again)
The watch/daemon span scan agrees with the whole-file fold: the reported sequence is non-actionable (rc 1, no record) and a keyed decision is still actionable ✅ pass live live-drain-scenarios.out Scenario 6 (real status_span_first_actionable + status_open_decisions)
A persisted partial span-scan cursor written under the previous scanner version is discarded and the span rebuilt, not trusted with a stale live keyless origin ✅ pass live before-after.txt cursor-migration section (base accepts the version-2 cursor and returns the blocker, head returns rc 1); targeted-suites.out span-scan run; new `test_pre-fix span-scan cursor is disca…
The supersede vocabulary follows the configured FM_CLASSIFY_PAUSED_VERB rather than a hardcoded paused ✅ pass live pause-verb-override.txt (FM_CLASSIFY_PAUSED_VERB=waiting retires on waiting: and not on paused:)
  • bash tests/fm-wake-drain-open-decisions.test.sh (exit 0, includes keyless-supersede and guards)
  • bash tests/fm-wake-drain-open-decisions-cursor.test.sh (exit 0, includes pre-fix fold-version rebuild)
  • bash tests/fm-classify-decision-key.test.sh (exit 0, includes keyless-superseded-by-terminal case)
  • bash tests/fm-classify-span-scan.test.sh (exit 0, incl. new test_pre-fix span-scan cursor is discarded and the span rebuilt under the supersede rule)
  • bash tests/fm-pending-reply.test.sh (exit 0, includes updated legacy-escalation contract)
  • Affected captain-hold case in isolation: test_terminal_single_owner_status_decision_does_not_block_empty_inventory (exit 0)
  • Affected watch-triage case in isolation: test_status_span_survives_a_later_routine_append (exit 0)
  • Live drain scenarios over crafted logs via live-drain-scenarios.sh (real bin/fm-wake-drain.sh, isolated FM_STATE_OVERRIDE state)
  • Live classifier scenarios via status_open_decisions, status_open_decisions_incremental and status_span_first_actionable on the real bin/fm-classify-lib.sh
  • Before/after comparison of base f42a979 vs target 4d3ee90 on the exact reported log and on a pre-fix span-scan cursor
  • FM_CLASSIFY_PAUSED_VERB=waiting override check on the real fold
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…line

A status log's needs-decision/blocked line with no [key=...] token folds
into the shared "default" bucket, which no later keyed transition can
name. So when the task then wrote its own done/paused line, the keyless
record stayed open forever and bin/fm-wake-drain.sh re-listed a finished
blocker on every wake.

_fm_decision_fold_line now drops the default record when a done/paused
line arrives, leaving every keyed decision untouched because a terminal
line names no key. FM_OPEN_DECISIONS_FOLD_VERSION goes 5 -> 6 so a
cursor persisted under the old reading is rebuilt from byte 0 instead of
serving the stale record from cache.

Tests pin both directions in the existing families: the supersede, the
no-terminal-line case that must still list, the keyed decision a
terminal line must never clear, and the fold-version rebuild that drops
a stale cached record.
@onyx-space onyx-space changed the title fix(classify): supersede a keyless open decision on a later terminal line fix(classify): 无 key 的 open 行被后续终态行取代后不再列出 Oct 2, 2026
@onyx-space
onyx-space force-pushed the fm/fm-open-decisions-keeps-superseded-keyless branch from 521a048 to 6aa3a0f Compare October 4, 2026 02:06
@onyx-space
onyx-space force-pushed the fm/fm-open-decisions-keeps-superseded-keyless branch from 6aa3a0f to 4d3ee90 Compare October 4, 2026 02:08
@onyx-space onyx-space changed the title fix(classify): 无 key 的 open 行被后续终态行取代后不再列出 fix(bin): retire keyless open decisions on a later terminal status line Oct 4, 2026
@onyx-space onyx-space changed the title fix(bin): retire keyless open decisions on a later terminal status line fix(classify): 无 key 的 open 行被后续终态行取代后不再列出 Oct 4, 2026
@onyx-space
onyx-space merged commit dd8ef10 into main Oct 4, 2026
16 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant