Skip to content

fix(bin): stop false wakes from killed forge reads and slow first beats - #6668

Closed
Vela3202019 wants to merge 6 commits into
kunchenguid:mainfrom
Vela3202019:fm/firstmate-contributions-observer-flap
Closed

Vela3202019 wants to merge 6 commits into
kunchenguid:mainfrom
Vela3202019:fm/firstmate-contributions-observer-flap

Conversation

@Vela3202019

@Vela3202019 Vela3202019 commented Oct 5, 2026 •

Copy link
Copy Markdown

What Changed

  • Contributions poll retries a failed observation once: bin/fm-contributions.sh re-observes a URL whose observation failed, as long as the remaining budget still covers a full observation reserve. The error and the unavailable wake are recorded only after a second consecutive failure. A transient forge failure, or a head that moved mid-read, now costs one extra read instead of raising a false wake.
  • Watcher beats while it starts up: bin/fm-watch.sh now runs the blocking recovery-marker transitions (reopen-announced and arm-check) after the singleton lock identity is published. A helper touches the liveness beacon every second while those transitions run, so a watcher waiting on a long wake-queue drain reads to the guard and racing arms as a healthy, identity-matched holder. Both the startup beat and the transitions' lock waits stop at WATCHER_STALL_BOUND, using a new optional max-seconds argument in bin/fm-wake-lib.sh, so a startup stuck behind a hung holder still goes stale. fm_lock_acquire_wait_max now gives up immediately when the lock's parent directory is gone.
  • Torn-down state reports the right reason: the per-cycle home/state/code-root check is now a shared exit_if_world_gone function. It also runs when a startup transition is refused and when the secondmate liveness or wake-stall ticks fail, so a deleted state directory exits with the teardown reason. A refused startup transition skips the cleanup trap and keeps the stale-lock evidence. Docs (turnend-guard.md, watcher-continuity.md) and tests (contributions, wake-queue, watch-arm, watch-triage) are updated to match.

Risk Assessment

⚠️ Medium: The change moves the recovery-marker startup transitions after the cleanup trap and identity publication, and adds a bounded background beat loop in the watcher's supervision-critical startup path. I traced the main paths and they hold up: a blocked startup, a wedged startup past the stall bound, a state directory torn down during the wait, and TERM during startup. I found no concrete defect, but the timing-sensitive reordering deserves the medium rating.

Testing

I drove the watcher startup scenarios live with the real arm and watcher scripts in throwaway marked lab homes. Each used a private tmux socket and its own wake-queue lock holder, and each lab was removed afterwards. - Blocked startup: a watcher stuck behind the lock was confirmed as started. A racing arm 8s later attached to it rather than refusing a stale heartbeat. The watcher kept polling once the lock was released. - Wedged startup: a watcher still blocked at the stall bound refused with "retaining stale lock evidence" and kept its lock evidence. Its beacon then went stale, and a later arm started a replacement. - State directory deleted during the block: the watcher exited at once with the state-gone reason in 4/4 live runs. The existing state-dir test passed 4/4; it flaked in an earlier round. For the contributions retry, the real poll ran only against a disposable stub forge, so these scenarios are marked untested rather than live: - With the stub, a single 502 was retried and left a clean record with no wake. - With the stub, a persistent 502 recorded the error and printed exactly one unavailable line. The surrounding targeted contributions tests also passed. This is a CLI and background-process change, so there is no visual surface; the evidence is the CLI transcripts.

  • Live validation: ✅ go - 3 of 5 scenarios driven live against the product
Scenario Result Live Evidence
An arm starts a watcher that blocks at startup on a held wake-queue lock for longer than the confirm window and the stale grace. The arm reports 'started', and a racing arm attaches instead of refusin… ✅ pass live blocked.log: 'watcher: started pid=78809', and 8s later the racing arm printed 'watcher: attached pid=78809 (beacon 1s)' with no 'heartbeat is stale'. Also test_arm_confirms_a_watcher_blocked_on_the_w…
A watcher whose startup stays wedged on the wake-queue lock past the stall bound stops beating and refuses with 'retaining stale lock evidence'. Its beacon goes stale, and a later arm can replace it. ✅ pass live wedged.log: exit rc=1 with 'recovery state could not be reopened safely; retaining stale lock evidence'. The lock pid was retained, beacon age grew from 1s to 4s, and the later arm printed 'watcher: s…
Adversarial: deleting the state directory while a just-started watcher is blocked on the startup lock makes the watcher exit promptly with the state-gone reason, not hang until the stall bound. ✅ pass live stategone.log: in 4/4 runs the watcher was gone within 0s and logged 'watcher: exiting - state directory no longer exists'. test_watcher_exits_when_its_state_directory_is_removed passed 4/4 (arm-targe…
A contributions poll whose forge read fails once with HTTP 502 and then recovers retries the observation, prints no unavailable wake, and records a clean observation. ⏸️ untested no The prior payload did not establish a live result. It ran the real bin/fm-contributions.sh poll only against a disposable stub gh forge (contributions-retry-transcript.log; test_transient_forge_fail…
A forge that keeps failing through the retry still records the error and wakes exactly once per failure episode. ⏸️ untested no The prior payload did not establish a live result. It ran the real poll only against a disposable stub forge (contributions-retry-transcript.log; test_persistent_forge_failure_still_records_after_retr…
Evidence: Live driver script (lab-home watcher scenarios)

Source: Live driver script (lab-home watcher scenarios)

#!/usr/bin/env bash
# Live driver: real bin/fm-watch-arm.sh / bin/fm-watch.sh against a disposable marked lab home.
# Usage: drive-watcher.sh <scenario>   (blocked | wedged | stategone)
set -u
ROOT=~/.no-mistakes/worktrees/34bae1aacd62/01M5MXY3YHDGWA20J941SW5GNM
SCEN=$1
LAB=$(cd "$(mktemp -d "${TMPDIR:-/tmp}/fm-lab.XXXXXX")" && pwd -P)
"$ROOT/bin/fm-lab-home.sh" create "$LAB" >/dev/null || exit 1
mkdir -p "$LAB/tmux"
STATE="$LAB/state"
unset FM_ROOT_OVERRIDE FM_STATE_OVERRIDE FM_DATA_OVERRIDE FM_CONFIG_OVERRIDE FM_PROJECTS_OVERRIDE FM_GATE_REFUSE_BYPASS TMUX TMUX_PANE
export FM_HOME="$LAB" TMUX_TMPDIR="$LAB/tmux"
log() { printf '[%s +%ss] %s\n' "$SCEN" "$SECONDS" "$*"; }
age() { echo $(( $(date +%s) - $(stat -f %m "$STATE/.last-watcher-beat" 2>/dev/null || echo 0) )); }
cleanup() {
  : > "$LAB/release"
  "$ROOT/bin/fm-watch-arm.sh" --stop >/dev/null 2>&1 || true
  for p in $(cat "$STATE/.watch.lock/pid" 2>/dev/null) ${HOLDER:-} ${ARM:-} ${RACE:-} ${W:-}; do kill "$p" 2>/dev/null; done
  sleep 1
  tmux -L fm-lab kill-server 2>/dev/null || true
  rm -rf "$LAB"
  log "lab removed: $LAB"
}
trap cleanup EXIT
log "lab home: $LAB"
# A live holder on the wake-queue lock (stands in for a long fm-wake-drain run).
( . "$ROOT/bin/fm-wake-lib.sh"
  fm_lock_try_acquire "$STATE/.wake-queue.lock" || exit 1
  : > "$LAB/holding"
  while [ ! -e "$LAB/release" ]; do sleep 0.2; done
  fm_lock_release "$STATE/.wake-queue.lock" ) &
HOLDER=$!
while [ ! -e "$LAB/holding" ]; do sleep 0.1; done
log "wake-queue lock held by pid $HOLDER"

case "$SCEN" in
blocked)
  FM_POLL=1 FM_GUARD_GRACE=3 FM_WATCHER_STALL_BOUND=60 FM_ARM_CONFIRM_TIMEOUT=2 \
    "$ROOT/bin/fm-watch-arm.sh" > "$LAB/arm.out" 2>&1 &
  ARM=$!
  for _ in $(seq 100); do grep -q '^watcher:' "$LAB/arm.out" && break; sleep 0.1; done
  log "arm A output: $(head -1 "$LAB/arm.out")"
  W=$(sed -n 's/^watcher: started pid=\([0-9]*\).*/\1/p' "$LAB/arm.out" | head -1)
  log "lock pid=$(cat $STATE/.watch.lock/pid 2>/dev/null) pid-identity present=$([ -s $STATE/.watch.lock/pid-identity ] && echo yes || echo no) beacon age=$(age)s"
  sleep 8
  log "after 8s more blocked (grace=3s, confirm=2s): watcher alive=$(kill -0 "$W" 2>/dev/null && echo yes || echo no) beacon age=$(age)s holder still holding=$([ -e $LAB/release ] && echo no || echo yes)"
  FM_GUARD_GRACE=3 FM_WATCHER_STALL_BOUND=60 FM_ARM_CONFIRM_TIMEOUT=2 FM_ARM_ATTACH_POLL=0.1 \
    "$ROOT/bin/fm-watch-arm.sh" > "$LAB/race.out" 2>&1 &
  RACE=$!
  for _ in $(seq 100); do grep -q '^watcher:' "$LAB/race.out" && break; sleep 0.1; done
  log "racing arm B output: $(head -3 "$LAB/race.out")"
  grep -q 'heartbeat is stale' "$LAB/race.out" && log "RESULT: FAIL stale-heartbeat refusal" || log "no stale-heartbeat refusal"
  : > "$LAB/release"
  log "released wake-queue lock"
  sleep 4
  log "watcher alive after release=$(kill -0 "$W" 2>/dev/null && echo yes || echo no) beacon age=$(age)s"
  ;;
wedged)
  FM_POLL=1 FM_CHECK_INTERVAL=999999 FM_HEARTBEAT=999999 FM_WATCHER_STALL_BOUND=4 \
    "$ROOT/bin/fm-watch.sh" > "$LAB/w.out" 2> "$LAB/w.err" &
  W=$!
  sleep 2
  log "watcher pid=$W blocked; beacon age=$(age)s lock pid=$(cat $STATE/.watch.lock/pid)"
  t0=$SECONDS; while kill -0 "$W" 2>/dev/null && [ $((SECONDS-t0)) -lt 20 ]; do sleep 0.2; done
  wait "$W"; rc=$?
  log "watcher exited rc=$rc after ~$((SECONDS-t0+2))s; stderr: $(cat "$LAB/w.err")"
  log "lock evidence retained: pid file=$(cat $STATE/.watch.lock/pid 2>/dev/null)"
  a1=$(age); sleep 3; a2=$(age)
  log "beacon age ${a1}s -> ${a2}s (keeps growing = stale, no helper still beating)"
  : > "$LAB/release"; sleep 1
  FM_POLL=1 FM_GUARD_GRACE=3 FM_ARM_CONFIRM_TIMEOUT=10 "$ROOT/bin/fm-watch-arm.sh" > "$LAB/rearm.out" 2>&1 &
  ARM=$!
  for _ in $(seq 150); do grep -q '^watcher:' "$LAB/rearm.out" && break; sleep 0.1; done
  log "later arm (grace 3s) after hung holder released: $(grep '^watcher:' "$LAB/rearm.out" | head -2)"
  ;;
stategone)
  FM_POLL=1 FM_ARM_CONFIRM_TIMEOUT=5 "$ROOT/bin/fm-watch-arm.sh" > "$LAB/arm.out" 2>&1 &
  ARM=$!
  for _ in $(seq 100); do grep -q '^watcher:' "$LAB/arm.out" && break; sleep 0.1; done
  log "arm output: $(head -1 "$LAB/arm.out")"
  W=$(sed -n 's/^watcher: started pid=\([0-9]*\).*/\1/p' "$LAB/arm.out" | head -1)
  sleep 1
  rm -rf "$STATE"
  kill "$HOLDER" 2>/dev/null
  log "state directory removed while watcher $W blocked at startup"
  t0=$SECONDS; while kill -0 "$W" 2>/dev/null && [ $((SECONDS-t0)) -lt 30 ]; do sleep 0.2; done
  log "watcher alive after $((SECONDS-t0))s: $(kill -0 "$W" 2>/dev/null && echo yes || echo no)"
  ls "$LAB"/state 2>/dev/null >/dev/null; 
  log "watcher log lines: $(grep -h 'watcher: exiting\|watcher:' "$LAB"/arm.out | tail -3)"
  ;;
esac
Evidence: Blocked startup: arm reports started, racing arm attaches, no stale refusal

Source: Blocked startup: arm reports started, racing arm attaches, no stale refusal

[blocked +0s] arm A output: watcher: started pid=78809 (beacon fresh) [blocked +0s] lock pid=78809 pid-identity present=yes beacon age=0s [blocked +8s] after 8s more blocked (grace=3s, confirm=2s): watcher alive=yes beacon age=1s holder still holding=yes [blocked +9s] racing arm B output: watcher: attached pid=78809 (beacon 1s) [blocked +9s] no stale-heartbeat refusal [blocked +13s] watcher alive after release=yes beacon age=1s

[blocked +0s] lab home: /private/var/folders/32/ng_xnctn3dj29mxdt024s0cc0000gn/T/fm-lab.m9tTWw
[blocked +0s] wake-queue lock held by pid 78756
[blocked +0s] arm A output: watcher: started pid=78809 (beacon fresh)
[blocked +0s] lock pid=78809 pid-identity present=yes beacon age=0s
[blocked +8s] after 8s more blocked (grace=3s, confirm=2s): watcher alive=yes beacon age=1s holder still holding=yes
[blocked +9s] racing arm B output: watcher: attached pid=78809 (beacon 1s)
[blocked +9s] no stale-heartbeat refusal
[blocked +9s] released wake-queue lock
[blocked +13s] watcher alive after release=yes beacon age=1s
[blocked +14s] lab removed: /private/var/folders/32/ng_xnctn3dj29mxdt024s0cc0000gn/T/fm-lab.m9tTWw
Evidence: Wedged startup goes stale at the stall bound and is replaceable

Source: Wedged startup goes stale at the stall bound and is replaceable

[wedged +5s] watcher exited rc=1 after ~4s; stderr: watcher: recovery state could not be reopened safely; retaining stale lock evidence [wedged +5s] lock evidence retained: pid file=91386 [wedged +8s] beacon age 1s -> 4s (keeps growing = stale, no helper still beating) [wedged +9s] later arm (grace 3s) after hung holder released: watcher: started pid=93376 (beacon fresh)

[wedged +1s] lab home: /private/var/folders/32/ng_xnctn3dj29mxdt024s0cc0000gn/T/fm-lab.xwsRPS
[wedged +1s] wake-queue lock held by pid 91210
[wedged +3s] watcher pid=91386 blocked; beacon age=1s lock pid=91386
[wedged +5s] watcher exited rc=1 after ~4s; stderr: watcher: recovery state could not be reopened safely; retaining stale lock evidence
[wedged +5s] lock evidence retained: pid file=91386
[wedged +8s] beacon age 1s -> 4s (keeps growing = stale, no helper still beating)
[wedged +9s] later arm (grace 3s) after hung holder released: watcher: started pid=93376 (beacon fresh)
[wedged +10s] lab removed: /private/var/folders/32/ng_xnctn3dj29mxdt024s0cc0000gn/T/fm-lab.xwsRPS
Evidence: State dir deleted during blocked startup: prompt state-gone exit (4/4)

Source: State dir deleted during blocked startup: prompt state-gone exit (4/4)

[stategone +0s] lab home: /private/var/folders/32/ng_xnctn3dj29mxdt024s0cc0000gn/T/fm-lab.COfheC
[stategone +0s] wake-queue lock held by pid 85781
[stategone +1s] arm output: watcher: started pid=85850 (beacon fresh)
[stategone +2s] state directory removed while watcher 85850 blocked at startup
./drive-watcher.sh: line 36: 85781 Terminated: 15          ( . "$ROOT/bin/fm-wake-lib.sh"; fm_lock_try_acquire "$STATE/.wake-queue.lock" || exit 1; : > "$LAB/holding"; while [ ! -e "$LAB/release" ]; do
    sleep 0.2;
done; fm_lock_release "$STATE/.wake-queue.lock" )
[stategone +2s] watcher alive after 0s: no
[stategone +2s] watcher log lines: watcher: started pid=85850 (beacon fresh)
watcher: exiting - state directory no longer exists: /private/var/folders/32/ng_xnctn3dj29mxdt024s0cc0000gn/T/fm-lab.COfheC/state
[stategone +3s] lab removed: /private/var/folders/32/ng_xnctn3dj29mxdt024s0cc0000gn/T/fm-lab.COfheC
[stategone +0s] lab home: /private/var/folders/32/ng_xnctn3dj29mxdt024s0cc0000gn/T/fm-lab.kqULel
[stategone +0s] wake-queue lock held by pid 86570
[stategone +1s] arm output: watcher: started pid=86685 (beacon fresh)
[stategone +2s] state directory removed while watcher 86685 blocked at startup
./drive-watcher.sh: line 36: 86570 Terminated: 15          ( . "$ROOT/bin/fm-wake-lib.sh"; fm_lock_try_acquire "$STATE/.wake-queue.lock" || exit 1; : > "$LAB/holding"; while [ ! -e "$LAB/release" ]; do
    sleep 0.2;
done; fm_lock_release "$STATE/.wake-queue.lock" )
[stategone +2s] watcher alive after 0s: no
[stategone +2s] watcher log lines: watcher: started pid=86685 (beacon fresh)
watcher: exiting - state directory no longer exists: /private/var/folders/32/ng_xnctn3dj29mxdt024s0cc0000gn/T/fm-lab.kqULel/state
[stategone +3s] lab removed: /private/var/folders/32/ng_xnctn3dj29mxdt024s0cc0000gn/T/fm-lab.kqULel
[stategone +0s] lab home: /private/var/folders/32/ng_xnctn3dj29mxdt024s0cc0000gn/T/fm-lab.fG2GZX
[stategone +0s] wake-queue lock held by pid 87583
[stategone +1s] arm output: watcher: started pid=87679 (beacon fresh)
[stategone +2s] state directory removed while watcher 87679 blocked at startup
./drive-watcher.sh: line 36: 87583 Terminated: 15          ( . "$ROOT/bin/fm-wake-lib.sh"; fm_lock_try_acquire "$STATE/.wake-queue.lock" || exit 1; : > "$LAB/holding"; while [ ! -e "$LAB/release" ]; do
    sleep 0.2;
done; fm_lock_release "$STATE/.wake-queue.lock" )
[stategone +2s] watcher alive after 0s: no
[stategone +2s] watcher log lines: watcher: started pid=87679 (beacon fresh)
watcher: exiting - state directory no longer exists: /private/var/folders/32/ng_xnctn3dj29mxdt024s0cc0000gn/T/fm-lab.fG2GZX/state
[stategone +3s] lab removed: /private/var/folders/32/ng_xnctn3dj29mxdt024s0cc0000gn/T/fm-lab.fG2GZX
[stategone +0s] lab home: /private/var/folders/32/ng_xnctn3dj29mxdt024s0cc0000gn/T/fm-lab.GREE0D
[stategone +0s] wake-queue lock held by pid 88575
[stategone +1s] arm output: watcher: started pid=88650 (beacon fresh)
[stategone +2s] state directory removed while watcher 88650 blocked at startup
./drive-watcher.sh: line 36: 88575 Terminated: 15          ( . "$ROOT/bin/fm-wake-lib.sh"; fm_lock_try_acquire "$STATE/.wake-queue.lock" || exit 1; : > "$LAB/holding"; while [ ! -e "$LAB/release" ]; do
    sleep 0.2;
done; fm_lock_release "$STATE/.wake-queue.lock" )
[stategone +2s] watcher alive after 0s: no
[stategone +2s] watcher log lines: watcher: started pid=88650 (beacon fresh)
watcher: exiting - state directory no longer exists: /private/var/folders/32/ng_xnctn3dj29mxdt024s0cc0000gn/T/fm-lab.GREE0D/state
[stategone +3s] lab removed: /private/var/folders/32/ng_xnctn3dj29mxdt024s0cc0000gn/T/fm-lab.GREE0D
Evidence: Contributions poll retry transcript (transient vs persistent 502, stub forge)

Source: Contributions poll retry transcript (transient vs persistent 502, stub forge)

retry-once: stdout <empty - no unavailable wake>; core reads 2; record error null fail-persist: stdout 'contributions: observation unavailable for https://github.com/o/r/pull/8 - core read exited 1 with 19s of budget left: HTTP 502'; core reads 2; record error retained

=== forge fault: retry-once (core read fails once with HTTP 502, then recovers)
$ fm-contributions.sh poll
exit=0 stdout: <empty - no unavailable wake>
core reads made: 2
record: {"checked_at":"2026-09-16T08:00:00Z","error":null}
tests/.tmp-contrib-drive.sh: line 1910: /private/var/folders/32/ng_xnctn3dj29mxdt024s0cc0000gn/T/fm-contributions.cWRFVD/drive-retry-once/state/.wake-queue: No such file or directory
wake-queue rows: 0

=== forge fault: fail-persist (core read keeps failing with HTTP 502)
$ fm-contributions.sh poll
exit=0 stdout: contributions: observation unavailable for https://github.com/o/r/pull/8 - core read exited 1 with 19s of budget left: HTTP 502
core reads made: 2
record: {"checked_at":"2026-09-16T08:00:00Z","error":"forge observation unavailable: core read exited 1 with 19s of budget left: HTTP 502"}
tests/.tmp-contrib-drive.sh: line 1910: /private/var/folders/32/ng_xnctn3dj29mxdt024s0cc0000gn/T/fm-contributions.cWRFVD/drive-fail-persist/state/.wake-queue: No such file or directory
wake-queue rows: 0
Evidence: Targeted watch-arm tests

Source: Targeted watch-arm tests

ok - watch-arm: a watcher blocked at startup on the wake-queue lock is confirmed and attached, never refused as stale
ok - watch-arm: a startup wedged on the wake-queue lock past the stall bound stops beating and refuses
ok - watch-arm: a watcher exits when its state directory is removed
ok - watch-arm: a watcher exits when its state directory is removed
ok - watch-arm: a watcher exits when its state directory is removed
ok - watch-arm: a watcher exits when its state directory is removed
Evidence: Targeted contributions tests

Source: Targeted contributions tests

ok - a transient first read failure is retried once and records a clean observation
ok - a failure that survives the retry records the error and wakes once
ok - a genuinely unavailable forge records an error and wakes once per failure episode
ok - one HTTP 500 is retried once and a successful retry stays healthy
jq: error (at /var/folders/32/ng_xnctn3dj29mxdt024s0cc0000gn/T//fm-contributions.DfmeqJ/after.json:1): null (null) cannot be matched, as it is not a string
jq: error (at /var/folders/32/ng_xnctn3dj29mxdt024s0cc0000gn/T//fm-contributions.DfmeqJ/after.json:1): null (null) cannot be matched, as it is not a string
ok - a URL owned by two tasks is observed once and every owner receives the result
ok - rotation preserves timed-out records and refreshes every slow PR on successive cycles
ok - a read killed at the five-second bound is budget refusal and stays silent

Pipeline

Updates from git push no-mistakes

⏭️ **intent** - skipped

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - medium risk

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 3 of 5 scenarios driven live against the product
Scenario Result Live Evidence
An arm starts a watcher that blocks at startup on a held wake-queue lock for longer than the confirm window and the stale grace. The arm reports 'started', and a racing arm attaches instead of refusin… ✅ pass live blocked.log: 'watcher: started pid=78809', and 8s later the racing arm printed 'watcher: attached pid=78809 (beacon 1s)' with no 'heartbeat is stale'. Also test_arm_confirms_a_watcher_blocked_on_the_w…
A watcher whose startup stays wedged on the wake-queue lock past the stall bound stops beating and refuses with 'retaining stale lock evidence'. Its beacon goes stale, and a later arm can replace it. ✅ pass live wedged.log: exit rc=1 with 'recovery state could not be reopened safely; retaining stale lock evidence'. The lock pid was retained, beacon age grew from 1s to 4s, and the later arm printed 'watcher: s…
Adversarial: deleting the state directory while a just-started watcher is blocked on the startup lock makes the watcher exit promptly with the state-gone reason, not hang until the stall bound. ✅ pass live stategone.log: in 4/4 runs the watcher was gone within 0s and logged 'watcher: exiting - state directory no longer exists'. test_watcher_exits_when_its_state_directory_is_removed passed 4/4 (arm-targe…
A contributions poll whose forge read fails once with HTTP 502 and then recovers retries the observation, prints no unavailable wake, and records a clean observation. ⏸️ untested no The prior payload did not establish a live result. It ran the real bin/fm-contributions.sh poll only against a disposable stub gh forge (contributions-retry-transcript.log; test_transient_forge_fail…
A forge that keeps failing through the retry still records the error and wakes exactly once per failure episode. ⏸️ untested no The prior payload did not establish a live result. It ran the real poll only against a disposable stub forge (contributions-retry-transcript.log; test_persistent_forge_failure_still_records_after_retr…
  • drive-watcher.sh blocked: in a marked lab home (fm-lab-home.sh create), a live holder keeps the wake-queue lock. The real bin/fm-watch-arm.sh runs with FM_GUARD_GRACE=3 and FM_ARM_CONFIRM_TIMEOUT=2. After 8s still blocked, a second real arm races it, then the lock is released.
  • drive-watcher.sh wedged: the real bin/fm-watch.sh runs with FM_WATCHER_STALL_BOUND=4 behind a wake-queue lock holder that never releases. Then the beacon age is measured and a later arm is run.
  • drive-watcher.sh stategone x4: an arm starts a watcher blocked at startup, the lab's state directory is deleted while the lock is still held, and the watcher's exit reason is checked.
  • fm-watch-arm.test.sh selectors: test_arm_confirms_a_watcher_blocked_on_the_wake_queue_lock, test_wedged_startup_goes_stale_at_the_stall_bound, test_watcher_exits_when_its_state_directory_is_removed (x4)
  • Real bin/fm-contributions.sh poll against a disposable stub forge with faults retry-once and fail-persist; transcript records stdout, read count, record error and wake queue.
  • fm-contributions.test.sh selectors: test_transient_forge_failure_retries_once, test_persistent_forge_failure_still_records_after_retry, test_unavailable_forge_records_error_and_wakes_once_per_episode, test_http_500_once_retries_without_waking, test_shared_url_observed_once, test_unmeasured_url_does_not_starve_the_tail, test_slow_read_deadline_kill_is_budget_refusal
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[High risk] Changes watcher startup locking and forge retry logic.

The PR appears safe to merge, with the previously reported contribution-poll budget cost remaining as non-blocking feedback.

Reviews (2) · Last reviewed commit: "no-mistakes(lint): Fix shellcheck findin..."

Comment thread bin/fm-contributions.sh Resolved
Comment thread bin/fm-watch.sh Resolved
Comment thread bin/fm-contributions.sh
Comment on lines +394 to +396
if [ "$observed" -ne 0 ] && [ $((DEADLINE - $(date +%s))) -ge "$OBSERVATION_RESERVE" ]; then
observed=0
observe "$url" || observed=$?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Repeated failures consume poll budget This retry also runs when the URL already has an open error episode, which cannot emit another unavailable wake. If a persistent forge failure takes seconds per read, the extra attempt uses the shared poll budget and can leave later healthy URLs unchecked. Skipping that extra read for an already-recorded failure would preserve more coverage.

Knowledge Base Used: Keep contribution records when the poll budget expires

Comment thread tests/fm-watch-triage.test.sh Resolved
@Vela3202019
Vela3202019 force-pushed the fm/firstmate-contributions-observer-flap branch from e1ebbd3 to d31c6b7 Compare October 5, 2026 23:25
@Vela3202019
Vela3202019 force-pushed the fm/firstmate-contributions-observer-flap branch from d31c6b7 to a3c21fe Compare October 23, 2026 17:56
@Vela3202019 Vela3202019 changed the title fix(bin): stop watcher false wakes from forge read flaps and slow startup fix(bin): stop false wakes from killed forge reads and slow first beats Oct 23, 2026
@Vela3202019

Copy link
Copy Markdown
Author

Note on test status: tests/fm-watch-arm.test.sh has one failure in this branch's local validation run: "re-append was not byte-identical to the inherited row" (test_append_wakes_handling_successor after-ack missing identical). This failure is pre-existing on origin/main - running origin/main's own fm-watch-arm suite fails the identical test - so it is not caused by this change and was intentionally left out of scope. The other affected suites (fm-contributions, fm-watch-triage, fm-wake-queue) pass.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @Vela3202019 for picking this back up with a fresh no-mistakes raise and live watcher runs.

What I checked (head a3c21fe2 vs main af1c6817): I read the diff myself. fm-contributions.sh re-observes a failed URL once while the budget still covers a full reserve. fm-watch.sh moves the reopen-announced/arm-check startup transitions after the lock identity is published and adds a one-second startup beat, both bounded by WATCHER_STALL_BOUND. fm-wake-lib.sh gains an optional max-seconds lock wait, and exit_if_world_gone is a straight extraction of the existing checks. No workflow, credential or new network surface is touched (the only forge read is the existing one, retried once). Since this is a fork PR on a new head, I've approved its CI runs.

Contract-class (my own read): new-default. These are reasonable fixes for false wakes, but they change what an unconfigured home does on default-on paths: the watcher's startup order changes, a background beat loop runs during startup, and every contributions poll gets an extra retry read. Under our rules that's a captain call, not an auto-merge, even though the motive is a bugfix. VISION.md per rule: One captain aligns (fewer false wakes) · Authority aligns (no new grant assumed) · Scripts aligns (bounded deterministic mechanics) · Restart aligns (stale-lock evidence kept on refusal, wedged startup still goes stale) · Delegation aligns · Vendor neutral · Scope aligns.

Status: waiting on CI, not on you. Once CI finishes green on this head, I'll pass it to Kun for the merge decision. The contributions retry scenarios ran against a stub forge rather than live. If you're able to capture one real transient forge failure being retried, that would strengthen the case, but it's optional. Thanks also for flagging the fm-watch-arm "re-append was not byte-identical" failure that also happens on main. I've noted it.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @Vela3202019. CI finished on head a3c21fe2, and a few things need your attention:

  • The branch now has merge conflicts with main.
  • Lint 1 fails on tests/fm-watch-arm.test.sh (ShellCheck SC2031 around L422, holder=$! after a subshell). Main's lint is green, so this comes from the branch.
  • serial 4 (cap-fire round expected exit 1 on the failed counter reset, got 124) and serial 9 (handling successor never resurfaced the startup-window row) fail in watcher areas this PR changes. Please check whether these come from the change.
  • parallel 2 (packing exactly at the budget) is inherited from main, so you can ignore it.

When you've rebased and fixed those, please re-raise through git push no-mistakes so the attestation binds the new head. This is waiting on you. Once it's green, it goes to Kun as a merge-or-leave decision (contract-class new-default, unchanged).

@Vela3202019

Copy link
Copy Markdown
Author

Superseded by #7944, which carries this same fix rebased onto current main, with the full suite green, Greptile at 5/5 and no open review threads. Closing this one so there is a single PR to review. The follow-up windows the maintainer asked about (rebase, Lint 1 / SC2031, serial 4, serial 9, re-raise through git push no-mistakes) were all handled there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants