Skip to content

fix(bin): reopen the remote-reply continuity decision on a later break - #6708

Merged
kunchenguid merged 9 commits into
kunchenguid:mainfrom
tiago-peixoto:fm/upstream-6701
Oct 7, 2026
Merged

kunchenguid merged 9 commits into
kunchenguid:mainfrom
tiago-peixoto:fm/upstream-6701

Conversation

@tiago-peixoto

@tiago-peixoto tiago-peixoto commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Fixes #6701.

Contribute the fix for #6701, which the maintainer labelled ready-for-pr (contract class: restore): a later remote-reply continuity break appends no status line after an operator resolve, so the new decision never opens. The issue's expected behaviour: after the operator closes a continuity break, a later distinct break for the same route and reason appends a new blocked line that opens the decision again, while a repeat of the same unchanged break, whose cursor has not moved, still appends nothing.

The maintainer's triage: status_event_recorded keeps a match recorded for the life of the file, and its own comment says a caller that owns evidence of a new episode has to decide that itself; the continuity caller does not. Episode detection from cursor and retirement evidence is exact script work, and the reproduction makes good regression coverage. It is the same shape pull request 6654 restored for the pending-reply escalation of issue 6635.

What Changed

  • bin/fm-procevent-remote-reply.sh now writes the continuity blocked line with the cursor offset, the first 12 characters of the cursor hash, and a retirement count for the route. A re-read of the same break builds the same line and appends nothing, while a break at a different reader position or after another retirement builds a new line that opens the decision again.
  • Retirement now keeps a per-route count in <id>.retirements beside the cursor. It removes the cursor first, fails if the cursor cannot be removed, and only then writes the next count, so a stop between the two steps leaves the count unchanged. Ingest only reads the count and rejects a symlinked or malformed count file.
  • tests/fm-remote-reply.test.sh adds regression cases: a later break after an operator resolve, a status line in the old format, a break after retirement with identical restored bytes, and the two retirement failure points. docs/remote-secondmates.md describes what the status line records and when a new one is appended.

Risk Assessment

✅ Low: The change is confined to the continuity branch of cmd_ingest and to cmd_retire_finalize_locked, the traced sequences (unchanged repeat, moved cursor, retirement with identical restore, failed cursor removal, stop before the count write) all give the intended result, and the remaining trade-offs were already decided by the user.

Testing

I wrote a driver script that runs the real bin/fm-procevent-remote-reply.sh, bin/fm-procevent.sh, and the remote delta reader against throwaway homes, and ran it on the target commit 5d445ac and on a git export of the base commit 99da16d. On the target all 17 expectations pass across six scenarios: first break, unchanged repeat after a resolve, later break after the reader advanced without retirement (the issue 6701 case), repeat of that later break, break after retirement with identical restored bytes, and a retirement that cannot remove the cursor. On the base the issue reproduces: the later break appends nothing and the decision stays closed. I also ran the focused test file tests/fm-remote-reply.test.sh, which passed. Two scenarios were not driven live and are marked untested: the retirement that stops after removing the cursor, and the upgrade from an old-format line. The focused test file covers both, but with a stand-in mktemp and a rewritten status file, so that is not live evidence. I did not run the full suite. The change has no UI, so the evidence is command transcripts of the parent status stream, not screenshots. All temporary homes and the base export were removed; the worktree is clean.

  • Live validation: ✅ go - 6 of 8 scenarios driven live against the product
Scenario Result Live Evidence
First continuity break: the remote log is truncated under the committed cursor, and the parent status stream gains one blocked line that records offset, 12-character prefix, and retirement count, and… ✅ pass live target-5d445ac1-transcript.txt step 1: line '... (truncated) at offset 41 prefix ce699f5e4021 retirements 0', blocked lines 1, open decisions [remote-reply-continuity-ios]
Unchanged repeat after operator resolve: the operator resolves the break, the same break is handled and ingested again with the cursor unmoved, and nothing is appended and the decision stays closed ✅ pass live target-5d445ac1-transcript.txt step 2: blocked lines stay 1, open decisions []
Issue 6701: after the resolve the log is repaired, the reader advances to a new offset without retirement, the log breaks again, and a new blocked line appends and the decision opens again ✅ pass live target-5d445ac1-transcript.txt step 3: second line 'at offset 79 prefix 654aba5c7088 retirements 0', blocked lines 2, decision open. base-99da16d9-transcript.txt step 3 shows the bug: blocked lines 1,…
Repeat of the later break before any resolve: the same later break is ingested again and no third line appends ✅ pass live target-5d445ac1-transcript.txt step 4: blocked lines stay 2
Break after retirement with identical restored bytes: the operator resolves, retires the route, restores the same bytes, the reader reaches the same offset and prefix, the log breaks, and a new line w… ✅ pass live target-5d445ac1-transcript.txt step 5: retirement count file count=1, third line 'at offset 79 prefix 654aba5c7088 retirements 1', decision open, repeat appends nothing. On base the same step appends…
Adversarial, cursor cannot be removed: the cursor path is a directory, retire fails with an error, the retirement count is unchanged, and the already resolved break still appends nothing ✅ pass live target-5d445ac1-transcript.txt step 6: 'error: cannot remove remote reply cursor', exit status 1, count stays count=1, blocked lines stay 3, open decisions []. On base retire reported success
Adversarial, retirement stops after removing the cursor and before writing the count: retire fails, the cursor is gone, and the old count remains ⏸️ untested no The prior payload did not establish a live result. This scenario ran only through the existing test file tests/fm-remote-reply.test.sh, which runs the real adapter but injects the stop with a stand-…
Upgrade from a line written before the reader position was recorded: the old line does not match, so the next break appends the new line once and a repeat appends nothing ⏸️ untested no The prior payload did not establish a live result. This scenario ran only through the existing test file tests/fm-remote-reply.test.sh, which rewrites the status file into the old form. The base tra…
Evidence: Target 5d445ac: driven transcript, all six scenarios

Source: Target 5d445ac1: driven transcript, all six scenarios

checkout under test: ~/.no-mistakes/worktrees/5284051b2355/01M49YMNWBPJD4V9PH67K3NVHZ (5d445ac1)

== 1. Read the route, then break it (first break)
registered: remote-reply-ios (remote-reply)
armed: remote-reply-ios offset=0
adapter classify: continuity-broken
continuity-broken: ios (truncated)
already-handled: remote-reply-ios 2
~/.no-mistakes/worktrees/5284051b2355/01M49YMNWBPJD4V9PH67K3NVHZ/bin/fm-procevent-remote-reply.sh: line 1: tmp: unbound variable
adapter handle exit status: 3
cursor: schema=fm-remote-reply-cursor.v1 offset=41 prefix_sha256=ce699f5e4021261174e3b3c9aa1a5ba75e37400a672f71b0dd12ce8797084a10 
retirement count file: absent
continuity lines in parent state/ios.status:
    blocked [key=remote-reply-continuity-ios] [at=1791335889]: remote reply continuity broke for ios (truncated) at offset 41 prefix ce699f5e4021 retirements 0
blocked lines: 1   open decisions: [remote-reply-continuity-ios ]
PASS: first break appends one blocked line (got 1)
PASS: first break opens the decision (got remote-reply-continuity-ios )

== 2. Operator resolves; the same unchanged break is read again
operator appended: resolved [key=remote-reply-continuity-ios]
continuity-broken: ios (truncated)
handled: remote-reply-ios 2
~/.no-mistakes/worktrees/5284051b2355/01M49YMNWBPJD4V9PH67K3NVHZ/bin/fm-procevent-remote-reply.sh: line 1: tmp: unbound variable
adapter handle exit status: 3
cursor: schema=fm-remote-reply-cursor.v1 offset=41 prefix_sha256=ce699f5e4021261174e3b3c9aa1a5ba75e37400a672f71b0dd12ce8797084a10 
retirement count file: absent
continuity lines in parent state/ios.status:
    blocked [key=remote-reply-continuity-ios] [at=1791335889]: remote reply continuity broke for ios (truncated) at offset 41 prefix ce699f5e4021 retirements 0
    resolved [key=remote-reply-continuity-ios]: operator accepted the break
blocked lines: 1   open decisions: []
PASS: unchanged repeat appends nothing (got 1)
PASS: unchanged repeat leaves the decision closed (got )

== 3. Issue 6701: repair the log, reader advances, later distinct break (no retirement)
registered: remote-reply-ios (remote-reply)
armed: remote-reply-ios offset=41
PASS: repair alone appends no blocked line (got 1)
adapter classify: continuity-broken
continuity-broken: ios (truncated)
already-handled: remote-reply-ios 4
~/.no-mistakes/worktrees/5284051b2355/01M49YMNWBPJD4V9PH67K3NVHZ/bin/fm-procevent-remote-reply.sh: line 1: tmp: unbound variable
adapter handle exit status: 3
cursor: schema=fm-remote-reply-cursor.v1 offset=79 prefix_sha256=654aba5c70886df322b8c26670a5a345dae67b62d11d47085b3ac9b4b2656ac9 
retirement count file: absent
continuity lines in parent state/ios.status:
    blocked [key=remote-reply-continuity-ios] [at=1791335889]: remote reply continuity broke for ios (truncated) at offset 41 prefix ce699f5e4021 retirements 0
    resolved [key=remote-reply-continuity-ios]: operator accepted the break
    blocked [key=remote-reply-continuity-ios] [at=1791335898]: remote reply continuity broke for ios (truncated) at offset 79 prefix 654aba5c7088 retirements 0
blocked lines: 2   open decisions: [remote-reply-continuity-ios ]
PASS: later distinct break appends a new blocked line (got 2)
PASS: later distinct break opens the decision again (got remote-reply-continuity-ios )

== 4. The later break is read again before any resolve
cursor: schema=fm-remote-reply-cursor.v1 offset=79 prefix_sha256=654aba5c70886df322b8c26670a5a345dae67b62d11d47085b3ac9b4b2656ac9 
retirement count file: absent
continuity lines in parent state/ios.status:
    blocked [key=remote-reply-continuity-ios] [at=1791335889]: remote reply continuity broke for ios (truncated) at offset 41 prefix ce699f5e4021 retirements 0
    resolved [key=remote-reply-continuity-ios]: operator accepted the break
    blocked [key=remote-reply-continuity-ios] [at=1791335898]: remote reply continuity broke for ios (truncated) at offset 79 prefix 654aba5c7088 retirements 0
blocked lines: 2   open decisions: [remote-reply-continuity-ios ]
PASS: repeat of the later break appends nothing (got 2)

== 5. Resolve, retire the route, restore identical bytes, break at the same position
operator appended: resolved [key=remote-reply-continuity-ios]
retired: remote-reply-ios
adapter retire exit status: 0
registered: remote-reply-ios (remote-reply)
armed: remote-reply-ios offset=0
PASS: identical restore alone appends no blocked line (got 2)
PASS: identical restore leaves the decision closed (got )
adapter classify: continuity-broken
continuity-broken: ios (truncated)
already-handled: remote-reply-ios 6
~/.no-mistakes/worktrees/5284051b2355/01M49YMNWBPJD4V9PH67K3NVHZ/bin/fm-procevent-remote-reply.sh: line 1: tmp: unbound variable
adapter handle exit status: 3
cursor: schema=fm-remote-reply-cursor.v1 offset=79 prefix_sha256=654aba5c70886df322b8c26670a5a345dae67b62d11d47085b3ac9b4b2656ac9 
retirement count file: count=1
continuity lines in parent state/ios.status:
    blocked [key=remote-reply-continuity-ios] [at=1791335889]: remote reply continuity broke for ios (truncated) at offset 41 prefix ce699f5e4021 retirements 0
    resolved [key=remote-reply-continuity-ios]: operator accepted the break
    blocked [key=remote-reply-continuity-ios] [at=1791335898]: remote reply continuity broke for ios (truncated) at offset 79 prefix 654aba5c7088 retirements 0
    resolved [key=remote-reply-continuity-ios]: operator accepted the break
    blocked [key=remote-reply-continuity-ios] [at=1791335907]: remote reply continuity broke for ios (truncated) at offset 79 prefix 654aba5c7088 retirements 1
blocked lines: 3   open decisions: [remote-reply-continuity-ios ]
PASS: break after retirement and identical restore appends a new blocked line (got 3)
PASS: break after retirement opens the decision again (got remote-reply-continuity-ios )
PASS: repeat of that break appends nothing (got 3)

== 6. Adversarial: retirement cannot remove the cursor (cursor path is a directory)
operator appended: resolved [key=remote-reply-continuity-ios]
retired: remote-reply-ios
rm: cannot remove '/tmp/fm-6701-drive.B1UwSH/parent/state/remote-replies/ios.cursor': Is a directory
error: cannot remove remote reply cursor
adapter retire exit status: 1
PASS: retirement reports failure (got failed)
PASS: failed retirement leaves the count unchanged (got count=1)
cursor: schema=fm-remote-reply-cursor.v1 offset=79 prefix_sha256=654aba5c70886df322b8c26670a5a345dae67b62d11d47085b3ac9b4b2656ac9 
retirement count file: count=1
continuity lines in parent state/ios.status:
    blocked [key=remote-reply-continuity-ios] [at=1791335889]: remote reply continuity broke for ios (truncated) at offset 41 prefix ce699f5e4021 retirements 0
    resolved [key=remote-reply-continuity-ios]: operator accepted the break
    blocked [key=remote-reply-continuity-ios] [at=1791335898]: remote reply continuity broke for ios (truncated) at offset 79 prefix 654aba5c7088 retirements 0
    resolved [key=remote-reply-continuity-ios]: operator accepted the break
    blocked [key=remote-reply-continuity-ios] [at=1791335907]: remote reply continuity broke for ios (truncated) at offset 79 prefix 654aba5c7088 retirements 1
    resolved [key=remote-reply-continuity-ios]: operator accepted the break
blocked lines: 3   open decisions: []
PASS: after the failed retirement the resolved break still appends nothing (got 3)
PASS: after the failed retirement the decision stays closed (got )

== RESULT: 0 expectation(s) failed
Evidence: Base 99da16d: same driver reproduces issue 6701

Source: Base 99da16d9: same driver reproduces issue 6701

checkout under test: <base-export> (base 99da16d9, exported with git archive)

== 1. Read the route, then break it (first break)
registered: remote-reply-ios (remote-reply)
armed: remote-reply-ios offset=0
adapter classify: continuity-broken
continuity-broken: ios (truncated)
already-handled: remote-reply-ios 2
<base-export>/bin/fm-procevent-remote-reply.sh: line 1: tmp: unbound variable
adapter handle exit status: 3
cursor: schema=fm-remote-reply-cursor.v1 offset=41 prefix_sha256=ce699f5e4021261174e3b3c9aa1a5ba75e37400a672f71b0dd12ce8797084a10 
retirement count file: absent
continuity lines in parent state/ios.status:
    blocked [key=remote-reply-continuity-ios] [at=1791335854]: remote reply continuity broke for ios (truncated)
blocked lines: 1   open decisions: [remote-reply-continuity-ios ]
PASS: first break appends one blocked line (got 1)
PASS: first break opens the decision (got remote-reply-continuity-ios )

== 2. Operator resolves; the same unchanged break is read again
operator appended: resolved [key=remote-reply-continuity-ios]
continuity-broken: ios (truncated)
handled: remote-reply-ios 2
<base-export>/bin/fm-procevent-remote-reply.sh: line 1: tmp: unbound variable
adapter handle exit status: 3
cursor: schema=fm-remote-reply-cursor.v1 offset=41 prefix_sha256=ce699f5e4021261174e3b3c9aa1a5ba75e37400a672f71b0dd12ce8797084a10 
retirement count file: absent
continuity lines in parent state/ios.status:
    blocked [key=remote-reply-continuity-ios] [at=1791335854]: remote reply continuity broke for ios (truncated)
    resolved [key=remote-reply-continuity-ios]: operator accepted the break
blocked lines: 1   open decisions: []
PASS: unchanged repeat appends nothing (got 1)
PASS: unchanged repeat leaves the decision closed (got )

== 3. Issue 6701: repair the log, reader advances, later distinct break (no retirement)
registered: remote-reply-ios (remote-reply)
armed: remote-reply-ios offset=41
PASS: repair alone appends no blocked line (got 1)
adapter classify: continuity-broken
continuity-broken: ios (truncated)
already-handled: remote-reply-ios 4
<base-export>/bin/fm-procevent-remote-reply.sh: line 1: tmp: unbound variable
adapter handle exit status: 3
cursor: schema=fm-remote-reply-cursor.v1 offset=79 prefix_sha256=654aba5c70886df322b8c26670a5a345dae67b62d11d47085b3ac9b4b2656ac9 
retirement count file: absent
continuity lines in parent state/ios.status:
    blocked [key=remote-reply-continuity-ios] [at=1791335854]: remote reply continuity broke for ios (truncated)
    resolved [key=remote-reply-continuity-ios]: operator accepted the break
blocked lines: 1   open decisions: []
FAIL: later distinct break appends a new blocked line (expected 2, got 1)
FAIL: later distinct break opens the decision again (expected remote-reply-continuity-ios , got )

== 4. The later break is read again before any resolve
cursor: schema=fm-remote-reply-cursor.v1 offset=79 prefix_sha256=654aba5c70886df322b8c26670a5a345dae67b62d11d47085b3ac9b4b2656ac9 
retirement count file: absent
continuity lines in parent state/ios.status:
    blocked [key=remote-reply-continuity-ios] [at=1791335854]: remote reply continuity broke for ios (truncated)
    resolved [key=remote-reply-continuity-ios]: operator accepted the break
blocked lines: 1   open decisions: []
FAIL: repeat of the later break appends nothing (expected 2, got 1)

== 5. Resolve, retire the route, restore identical bytes, break at the same position
operator appended: resolved [key=remote-reply-continuity-ios]
retired: remote-reply-ios
adapter retire exit status: 0
registered: remote-reply-ios (remote-reply)
armed: remote-reply-ios offset=0
PASS: identical restore alone appends no blocked line (got 1)
PASS: identical restore leaves the decision closed (got )
adapter classify: continuity-broken
continuity-broken: ios (truncated)
already-handled: remote-reply-ios 6
<base-export>/bin/fm-procevent-remote-reply.sh: line 1: tmp: unbound variable
adapter handle exit status: 3
cursor: schema=fm-remote-reply-cursor.v1 offset=79 prefix_sha256=654aba5c70886df322b8c26670a5a345dae67b62d11d47085b3ac9b4b2656ac9 
retirement count file: absent
continuity lines in parent state/ios.status:
    blocked [key=remote-reply-continuity-ios] [at=1791335854]: remote reply continuity broke for ios (truncated)
    resolved [key=remote-reply-continuity-ios]: operator accepted the break
    resolved [key=remote-reply-continuity-ios]: operator accepted the break
blocked lines: 1   open decisions: []
FAIL: break after retirement and identical restore appends a new blocked line (expected 2, got 1)
FAIL: break after retirement opens the decision again (expected remote-reply-continuity-ios , got )
FAIL: repeat of that break appends nothing (expected 2, got 1)

== 6. Adversarial: retirement cannot remove the cursor (cursor path is a directory)
operator appended: resolved [key=remote-reply-continuity-ios]
retired: remote-reply-ios
rm: cannot remove '/tmp/fm-6701-drive.sRBrb0/parent/state/remote-replies/ios.cursor': Is a directory
adapter retire exit status: 0
FAIL: retirement reports failure (expected failed, got succeeded)
PASS: failed retirement leaves the count unchanged (got absent)
cursor: schema=fm-remote-reply-cursor.v1 offset=79 prefix_sha256=654aba5c70886df322b8c26670a5a345dae67b62d11d47085b3ac9b4b2656ac9 
retirement count file: absent
continuity lines in parent state/ios.status:
    blocked [key=remote-reply-continuity-ios] [at=1791335854]: remote reply continuity broke for ios (truncated)
    resolved [key=remote-reply-continuity-ios]: operator accepted the break
    resolved [key=remote-reply-continuity-ios]: operator accepted the break
    resolved [key=remote-reply-continuity-ios]: operator accepted the break
blocked lines: 1   open decisions: []
PASS: after the failed retirement the resolved break still appends nothing (got 1)
PASS: after the failed retirement the decision stays closed (got )

== RESULT: 7 expectation(s) failed
Evidence: Driver script used for both transcripts

Source: Driver script used for both transcripts

#!/usr/bin/env bash
# Drives the real remote-reply adapter, process-event runner, and remote reader
# of the checkout at <root> against a disposable parent home and remote home.
# Only the SSH transport is replaced: a local stand-in runs the real
# fm-remote-entrypoint.sh in place of a network hop.
#
# Usage: drive-continuity.sh <root>
set -u
# The process-event runner refuses a group-writable state root.
umask 022
ROOT=$(cd "$1" && pwd -P)
TMP_ROOT=$(mktemp -d "${TMPDIR:-/tmp}/fm-6701-drive.XXXXXX")
TMP_ROOT=$(cd "$TMP_ROOT" && pwd -P)
PARENT="$TMP_ROOT/parent"
REMOTE="$TMP_ROOT/remote"
FAKEBIN="$TMP_ROOT/fakebin"
CLAIMS="$TMP_ROOT/claims"
mkdir -p "$PARENT/data" "$PARENT/state" "$REMOTE/state" "$REMOTE/data" "$CLAIMS" "$FAKEBIN"
# shellcheck disable=SC1091
. "$ROOT/bin/fm-remote-job-lib.sh"
# shellcheck disable=SC1091
. "$ROOT/bin/fm-classify-lib.sh"

cleanup() {
  local worker_pid=''
  FM_HOME="$PARENT" FM_PROCEVENT_CLAIM_ROOT="$CLAIMS" \
    "$ROOT/bin/fm-procevent.sh" sweep-home >/dev/null 2>&1 || true
  if [ -f "$TMP_ROOT/remote-jobs/worker.pid" ]; then
    worker_pid=$(cat "$TMP_ROOT/remote-jobs/worker.pid")
    fm_remote_job_stop_worker_tree "$worker_pid" || true
  fi
  rm -rf -- "$TMP_ROOT"
}
trap cleanup EXIT

cat > "$PARENT/data/secondmates.md" <<EOF
- ios - iOS delivery (host: remote-mac; root: $ROOT; home: $REMOTE; scope: iOS work; projects: alpha; added 2026-08-02)
EOF
: > "$REMOTE/state/parent-replies.status"

cat > "$FAKEBIN/fake-ssh" <<'SH'
#!/usr/bin/env bash
while [ "$#" -gt 0 ]; do
  case "$1" in
    -o) shift 2 ;;
    --) shift; break ;;
    *) exit 90 ;;
  esac
done
host=$1
entry=$2
shift 2
[ "$host" = remote-mac ] || exit 91
[ "$entry" = fm-remote-entrypoint.sh ] || exit 92
exec "$FM_FAKE_REMOTE_ENTRYPOINT" "$@"
SH
chmod +x "$FAKEBIN/fake-ssh"

remote_env() {
  FM_HOME="$PARENT" \
  FM_ROOT_OVERRIDE="$ROOT" \
  FM_PROCEVENT_CLAIM_ROOT="$CLAIMS" \
  FM_SSH_BIN="$FAKEBIN/fake-ssh" \
  FM_FAKE_REMOTE_ENTRYPOINT="$ROOT/bin/fm-remote-entrypoint.sh" \
  FM_REMOTE_JOB_PLATFORM_OVERRIDE=Linux \
  FM_REMOTE_JOB_STATE_ROOT="$TMP_ROOT/remote-jobs" \
  FM_REMOTE_REPLY_WAIT_SECONDS=10 \
  "$@"
}

ADAPTER="$ROOT/bin/fm-procevent-remote-reply.sh"
STATUS="$PARENT/state/ios.status"
CURSOR="$PARENT/state/remote-replies/ios.cursor"
COUNT="$PARENT/state/remote-replies/ios.retirements"
SID=$(remote_env "$ADAPTER" source-id ios)
GEN=0
FAILED=0

say() { printf '\n== %s\n' "$*"; }
abort() { printf 'DRIVER ABORT: %s\n' "$*"; sed 's/^/  runner: /' "$TMP_ROOT/runner.log" 2>/dev/null; exit 2; }
blocked_count() { grep -cF 'blocked [key=remote-reply-continuity-ios]' "$STATUS" 2>/dev/null || true; }
open_decisions() { status_open_decisions "$STATUS" | cut -f1 | tr '\n' ' '; }
show() {
  printf 'cursor: %s\n' "$(tr '\n' ' ' < "$CURSOR" 2>/dev/null || echo absent)"
  printf 'retirement count file: %s\n' "$(cat "$COUNT" 2>/dev/null || echo absent)"
  printf 'continuity lines in parent state/ios.status:\n'
  grep -F 'key=remote-reply-continuity-ios' "$STATUS" | sed 's/^/    /'
  printf 'blocked lines: %s   open decisions: [%s]\n' "$(blocked_count)" "$(open_decisions)"
}
expect() { # <description> <actual> <expected>
  if [ "$2" = "$3" ]; then
    printf 'PASS: %s (got %s)\n' "$1" "$2"
  else
    printf 'FAIL: %s (expected %s, got %s)\n' "$1" "$3" "$2"
    FAILED=$((FAILED + 1))
  fi
}

reply_owner() {
  remote_env "$ROOT/bin/fm-procevent.sh" list 2>/dev/null \
    | awk -v id="$SID" 'NR > 1 && $1 == id { print $3; exit }'
}
stop_listener() {
  local pid _
  pid=$(sed -n '2p' "$CLAIMS/$SID.claim" 2>/dev/null || true)
  case "$pid" in ''|*[!0-9]*) return 0 ;; esac
  kill -TERM -- -"$pid" 2>/dev/null || kill -TERM "$pid" 2>/dev/null || true
  for _ in $(seq 1 80); do
    kill -0 "$pid" 2>/dev/null || return 0
    sleep 0.05
  done
  return 1
}
# Put <content> in the remote log, arm, and let the runner read it.
read_route() { # <content>
  local result _
  printf '%s' "$1" > "$REMOTE/state/parent-replies.status"
  remote_env "$ADAPTER" arm ios
  GEN=$((GEN + 1))
  result="$PARENT/state/procevent-inbox/$SID.$GEN.result"
  if [ "$(reply_owner)" != live ]; then
    remote_env "$ROOT/bin/fm-procevent.sh" start "$SID" >> "$TMP_ROOT/runner.log" 2>&1 &
  fi
  for _ in $(seq 1 800); do
    [ -s "$result" ] && [ -f "${result%.result}.handled" ] && return 0
    sleep 0.05
  done
  abort "generation $GEN was not read"
}
# Empty the remote log under the committed cursor, let the runner capture the
# break, and run the adapter's handle on it. Sets RESULT_BREAK.
break_route() {
  local rc
  stop_listener || abort "listener did not stop"
  : > "$REMOTE/state/parent-replies.status"
  GEN=$((GEN + 1))
  remote_env "$ROOT/bin/fm-procevent.sh" start "$SID" >/dev/null 2>&1
  RESULT_BREAK=$(find "$PARENT/state/procevent-inbox" -name "$SID.$GEN.result" -print -quit)
  [ -n "$RESULT_BREAK" ] || abort "break produced no result for generation $GEN"
  printf 'adapter classify: %s\n' "$(remote_env "$ADAPTER" classify "$RESULT_BREAK")"
  remote_env "$ADAPTER" handle ios "$GEN" "$RESULT_BREAK"
  rc=$?
  printf 'adapter handle exit status: %s\n' "$rc"
}
resolve() {
  printf '%s\n' 'resolved [key=remote-reply-continuity-ios]: operator accepted the break' >> "$STATUS"
  printf 'operator appended: resolved [key=remote-reply-continuity-ios]\n'
}

printf 'checkout under test: %s (%s)\n' "$ROOT" "$(git -C "$ROOT" rev-parse --short HEAD 2>/dev/null || echo exported)"

LOG_A=$'working: first line from the remote mate\n'
LOG_B=$LOG_A$'working: second line after the repair\n'

say "1. Read the route, then break it (first break)"
read_route "$LOG_A"
break_route
RESULT_FIRST=$RESULT_BREAK
show
expect "first break appends one blocked line" "$(blocked_count)" 1
expect "first break opens the decision" "$(open_decisions)" "remote-reply-continuity-ios "

say "2. Operator resolves; the same unchanged break is read again"
resolve
rm -f "$PARENT/state/procevent-inbox/$SID.$GEN.handled"
remote_env "$ADAPTER" handle ios "$GEN" "$RESULT_FIRST"
printf 'adapter handle exit status: %s\n' "$?"
remote_env "$ADAPTER" ingest ios "$RESULT_FIRST" >/dev/null 2>&1
show
expect "unchanged repeat appends nothing" "$(blocked_count)" 1
expect "unchanged repeat leaves the decision closed" "$(open_decisions)" ""

say "3. Issue 6701: repair the log, reader advances, later distinct break (no retirement)"
read_route "$LOG_B"
expect "repair alone appends no blocked line" "$(blocked_count)" 1
break_route
RESULT_SECOND=$RESULT_BREAK
show
expect "later distinct break appends a new blocked line" "$(blocked_count)" 2
expect "later distinct break opens the decision again" "$(open_decisions)" "remote-reply-continuity-ios "

say "4. The later break is read again before any resolve"
remote_env "$ADAPTER" ingest ios "$RESULT_SECOND" >/dev/null 2>&1
show
expect "repeat of the later break appends nothing" "$(blocked_count)" 2

say "5. Resolve, retire the route, restore identical bytes, break at the same position"
resolve
remote_env "$ADAPTER" retire ios
printf 'adapter retire exit status: %s\n' "$?"
before=$(blocked_count)
read_route "$LOG_B"
expect "identical restore alone appends no blocked line" "$(blocked_count)" "$before"
expect "identical restore leaves the decision closed" "$(open_decisions)" ""
break_route
RESULT_THIRD=$RESULT_BREAK
show
expect "break after retirement and identical restore appends a new blocked line" "$(blocked_count)" $((before + 1))
expect "break after retirement opens the decision again" "$(open_decisions)" "remote-reply-continuity-ios "
remote_env "$ADAPTER" ingest ios "$RESULT_THIRD" >/dev/null 2>&1
expect "repeat of that break appends nothing" "$(blocked_count)" $((before + 1))

say "6. Adversarial: retirement cannot remove the cursor (cursor path is a directory)"
resolve
count_before=$(cat "$COUNT" 2>/dev/null || echo absent)
cp "$CURSOR" "$TMP_ROOT/cursor.saved"
rm -f "$CURSOR"; mkdir "$CURSOR"
remote_env "$ADAPTER" retire ios
rc=$?
printf 'adapter retire exit status: %s\n' "$rc"
expect "retirement reports failure" "$([ "$rc" -ne 0 ] && echo failed || echo succeeded)" failed
expect "failed retirement leaves the count unchanged" "$(cat "$COUNT" 2>/dev/null || echo absent)" "$count_before"
rmdir "$CURSOR"; cp "$TMP_ROOT/cursor.saved" "$CURSOR"
before=$(blocked_count)
remote_env "$ADAPTER" ingest ios "$RESULT_THIRD" >/dev/null 2>&1
show
expect "after the failed retirement the resolved break still appends nothing" "$(blocked_count)" "$before"
expect "after the failed retirement the decision stays closed" "$(open_decisions)" ""

say "RESULT: $FAILED expectation(s) failed"
[ "$FAILED" -eq 0 ]
Evidence: Focused test file output

Source: Focused test file output

ok - default delta reader waits 0.5 seconds then delivers a non-destructive complete-line delta
ok - override delta reader waits 0.07 seconds then delivers a non-destructive complete-line delta
ok - a blocking non-destructive remote delta reaches durable process-event capture
ok - a captured delta is applied, acknowledged, and re-armed without a handler
ok - ingest appends one validated line, fetches its document, and advances the cursor
ok - replayed capture has one deduplicated append and one durable handling identity
ok - later generations cannot invalidate an unacknowledged ingested result
ok - the remote status and decision model mirrors and the cursor advances
ok - a remote mate's new decision folds open exactly as a local mate's does
ok - a replayed mirrored delta is idempotent in both the stream and the cursor
ok - transported control bytes are normalized in place and never stop the stream
ok - payload protocol-field names cannot collide with transport metadata
ok - NUL bytes are normalized in place before shell line processing
ok - local document storage failures remain retryable until delivery succeeds
ok - a structured pointer must end at its token boundary
ok - adjacent pointers are fetched while malformed tokens remain unchanged
ok - a rejected candidate never gives the following text a false leading boundary
ok - nested remote reports relay while an undeliverable foreign pointer fails open
ok - the reported incident raises no standing decision and still delivers the report
ok - an undeliverable structured offer fails open with one note and never a decision
ok - a remote refusal surfaces its own reason without opening a decision
ok - a failed pointer extraction never commits a partial delta
ok - a failed mirror write never drops status content or advances the cursor
ok - source-line identity survives commit failure and cursor-loss recapture
ok - a mirrored reserved-key line cannot squat or clear the parent's own decision
ok - a reply that arrives after escalation resolves it and clears the open decision
ok - a remote reply listener stays owned across empty waits and a delta
ok - a failed remote read exits instead of relistening
ok - persistent ingestion failure leaves exactly one durable capture
ok - a preempted reply poll reports a closed window without publishing channel freshness
ok - a preempted reply poll keeps its listener and reconcile launches nothing
ok - a quiet reply window publishes the caught-up watermark the reply guard reads
ok - a cursor-loss whole-log recapture is acknowledged quietly with no duplicate wake
ok - truncation is detected, escalated once, and not silently rebased
ok - a repeated continuity break after an operator resolve appends nothing
ok - remote reply retirement quiesces and refuses unhandled captured results
ok - a later continuity break after repair and re-advance opens the decision again
ok - an old-format continuity line does not swallow the next break
ok - a later continuity break after the cursor moves without retirement opens the decision again
ok - a continuity break after retirement and an identical restore opens the decision once
ok - a failed cursor removal does not increase the retirement count
ok - a retirement that stops after removing the cursor leaves the old count
ALL TESTS PASSED
Evidence: Issue 6701 step, base versus target (parent state/ios.status after the later break)
BASE 99da16d9
blocked [key=remote-reply-continuity-ios] [at=1791335854]: remote reply continuity broke for ios (truncated)
resolved [key=remote-reply-continuity-ios]: operator accepted the break
blocked lines: 1 open decisions: []
FAIL: later distinct break appends a new blocked line (expected 2, got 1)

TARGET 5d445ac1
blocked [key=remote-reply-continuity-ios] [at=1791335661]: remote reply continuity broke for ios (truncated) at offset 41 prefix ce699f5e4021 retirements 0
resolved [key=remote-reply-continuity-ios]: operator accepted the break
blocked [key=remote-reply-continuity-ios] [at=1791335670]: remote reply continuity broke for ios (truncated) at offset 79 prefix 654aba5c7088 retirements 0
blocked lines: 2 open decisions: [remote-reply-continuity-ios ]
PASS: later distinct break appends a new blocked line (got 2)
- Outcome: ⚠️ 1 info across 1 run (11m39s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ℹ️ bin/fm-procevent-remote-reply.sh:795 - The retirement count increases once per successful run of cmd_retire_finalize_locked, not once per retirement. Sequence: bin/fm-teardown.sh:1060 finalizes (count 1 to 2), a later step such as remote_pending_replies_cleanup fails and teardown keeps the route "for retry", the operator runs teardown again, and finalize runs again (count 2 to 3) because removing an absent cursor succeeds. Break detection stays correct, because the count only has to differ after each cursor removal and it never decreases. The only inexact part is the sentence at docs/remote-secondmates.md:592, which describes the number as "how many times the route has been retired". No change is needed.
⚠️ **Test** - 1 info
  • ℹ️ bin/fm-procevent-remote-reply.sh:547 - Not caused by this change: every handle of a continuity break prints 'fm-procevent-remote-reply.sh: line 1: tmp: unbound variable' on stderr. The base commit 99da16d prints the same message (see both transcripts). The likely source is the EXIT trap rm -rf -- &#34;$tmp&#34; at line 547, which runs after the function's local tmp is out of scope under set -u. The exit status (3) and the status stream are correct, so it does not affect this fix; it belongs in a separate issue.
  • Live validation: ✅ go - 6 of 8 scenarios driven live against the product
Scenario Result Live Evidence
First continuity break: the remote log is truncated under the committed cursor, and the parent status stream gains one blocked line that records offset, 12-character prefix, and retirement count, and… ✅ pass live target-5d445ac1-transcript.txt step 1: line '... (truncated) at offset 41 prefix ce699f5e4021 retirements 0', blocked lines 1, open decisions [remote-reply-continuity-ios]
Unchanged repeat after operator resolve: the operator resolves the break, the same break is handled and ingested again with the cursor unmoved, and nothing is appended and the decision stays closed ✅ pass live target-5d445ac1-transcript.txt step 2: blocked lines stay 1, open decisions []
Issue 6701: after the resolve the log is repaired, the reader advances to a new offset without retirement, the log breaks again, and a new blocked line appends and the decision opens again ✅ pass live target-5d445ac1-transcript.txt step 3: second line 'at offset 79 prefix 654aba5c7088 retirements 0', blocked lines 2, decision open. base-99da16d9-transcript.txt step 3 shows the bug: blocked lines 1,…
Repeat of the later break before any resolve: the same later break is ingested again and no third line appends ✅ pass live target-5d445ac1-transcript.txt step 4: blocked lines stay 2
Break after retirement with identical restored bytes: the operator resolves, retires the route, restores the same bytes, the reader reaches the same offset and prefix, the log breaks, and a new line w… ✅ pass live target-5d445ac1-transcript.txt step 5: retirement count file count=1, third line 'at offset 79 prefix 654aba5c7088 retirements 1', decision open, repeat appends nothing. On base the same step appends…
Adversarial, cursor cannot be removed: the cursor path is a directory, retire fails with an error, the retirement count is unchanged, and the already resolved break still appends nothing ✅ pass live target-5d445ac1-transcript.txt step 6: 'error: cannot remove remote reply cursor', exit status 1, count stays count=1, blocked lines stay 3, open decisions []. On base retire reported success
Adversarial, retirement stops after removing the cursor and before writing the count: retire fails, the cursor is gone, and the old count remains ⏸️ untested no The prior payload did not establish a live result. This scenario ran only through the existing test file tests/fm-remote-reply.test.sh, which runs the real adapter but injects the stop with a stand-…
Upgrade from a line written before the reader position was recorded: the old line does not match, so the next break appends the new line once and a repeat appends nothing ⏸️ untested no The prior payload did not establish a live result. This scenario ran only through the existing test file tests/fm-remote-reply.test.sh, which rewrites the status file into the old form. The base tra…
  • bash ~/.no-mistakes/evidence/01M49YMNWBPJD4V9PH67K3NVHZ/drive-continuity.sh &#34;$PWD&#34; on target 5d445ac1: exit 0, 17 expectations pass, 0 fail
  • bash drive-continuity.sh &lt;git export of base 99da16d9&gt;: exit 1, 7 expectations fail, including 'later distinct break appends a new blocked line (expected 2, got 1)'
  • bash tests/fm-remote-reply.test.sh on target: exit 0, ALL TESTS PASSED (not live; includes 'ok - a retirement that stops after removing the cursor leaves the old count' and 'ok - an old-format continuity line does not swallow the next break')
  • git status --short after testing: clean
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Adds continuity tracking to remote reply processing.

No new, non-duplicate blocking finding remains from the changes since the previous review.

Reviews (5) · Last reviewed commit: "fix: remove the reply cursor before reco..." · Reviewed by Greptile

Comment thread bin/fm-procevent-remote-reply.sh Resolved
Comment thread bin/fm-procevent-remote-reply.sh Resolved
Comment thread bin/fm-procevent-remote-reply.sh Resolved
Comment thread tests/fm-remote-reply.test.sh Resolved
@tiago-peixoto tiago-peixoto changed the title fix: reopen a remote-reply continuity break after repair fix: reopen a remote-reply continuity decision on a later break Oct 6, 2026
@kunchenguid

ghost commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: reviewed against main e06a46fe. Thanks, @tiago-peixoto. The direction is right and CI is green, but one open Greptile P1 on this head is a real gap, so this is waiting on you.

What I checked: the body says Fixes #6701, and the diff does target that issue. cmd_ingest in bin/fm-procevent-remote-reply.sh now keeps a per-route <id>.continuity episode (offset, prefix hash, retired). A moved cursor or a retirement makes the next continuity-broken append a new blocked [key=remote-reply-continuity-<id>] line. An unchanged re-read still falls through to status_event_recorded and appends nothing. cmd_retire_finalize_locked marks the episode retired. status_event_recorded itself is unchanged. No workflow files are touched. Head 4c5f2266 matches the no-mistakes attestation, and every CI job on that head passed. The only red check is Greptile Review.

What still needs fixing (Greptile P1 on 4c5f2266, "Later break can disappear"): I traced it, and it holds. The episode is now written before the line (write_continuity_episode ... 0 comes before the append). If the handler dies between those two steps (kill, crash, host loss), the retry sees an episode that already equals the current cursor. continuity_break_is_new_episode then returns 1, status_event_recorded matches the earlier break's line, and nothing is appended. The later decision never opens, which is the #6701 failure again. Separately, the rollback on a failed append ignores its own failure (write_continuity_episode ... || true), so a failed restore leaves the same state. Your reply covered the earlier "failed episode write duplicates" P1. This newer one needs its own fix. Please:

  1. Make the store-then-append ordering crash-safe. For example, write the episode in a pending state and finalize it only after the line lands, and treat a pending episode at the same cursor as new on retry. Any equivalent that can't strand a break works too.
  2. Don't swallow a failed rollback. Refuse loudly, or leave the episode in a state the retry reads as new.
  3. Add a regression case for "episode stored, append never ran, retry" that shows the decision opens exactly once.
  4. Optional, for the Greptile P2s: skip rewriting the episode on an unchanged re-read, and guard the chmod 444 test against running as root.

Heads-up: #6710 also edits bin/fm-procevent-remote-reply.sh (in cmd_source). The hunks don't overlap today, but whichever lands second may need a rebase.

Contract-class: restore. Main already escalates a remote-reply continuity break as a keyed open decision that the operator resolve closes. Today a later distinct break on the same route is silently read as already recorded. The fix restores that specified escalation and keeps an unchanged repeat silent. It adds no new default surface. The episode file is internal state for an existing path.

VISION.md, rule by rule

  • One captain, one interface: aligns. A new continuity failure that reads as settled hides a failure, and this makes it visible again.
  • Authority is explicit and never inferred: aligns. No new autonomy. The operator still closes the decision.
  • Scripts own the mechanics, agents own the judgment: aligns. Episode detection from cursor and retirement is exact script work.
  • A restart is a non-event: does not align yet. Durable records are the right tool here, but the store-before-append window means a crash at the wrong moment loses an obligation (the P1 above).
  • Delegation with a spine: aligns. No change to task contracts.
  • The fleet outlives any vendor: aligns. Nothing vendor-specific.
  • Scope: aligns. Command-layer relay state, with regression coverage from a field reproduction.

Next step: push a fix for the P1. I'll look again once a fresh no-mistakes raise and green CI are on the new head.

Comment thread bin/fm-procevent-remote-reply.sh Resolved
Comment thread bin/fm-procevent-remote-reply.sh Resolved
@tiago-peixoto

ghost commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

The newer commit c8db405c takes the equivalent route. The separate episode file is gone, and the continuity line itself carries the reader offset and prefix hash, so there is one append and no state that can be stored without its line. A retry of the same break builds the identical line and is deduplicated. A distinct break builds a different line.

That settles points 1, 2, and 3 by removal. The regression tests on this pull request cover a later break after repair, an unchanged re-read, and an old-format line. Point 4 is settled because the episode rewrite and the permission test no longer exist.

Two limits, as the description states. Once per route after upgrading, a break recorded and resolved in the old line form is reported one more time when it is read again unchanged. A route that is retired, restored with byte-identical content and broken again at the same position builds the same line, so that break is not reported. Covering the second needs durable retirement evidence, which this change does not keep. Do you want that in this pull request or in a follow-up?

I saw the note that pull request 6710 also edits bin/fm-procevent-remote-reply.sh.

@kunchenguid

ghost commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: re-reviewed head c8db405c against main e06a46fe. Thanks, @tiago-peixoto. Dropping the episode file and putting the reader position in the line does fix the crash-ordering P1 I raised: there is now one append and nothing to strand. CI is green and the no-mistakes attestation matches this head. This is still waiting on you for one gap, though, and you asked whether it goes here or in a follow-up. Here, please.

Why here: the case you list as a limit is a retirement followed by a byte-identical restore at the same position. #6701's own reproduction is "retire, restore, break again", and the ready-for-pr note named cursor and retirement evidence. Restoring from a backup is the likely way an operator repairs a route. In that case the later break builds the same line, matches the old blocked line, and the decision never opens. That is the #6701 failure again, on the path this PR restores. A restore can't ship knowing it still hides that break.

Please:

  1. Cover a break after retirement even when the restored content is identical. One option: cmd_retire_finalize_locked bumps a durable per-route retirement count (a single write in retire, not in ingest, so the ordering problem doesn't come back), and the line carries it alongside the offset and hash. Add a regression case: retire, restore the same bytes, reach the same offset, break, and check the decision opens exactly once.
  2. The no-mistakes review flagged that resolve_and_extend_route is defined but never called, and that break_repaired_route's expected parameter is never passed. So no test covers a moved cursor with no retirement. Please wire up that test (it was on this branch before) or delete the dead helper.
  3. Optional: the decision text now carries a full 64-character hash. A short prefix (for example 12 characters) would keep it readable and still tell breaks apart.

The one-time reopen of an old-format line after an upgrade is documented and bounded. I'm fine with it as a stated limit.

Overlap: #6710 also edits bin/fm-procevent-remote-reply.sh (in cmd_source). The hunks still don't overlap.

Contract-class: restore (unchanged). The specified continuity escalation should reopen on a later distinct break. The tip adds no new default surface.

VISION.md, rule by rule

  • One captain, one interface: does not fully align yet. A later break after retirement and an identical restore still reads as settled.
  • Authority is explicit and never inferred: aligns. No new autonomy, and the operator still closes the decision.
  • Scripts own the mechanics, agents own the judgment: aligns. Position matching is exact script work.
  • A restart is a non-event: aligns. A single append is crash-safe, and a retry is deduplicated.
  • Delegation with a spine: aligns. Task contracts are unchanged.
  • The fleet outlives any vendor: aligns. Nothing vendor-specific.
  • Scope: aligns. Command-layer relay state, with regression coverage.

Next step: push (1) and (2). Once a fresh no-mistakes raise and green CI are on the new head, I'll look again. As a restore, it can auto-merge then.

Tiago Peixoto added 8 commits October 7, 2026 01:00
A later break for the same route and reason was swallowed after the
operator resolved the first one, because the status line matched for
the life of the log. The continuity ingest now appends again when the
cursor has moved or retirement has reset that episode, and an unchanged
re-read still appends nothing.

status_event_recorded is unchanged. Its other callers are the
pending-reply escalation, which already decides its own episode, the
parent-channel note append, and the remote document transfer note.
… before it appends the `blocked` line, so a failed store appends nothing. The changes are uncommitted in the worktree, in `bin/fm-procevent-remote-reply.sh` and `tests/fm-remote-reply.test.sh`. **Invariant:** a continuity `blocked` line is on the parent status log only when the episode record for that break is already stored. Only the `continuity-broken` branch of `cmd_ingest` appends that line, so the fix is at that one place. **What changed in `cmd_ingest`:** - It decides first whether the break needs a line, then stores the episode record, then appends. - If storing the record fails, it stops with "cannot record continuity episode" and appends nothing. - If the line is already on the log and no episode record exists, it stores the record and does not append. **One addition you did not ask for:** if the append fails after the record is stored, the adapter puts the earlier record back (or deletes the new one when none existed). Without that, the retry would read as the unchanged repeat and append nothing, which is the issue 6701 failure again. **Deviation from your test instruction:** the test does not use `chmod` on the cursor directory. `write_continuity_episode` runs `chmod 700` on that directory before every write, so a read-only directory is made writable again. The test instead makes `mktemp` fail for the episode's temporary file in that directory, the same way the existing receipt-failure test does. **Tests added to `tests/fm-remote-reply.test.sh`:** - Store failure: the second break exits 1, appends no `blocked` line and opens no decision. One retry after storage recovers exits 3 and appends a single line. - Append failure: with the status log read-only, the third break exits 1 and appends nothing. One retry after the log is writable exits 3 and appends a single line. **Verification:** `bash tests/fm-remote-reply.test.sh` ends with "ALL TESTS PASSED" with the fix. Against the script at commit b750c828 the same test file fails at "a continuity break appended its line before its episode was stored". `shellcheck -S warning` reports only an unused loop variable at line 667 of the test file, which this change does not touch. I ran no other test files. The Greptile Review check log could not be retrieved, so I worked from the finding text alone
A later break at another cursor is then a different line, so the existing
duplicate check appends it and reopens the decision. An unchanged re-read
builds the same line and appends nothing.
A retirement that puts the same bytes back used to rebuild the recorded line, so the later break stayed closed. The retirement count on that line makes the later break distinct.
@tiago-peixoto tiago-peixoto changed the title fix: reopen a remote-reply continuity decision on a later break fix: reopen the remote-reply continuity decision on a later break Oct 6, 2026
Comment thread bin/fm-procevent-remote-reply.sh Resolved
@tiago-peixoto

ghost commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Items 1 to 3 are on this pull request.

  1. Retire writes one count for the route, in state/remote-replies/<id>.retirements, before it removes the cursor. Ingest only reads that count. The continuity line carries the offset, the first 12 characters of the prefix hash, and the count. After a retirement, restoring the same bytes and breaking at the same offset appends one new line and opens the decision once. Reading that same break again appends nothing.

  2. A later break after the cursor moves, with no further retirement, is covered. The test uses resolve_and_extend_route and passes the expected status to break_repaired_route.

  3. The hash on the line is 12 characters.

A line written before the reader position was recorded still does not match, so that one unchanged read appends once. A repair that does not move the cursor and does not retire the route still builds the same line, so it appends nothing. The match for a full prefix hash with no count was removed, because only an intermediate commit of this branch wrote that form.

A stop between those steps must leave the count unchanged, so an unchanged continuity break still builds the same line.
@tiago-peixoto tiago-peixoto changed the title fix: reopen the remote-reply continuity decision on a later break fix(bin): reopen the remote-reply continuity decision on a later break Oct 7, 2026
@tiago-peixoto

ghost commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Correction to the earlier note on this pull request: the count is not written before the cursor is removed. Retirement removes the cursor first, and only then writes the next count. If removal fails, retirement fails and the count stays unchanged.

@kunchenguid

ghost commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: re-reviewed head 5d445ac1 against main 99da16d9, and this is ready to land. Thanks, @tiago-peixoto, for working through every round.

What I checked:

  • Closes A later remote-reply continuity break appends no status line after an operator resolve #6701: verified. The continuity blocked line in cmd_ingest now carries the cursor offset, a 12-character prefix hash, and a per-route retirement count from state/remote-replies/<id>.retirements. So a later distinct break builds a new line, including after a retirement and an identical restore. An unchanged re-read builds the same line, status_event_recorded deduplicates it, and nothing is appended.
  • My 2026-10-06 asks are all addressed. (1) The retirement count is written only by cmd_retire_finalize_locked. Ingest only reads it. (2) The moved-cursor-without-retirement case is now tested through resolve_and_extend_route, and break_repaired_route uses expected. (3) The hash is 12 characters.
  • Greptile's last P1 is fixed on this head ("partial retirement reopens old breaks", raised on b9eaf0bc). Retirement now removes the cursor first, checks that it is gone, and only then writes count+1. If the count write fails, retirement fails loudly. If retirement stops between those two steps, the count stays unchanged, so a resolved break can't reopen. Greptile on 5d445ac1 reports no remaining blocking finding.
  • The diff touches only bin/fm-procevent-remote-reply.sh, docs/remote-secondmates.md, and tests/fm-remote-reply.test.sh. No workflow edits. Nothing else in bin/ globs remote-replies/<id>.*, so no cleanup will eat the count file.
  • The one-time reappend of an old-format line after an upgrade is documented and bounded, and I accepted it last round.
  • The attestation matches this head (MATCH). CI, no-mistakes, and Greptile are all green. The PR is MERGEABLE/CLEAN and up to date with main.

Overlap with #6710: #6710 has not landed and is still open. Both PRs edit bin/fm-procevent-remote-reply.sh: #6710 in cmd_source, this one in cmd_ingest and retirement. A trial merge of the two heads applies cleanly. #6710 will re-run CI on top of this.

Contract-class: restore. Main already escalates a remote-reply continuity break as a keyed decision. This makes that specified escalation reopen on a later distinct break and keeps an unchanged repeat quiet. The retirement count is internal state for that existing path, so there is no new default surface.

VISION (compact, per rule): One captain / one interface: aligns (a new break no longer reads as settled). Authority explicit: aligns (the operator still resolves, and no new autonomy). Scripts own mechanics: aligns (exact position and count matching). Restart non-event: aligns (one append, and the retirement ordering is crash-safe). Delegation with a spine: aligns. Fleet outlives vendor: aligns. Scope: aligns (command-layer relay state with regression coverage).

Squash-merging. Closes #6701.

@kunchenguid
kunchenguid merged commit 2e8cd9e into kunchenguid:main Oct 7, 2026
@kunchenguid

ghost commented Oct 7, 2026

Copy link
Copy Markdown
Owner

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

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.

A later remote-reply continuity break appends no status line after an operator resolve

2 participants