Repository navigation
fix(crew-state): stop reading an aborted post-green run as failed - #16
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
bin/fm-crew-state.sh, the full-run (axi-status) path now overrides a terminalfailed/cancelledrun todonewhen the ci step's own log already recorded checks green, reusing the existingnm_ci_checks_statelog-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 readsdonewith the terminal fact preserved in the detail (checks green: PR ready for review (... after checks green)).unknown) and still readsfailed, and genuinely red checks leave a not-ready marker and still readfailed. 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.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.shsuite (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 failedfor a healthy parked crew), and confirmed the two no-masking guardrail cases keep genuine failures readingfailed. 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 failedPipeline
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 casesRevertedbin/fm-crew-state.shto base commit 0fcd4b4 and re-ran:test_terminal_failed_after_checks_green_surfaces_donefails withnot ok - aborted run after checks green -> done (missing: 'state: done'), renderingstate: failed · source: run-step · run failed— the exact reported defectConfirmed no-masking guardrails on fixed script:test_terminal_failed_with_red_checks_stays_failedandtest_terminal_failed_before_ci_stays_failedboth 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.
🔧 Fix: lint clean with pinned ShellCheck 0.11.0, no code changes
1 warning still open:
✅ **Push** - passed
✅ No issues found.