Skip to content
This repository was archived by the owner on Aug 25, 2026. It is now read-only.

fix: preserve supervision state across multi-stage work - #85

Merged
JTInventory merged 8 commits into
mainfrom
fm/firstmate-adopt-phase3-758-0726
Jul 29, 2026
Merged

JTInventory merged 8 commits into
mainfrom
fm/firstmate-adopt-phase3-758-0726

Conversation

@JTInventory

Copy link
Copy Markdown
Owner

Intent

Port upstream owner PR kunchenguid#758 onto current JT firstmate main. Preserve verb-aware captain relevance so nonterminal working/paused and other progress verbs never become terminal from free-text merged, PR ready, or checks green tokens while genuine done, needs-decision, blocked, failed, legacy bare free text, and validated merge-check events still escalate. Preserve independent bounded AFK stale/possible-wedge aging even when seen-status dedupe matches. Bind no-mistakes current-state attribution to branch plus compatible code identity: equal HEAD or local HEAD ancestor of the pipeline run HEAD, rejecting rewritten, diverged, missing, and local-advanced heads. Protect multi-stage ship briefs so setup-complete working lines stay nonterminal until a defined done gate. Adapt owner kunchenguid#758 source commits without blind replay, preserve existing JT Herdr, Grok, lifecycle, multi-home, and parallel kunchenguid#1092 isolation contracts, ship only to JTInventory/firstmate through no-mistakes, never merge, never use --yes for ask-user findings, and keep deterministic incident and counterfactual regressions.

What Changed

  • Make captain wake classification verb-aware so terminal states and legacy bare signals still escalate, while working, paused, and other progress states remain nonterminal; custom captain vocabulary is now additive.
  • Attribute no-mistakes state only to bounded same-branch runs with a compatible HEAD, accepting pipeline-added descendants while rejecting missing, rewritten, diverged, or stale run heads.
  • Clarify multi-stage ship briefs and supervision docs, and add deterministic regression coverage for classification, run attribution, CI-ready fixtures, and watcher readiness.

Risk Assessment

✅ Low: Captain, the prior three findings are resolved, and the bounded classifier and run-attribution changes now conform to the supplied intent without a substantiated material regression.

Testing

The supplied full behavior baseline was green; focused current-state, classification, generated-brief, CI-ready, AFK, instruction-owner, and watcher-lock tests passed, including two deterministic watcher-lock runs. Reviewer-visible transcripts demonstrate the intended CLI behavior end to end; no UI surface changed, so visual screenshots were not applicable.

Evidence: Verb classification and commit-attribution transcript
Script started on 2026-07-29 02:20:58+00:00 [COMMAND=" set -u . tests/lib.sh . <(sed -e "/^# shellcheck source=tests\/lib.sh$/,+1d" -e "/^test_active_run_is_authoritative$/,\$d" tests/fm-crew-state.test.sh)  printf "=== Captain relevance as seen by supervision ===\n" . bin/fm-classify-lib.sh for line in   "working: setup complete; rebased onto merged #76; checks green"   "paused: checks green pending approval"   "done: PR https://example.invalid/pull/76 checks green"   "needs-decision: choose release gate"   "blocked: missing credentials"   "failed: rc 2"   "merged"   "PR ready https://example.invalid/pull/2"; do   if status_is_captain_relevant "$line"; then verdict=SURFACE; else verdict=ABSORB_NONTERMINAL; fi   printf "%-20s | %s\n" "$verdict" "$line" done  printf "\n=== Current-state attribution: pipeline fix descendant is accepted ===\n" reset_fakes d=$(new_case evidence-descendant) make_repo_on_branch "$d/wt" fm/evidence-descendant base_head=$FM_FAKE_RUN_HEAD git -C "$d/wt" commit -q --allow-empty -m "pipeline fix commit" fix_head=$(git -C "$d/wt" rev-parse HEAD) git -C "$d/wt" reset -q --hard "$base_head" make_fakebin "$d" >/dev/null fm_write_meta "$d/state/crew.meta" "window=fm:fm-crew" "worktree=$d/wt" "kind=ship" FM_FAKE_RUN_HEAD=$fix_head FM_FAKE_AXI_STATUS=$(run_fixing fm/evidence-descendant) export FM_FAKE_RUN_HEAD FM_FAKE_AXI_STATUS printf "local HEAD: %s\npipeline HEAD: %s\n" "$base_head" "$fix_head" run_crew_state "$d" crew  printf "\n=== Current-state attribution: local-advanced historical run is rejected ===\n" reset_fakes d=$(new_case evidence-local-advanced) make_repo_on_branch "$d/wt" fm/evidence-local-advanced run_head=$FM_FAKE_RUN_HEAD git -C "$d/wt" commit -q --allow-empty -m "new local stage" local_head=$(git -C "$d/wt" rev-parse HEAD) make_fakebin "$d" >/dev/null fm_write_meta "$d/state/crew.meta" "window=fm:fm-crew" "worktree=$d/wt" "kind=ship" printf "working: stage 2 implementation in progress\n" > "$d/state/crew.status" FM_FAKE_RUN_HEAD=$run_head FM_FAKE_AXI_STATUS=$(run_parked fm/evidence-local-advanced) FM_FAKE_BUSY=0 export FM_FAKE_RUN_HEAD FM_FAKE_AXI_STATUS FM_FAKE_BUSY printf "local HEAD: %s\nhistorical run HEAD: %s\n" "$local_head" "$run_head" run_crew_state "$d" crew " <not executed on terminal>]
=== Captain relevance as seen by supervision ===
ABSORB_NONTERMINAL   | working: setup complete; rebased onto merged #76; checks green
ABSORB_NONTERMINAL   | paused: checks green pending approval
SURFACE              | done: PR https://example.invalid/pull/76 checks green
SURFACE              | needs-decision: choose release gate
SURFACE              | blocked: missing credentials
SURFACE              | failed: rc 2
SURFACE              | merged
SURFACE              | PR ready https://example.invalid/pull/2

=== Current-state attribution: pipeline fix descendant is accepted ===
local HEAD: 866f0b6913c4dd0efa384be56e646d0a6a44c234
pipeline HEAD: 8d3164b9f7dc469e28efac7e60674ed4d1c4e522
state: working · source: run-step · validating (fixing) · convergence-round=unknown · convergence-fingerprint=unavailable

=== Current-state attribution: local-advanced historical run is rejected ===
local HEAD: 6967e81bc00cff5c6fa7cf5b3f8a4444dfbd37b5
historical run HEAD: 866f0b6913c4dd0efa384be56e646d0a6a44c234
state: working · source: status-log · stage 2 implementation in progress

Script done on 2026-07-29 02:20:59+00:00 [COMMAND_EXIT_CODE="0"]
Evidence: Bounded AFK possible-wedge transcript
Script started on 2026-07-29 02:21:15+00:00 [COMMAND=" set -u . tests/wake-helpers.sh TMP_ROOT=$(fm_test_tmproot phase3-afk-evidence) export FM_TEST_DAEMON_SOURCED=1 . bin/fm-supervise-daemon.sh  dir=$(make_supercase afk-working-merged-wedge) state=$dir/state fakebin=$dir/fakebin win=sess:fm-wishlist-w1 pane=$dir/pane.txt incident="working: stage 2 setup complete on PR #74 exact source branch rebased onto merged #76; task dates preserved" printf "%s\n" "$incident" > "$state/wishlist-w1.status" printf "idle prompt $\n" > "$pane" key=$(printf "%s" wishlist-w1 | tr ":/." "___") printf "%s" "$incident" > "$state/.subsuper-seen-status-$key"  printf "=== AFK stale classification with matching seen-status ===\n" printf "status: %s\n" "$incident" printf "classification: %s\n" "$(FM_STATE_OVERRIDE=$state classify_stale "$win" "$state")" FM_STATE_OVERRIDE=$state handle_wake "stale: $win" "$state" printf "wedge timer recorded: " if [ -s "$state/.subsuper-stale-$key" ]; then printf "yes (epoch %s)\n" "$(cat "$state/.subsuper-stale-$key")"; else printf "no\n"; fi printf "immediate escalation buffer: " if [ -s "$state/.subsuper-escalations" ]; then cat "$state/.subsuper-escalations"; else printf "empty\n"; fi  printf "%s\n" $(( $(date +%s) - 500 )) > "$state/.subsuper-stale-$key" PATH="$fakebin:$PATH" FM_FAKE_TMUX_WINDOW="$win" FM_FAKE_TMUX_CAPTURE="$pane" FM_STATE_OVERRIDE="$state" FM_STALE_ESCALATE_SECS=240 housekeeping "$state" printf "after bounded aging: " cat "$state/.subsuper-escalations" " <not executed on terminal>]
=== AFK stale classification with matching seen-status ===
status: working: stage 2 setup complete on PR #74 exact source branch rebased onto merged #76; task dates preserved
classification: self|transient stale (sess:fm-wishlist-w1): working: stage 2 setup complete on PR #74 exact source branch rebased onto merged #76; task dates preserved
wedge timer recorded: yes (epoch 1785291675)
immediate escalation buffer: empty
after bounded aging: stale persisted 500s (possible wedge): sess:fm-wishlist-w1

Script done on 2026-07-29 02:21:15+00:00 [COMMAND_EXIT_CODE="0"]
Evidence: Generated multi-stage ship brief
You are a crewmate: an autonomous worker agent managed by firstmate. Work on your own; do not wait for a human.

# Task
{TASK}

# Setup
You are in a disposable git worktree of local-project, at a detached HEAD on a clean default branch.

**Verify isolation before anything else.** Run `pwd -P` and `git rev-parse --show-toplevel`; both must resolve to the disposable treehouse worktree you were launched in, typically a path under a `.treehouse/` pool, not the primary checkout firstmate operates from.
The path check is authoritative: `git rev-parse --git-dir` and `git rev-parse --git-common-dir` can help inspect the repo, but they do not prove you are outside the primary checkout.
If the top-level path is the primary checkout or not the worktree you were launched in, STOP - do not branch or commit here - append `blocked: launched in primary checkout, not an isolated worktree` to the status file and stop.

1. First action: create your branch: `git checkout -b fm/phase3-brief`

# Rules
1. Never push to any remote and never open a PR. Work only on your `fm/phase3-brief` branch; firstmate handles the merge into local `main`.
2. Stay inside this worktree except for the status file; modify nothing else outside it.
3. Use gh-axi for GitHub operations and chrome-devtools-axi for browser operations.
4. Report status by appending one line:
   `echo "{state}: {one short line}" >> '/tmp/no-mistakes-evidence/01KYNK83RXYSMSAHPAY2SSSBCD/brief-home/state/phase3-brief.status'`
   States: working, needs-decision, blocked, done, failed.
   Each append wakes firstmate, so report sparingly: only phase changes a supervisor
   would act on (setup done, bug reproduced, fix implemented, validation passed) and the
   needs-decision/blocked/done/failed states. No step-by-step FYI progress lines;
   firstmate reads your pane for that.
   A mid-task `working:` line (including setup complete) is nonterminal: do not end the
   turn after it; continue the same stage until a defined `done:` gate under Definition of done.
5. If you hit the same obstacle twice, append `blocked: {why}` and stop; firstmate will help.
6. If a decision belongs to a human (product choices, destructive actions, ask-user findings),
   append `needs-decision: {summary of options}` and stop. Firstmate will reply with the decision.
7. Never stop, restart, or update the shared `no-mistakes` daemon - one instance serves
   every lane/home, so restarting it can kill another lane's in-flight pipeline. On any
   no-mistakes daemon error, append `blocked: {the daemon error}` and stop; only firstmate manages it.

# Cognee memory hints
Cognee is memory/context only. It is not proof, source of truth, durable archive, or action authority.
Official docs expose raw readback and session/model cost surfaces, but Firstmate still treats raw retention/source-authority guarantees and per-wrapper-call cost correlation as unproven.
Do not run automatic Cognee lookup for every task.
Use a Cognee hint only when this brief says all of these are true:
- Firstmate manually performed the lookup.
- The hint maps to a local manifest row or known local report.
- Firstmate reopened and checked the local source path before attaching it.
- The hint is labeled as memory/context only.
- The hint includes stale-risk and says live state still needs verification.
- `external_action_authorized=false`.

Never use raw Cognee answer text as proof.
Never use memory to authorize merge, deploy, cleanup, vendor/customer action, purchase, refresh, import, or deletion.
If a Cognee hint lacks a reopened local source path, ignore it and proceed from repo files, named local reports, live endpoints, GitHub state, service state, and canonical proof artifacts.

# Project memory
If `AGENTS.md` or `CLAUDE.md` already exists, or if this task produced durable project-intrinsic knowledge, run `/root/.no-mistakes/worktrees/e76b005985df/01KYNK83RXYSMSAHPAY2SSSBCD/bin/fm-ensure-agents-md.sh .` in the worktree.
If this task produced durable project-intrinsic knowledge, record it in `AGENTS.md` as part of your change.
Keep it proportionate: skip `AGENTS.md` edits for trivial tasks that produced no durable project knowledge.

# Definition of done
This project ships **local-only**: no remote, no PR, no pipeline.
The task is complete only when committed on your branch `fm/phase3-brief`. Do NOT push, do NOT open a PR, do NOT merge.
Keep your branch a clean fast-forward onto the current default branch - if `main` has advanced, rebase onto it so the eventual merge stays a fast-forward.
When it is implemented and committed, append `done: ready in branch fm/phase3-brief` to the status file and stop.
Firstmate then reviews your branch diff, the captain approves, and firstmate merges it into local `main`.
- Outcome: 🔧 1 issue found → auto-fixed ✅ across 2 runs (1h54m2s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 2 issues found → auto-fixed (2) ✅
  • 🚨 bin/fm-classify-lib.sh:111 - Intent requires “genuine done, needs-decision, blocked, failed ... still escalate,” but terminal verbs are recognized only when FM_CAPTAIN_RE is unset. Any custom override can therefore suppress a genuine terminal status. Confirm whether the existing whole-vocabulary override may supersede this required terminal guarantee; otherwise terminal verbs must remain unconditional before applying the custom regex.
  • 🚨 bin/fm-crew-state.sh:380 - Intent requires branch plus compatible-code attribution, but fallback selects only the first same-branch run and stops if its HEAD is incompatible. A newer rewritten/reused-branch run can mask a later listed equal-or-descendant-compatible run, forcing stale pane/status-log fallback. Scan bounded same-branch candidates until a compatible HEAD is found, honoring the documented FM_CREW_STATE_RUNS_LIMIT.

🔧 Fix: Captain, preserve terminal escalation and compatible run attribution
1 error still open:

  • 🚨 bin/fm-classify-lib.sh:113 - Intent requires “legacy bare free text ... still escalate,” and the changed comment says FM_CAPTAIN_RE adds vocabulary, but this expression replaces the default legacy-token regex whenever the override is set. For example, FM_CAPTAIN_RE=&#39;custom-verb:&#39; suppresses bare merged, PR ready, and checks green. Keep required legacy matching unconditional and make the custom expression additive.

🔧 Fix: Captain, preserve legacy signals with custom vocabulary
✅ Re-checked - no issues remain.

🔧 **Test** - 1 issue found → auto-fixed ✅
  • 🚨 tests failed with exit code 1
  • bash bin/fm-run-behavior-tests.sh

🔧 Fix: Wait for watcher readiness before legacy lock migration
✅ Re-checked - no issues remain.

  • bash bin/fm-run-behavior-tests.sh
  • Baseline supplied by the gate: bash bin/fm-run-behavior-tests.sh
  • bash tests/fm-watch-triage.test.sh
  • bash tests/fm-crew-state.test.sh
  • bash tests/fm-crew-state-ci-ready.test.sh
  • bash tests/fm-instruction-owners.test.sh
  • bash tests/fm-watcher-lock.test.sh twice
  • bash tests/fm-daemon.test.sh and env -u NO_MISTAKES_GATE bash tests/fm-daemon.test.sh — all Phase 3 cases passed before the unrelated lifecycle test correctly refused execution from a gate worktree; the supplied full-suite baseline exercises it from the runner's neutral clone
  • Manual production-function transcript covering nonterminal/terminal classification, compatible pipeline-fix ancestry, and rejection of a local-advanced historical run
  • Manual AFK scenario with matching seen-status marker, immediate suppression, retained aging timer, and a possible wedge escalation after 500 seconds
  • FM_HOME=/tmp/no-mistakes-evidence/01KYNK83RXYSMSAHPAY2SSSBCD/brief-home bin/fm-brief.sh phase3-brief local-project
✅ **Document** - passed

✅ No issues found.

🔧 **Lint** - 1 issue found → auto-fixed ✅
  • ⚠️ linter found issues (exit code 1)

🔧 Fix: Quote terminal status token for ShellCheck
✅ Re-checked - no issues remain.

✅ **Push** - passed

✅ No issues found.

@JTInventory
JTInventory merged commit c270953 into main Jul 29, 2026
6 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant