Skip to content

fix(crew-state): stop reading an aborted post-green run as failed - #16

Merged
knowttl merged 1 commit into
mainfrom
fm/fm-crew-state-stale-runstep
Aug 5, 2026
Merged

knowttl merged 1 commit into
mainfrom
fm/fm-crew-state-stale-runstep

Conversation

@knowttl

@knowttl knowttl commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Intent

Fix the stale run-step reading in bin/fm-crew-state.sh (firstmate backlog id fm-crew-state-stale-runstep, captain-authorized 2026-08-04).

THE REPORTED DEFECT: fm-crew-state.sh's run-step source can report 'failed' (or another terminal label) while the task's current reality is healthy. Three observations: 2026-07-26 main home (at-upstream-sync read failed mid-push while the current run was healthy); 2026-07-26 flex home (at-annotate-default-off, same); and fresh on 2026-08-04, in the nextrade domain home, 'fm-crew-state.sh nx-broker-redesign-ladder-boundary' printed 'state: failed - source: run-step - run failed' while the task was deliberately parked healthy: branch held at 2912aedd, PR knowttl/nextrade#267 OPEN and MERGEABLE at exactly that head, pipeline green, worker paused for a morning window.

THE BRIEF'S PROPOSED FIX SHAPE AND WHY THE IMPLEMENTATION DELIBERATELY DIVERGES (important review context - this divergence is intentional and was reported to and accepted by the supervisor before delivery): the brief asked to match the run record against the task's current worktree head / active run id and ignore a record that fails the match, reporting 'stale-run (ignored)'. I reproduced the fresh case against the live artifacts BEFORE writing any code and the brief's premise does not hold: the failing run's head IS the current head (2912aedd), and head/code-identity matching already exists in the script and has since 2026-07-21 (commit ea3ac2e), with tests (test_historical_same_branch_rewritten_head_not_current, test_active_run_descendant_fix_head_remains_current, test_local_advanced_past_run_head_invalidates, test_missing_run_head_falls_back_to_current_state). Implementing the requested head match again would have changed nothing. So no head-matching code was added or altered - that is deliberate, not an omission.

THE ACTUAL VERIFIED CAUSE: the run reached its ci step, that step's own log recorded checks green in the GitHub-Actions-disabled form ('no CI checks reported - still monitoring until merged or closed'), and then the run died with 'error: daemon shutting down' / 'error: context canceled'. 'no-mistakes axi status' therefore reported status: failed and outcome: failed for the CURRENT head while the PR stayed open and green, so the helper read 'failed' for a healthy parked crew.

THE FIX (smallest correct change, full-run path only, in bin/fm-crew-state.sh): ci is the LAST pipeline step, so once its own log reports checks green there is nothing left that can fail on merit - a terminal failed/cancelled recorded after that point is the run being aborted (daemon shutdown, cancel, monitor timeout), not the code failing. The script's existing ci-step log-tail check (nm_ci_checks_state, the single owner of that read, added for the PR kunchenguid#252 incident) now also overrides a terminal failed run to done, with the terminal fact preserved in the detail: 'checks green: PR ready for review (run failed after checks green)'. Restricted to the full axi-status path because the coarse runs-list fallback has no run id of its own and probing another branch's ci log there is the exact mistake test_coarse_run_does_not_probe_other_branch_ci_log_for_ready_status pins.

NO MASKING OF REAL FAILURES (an explicit acceptance criterion): a run that failed before ci has an empty ci log (nm_ci_checks_state returns unknown) and still reads failed; genuinely red checks leave a red marker (not-ready) and still read failed. Both are covered by new tests.

ACCEPTANCE CRITERIA THE WORK WAS HELD TO: (1) a reproduction test proven to FAIL on pre-fix code and pass after - done, verified by stashing the script change and observing 'not ok - aborted run after checks green -> done'; (2) a current-run genuine failure still reads failed; (3) non-run-step behavior unchanged and existing tests stay green - all 53 fm-crew-state cases pass, plus fm-backend, fm-backend-orca, fm-wake-queue and fm-watch-triage; (4) bin/fm-lint.sh passes (verified with the pinned ShellCheck 0.11.0 the repo's own bin/fm-install-shellcheck.sh provides; no shellcheck is on this machine's PATH by default) and tests are colocated in tests/ extending the existing runner pattern rather than inventing a new one.

CONSTRAINTS ACCEPTED FROM THE CAPTAIN AND SUPERVISOR: this is firstmate shared tracked material, so .agents/skills/firstmate-coding-guidelines applies - the script header stays the single owner of this contract (docs/architecture.md and docs/scripts.md describe the helper at an altitude that remains accurate, so no second prose copy was added); repo style is one full sentence per line in Markdown, plain dash never an em dash, and no agent name as a commit co-author. The PR must be opened explicitly against --repo knowttl/firstmate with base main, NEVER the upstream kunchenguid repo and never any other remote. GitHub Actions is disabled on this repo under the standing billing-outage posture, so zero registered checks is expected and the pipeline bundle plus local test runs are the validation. Merge authority stays with the captain: stop at PR-ready, do not merge.

What Changed

  • In bin/fm-crew-state.sh, the full-run (axi-status) path now overrides a terminal failed/cancelled run to done when the ci step's own log already recorded checks green, reusing the existing nm_ci_checks_state log-tail check. Because ci is the last pipeline step, a terminal failure recorded after checks read green is the run being aborted (daemon shutdown, cancel, monitor timeout) rather than the code failing, so the crew reads done with the terminal fact preserved in the detail (checks green: PR ready for review (... after checks green)).
  • Guardrails keep real failures visible: a run that died before ci has an empty ci log (unknown) and still reads failed, and genuinely red checks leave a not-ready marker and still read failed. The override is scoped to the full-run path only, since the coarse runs-list fallback has no run id and must not probe another branch's ci log.
  • Updated the script header contract and added 3 cases to tests/fm-crew-state.test.sh (aborted-after-green surfaces done, plus the two no-masking cases), bringing the suite to 53 passing cases.

Risk Assessment

✅ Low: The change is a small, well-bounded override that reuses the existing single-owner ci-log helper, is correctly restricted to the full-run path, preserves the terminal fact in the detail, does not mask pre-ci or red-check failures, and is covered by three new tests plus an updated single-owner header contract, fully matching the authorized intent.

Testing

Ran the targeted tests/fm-crew-state.test.sh suite (all 53 cases pass on the fixed script), then proved the regression by stashing the script change back to the base commit and observing the reproduction case fail (state: failed · source: run-step · run failed for a healthy parked crew), and confirmed the two no-masking guardrail cases keep genuine failures reading failed. Captured the real before/after CLI output for the reported 2026-08-04 nx-broker parked-crew scenario as reviewer-visible evidence. The change is isolated to bin/fm-crew-state.sh and its only downstream consumer (crew_is_provably_working) is covered within the same suite, so no broader run was warranted; per the phase rules I did not run linters or the full repository suite. Worktree left clean.

Evidence: Parked-crew before/after transcript (real fm-crew-state.sh output)

BEFORE (base 0fcd4b4): state: failed · source: run-step · run failed AFTER (fix 09e52b6): state: done · source: run-step · checks green: PR ready for review (run failed after checks green) Reproduction test: pre-fix: not ok - aborted run after checks green -> done (missing: 'state: done') post-fix: ok - terminal failure after checks green surfaces done No-masking guardrails (post-fix): ok - red checks stays failed; ok - before ci stays failed

fm-crew-state.sh stale run-step fix (fm-crew-state-stale-runstep) - end-user output
Scenario reproduced hermetically: a run whose ci step reported checks green,
then died terminally ("error: daemon shutting down"/"context canceled"), while
the PR stayed open and green - the exact 2026-08-04 nx-broker-redesign case.

Command exercised (the helper an operator runs): fm-crew-state.sh <task-id>
Rendered via the fm-crew-state.test.sh hermetic harness (fake axi status + fake
ci log), which drives the REAL bin/fm-crew-state.sh over a throwaway git repo.

BEFORE (base commit 0fcd4b4, script reverted):
  state: failed · source: run-step · run failed
  -> healthy parked crew reported as a FAILURE (the reported defect)
  reproduction test result: not ok - aborted run after checks green -> done (missing: 'state: done')

AFTER (target commit 09e52b6, delivered fix):
  state: done · source: run-step · checks green: PR ready for review (run failed after checks green)
  -> reads healthy; terminal run fact preserved in the detail
  reproduction test result: ok - terminal failure after checks green surfaces done

No-masking guardrails (both pass on the fixed script):
  ok - terminal failure with red checks stays failed   (genuine red CI -> still failed)
  ok - terminal failure before ci stays failed          (failure before ci, empty ci log -> still failed)

Full suite: all 53 fm-crew-state cases pass on the fixed script; worktree clean after probing.

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-crew-state.test.sh — all 53 cases pass on the delivered (fixed) script, including the 3 new cases
  • Reverted bin/fm-crew-state.sh to base commit 0fcd4b4 and re-ran: test_terminal_failed_after_checks_green_surfaces_done fails with not ok - aborted run after checks green -&gt; done (missing: &#39;state: done&#39;), rendering state: failed · source: run-step · run failed — the exact reported defect
  • Confirmed no-masking guardrails on fixed script: test_terminal_failed_with_red_checks_stays_failed and test_terminal_failed_before_ci_stays_failed both pass (real failures still read failed)
  • Captured the real helper output for the parked-crew scenario before (state: failed) and after (state: done · checks green: PR ready for review (run failed after checks green)) via the hermetic harness driving the real bin/fm-crew-state.sh
✅ **Document** - passed

✅ No issues found.

⚠️ **Lint** - 1 warning
  • ⚠️ linter found issues (exit code 127)

🔧 Fix: lint clean with pinned ShellCheck 0.11.0, no code changes
1 warning still open:

  • ⚠️ linter found issues (exit code 127)
✅ **Push** - passed

✅ No issues found.

The ci step is the last step of a no-mistakes run, so once its own log
reports checks green there is nothing left that can fail on merit: a
terminal failed/cancelled recorded after that point is the run being
aborted (daemon shutdown, cancel, monitor timeout), not the code
failing.

Observed 2026-08-04 on a run whose ci log recorded "no CI checks
reported - still monitoring until merged or closed" and then died with
"error: daemon shutting down": `axi status` reported failed for the
current head while the PR was open, mergeable and green, and
fm-crew-state read `failed` for a healthy parked crew.

The existing ci-step log-tail check now also overrides a terminal
failure to done. A run that failed before ci has an empty ci log, and
genuinely red checks leave a red marker, so neither is masked. Full-run
only, since the coarse runs-list path has no run id of its own.
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