Skip to content

fix(bin): let a backlog captain hold bound the watcher's wedge escalation - #7338

Merged
kunchenguid merged 4 commits into
kunchenguid:mainfrom
falkoro:fix/fm-wedge-ignores-captain-hold
Oct 15, 2026
Merged

kunchenguid merged 4 commits into
kunchenguid:mainfrom
falkoro:fix/fm-wedge-ignores-captain-hold

Conversation

@falkoro

@falkoro falkoro commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Intent

Fix the firstmate watcher so a stuck worker whose task is held for the captain stops being re-escalated every few minutes, and take the fix to an upstream PR (kunchenguid/firstmate).

What was seen on 2026-10-13: a worker sat at a dialog only the captain could answer, and its task was held for the captain through bin/fm-captain-hold.sh. For the whole time the captain was deciding, bin/fm-watch.sh raised a stale, possible-wedge wake about every 4 minutes. In the same-hash branch of the non-terminal stale path, wedge_timer_check escalates every STALE_ESCALATE_SECS. Its wedge_wait_evidence counts only a status-file captain-held: line (or a declared pause) as a wait, and never consults the backlog captain hold that captain_call_stale_bound already honours on the first-sight surface_nonterminal_stale path. Only status-declared pauses are bounded there.

Expected: a backlog captain hold bounds the wedge escalation the same way it already bounds the first-sight stale alarm, so the captain-held worker gets the existing bounded re-surface cadence (and silence while the away record exists) instead of a wake every STALE_ESCALATE_SECS.

What Changed

  • wedge_wait_evidence in bin/fm-watch.sh now checks task_captain_call_open when the status line accounts for nothing. A task held for the captain in the backlog now gets the FM_PAUSE_RESURFACE_SECS recheck naming the captain, with no wait age, so it no longer escalates as a possible wedge every FM_STALE_ESCALATE_SECS. A paused: … until line whose time has already passed now falls through to the hold check instead of skipping it. While the away-posture record exists the hold is absorbed silently, and its idle timer restarts so the backlog read runs at most once per FM_STALE_ESCALATE_SECS.
  • Added test_wedge_threshold_defers_to_a_backlog_captain_hold to tests/fm-watch-triage.test.sh. It covers the first recheck with no wait age, absorption inside the cadence, the expired paused: … until case, and absorption while the away record exists, where the timer is paced.
  • Updated docs/architecture.md (wedge wait-evidence order, busy-pane exceptions) and the docs/configuration.md entries for FM_STALE_ESCALATE_SECS, FM_BUSY_TURN_MAX_SECS and FM_PAUSE_RESURFACE_SECS to list the backlog captain hold.

🤖 Generated with Claude Code

Risk Assessment

✅ Low: The change adds one well-bounded arm to wedge_wait_evidence. The arm reuses the existing task_captain_call_open predicate, which fails closed. It runs only at the STALE_ESCALATE_SECS threshold, and it goes through the existing wedge_defer_wait/resurface_absorbed cadence. Both prior-round fixes are present and correct: the empty age anchor, and an elapsed paused-until line falling through to the backlog and parked-gate checks. The regression tests cover the first recheck naming the captain without a wait age, the silent absorbs inside the cadence, the elapsed-pause case, and the away-posture silence with the timer restarted.

Testing

I ran the new regression test at HEAD, where it passes, and against the base watcher, where it fails with 'possible wedge'. So the test reproduces the reported bug. I also ran two neighbouring wedge tests, which still pass. For the live check I built a disposable lab: a home from fm-lab-home.sh, a tmux server on the private fm-lab socket with a pane whose foreground process is grok and which shows a captain-only dialog, a real tasks-axi backlog, and a real fm-captain-hold.sh hold. I drove the real bin/fm-watch.sh against it, draining and acking each wake with the real fm-wake-drain.sh. The one stub is the crew-state verdict, fixed at 'working · run-step'. It stands in for a no-mistakes pipeline run, which this gate is not allowed to start. With a 3s escalation threshold, the base watcher woke 4 times in 30s with escalations 1→4 and demand-deep-inspection. The fixed watcher woke once ('captain hold, awaiting the captain - held in the backlog', no wait age), then stayed quiet with no escalation counter. While away it stayed silent. With a 15s re-surface it rechecked about every 15s. With an expired paused-until line it still honoured the hold, where base woke 5 times. With no hold it still escalates 1→4. All lab homes and tmux servers were torn down, and the temporary base copy was deleted.

  • Live validation: ✅ go - 6 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Stuck worker whose task is held for the captain in the backlog (attended): the watcher gives one bounded recheck naming the captain instead of a possible-wedge wake every STALE_ESCALATE_SECS ✅ pass live lab-head.log: 1 wake in 30s ('captain hold, awaiting the captain - held in the backlog'), no wedge counter; lab-base.log shows base woke 4 times with escalations 1→4 under identical setup
Captain-hold recheck publishes no wait age taken from the worker's older status line ✅ pass live lab-head.log / lab-head-cadence.log: recheck reads 'idle 3s - captain hold, ...' with no ', waiting Ns' clause
Held task over time: rechecks follow the bounded FM_PAUSE_RESURFACE_SECS cadence, not the escalation threshold ✅ pass live lab-head-cadence.log: with resurface=15s and escalate=3s, rechecks came at t+9s, t+24s, t+39s; escalation counter none
Captain away (away-posture record exists): a backlog-held stuck worker is never rechecked ✅ pass live lab-head-away.log: 0 wakes in 30s, no escalation counter
Adversarial: worker's last line is a paused-until whose time has passed, plus a backlog hold: the hold still bounds the escalation ✅ pass live lab-head-expired-pause.log: 1 captain-hold recheck, no counter; lab-base-expired-pause.log: base escalates 1→5 in 30s
Guard: a stuck worker with no captain hold still wedge-escalates on the unchanged ladder ✅ pass live lab-head-nohold.log: possible wedge escalations 1→4 with demand-deep-inspection from escalation 3
Regression test fails before the fix and passes after it ⏸️ untested no The earlier report had no live result for this one. It was an automated test with fake tmux, not run against the live product. It only backs up the live lab scenarios above, which cover the same behav…
Evidence: Lab driver script (real watcher, real tmux pane, real backlog captain hold)

Source: Lab driver script (real watcher, real tmux pane, real backlog captain hold)

#!/usr/bin/env bash
# Live lab drive: a real fm-watch.sh watching a real tmux pane (private fm-lab
# socket) whose task is held for the captain in a real backlog through the real
# bin/fm-captain-hold.sh. Only the crew-state verdict is stubbed to "working"
# (it stands in for a no-mistakes run-step, which this gate may not start).
# Usage: [LAB_STATUS_LINE=..] [LAB_NOHOLD=1] [LAB_RESURFACE=secs] lab-drive.sh <bin-dir> <label> <duration-secs> [away]
set -u
BIN=$1 LABEL=$2 DUR=$3 AWAY=${4:-}
LAB=$(mktemp -d "${TMPDIR:-/tmp}/fm-lab.XXXXXX")
"$BIN/fm-lab-home.sh" create "$LAB" >/dev/null || exit 1
mkdir -p "$LAB/tmux" "$LAB/stub" "$LAB/xbin"
export TMUX_TMPDIR="$LAB/tmux"
cleanup() { tmux -L fm-lab kill-server 2>/dev/null; rm -rf "$LAB"; }
trap cleanup EXIT

cp "$(command -v sleep)" "$LAB/xbin/grok"
tmux -L fm-lab new-session -d -s lab -n fm-wedge -x 120 -y 30 \
  "printf 'Captain-only dialog: approve the production migration? [y/N]\n'; exec '$LAB/xbin/grok' 100000"
sleep 0.5
SOCK=$(tmux -L fm-lab display -p '#{socket_path}')
SPID=$(tmux -L fm-lab display -p '#{pid}')
export TMUX="$SOCK,$SPID,0"
echo "[$LABEL] pane: $(tmux list-panes -t lab:fm-wedge -F '#{pane_current_command}')  capture: $(tmux capture-pane -p -t lab:fm-wedge | head -1)"

printf 'window=lab:fm-wedge\nkind=ship\nharness=grok\nbackend=tmux\n' > "$LAB/state/wedge.meta"
printf '%s\n' "${LAB_STATUS_LINE:-working: answering the dialog}" > "$LAB/state/wedge.status"
cat > "$LAB/.tasks.toml" <<'TOML'
backend = "markdown"

[markdown]
path = "data/backlog.md"
archive = "data/done-archive.md"
done_keep = 10
TOML
printf '## In flight\n\n## Queued\n\n## Done\n' > "$LAB/data/backlog.md"
(cd "$LAB" && tasks-axi add wedge 'stuck at a captain-only dialog' --file data/backlog.md) >/dev/null
[ -n "${LAB_NOHOLD:-}" ] || FM_HOME="$LAB" "$BIN/fm-captain-hold.sh" hold wedge --reason 'awaiting the captain on the dialog' >/dev/null
echo "[$LABEL] captain hold open: $(FM_HOME="$LAB" "$BIN/fm-captain-hold.sh" open wedge --identity 2>&1 && echo yes)"
[ -z "$AWAY" ] || { FM_HOME="$LAB" "$BIN/fm-afk-contract.sh" enter >/dev/null && echo "[$LABEL] away-posture record written"; }

printf '#!/bin/sh\necho "state: working · source: run-step · ci running"\n' > "$LAB/stub/fm-crew-state.sh"
chmod +x "$LAB/stub/fm-crew-state.sh"

start=$(date +%s) wakes=0
while [ $(( $(date +%s) - start )) -lt "$DUR" ]; do
  env -u NO_MISTAKES_GATE -u FM_GATE_REFUSE_BYPASS -u FM_ROOT_OVERRIDE -u FM_STATE_OVERRIDE \
    -u FM_DATA_OVERRIDE -u FM_CONFIG_OVERRIDE -u FM_PROJECTS_OVERRIDE \
    FM_HOME="$LAB" FM_CREW_STATE_BIN="$LAB/stub/fm-crew-state.sh" FM_WATCH_HANDLING_SUCCESSOR=1 \
    FM_STALE_ESCALATE_SECS=3 FM_PAUSE_RESURFACE_SECS=${LAB_RESURFACE:-3600} FM_POLL=1 FM_SIGNAL_GRACE=1 \
    FM_CHECK_INTERVAL=999999 FM_HEARTBEAT=999999 FM_SECONDMATE_LIVENESS_SECS=99999999 \
    timeout $(( DUR - ($(date +%s) - start) + 1 )) "$BIN/fm-watch.sh" > "$LAB/out" 2>/dev/null
  rc=$?
  if [ -s "$LAB/out" ]; then
    wakes=$((wakes + 1))
    echo "[$LABEL] t+$(( $(date +%s) - start ))s wake: $(cat "$LAB/out")"
    err="$LAB/drain.err"
    FM_HOME="$LAB" "$BIN/fm-wake-drain.sh" >/dev/null 2>"$err"
    seq=$(sed -n 's/^WAKE_ACK_REQUIRED:.*--ack-through \([0-9]*\) --recovery-generation \([A-Za-z0-9._-]*\)$/\1/p' "$err")
    gen=$(sed -n 's/^WAKE_ACK_REQUIRED:.*--ack-through [0-9]* --recovery-generation \([A-Za-z0-9._-]*\)$/\1/p' "$err")
    [ -z "$seq" ] || FM_HOME="$LAB" "$BIN/fm-wake-drain.sh" --ack-through "$seq" --recovery-generation "$gen" >/dev/null 2>&1
  elif [ "$rc" -ne 124 ]; then
    echo "[$LABEL] watcher exited rc=$rc with no output"; sleep 1
  fi
done
echo "[$LABEL] total wakes in ${DUR}s (escalate threshold 3s): $wakes"
echo "[$LABEL] wedge escalation counter: $(cat "$LAB"/state/.wedge-escalations-* 2>/dev/null || echo none)"
grep -h 'wedge\|captain hold\|absorbed' "$LAB"/state/.triage-log* "$LAB"/state/*triage* 2>/dev/null | tail -5 | sed "s/^/[$LABEL] triage: /"
Evidence: Base a24f4cb: backlog-held stuck worker wedge-escalates every threshold (the reported bug)

Source: Base a24f4cb: backlog-held stuck worker wedge-escalates every threshold (the reported bug)

t+9s wake: stale: lab:fm-wedge (idle 3s, possible wedge, escalation 1) t+15s ... escalation 2 t+21s ... escalation 3, demand-deep-inspection t+28s ... escalation 4, demand-deep-inspection total wakes in 30s: 4

[base-a24f4cb] pane: grok  capture: Captain-only dialog: approve the production migration? [y/N]
[base-a24f4cb] captain hold open: 2026-10-15T08:37:10Z#0
yes
[base-a24f4cb] t+9s wake: stale: lab:fm-wedge (idle 3s, possible wedge, escalation 1)
[base-a24f4cb] t+15s wake: stale: lab:fm-wedge (idle 4s, possible wedge, escalation 2)
[base-a24f4cb] t+21s wake: stale: lab:fm-wedge (idle 3s, possible wedge, escalation 3, demand-deep-inspection: same pane has wedge-escalated 3 times in a row - do not re-absorb on the run-step/pane state alone)
[base-a24f4cb] t+28s wake: stale: lab:fm-wedge (idle 4s, possible wedge, escalation 4, demand-deep-inspection: same pane has wedge-escalated 4 times in a row - do not re-absorb on the run-step/pane state alone)
[base-a24f4cb] total wakes in 30s (escalate threshold 3s): 4
[base-a24f4cb] wedge escalation counter: 4
Evidence: HEAD 3e6f7c4: one captain-hold recheck, then silent, no wedge counter

Source: HEAD 3e6f7c4: one captain-hold recheck, then silent, no wedge counter

t+8s wake: stale: lab:fm-wedge (idle 3s - captain hold, awaiting the captain - held in the backlog, rechecked on a long cadence not a wedge; answer the held decision or release the hold) total wakes in 30s: 1 wedge escalation counter: none

[head-3e6f7c4] pane: grok  capture: Captain-only dialog: approve the production migration? [y/N]
[head-3e6f7c4] captain hold open: 2026-10-15T08:37:47Z#0
yes
[head-3e6f7c4] t+8s wake: stale: lab:fm-wedge (idle 3s - captain hold, awaiting the captain - held in the backlog, rechecked on a long cadence not a wedge; answer the held decision or release the hold)
[head-3e6f7c4] total wakes in 30s (escalate threshold 3s): 1
[head-3e6f7c4] wedge escalation counter: none
Evidence: HEAD: away-posture record present, zero wakes

Source: HEAD: away-posture record present, zero wakes

[head-3e6f7c4-away] pane: grok  capture: Captain-only dialog: approve the production migration? [y/N]
[head-3e6f7c4-away] captain hold open: 2026-10-15T08:38:21Z#0
yes
[head-3e6f7c4-away] away-posture record written
[head-3e6f7c4-away] total wakes in 30s (escalate threshold 3s): 0
[head-3e6f7c4-away] wedge escalation counter: none
Evidence: HEAD: bounded re-surface cadence (FM_PAUSE_RESURFACE_SECS=15) gives rechecks at t+9/24/39s

Source: HEAD: bounded re-surface cadence (FM_PAUSE_RESURFACE_SECS=15) gives rechecks at t+9/24/39s

[head-cadence] pane: grok  capture: Captain-only dialog: approve the production migration? [y/N]
[head-cadence] captain hold open: 2026-10-15T08:39:10Z#0
yes
[head-cadence] t+9s wake: stale: lab:fm-wedge (idle 3s - captain hold, awaiting the captain - held in the backlog, rechecked on a long cadence not a wedge; answer the held decision or release the hold)
[head-cadence] t+24s wake: stale: lab:fm-wedge (idle 3s - captain hold, awaiting the captain - held in the backlog, rechecked on a long cadence not a wedge; answer the held decision or release the hold)
[head-cadence] t+39s wake: stale: lab:fm-wedge (idle 3s - captain hold, awaiting the captain - held in the backlog, rechecked on a long cadence not a wedge; answer the held decision or release the hold)
[head-cadence] total wakes in 40s (escalate threshold 3s): 3
[head-cadence] wedge escalation counter: none
Evidence: HEAD vs base: expired paused-until line plus backlog hold

Source: HEAD vs base: expired paused-until line plus backlog hold

[head-expired-pause] pane: grok  capture: Captain-only dialog: approve the production migration? [y/N]
[head-expired-pause] captain hold open: 2026-10-15T08:39:10Z#0
yes
[head-expired-pause] t+10s wake: stale: lab:fm-wedge (idle 3s - captain hold, awaiting the captain - held in the backlog, rechecked on a long cadence not a wedge; answer the held decision or release the hold)
[head-expired-pause] total wakes in 30s (escalate threshold 3s): 1
[head-expired-pause] wedge escalation counter: none
Evidence: Base: expired paused-until line plus backlog hold escalates 1→5

Source: Base: expired paused-until line plus backlog hold escalates 1→5

[base-expired-pause] pane: grok  capture: Captain-only dialog: approve the production migration? [y/N]
[base-expired-pause] captain hold open: 2026-10-15T08:39:10Z#0
yes
[base-expired-pause] t+9s wake: stale: lab:fm-wedge (idle 4s, possible wedge, escalation 1)
[base-expired-pause] t+14s wake: stale: lab:fm-wedge (idle 3s, possible wedge, escalation 2)
[base-expired-pause] t+19s wake: stale: lab:fm-wedge (idle 3s, possible wedge, escalation 3, demand-deep-inspection: same pane has wedge-escalated 3 times in a row - do not re-absorb on the run-step/pane state alone)
[base-expired-pause] t+24s wake: stale: lab:fm-wedge (idle 3s, possible wedge, escalation 4, demand-deep-inspection: same pane has wedge-escalated 4 times in a row - do not re-absorb on the run-step/pane state alone)
[base-expired-pause] t+30s wake: stale: lab:fm-wedge (idle 3s, possible wedge, escalation 5, demand-deep-inspection: same pane has wedge-escalated 5 times in a row - do not re-absorb on the run-step/pane state alone)
[base-expired-pause] total wakes in 30s (escalate threshold 3s): 5
[base-expired-pause] wedge escalation counter: 5
Evidence: HEAD guard: no backlog hold still wedge-escalates 1→4

Source: HEAD guard: no backlog hold still wedge-escalates 1→4

[head-nohold] pane: grok  capture: Captain-only dialog: approve the production migration? [y/N]
[head-nohold] captain hold open: 
[head-nohold] t+9s wake: stale: lab:fm-wedge (idle 3s, possible wedge, escalation 1)
[head-nohold] t+15s wake: stale: lab:fm-wedge (idle 3s, possible wedge, escalation 2)
[head-nohold] t+20s wake: stale: lab:fm-wedge (idle 3s, possible wedge, escalation 3, demand-deep-inspection: same pane has wedge-escalated 3 times in a row - do not re-absorb on the run-step/pane state alone)
[head-nohold] t+26s wake: stale: lab:fm-wedge (idle 3s, possible wedge, escalation 4, demand-deep-inspection: same pane has wedge-escalated 4 times in a row - do not re-absorb on the run-step/pane state alone)
[head-nohold] total wakes in 30s (escalate threshold 3s): 4
[head-nohold] wedge escalation counter: 4

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-watch.sh:1333 - The backlog-hold wait_record passes "$statusf" as its <age-record>. The wait_record contract (bin/fm-watch.sh:1224) says this must be "the file whose mtime is when this wait started". For a backlog-only hold, though, the worker's status line was written before firstmate ran fm-captain-hold.sh, and the comment at 1245 says the line never reflects the hold. wedge_defer_wait therefore uses the wrong clock in two ways. (1) It publishes waiting ${wage}s as the age of the worker's last line, not the age of the hold. Example: a working: line written 3 days ago and a hold placed 1 minute ago gives a recheck saying "waiting 259200s - captain hold". (2) It gates the first recheck with min_age=PAUSE_RESURFACE_SECS against that unrelated age. A line written just before the hold keeps the lane silent until the line is 4h old, while an old line fires a recheck at the very first threshold. The cadence still holds at about one per PAUSE_RESURFACE_SECS, so the intent's main goal (no wake every STALE_ESCALATE_SECS) is met, but the published value is wrong. Smallest fix: pass an empty anchor (''), the documented answer for a wait with no written record, so no age is published and the resurface_absorbed throttle alone governs the cadence. Same change needed in tests/fm-watch-triage.test.sh:3281-3292: the 'backlog-hold-quiet' case (status age 0, three silent thresholds) only passes because of the status-file anchor and would need a first-threshold recheck followed by absorbs.
  • ℹ️ docs/configuration.md:2545 - The FM_PAUSE_RESURFACE_SECS line and docs/architecture.md now list a backlog captain hold as deferring the wedge escalation. Two neighbouring lines that list the exceptions to that escalation were not updated: FM_STALE_ESCALATE_SECS (line 2545: 'unless that pane's own worker declared a wait ... or ... parked at a validation gate') and FM_BUSY_TURN_MAX_SECS (line 2546: 'a declared external wait, an attended verified captain-held transfer, or ... a validation gate'). Both still omit the new backlog-hold deferral, so the configuration reference contradicts itself.

🔧 Fix applied.
2 warnings still open:

  • ⚠️ bin/fm-watch.sh:1333 - The backlog-hold wait_record passes "$statusf" as its <age-record>. The wait_record contract (bin/fm-watch.sh:1224) says this must be "the file whose mtime is when this wait started". For a backlog-only hold, though, the worker's status line was written before firstmate ran fm-captain-hold.sh, and the comment at 1245 says the line never reflects the hold. wedge_defer_wait therefore uses the wrong clock in two ways. (1) It publishes waiting ${wage}s as the age of the worker's last line, not the age of the hold. Example: a working: line written 3 days ago and a hold placed 1 minute ago gives a recheck saying "waiting 259200s - captain hold". (2) It gates the first recheck with min_age=PAUSE_RESURFACE_SECS against that unrelated age. A line written just before the hold keeps the lane silent until the line is 4h old, while an old line fires a recheck at the very first threshold. The cadence still holds at about one per PAUSE_RESURFACE_SECS, so the intent's main goal (no wake every STALE_ESCALATE_SECS) is met, but the published value is wrong. Smallest fix: pass an empty anchor (''), the documented answer for a wait with no written record, so no age is published and the resurface_absorbed throttle alone governs the cadence. Same change needed in tests/fm-watch-triage.test.sh:3281-3292: the 'backlog-hold-quiet' case (status age 0, three silent thresholds) only passes because of the status-file anchor and would need a first-threshold recheck followed by absorbs.
  • ⚠️ bin/fm-watch.sh:1327 - In wedge_wait_evidence, a paused: ... until &lt;t&gt; line whose time has passed returns 1 straight away ([ &#34;$(date +%s)&#34; -lt &#34;$until&#34; ] || return 1), so the new task_captain_call_open check at line 1334 never runs for that lane. Here is a sequence that reaches it. A worker writes paused: waiting on X until 2026-10-13T12:00Z, then gets stuck on something only the captain can answer. Firstmate holds the task with fm-captain-hold.sh, which leaves the worker's line unchanged. pause_state_class answers working, so the lane reaches wedge_timer_check. Once until passes, wedge_wait_evidence returns 1 even though the backlog captain call is open. The lane then escalates with 'possible wedge, escalation n' every STALE_ESCALATE_SECS for as long as the captain is deciding, which is the exact failure the intent asks to fix. Smallest fix: make an expired paused: line fall through to the backlog-hold check (and the parked-gate check after it) instead of returning 1. For example, only take the declared-wait arm when there is no until or now < until. Otherwise continue to if task_captain_call_open. This branch existed before the change; it was not introduced by the prior fix round, but the new backlog arm is the code that needs to see this case.

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

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 6 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Stuck worker whose task is held for the captain in the backlog (attended): the watcher gives one bounded recheck naming the captain instead of a possible-wedge wake every STALE_ESCALATE_SECS ✅ pass live lab-head.log: 1 wake in 30s ('captain hold, awaiting the captain - held in the backlog'), no wedge counter; lab-base.log shows base woke 4 times with escalations 1→4 under identical setup
Captain-hold recheck publishes no wait age taken from the worker's older status line ✅ pass live lab-head.log / lab-head-cadence.log: recheck reads 'idle 3s - captain hold, ...' with no ', waiting Ns' clause
Held task over time: rechecks follow the bounded FM_PAUSE_RESURFACE_SECS cadence, not the escalation threshold ✅ pass live lab-head-cadence.log: with resurface=15s and escalate=3s, rechecks came at t+9s, t+24s, t+39s; escalation counter none
Captain away (away-posture record exists): a backlog-held stuck worker is never rechecked ✅ pass live lab-head-away.log: 0 wakes in 30s, no escalation counter
Adversarial: worker's last line is a paused-until whose time has passed, plus a backlog hold: the hold still bounds the escalation ✅ pass live lab-head-expired-pause.log: 1 captain-hold recheck, no counter; lab-base-expired-pause.log: base escalates 1→5 in 30s
Guard: a stuck worker with no captain hold still wedge-escalates on the unchanged ladder ✅ pass live lab-head-nohold.log: possible wedge escalations 1→4 with demand-deep-inspection from escalation 3
Regression test fails before the fix and passes after it ⏸️ untested no The earlier report had no live result for this one. It was an automated test with fake tmux, not run against the live product. It only backs up the live lab scenarios above, which cover the same behav…
  • FM_TEST_ONLY=test_wedge_threshold_defers_to_a_backlog_captain_hold bash tests/fm-watch-triage.test.sh at HEAD (pass)
  • Same test against a tree copy whose bin/fm-watch.sh is the base a24f4cb version (fails with 'possible wedge, escalation 1', so the test reproduces the bug)
  • FM_TEST_ONLY=test_wedge_threshold_recheck_names_the_captain_for_a_held_lane and test_wedge_threshold_defers_to_a_declared_wait_under_a_working_verdict at HEAD (pass, neighbouring wedge behaviour unchanged)
  • Live lab: lab-drive.sh &lt;base bin&gt; base-a24f4cb 30: real fm-watch.sh on a real fm-lab tmux pane (grok foreground), real tasks-axi backlog, real fm-captain-hold.sh hold, STALE_ESCALATE_SECS=3
  • Live lab: lab-drive.sh $PWD/bin head-3e6f7c4 30 (attended)
  • Live lab: lab-drive.sh $PWD/bin head-3e6f7c4-away 30 away (away-posture record via fm-afk-contract.sh enter)
  • Live lab: LAB_RESURFACE=15 lab-drive.sh $PWD/bin head-cadence 40 (bounded re-surface cadence)
  • Live lab: LAB_STATUS_LINE=&#39;paused: ... until &lt;2h ago&gt;&#39; lab-drive.sh at HEAD and at base (expired paused-until plus backlog hold)
  • Live lab: LAB_NOHOLD=1 lab-drive.sh $PWD/bin head-nohold 30 (guard: no hold still wedge-escalates)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…tion

A stuck worker whose task was held for the captain through
bin/fm-captain-hold.sh kept wedge-escalating every STALE_ESCALATE_SECS,
because wedge_wait_evidence only read the status line. It now also reads
the open backlog captain call (task_captain_call_open) and defers to the
existing captain-facing long recheck, silent while the away record exists.
@kunchenguid
kunchenguid merged commit 9b1ada0 into kunchenguid:main Oct 15, 2026
19 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @falkoro — really appreciate you taking the time on this.

valerius21 added a commit to valerius21/firstmate that referenced this pull request Oct 15, 2026
* fix: require explicit authority for Firstmate upstream contributions (kunchenguid#7172)

* feat(bin): gate firstmate-upstream publication behind a declared home role

Users who clone firstmate and run it as-is got a surprise: when their
agent hit a firstmate bug, it could drive a pull request at upstream
because nothing distinguished the maintainer's home from an ordinary
user's. Every home now resolves to user/operator unless the gitignored
config/firstmate-role grants a maintainer scope, or a single task
carries the captain's recorded --upstream-consent on the brief, spawn,
and promotion. fm-brief, fm-spawn, and fm-promote apply one fail-closed
gate in bin/fm-role-lib.sh; the role is never inferred from gh identity,
remotes, permissions, or CI, and secondmates honor only receipt-proven
inherited grants so a child cannot grant itself. Session start reports
the resolved role with no network call. Ordinary project delivery and
the clone-and-run setup flow are unchanged.

* no-mistakes(review): Harden firstmate role parsing, normalization, and inheritance

* no-mistakes(review): Detect firstmate by lineage; drop consent fallback; fix claims

* no-mistakes(document): Correct and consolidate Firstmate role documentation

* fix(pi): narrow before_agent_start events before reading prompt (kunchenguid#7248)

* fix: narrow Pi before-agent prompt events

* no-mistakes(review): Restore processing-run abort detection and type Pi test events

* feat: let a home declare authoritative external memory tiers (kunchenguid#6608)

* docs: let a home declare authoritative external memory tiers

AGENTS.md section 6 routed durable knowledge only to firstmate-local files,
so a home whose captain keeps reasoning and facts in external stores had no
tracked rule keeping those stores authoritative over the per-machine data/
cache. Add a generic home-declared Memory layering contract (schema in
docs/configuration.md), make firstmate the capture path for workers whose
harness cannot reach a declared tier, and teach the stow skill to route to
declared tiers first and never prune a tier-owned entry without capturing it.

* no-mistakes(review): Report missing memory-layering declaration and index tier docs

* no-mistakes(document): Narrow memory-tier re-seed step to captain re-declaration

* no-mistakes(ci): Environment: 2026-10-05, host wildrobot, Linux 7.0.0-34. Finding ci-1 (Greptile): a tier-owned fact could be lost when its declared tier was unreachable from the session. - The invariant that was broken: until the declared tier holds a tier-owned fact, that fact must stay in a memory file loaded at startup. - Where it could be broken: the declared-tier guard, which said to archive the entry to the never-loaded cold tier; the routing step for new findings, which only mentioned the receipt; and the budget-eviction and offload eligibility rules. Fix, made only in .agents/skills/stow/SKILL.md: - **New marker.** Added `<!--t:NAME-->` to the existing compact marker list, so its meaning lives in one place. It marks a tier-owned entry that tier NAME does not hold yet. Stow never prunes, ages out, evicts, offloads, consolidates away, or archives an entry carrying it, whatever its tier clock says. A later pass that can reach NAME captures the entry there and removes the marker. - **Declared-tier guard.** "still archive rather than delete" now says to leave the entry in place with its pending-capture marker, and the receipt still names it. - **Routing step 2.** When the tier is unreachable, a new finding is written to the startup-loaded local file its class would otherwise use, or kept where it already lives, with the marker. It is still reported as an exception in the receipt. - **Budget eviction and offload eligibility.** Both now exclude entries pending capture, so the convergence pool is counted correctly. - **Receipt bullet.** Changed "finding or pruned entry" to entries left carrying the pending-capture marker, because those entries are no longer pruned. docs/configuration.md ("protects tier-owned entries from pruning") and AGENTS.md section 6 are still accurate, so I left them unchanged. No new file, queue, script, or digest section. One sentence per line, plain dashes. Verification: tests/fm-stow-cascade.test.sh, tests/fm-documentation-audiences.test.sh, and tests/fm-lint.test.sh all pass

* docs: keep undeclared memory-tier path silent and close stuck tier markers

Drop the stow receipt line reporting a missing Memory layering declaration
(AGENTS.md section 6, the stow skill, docs/configuration.md) so a home with
no declaration behaves exactly as before. Name pending-capture entries in the
exempt floor wording, and say how stow retargets or clears a pending-capture
marker whose tier was renamed or retired.

* fix: keep unsupported contribution URLs unmeasured (kunchenguid#7233)

* fix: keep unsupported contributions unmeasured during polling

* no-mistakes(document): Clarify unsupported contribution polling documentation

* no-mistakes(review): Match literal GitHub hostname and cover unsupported lookalikes

* no-mistakes(review): Separate durable ownership compatibility from GitHub observation eligibility

* no-mistakes(document): Clarify unsupported contribution coverage and ownership compatibility

* fix(bin): keep inherited Git config entries when installing the trailer-strip hooks path (kunchenguid#6341)

* fix(bin): keep inherited Git credential helpers when installing the trailer hooks path

Problem:
Every fleet launch prefixed the worker command with `export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=core.hooksPath GIT_CONFIG_VALUE_0=...`.
That replaced any `GIT_CONFIG_*` entries the pane already carried, so a scoped HTTPS credential setup such as `credential.helper=` followed by `credential.helper=!gh auth git-credential` was silently dropped.
Git then fell back to the system or global helper (for example `osxkeychain` from the system gitconfig on macOS), so a worker meant to use a scoped token pushed with the user's personal credentials.

Reproduction on main:
GIT_CONFIG_COUNT=2 GIT_CONFIG_KEY_0=credential.helper GIT_CONFIG_VALUE_0= GIT_CONFIG_KEY_1=credential.helper GIT_CONFIG_VALUE_1='!gh auth git-credential' sh -c "<emitted launch>; git config --get-all credential.helper" prints none of the inherited entries, only the system helper (`osxkeychain` from Homebrew's system gitconfig on the reporting machine).

Fix:
The launch prefix now appends `core.hooksPath` at index `GIT_CONFIG_COUNT` and increments the count, resolved in the destination shell after any `config/launch-env-allowlist` filtering.
The inherited count is validated as decimal before shell arithmetic, leading zeros are normalized (Git accepts `02`), and a count that cannot be extended within Git's signed int refuses.
A refusal uses `return 1 2>/dev/null || exit 1`, so when the pane sources the launch file the error stays visible and the interactive shell survives instead of the pane dying with the message.

Tests:
`tests/fm-spawn-dispatch-profile.test.sh` gains a behavior test that runs the real emitted launch under sh, bash, and zsh with inherited credential-helper entries and counts `2` and `02`, then asks Git for `credential.helper` and `core.hooksPath`.
The same test checks that an invalid or overflowing count refuses, and that sourcing the launch file from an interactive shell keeps that shell alive with the error visible.
The exact-launch assertions in the dispatch-profile and Kimi suites now extract the emitted prefix through one `fm_test_launch_git_prefix` helper in `tests/lib.sh` instead of two hand-copied strings, whose content the behavior test covers.

Risk:
Top-level `return` outside a sourced file is unspecified by POSIX; verified on macOS sh (bash 3.2 in POSIX mode), bash, and zsh, and every path still ends nonzero before the worker command runs.
The hook wrapper still unsets only `GIT_CONFIG_COUNT` and index 0, which is sufficient because Git ignores indexed entries once the count is unset.
A launch that forwards `GIT_CONFIG_COUNT` without all of its indexed keys now fails in Git instead of being masked by the overwrite.

* no-mistakes(review): Keep inherited Git config in hooks and fish-safe launch

* no-mistakes(document): docs: describe appended hooksPath keeping inherited Git config

* test: run the fish pane launch cases in CI

Install fish in the portable serial lane and run the credential-append
and invalid-count refusal cases under fish. Under CI the spawn test
fails instead of falling back to the static syntax check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test: strip the Git config launch prefix before reading the Claude doorbell

The trust suite evaluated the whole launch command to find the final prompt
argument, so it now also sourced the per-spawn git-config env file that the
fake pane never writes. Drop that prefix the same way the dispatch suite does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test: share the launch command parser across the spawn suites

The trust suite failed in CI because its copy of the launch parser missed
the Git configuration prefix the dispatch suite's copies already stripped.
Move the prefix and export stripping into tests/lib.sh next to
fm_test_launch_git_prefix so the three parsers cannot drift again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(bin): canonicalize env-file hooks path and tighten launch-config tests

env-file now writes the canonical (pwd -P) spelling of the hooks directory, matching what install records, so a symlinked path no longer makes the hook wrapper miss its own entry and silently skip the repository's hook.
A new strip test passes a symlinked hooks path through env-file and fails without this change.

The launch-env-allowlist test now also asserts the appended core.hooksPath, so a regression that drops the strip-hook entry only on the env -i path is caught.

Without fish installed locally, the launch test now prints an explicit fish skip line and limits its pass message to sh, bash and zsh, instead of claiming every pane shell after only a static token check.

* no-mistakes(review): Drop CI fish install and CI-only fish refusal

* no-mistakes(document): Document GIT_CONFIG_COUNT overflow refusal in configuration docs

* test: prove a refused Git config count never starts the worker

The invalid-count refusal checks only asserted a nonzero status and the helper's own error text.
If the launch line kept going after the refusal, the worker probe's final `git config` also failed under the bad count, so the checks still passed.
The probe now prints a marker on stderr, and every refusal case in sh, bash, zsh and fish asserts the marker never appears.
Dropping the `|| return 1 2>/dev/null || exit 1` guard from the launch line now fails the test.

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>

* fix(bin): name the failing step when a contribution observation is unavailable (kunchenguid#6810)

* fix(bin): name the failing read when a contribution observation is unavailable

An unavailable contribution observation recorded one constant error and
discarded the failing read's exit status and error output on cleanup, so a
network failure, a forge refusal and a structural check failure all looked
the same and left nothing to diagnose once the next good read cleared it.

The record's error and the unavailable line now name the first failing step:
the read's label, exit status, budget seconds left and the first line of its
error output, or the structural check that refused the observation. Budget
refusal stays silent and unmeasured as before.

* no-mistakes(review): Label closing head read's structural failure as its own cause

* no-mistakes(document): Note structural refusals record contribution errors too

* fix(spawn): scope Orca worker launch env to an opt-in tmux session (kunchenguid#6365)

* fix(spawn): give Orca workers an opt-in scoped environment source

Fixes kunchenguid#6339

On the Orca backend, `config/launch-env-allowlist` expands each allowlisted name in the destination pane, and that pane is an Orca terminal whose environment comes from the Orca app and the user's shell startup files.
Allowlisted credentials therefore resolve to the user's personal values or to nothing, with no warning, while the same allowlist scopes tmux workers correctly.

Add an opt-in `config/launch-env-tmux-session` naming one tmux session.
On a fresh Orca spawn, before the worktree or terminal is allocated, fm-spawn reads each allowlisted name from that session's local environment with `tmux -u show-environment -t =<session> <name>`.
The worker launches with the existing `env -i` boundary and operational floor, the snapshotted values in place of destination expansion, and `GIT_CONFIG_NOSYSTEM=1` so a system credential helper cannot answer for the worker.
The source requires an allowlist, so tmux's automatic update-environment names such as `SSH_AUTH_SOCK` are never forwarded unless listed.
A listed name missing from the session, an unreadable session, or a malformed selector refuses before allocation; an explicit `-NAME` record stays a deliberate unset.
Values are shell-quoted only in the existing owner-only staged launch file, never terminal input, and the pane deletes that file as sourcing starts; a deletion failure refuses the worker launch and keeps the interactive shell.
`-u` is required because tmux's non-UTF-8 client output replaces newlines and non-ASCII bytes in values with underscores.

The source is opt-in and nothing changes for homes that do not create the file.
When `config/backend` is orca, the allowlist is nonempty, and no source is configured, fm-spawn now prints a stderr warning that allowlisted names resolve from the Orca terminal, so the mismatch is no longer silent.
It warns rather than refuses because refusing would stop every existing Orca home that uses an allowlist, which the triage asked not to assume.
Other backends, relaunch (already refused on Orca), and secondmate inheritance are unchanged; the selector is not in the inherited configuration list.

The scoped Git credential helper case also needs kunchenguid#6341, which stops fm-spawn's `core.hooksPath` entry from overwriting inherited `GIT_CONFIG_*` entries; this change does not depend on it.

Tests in `tests/fm-spawn-orca-worktree.test.sh`:

- A real-tmux regression on a private socket checks exact multiline UTF-8 values under absent and C locales through sh, Bash, and zsh, refusal of names that exist only server-globally or only inside another value, and exclusion of the automatic `SSH_AUTH_SOCK`.
- Fake-Orca spawns execute the real staged launch file under synthetic personal credentials and cover the configured source, an empty allowlist, refusal before allocation for each invalid setting, file privacy and deletion before the worker runs, and the deletion-failure path.
- The warning appears for a nonempty allowlist without a source and not for an empty allowlist or a configured source.

Risk: the source keeps tmux and the named session as dependencies of Orca spawns, and secret values sit in a 0600 file under a 0700 directory until the pane sources it.
It is not a filesystem sandbox; a worker can still read the user's credential files unless the harness restricts that.
The hardened path was verified with the regressions above, not with a live Orca spawn.

* no-mistakes(review): Harden Orca launch-file cleanup, floor unsets, and stat portability

* no-mistakes(review): Scope Orca abort cleanup to the staged launch file

* docs: scope Orca source to fresh spawns and qualify pane values

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs: state that Orca relaunch is refused

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* no-mistakes: apply CI fixes

* no-mistakes(review): Keep Orca launch file while delivered terminal stays open

* no-mistakes(document): Qualify fm-spawn help's destination-pane expansion claim for Orca

* fix(spawn): keep launch-send failures fatal and compare tmux bytes per version

The Orca launch-file cleanup wrapped both launch sends in a condition, which runs outside errexit.
A failed send on tmux and every other non-Orca backend then continued as success, so a post-publication relaunch failure no longer failed closed.
Each send failure now exits again, and Orca source mode removes its staged file first.

The real-tmux regression asserted that invalid UTF-8 bytes survive tmux itself, which holds on tmux 3.6a but not on the CI runner's tmux.
It now asserts that the snapshot reproduces exactly the bytes the installed tmux reports for that name.

* fix(spawn): reclaim an Orca launch file the pane never runs

In Orca source mode the pane unlinks the credential-bearing launch file as it starts sourcing it.
A pane that accepted the source command but never ran it left the file on disk until teardown, because the abort cleanup keeps the file for a delivered, still-open terminal.
After delivery, fm-spawn now waits up to 30 seconds for the pane to consume the file; if it has not, fm-spawn removes it and fails the spawn with a status line naming the unrun command.

The snapshot already reads and writes tmux output as latin1, so bytes that are not valid UTF-8 reach the launch file unchanged.
A deterministic fake-tmux regression now pins that, independent of how the installed tmux stores such values.

The live-terminal test now drives a slow pane and fails unless the spawn waits for it, and the controlled-source test reads the file the fake pane consumed.

* no-mistakes(review): Keep Orca terminal open when launch file is unconsumed

* no-mistakes(review): Refuse Orca worker when launch file already reclaimed

* no-mistakes(review): Make Orca spawn's deadline launch-file reclaim exclusive

* no-mistakes(document): Document Orca launch-file reclaim keeping the terminal open

* fix(spawn): reclaim an interrupted Orca launch file and keep errexit panes open

An HUP, INT or TERM after the source command reached the Orca terminal left
the credential-bearing launch file on disk: bash ran the EXIT trap with status
0 and abort cleanup kept a delivered file for the pane. Source mode now traps
those signals until the pane consumes the file, and abort cleanup reclaims it
with the same non-forced unlink arbitration as the consume deadline, refusing
the worker when the spawn wins and leaving the terminal open.

The delivered source line now keeps a pane shell with errexit set open when
the launch is refused, including when the file was already reclaimed.

* no-mistakes(review): Trap signals as soon as Orca launch file is published

* no-mistakes(document): Record pre-send interrupt coverage in Orca verification notes

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>

* fix(bin): treat OpenCode's right-aligned cwd rail as composer furniture, including absolute paths (kunchenguid#7307)

* fix(composer): treat OpenCode >= 1.18 right-aligned cwd:branch as furniture

OpenCode 1.18.31 draws the worker pane's working directory and branch
right-aligned inside the left-bar composer rows above the Build footer,
wrapped over up to three rail-width fragments whose final fragment
continues onto the footer row's right end. The fragments are RGB 128
grey with luminance exactly on the ghost-luma ceiling, so they survive
ghost stripping, and the left-bar classifier read them as unsent typed
text: every idle 1.18.31 pane answered pending, which skipped the
steering doorbell, the watcher's re-ring ladder, and /exit typing.

_fm_composer_leftbar_cwd_start recognises the run structurally and
position-gated: contiguous single-token rows immediately above the
footer row whose gap after the bar exceeds half the row, whose
fragments plus the footer row's gap-separated right-hand tail
concatenate to a path, optionally followed by :<branch>. A path-shaped
string typed at the composer's left edge is still typed text, so a
wrong call can only defer, never inject. Extraction shares the same
rule so extracted composer content stays user-scoped.

* no-mistakes(review): drop dead footer-tail concat, add live short-cwd fixture

* no-mistakes(review): accept only ~/ cwd rail; lone slash stays pending

* no-mistakes(review): require footer row for leftbar cwd furniture walk

* no-mistakes(review): Require topmost cwd fragment to carry ~/ prefix

* no-mistakes(document): Correct cwd furniture recognition doc to topmost-fragment check

* fix(composer): gate cwd rail on region width; correct version story

Review round on the independent PR review: the position gate now measures
the gap against the region's width (the widest trimmed plain row across
first..last), so a short space-prefixed home path typed into an otherwise
empty composer no longer reads empty; the right-half lone-token residual
is pinned explicitly. The cwd:branch furniture is documented as present
since OpenCode 1.18.0 (upstream anomalyco/opencode#36457, merged
2026-07-11), not a 1.18.31 layout change. The 1.18.30 capture comment
notes it omits the directory footer, and a cropped-composer extraction
assertion scopes user content to the typed row above the rail.

* no-mistakes(document): correct OpenCode cwd-furniture version framing and doc typos

* fix(composer): accept an absolute cwd rail outside $HOME as OpenCode furniture

Refs kunchenguid#4632, builds on kunchenguid#5030.

* no-mistakes(review): Harden live abs-cwd check waits and qualify rail comment

* no-mistakes(review): Fix composer-lib relative path in OpenCode harness doc

* no-mistakes(test): Relax live check's DONE wait for wide OpenCode panes

* no-mistakes(document): Separate absolute-cwd verification output block from following prose

---------

Co-authored-by: Konrad Heimel <[email protected]>

* fix(bin): report a worker parked on the exit picker as blocked-on-prompt (kunchenguid#6682)

* fix: name the Claude exit picker on existing stale wakes

A pane parked on that picker still read as healthy quiet after Enter was refused. The existing stale and wedge reports now carry the dialog name, including through away-mode escalation.

Refs kunchenguid#4754

* no-mistakes(review): fix: report exit picker on terminal-status away stales

* no-mistakes(document): docs: describe exit-picker reporting in stale supervision

* no-mistakes(review): fix: drop away stale marker when second-mate picker closes

* fix: keep the exit-picker name off paths main does not already run

A second mate stays exempt from stale capture, and a finished worker in away mode no longer ages into a wedge. The name remains on the stale and wedge wakes a worker already raises.

* no-mistakes(review): name the exit picker on wedge deferral reasons

* no-mistakes(review): limit exit-picker name to plain stale and wedge escalation

* feat: set afk spend cap from live ordinary workers at entry (kunchenguid#7308)

* feat(afk): Spend-Obergrenze beim Eintritt aus der lebenden Worker-Zahl

Ohne ausdrückliches --spend nimmt der Eintritt in den Away-Modus die Zahl der
gerade im Home stehenden gewöhnlichen Worker als Obergrenze, damit der Modus
laufende Parallelität nicht einengt. Der bisherige Default bleibt Untergrenze,
0 bleibt ausgeschlossen, und ein ausdrückliches --spend gewinnt weiterhin.

Die Zählung bekommt mit `live-workers` genau eine Implementierung in
bin/fm-afk-contract.sh. bin/fm-spawn.sh liest sie dort statt mit einer eigenen
Schleife, sodass Eintritt und spätere Sperre nicht auseinanderlaufen können.

* no-mistakes(document): Remove misplaced afk spend-cap plan

---------

Co-authored-by: ladwein <[email protected]>

* fix(bin): guide completed-scout cleanup and permit stock lab supervision paths (kunchenguid#6965)

* fix(bin): guide supervision through completed-scout cleanup

* no-mistakes(document): Document completed-scout cleanup ownership and regression coverage

* no-mistakes(test): Allow confined lab overrides and verify live scout cleanup

* no-mistakes(test): Clarify per-task cleanup reporting and verify live outcomes

* ci: let a fork skip the push run and the macOS job by repository variable (kunchenguid#7260)

* fix(bin): have workers paused on their own background job set until to the job's timeout (kunchenguid#7240)

* fix: recheck a worker paused on its own background job

A worker that declares `paused:` on its own background job and then misses the job's completion stays idle until the long declared-wait recheck, because the first-sight alert spends the declaration's throttle and nothing else names when the job must have ended.
The worker pause instructions now say that `until` for such a job is its start plus its timeout, and the watcher already rechecks once when that time passes.
The recovery playbook now tells the supervisor to verify the condition a declared wait names before reporting the wait as healthy.

Fixes kunchenguid#7239

* test: give the background-job until test headroom over its quiet round

The first absorb round of the until test may take four poll cycles of up to 30 s each on a loaded runner.
With `until` only 15 s ahead, that time could pass during the round and fail the test although the watcher behaves correctly.
Set `until` 120 s ahead so the window covers those four cycles, as CONTRIBUTING asks of fixture windows.

* chore: retrigger CI

* chore: retrigger CI

* no-mistakes(review): Rebuild bg-job until test with passed until, no sleep

* no-mistakes(review): Restore bg-job absorb checks and assert due recheck marker

---------

Co-authored-by: pedromuller-del <[email protected]>

* feat(bin): add a verified Command Code (commandcode) crewmate/scout adapter (kunchenguid#6679)

* feat: add Command Code crewmate and scout adapter

Add `commandcode` as a verified worker runtime for crewmate and scout work
only, so Firstmate can dispatch workers on Command Code models such as
deepseek/deepseek-v4.1-flash.

- Detection: the anchored `command-code` process title identifies the
  adapter in fm-harness.sh and the shared liveness classifier.
- Launch: fm-spawn passes --yolo, --trust, --skip-onboarding, the model, an
  effort only where the model's accepted set is verified, and the typed
  launch brief after --; taste-learning state is kept out of git.
- Busy state: a tracked mod, bin/fm-commandcode-mod.ts, is loaded per
  process with --mod and --mod-option, writing run_start/run_end/session
  end through fm-busy-event.sh; no user or project settings are edited
  (Command Code's --config persists globally, so it is never used).
- Control: one Escape interrupts; the idle double-Escape Rewind picker is a
  recognized hazard that exit refuses and interrupt dismisses; /quit exits.
- Composer: the bright truecolor placeholder is read with an
  identity-scoped ghost ceiling, and the tmux adapter supplies the identity
  for a cursor parked below the footer; Herdr reports it natively as `cmd`.
- Attribution: the fleet commit-msg strip removes the CommandCodeBot
  trailer.
- Docs, harness reference, verification record, portable regressions, and
  the FM_COMMANDCODE_SIGNALS_LIVE live guard.

* no-mistakes(review): Drop flash-fast effort pairs; correct identity-probe cost comments

* no-mistakes(ci): I fixed both Greptile findings the way you asked. Both new regression tests fail on the old code and pass now. The changes are not committed. **ci-1: Command Code on zellij, cmux and orca.** The rule that must hold is that a Command Code worker only runs on a backend that tells Firstmate the pane is Command Code. Without that, its idle placeholder never reads as an empty composer, so steering stalls. `bin/fm-spawn.sh` now refuses `--harness commandcode` unless the backend is tmux or herdr. The error reads: `commandcode is verified on the tmux and herdr backends only; backend=<b> cannot prove its composer empty. Select backend tmux or herdr.` - The check runs after both the harness and the backend are known, so it covers fresh spawns and `--relaunch`. - It runs before any pane, worktree, task record or busy state is created. - New test in `tests/fm-commandcode-harness.test.sh`: tries a scout spawn on each of zellij, cmux and orca (with a fake `orca` that reports ready). It checks for the refusal and that nothing was launched, no task record was written and busy state was not armed. It needs no real backend installed. - Documented in `docs/configuration.md`, the Command Code adapter reference and the `fm-spawn.sh` header. **ci-2: an old process signalling its replacement.** The rule is that the `turn-ended` notification may only be raised under the same generation check as the idle write. The mod used to touch the file itself after the writer returned, which left a gap for a relaunch to slip in. - `bin/fm-busy-event.sh apply` takes a new `--turn-ended` flag. It touches `state/<id>.turn-ended` while still holding the writer lock, after the generation check passes. A stale generation is refused with no touch, and the flag is rejected on any subcommand other than `apply`. - `bin/fm-commandcode-mod.ts` no longer touches files itself. On `run_end` it passes `--turn-ended` unless the turn was interrupted. - New test in `tests/fm-commandcode-harness.test.sh`: a fake writer accepts the idle write and then arms a replacement before the mod continues. It asserts no notification appears. - New test in `tests/fm-busy-state.test.sh`: the notification is raised for the current generation, not for a stale one, and not outside `apply`. **Checks run:** - Passing: `fm-commandcode-harness`, `fm-busy-state`, `fm-busy-adapter-wiring`, `fm-backend`, `fm-documentation-audiences`, and `bash -n` on the changed shell files. - `fm-bootstrap.test.sh` fails one case ("backend=herdr must fail closed on its own missing session CLI"). It fails the same way on an untouched copy of the branch, because herdr is installed at `/usr/bin/herdr` on this machine. - `bin/fm-lint.sh` could not run because ShellCheck 0.11.0 is not on PATH, so the changed shell files have not been linted. **Not changed:** Devin's hook does the same thing outside this PR: it runs `apply ... && touch` in `bin/fm-devin-config.sh`. That predates this PR and is not in the changed area, so I left it alone

* no-mistakes(ci): I fixed ci-sc2016. ShellCheck is not installed on this machine, so I could not confirm that the lint warning is gone. **The rule that was broken:** the repo lints with ShellCheck at its default severity, which also fails on info-level notes. Any single-quoted `$` that is meant to stay literal needs a scoped disable comment that says why. Only one place in the changed area needed this: the racing-writer `printf` in `tests/fm-commandcode-harness.test.sh`. Its format string writes `"$2" "$3"` on purpose, so the generated fake writer reads its own arguments when it runs. **The fix:** I added one line just above that `printf`: `# shellcheck disable=SC2016 # positional params expand in the generated writer.` The repo already does this the same way, for example in `tests/fm-afk-launch.test.sh` and `tests/fm-ask-user-authority.test.sh`. Nothing else changed, so the test behaves exactly as before. **Checks run:** - `bash -n tests/fm-commandcode-harness.test.sh` passes. - `bash tests/fm-commandcode-harness.test.sh` passes all six cases, including the busy-mod case with the racing writer. **Not run:** `bin/fm-lint.sh` stops with "ShellCheck not found" because ShellCheck 0.11.0 is not on PATH and there is no copy in the repo. I did not install it, since installs outside the worktree are off limits here. The upstream lint run will be the first ShellCheck pass on this change. The change is not committed

* no-mistakes(review): Hard-code Command Code ghost luma ceiling at 160

* no-mistakes(review): Test commandcode relaunch refusal off tmux/herdr before stop

* no-mistakes(document): Note Command Code fixed ghost luma ceiling in config docs

* fix: put a read cue at the head of a context re-emit (kunchenguid#7298)

Claude spills a hook output over 10,000 characters and shows only the first
2,000 plus a saved-file path. The re-emit prints captain.md and learnings.md
last, so they never reached the session. Print a short cue first that names
the saved file and the memory files, and document the cap.

Refs kunchenguid#6303

* fix(bin): retry transient contribution forge reads once before waking (kunchenguid#7302)

* fix: retry transient contribution reads once

* fix: classify contribution read errors safely

Address review findings for kunchenguid#7262 by parsing only gh status forms, recognizing real DNS errors, refusing GraphQL not-found retries, clearing per-URL diagnostics, and restoring exit-137 handling.

* fix: recognize bare gh HTTP errors

Complete kunchenguid#7262 review fixes by accepting bodyless gh status lines and keeping all GraphQL errors out of transient network classification.

* no-mistakes(review): Classify gh network errors by Go error tokens

* no-mistakes(document): Note why contribution 404 reads are never retried

* no-mistakes(review): Retry message-less GraphQL HTTP 5xx on closing read

* fix: retry transient contribution reads once

* fix: classify contribution read errors safely

Address review findings for kunchenguid#7262 by parsing only gh status forms, recognizing real DNS errors, refusing GraphQL not-found retries, clearing per-URL diagnostics, and restoring exit-137 handling.

* fix: recognize bare gh HTTP errors

Complete kunchenguid#7262 review fixes by accepting bodyless gh status lines and keeping all GraphQL errors out of transient network classification.

* no-mistakes(review): Classify gh network errors by Go error tokens

* no-mistakes(document): Note why contribution 404 reads are never retried

* no-mistakes(review): Retry message-less GraphQL HTTP 5xx on closing read

* fix(bin): let a backlog captain hold bound the watcher's wedge escalation (kunchenguid#7338)

* fix(bin): let a backlog captain hold bound the watcher's wedge escalation

A stuck worker whose task was held for the captain through
bin/fm-captain-hold.sh kept wedge-escalating every STALE_ESCALATE_SECS,
because wedge_wait_evidence only read the status line. It now also reads
the open backlog captain call (task_captain_call_open) and defers to the
existing captain-facing long recheck, silent while the away record exists.

* no-mistakes(review): Publish no wait age for backlog captain holds

* no-mistakes(review): Let an elapsed paused-until line fall through to backlog hold

* no-mistakes(document): Document backlog captain hold in wedge wait-evidence contract

---------

Co-authored-by: Kun Chen <[email protected]>
Co-authored-by: Ian Brown <[email protected]>
Co-authored-by: Stephen Haptonstahl <[email protected]>
Co-authored-by: Michal Zuber <[email protected]>
Co-authored-by: Andrew Li <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Steven G Woods <[email protected]>
Co-authored-by: Kostadin Pop-Kochev <[email protected]>
Co-authored-by: Konrad Heimel <[email protected]>
Co-authored-by: Tiago <[email protected]>
Co-authored-by: Sebastian <[email protected]>
Co-authored-by: ladwein <[email protected]>
Co-authored-by: Phu <[email protected]>
Co-authored-by: Pedro Müller <[email protected]>
Co-authored-by: pedromuller-del <[email protected]>
Co-authored-by: pback34 <[email protected]>
Co-authored-by: Tim Kleinschmidt <[email protected]>
Co-authored-by: Liam Sarsfield <[email protected]>
Co-authored-by: yairtech <[email protected]>
Co-authored-by: Valerius Mattfeld <[email protected]>
tiago-peixoto added a commit to tiago-peixoto/firstmate that referenced this pull request Oct 15, 2026
Upstream main (kunchenguid#7338) bounds the wedge ladder on a backlog captain hold the
worker's status log never shows, and its test records that hold through the
real bin/fm-captain-hold.sh hold. On this branch that command also declares
the hold on the lane's status log, so the fixture's lane took the captain-held
arm with the hold's own age and was absorbed inside the cadence instead of
being rechecked at once with no age.

The backlog arm still owns a hold recorded before that declaration existed,
or one a later worker line replaced, so the fixture now restores the worker's
line after the hold is recorded, and the watcher comment and architecture doc
name that case instead of saying the log never shows a hold.