Skip to content

fix(bin): report an unreadable crew state as unreadable, not unknown - #7363

Open
max-metaplanet wants to merge 4 commits into
kunchenguid:mainfrom
max-metaplanet:fm/up-run-inventory-v2
Open

max-metaplanet wants to merge 4 commits into
kunchenguid:mainfrom
max-metaplanet:fm/up-run-inventory-v2

Conversation

@max-metaplanet

@max-metaplanet max-metaplanet commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Contribute to upstream firstmate a fix so that the worker-state reader (bin/fm-crew-state.sh and the shared run-inventory helpers) never reports a confident-sounding "unknown" when the validation tool's run state is in fact readable.

The problem: for a worker in a task worktree, the reader printed state: unknown - source: run-step - unreadable runs table while running the validation tool's own status command inside that same worktree returned clean, well-formed output; other workers read correctly at the same instant.
The supervision contract tells a supervisor to reconcile a worker's current state with this reader before deciding the worker is stuck, so a reader that degrades to unknown as a fleet grows is least reliable exactly when a busy fleet needs it most, and fails silently.

The fix: the run inventory must be looked up where the validation tool actually keys it (the primary checkout rather than the task worktree path), the reader must distinguish "I could not read this" from "this worker has no run of its own", and whenever it genuinely cannot read it must say unreadable with the reason, never a bare unknown that reads like a fact about the worker.

What Changed

  • bin/fm-crew-state.sh gains an unreadable state word for the run-step source. It means the reader could not establish anything about the crew, so it is not a claim about the crew. A failed or timed-out primary no-mistakes axi status, a failed or empty no-mistakes axi inventory, a selected run whose status read fails or mismatches, contradicting records, an unrecognized status or outcome word, an untied head, and a daemon proven down all used to report unknown. Each now emits unreadable with a reason that starts with could not read …, could not settle …, or could not verify …. A failed primary status read no longer falls through to the pane or status log. When the inventory read fails, the run ids: list is rebuilt from candidate ids only, so a selection reason is no longer spliced into it.
  • In bin/fm-nm-run-lib.sh, fm_nm_select_run now gives each structural failure of the runs table its own reason: a missing or duplicate count line, a malformed count line, a repeated or unrecognized header, a wrong field count, or a row-count mismatch. Before, they all shared one "unreadable runs table" message. The Python reader for the state database also names its failure: the overview's repo: line is missing or invalid JSON, the path is not absolute, the database cannot be opened, the repository is missing or recorded twice, or the rows do not validate. The displayed table naming runs the database lacks is reported as could not settle. The selector still returns unknown|… internally, and fm-crew-state.sh turns that into unreadable.
  • Consumers and docs are updated for the new state word. fm-fleet-snapshot.sh's secondmate home summary counts both unknown and unreadable children as current-state unavailable. Comments in fm-classify-lib.sh and fm-inactive-reconcile.sh, and docs/architecture.md, now say unreadable where the dead-daemon verdicts used to say unknown. tests/fm-crew-state.test.sh now expects the new unreadable lines. tests/fm-fleet-snapshot-view.test.sh gains one home-summary test, so the CI check now expects 19 tests instead of 18.

Looking up the run inventory by the primary checkout rather than the task worktree path already landed in #5327. Separately, #5888 already distinguishes a worker with no run of its own from everything else, using its own runs_on_current_branch: 0 check from no-mistakes axi status. This change builds on both: it adds the unreadable state word and a per-cause reason for every remaining case where the reader itself failed to read or settle the run, and it leaves #5888's no-run branch untouched. The other reader-side sources - the pane fallback and the ledger/daemon-down read - are deliberately left as they were; this change does not touch them.

Risk Assessment

✅ Low: The change is bounded: run-step verdicts are relabelled, more precise reasons are added, and one consumer is widened. Every positive-match consumer (crew_absorb_class, fm-inactive-reconcile, the fleet-snapshot state parser) handles unreadable the same way it handled unknown. The fix round's new branch for a failed primary axi status read fires only on a non-zero exit with empty stdout, so the uninitialized-repo error that the CLI prints on stdout still falls through to the pane as before.

Testing

I drove six live scenarios. Each one ran the real fm-crew-state.sh, at both the target and the base commit, against the real no-mistakes CLI in a disposable NM_HOME and lab FM_HOME. The task-worktree happy path reads working with the run id even though the run is outside the overview window. A hung primary axi status, an unreadable state DB, and an invalid same-branch DB row each now report state: unreadable with a named cause; the base reported unknown, and for the hang it fell through to the pane. A comma in a branch name does not cause a false unreadable, and a worker with no run is not called unreadable. The secondmate home-summary scenario is untested live; its unit suite passed 19/19. The 6k-line crew-state suite stopped at the 10-minute background limit after 249 passing cases and no failures, so CI owns its full run. The lab, the base worktree, and any stopped processes were all torn down. The result is go.

  • Live validation: ✅ go - 6 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Ship worker in a task worktree whose run is pushed out of the capped no-mistakes axi overview (10 of 26) reads state: working · source: run-step with its run id ✅ pass live crew-state-live-transcript.txt S1: state: working · source: run-step · validating (running) · run: 01TASKRUN001
Primary no-mistakes axi status hangs (real CLI SIGSTOPped, 3s budget): reader reports unreadable naming the call instead of falling back to pane/status log ✅ pass live crew-state-live-transcript.txt S2: target state: unreadable · source: run-step · could not read the run: \no-mistakes axi status` did not answer(3s); basestate: unknown · source: none`
State database cannot be opened, so the real CLI errors: reader reports unreadable with the reason, never a bare unknown ✅ pass live crew-state-live-transcript.txt S3: target state: unreadable ... \no-mistakes axi` failed; base state: unknown ... run inventory unreadable`
State DB holds an invalid same-branch run row: reader reports unreadable with the specific validation cause and candidate run ids ✅ pass live crew-state-live-transcript.txt S4
Adversarial: a comma in another branch's name in the displayed runs table does not trip a false unreadable ✅ pass live crew-state-live-transcript.txt S5: target still state: working · source: run-step
Worker on a branch with no run of its own (runs_on_current_branch: 0) is not reported unreadable (has-no-run is distinguished from could-not-read) ✅ pass live crew-state-live-transcript.txt S6: state: unknown · source: none · backend target gone (pane-source claim, not run-step unreadable)
Secondmate home summary counts a child whose state is unreadable as current-state-unavailable ⏸️ untested no The prior payload did not establish a live result for this scenario. Only the unit suite tests/fm-fleet-snapshot-view.test.sh was run (19/19 ok), and a unit test is not live. A live check needs a ru…
Evidence: Live crew-state transcript: target vs base across six scenarios

Source: Live crew-state transcript: target vs base across six scenarios

# Live fm-crew-state.sh transcript: real no-mistakes CLI (v1.99.0-1531-1535-evidence-push-recovery-jobless-cancel+f4b9ede6edd2), disposable NM_HOME=/tmp/fmcs.9vBuAr/nm (daemon stopped), lab FM_HOME=/tmp/fmcs.9vBuAr/fm
# primary checkout: /private/tmp/fmcs.9vBuAr/repo ; task worktree: /private/tmp/fmcs.9vBuAr/wt on fm/task ; 25 newer runs on other branches push fm/task's run out of the overview's 10-row window
# target = 562dd14d (this change), base = 127f0f30

$ (in task worktree) no-mistakes axi | grep -E "^repo|^count"
repo: /private/tmp/fmcs.9vBuAr/repo
count: 10 of 26 total

## S1 task worktree with a capped run inventory, run readable (state DB keyed by primary checkout)
target: state: working · source: run-step · validating (running) · run: 01TASKRUN001
base:   state: working · source: run-step · validating (running) · run: 01TASKRUN001

## S2 primary 'no-mistakes axi status' hangs (real CLI copy SIGSTOPped, FM_CREW_STATE_NM_TIMEOUT=3); status log says 'working:'
target: state: unreadable · source: run-step · could not read the run: `no-mistakes axi status` did not answer   [stopped 90504: no-mistakes axi status]
base:   state: unknown · source: none · backend target gone: fm:fm-task   [stopped 91772: no-mistakes axi status]

## S3 state database unreadable (chmod 000): real CLI reports error, reader must say unreadable with the reason
target: state: unreadable · source: run-step · could not read the run inventory: `no-mistakes axi` failed; run ids: 
base:   state: unknown · source: run-step · run inventory unreadable; run ids: , unavailable

## S4 state database holds a same-branch run row that fails validation (head_sha 'not-a-sha')
target: state: unreadable · source: run-step · could not read this branch's run inventory: the state database's own run rows for this branch did not validate; run ids: 01TASKOLD001, 01TASKRUN001; last reported run id: 01TASKRUN001
base:   state: unknown · source: run-step · complete same-branch run inventory unreadable; run ids: 01TASKOLD001, 01TASKRUN001; last reported run id: 01TASKRUN001

## S5 hostile branch name with a comma ('fm/a,b') in the displayed window must not trip a false unreadable
  "01COMMA001","fm/a,b",completed,b9f20d58,""
target: state: working · source: run-step · validating (running) · run: 01TASKRUN001

## S6 worker on a branch with no run of its own (fm/none, runs_on_current_branch: 0) is NOT reported unreadable
target: state: unknown · source: none · backend target gone: fm:fm-none
base:   state: unknown · source: none · backend target gone: fm:fm-none
Evidence: fm-fleet-snapshot-view test run (19 ok)

Source: fm-fleet-snapshot-view test run (19 ok)

ok - empty fleet snapshot and view use explicit absence markers
ok - fixture snapshot covers task rows, backlog rows, pointers, stable ordering, and emission-time event age
ok - home-summary excludes kind=secondmate from unowned_current and terminal_in_flight
ok - undated captain holds age after a configurable threshold, decided only from structured fields
ok - captain-hold buckets are total, mutually exclusive, and never decided by prose
ok - main_inventory discloses orphan/unstructured and clears when inventory is consistent
ok - backlog normalization preserves strict roles and resolves every blocker compatibly
ok - snapshot event hints follow reconciled current state
ok - durable fold keeps an open decision past a later unrelated event
ok - a live secondmate endpoint preserves unrelated open decisions
ok - durable captain-held transfer closes the duplicate live status decision
ok - durable fold clears a decision only on a keyed resolution
ok - a completed scout's stale decision surfaces as a report pointer, not pending
ok - a scout still parked at a decision stays pending (terminal clear does not over-fire)
ok - snapshot includes durable scout reports after teardown
ok - snapshot parses tasks-axi rows and respects operational overrides
ok - fleet view renders the snapshot without secondmate peek guidance
ok - fleet view renders secondmate agent liveness
ok - home summary reports an unreadable child state as current-state-unavailable
Evidence: Key before/after lines
S2 hung axi status target: state: unreadable · source: run-step · could not read the run: `no-mistakes axi status` did not answer
base: state: unknown · source: none · backend target gone: fm:fm-task
S3 DB chmod 000 target: state: unreadable · source: run-step · could not read the run inventory: `no-mistakes axi` failed; run ids:
base: state: unknown · source: run-step · run inventory unreadable; run ids: , unavailable
S4 invalid DB row target: state: unreadable · ... the state database's own run rows for this branch did not validate; run ids: 01TASKOLD001, 01TASKRUN001
base: state: unknown · ... complete same-branch run inventory unreadable; ...
  • Outcome: ⚠️ 1 info across 1 run (23m20s)

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

🔧 **Rebase** - 1 issue found → auto-fixed ✅
  • ⚠️ bin/fm-crew-state.sh - merge conflict rebasing onto origin/main

🔧 Fix applied.
✅ Re-checked - no issues remain.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • ⚠️ bin/fm-crew-state.sh:1022 - One run-step read failure still ends in a bare unknown. That is the failed or timed-out primary no-mistakes axi status call. nm_run → fm_nm_run (bin/fm-nm-run-lib.sh:110-112) swallows the failure with || true, so RUN_OUT is empty and the whole [ -n "$RUN_OUT" ] block is skipped. The reader then treats the crew exactly as if it had no run (fallback at bin/fm-crew-state.sh:1345). Concrete sequence: a ship crew is mid-validation on a busy fleet, axi status exceeds NM_TIMEOUT against the contended daemon, and the pane is idle. If the status log has no mappable verb, the output is state: unknown · source: none · no current-state source available (line 1440). If the log says working:, a status-log claim answers instead and the run is never mentioned. The intent requires that the reader "distinguish 'I could not read this' from 'this worker has no run of its own'" and that "whenever it genuinely cannot read it must say unreadable with the reason, never a bare unknown". This path does neither, and it is exactly the busy-fleet degradation the intent describes. The new header comment (lines 43-44, "the other sources still report unknown and are unchanged") and the existing "nonresponding CLI is not retried" comment suggest this was a deliberate scope choice. Fixing it would change fallback behavior: a timeout would emit unreadable run-step "could not read the run: \no-mistakes axi status` did not answer"` instead of falling back to the pane or status log. So the author needs to decide whether this path is in scope.

🔧 Fix applied.
✅ Re-checked - no issues remain.

⚠️ **Test** - 1 info
  • ℹ️ bin/fm-crew-state.sh:1061 - When the overview read fails and no run ids are available, the unreadable detail ends with an empty run ids: clause (S3 live output). This is cosmetic only: the state and reason are correct, and it is cleaner than the base's run ids: , unavailable.
  • Live validation: ✅ go - 6 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Ship worker in a task worktree whose run is pushed out of the capped no-mistakes axi overview (10 of 26) reads state: working · source: run-step with its run id ✅ pass live crew-state-live-transcript.txt S1: state: working · source: run-step · validating (running) · run: 01TASKRUN001
Primary no-mistakes axi status hangs (real CLI SIGSTOPped, 3s budget): reader reports unreadable naming the call instead of falling back to pane/status log ✅ pass live crew-state-live-transcript.txt S2: target state: unreadable · source: run-step · could not read the run: \no-mistakes axi status` did not answer(3s); basestate: unknown · source: none`
State database cannot be opened, so the real CLI errors: reader reports unreadable with the reason, never a bare unknown ✅ pass live crew-state-live-transcript.txt S3: target state: unreadable ... \no-mistakes axi` failed; base state: unknown ... run inventory unreadable`
State DB holds an invalid same-branch run row: reader reports unreadable with the specific validation cause and candidate run ids ✅ pass live crew-state-live-transcript.txt S4
Adversarial: a comma in another branch's name in the displayed runs table does not trip a false unreadable ✅ pass live crew-state-live-transcript.txt S5: target still state: working · source: run-step
Worker on a branch with no run of its own (runs_on_current_branch: 0) is not reported unreadable (has-no-run is distinguished from could-not-read) ✅ pass live crew-state-live-transcript.txt S6: state: unknown · source: none · backend target gone (pane-source claim, not run-step unreadable)
Secondmate home summary counts a child whose state is unreadable as current-state-unavailable ⏸️ untested no The prior payload did not establish a live result for this scenario. Only the unit suite tests/fm-fleet-snapshot-view.test.sh was run (19/19 ok), and a unit test is not live. A live check needs a ru…
  • Disposable no-mistakes home (NM_HOME=/tmp/fmcs.*/nm): the real CLI created the schema skeleton without starting a daemon; then I seeded repos/runs rows with sqlite3, added a gate bare repo plus a no-mistakes remote, and checked that no-mistakes axi status and no-mistakes axi answer from the task worktree (count: 10 of 26 total, repo: <primary checkout>)
  • Lab FM home via bin/fm-lab-home.sh create, with a kind=ship meta for the task worktree; ran bin/fm-crew-state.sh task from both the target and a base (127f0f30) worktree, with TMUX/fleet overrides unset and TMUX_TMPDIR pointing at a private dir
  • S2: ran a lab-only copy of the real no-mistakes binary on PATH, SIGSTOPped only the axi status process descended from my own reader, set FM_CREW_STATE_NM_TIMEOUT=3, and had a working: status log present
  • S3: chmod 000 on the lab state.sqlite, so the real CLI fails with error: open database ...
  • S4: inserted a same-branch run row with head_sha='not-a-sha' into the lab DB
  • S5: inserted a newest run on the branch name fm/a,b so it appears in the displayed runs table
  • S6: second task worktree on fm/none, which has no runs (runs_on_current_branch: 0)
  • bash tests/fm-fleet-snapshot-view.test.sh (19/19 ok, including the case where the home summary reports an unreadable child state as current-state-unavailable)
  • bash tests/fm-crew-state.test.sh: stopped at the 10-minute background limit after 249 passing cases and no failures; CI owns the full run
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @max-metaplanet — first stamp on tip 126ac128 vs main fc8972cd (9 files).

Contract-class: restore (my read, not the PR's claim). The run-step reader was labeling instrument / inventory failures as crew unknown. Tip reports those paths as unreadable with a named cause; inactive-reconcile and fleet-snapshot home summary treat unreadable like unknown. Honesty restore on an existing default path — not a new captain-facing surface. ci.yml only bumps the expected fleet-snapshot test count 18→19.

VISION.md: one captain — aligns (honest fleet state); authority — aligns; scripts/judgment — aligns (deterministic reader); restart — aligns; delegation — aligns (supervisor sees instrument failure); vendor — aligns (no-mistakes inventory semantics); scope — aligns.

This pass: attestation MATCHES tip (live go 4/6; untested rows are stub-only paths real NM never emits). Security clean (workflow edit is count-only) → approved fork CI 38792569845 and Require no-mistakes 38792569829/38812308566 (NM SUCCESS). On the restore auto-merge path once required checks are green — nothing needed from you right now.

`bin/fm-crew-state.sh` prints one state word per task, and every one of
them reads as a claim about the worker. A run-step read that fails printed
`state: unknown`, which says the worker's state is unknowable when what
actually happened is that this reader could not see. The supervision
contract tells a supervisor to reconcile a worker's current state with
this reader before deciding the worker is stuck, so the two cases have to
be told apart, and on a busy repository the read failure is routine rather
than rare.

The reader's own failures were also indistinguishable from each other. Five
of them shared two labels - `unreadable runs table` and `complete
same-branch run inventory unreadable` - so a contradicted count header, a
malformed row, a state database that could not be opened, a repository the
CLI never recorded, and a reader that never finished all produced the same
sentence, and none of them said which had happened.

A run-step read that cannot establish a verdict now reports
`state: unreadable` with a detail that opens on the specific thing it could
not read or could not settle. `unreadable` is the one state word that is a
claim about the reader rather than about the worker; `bin/fm-crew-state.sh`'s
header owns that contract, including which consumers must accept it.

The other sources - pane, status log, remote endpoint, missing metadata -
still report `unknown` and are unchanged. Consumers that act on a worker
claim match `working`, `paused`, `parked`, `done` and `failed` positively,
so the new word is handled exactly as `unknown` was. One consumer matches
the unread verdict itself: the secondmate home summary in
`bin/fm-fleet-snapshot.sh` reported a child whose current state could not be
read as `child_current_unavailable` by selecting only `unknown`, and now
accepts both words, so an unread child cannot silently promote a home to
valid.

One defect fixed along the way: when `no-mistakes axi` exits nonzero after
printing part of its table, the verdict spliced the whole selection reason
into its own `run ids:` field, because the trailing-field split that reads
ids off a `selected|...` choice finds no `|` in a reason sentence. That
produced one line asserting two different causes with prose inside an id
list, for example `run ids: 01OLD, competing live runs; run ids: 01NEW,
01OLD`. Only the candidate ids are spliced now.

Regressions are colocated in `tests/fm-crew-state.test.sh` and
`tests/fm-fleet-snapshot-view.test.sh`: an unreadable read names the specific
thing it could not read and two different failures do not share one reason;
a failed inventory call reports one cause and only run ids; and the home
summary reports an unreadable child as current-state-unavailable. Each fails
against the code before this change. The stock-Bash snapshot step in
`.github/workflows/ci.yml` pins an exact test count for the fleet-view suite,
so it moves from 18 to 19 with the test added there.
@max-metaplanet max-metaplanet changed the title fix(bin): report an unreadable run inventory as unreadable, with its reason fix(bin): report an unreadable crew state as unreadable, not unknown Oct 26, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @max-metaplanet for re-raising this on current main. My last stamp was on 126ac128, and the head is now 562dd14d. The attestation binds that head, and live validation is go with 6 of 7 scenarios.

What I checked: 9 files against main 127f0f30. fm-crew-state.sh now reports instrument and inventory read failures (axi status not answering, overview failed or empty, a selected run that won't confirm, a dead daemon, unrecognised ledger words) as unreadable with a named reason instead of unknown. fm-nm-run-lib.sh names each runs-table structural failure. Inactive-reconcile and the secondmate home summary treat unreadable like unknown. The ci.yml edit only bumps the snapshot test count from 18 to 19. There are no secrets or network changes. Security: none.

I'm correcting my contract class, and that's on me, not on anything you changed: new-default, not restore. On 15 Oct I called this a restore. Looking again, docs/architecture.md on main currently specifies unknown for these cases ("reports unknown as unverified", "classify unavailable ... as unknown"), and this PR rewrites those lines. So the unconfigured reader changes its specified verdict vocabulary rather than fixing a broken promise. It's an honest, well-reasoned change, but under our rules it goes to Kun as merge-or-leave instead of auto-merging.

VISION, rule by rule: One captain aligns (it names the failure plainly instead of a bare unknown). Authority aligns (it adds no autonomy). Scripts/judgment aligns (a deterministic reader with named reasons). Restart aligns. Delegation aligns (a supervisor can tell can't-read from no-run). Vendor aligns (it binds to no-mistakes' exposed axi output). Scope aligns.

CI: run 40299484344 is red on serial 1, 3, 4, 5, 6, 7 and 9, and serial 2 was cancelled. Those are the same assertions main 127f0f30 fails on its own CI, so they're inherited from main, not this branch. Rerunning now would just repeat main's failures, so I'll rerun once main is green. Nothing is needed from you right now. When it's green, it goes to Kun.

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.

2 participants