Skip to content

fix(backlog-handoff): move full item blocks including indented bodies - #401

Merged
kunchenguid merged 4 commits into
mainfrom
fm/fm-backlog-handoff-body-b3
Jul 10, 2026
Merged

kunchenguid merged 4 commits into
mainfrom
fm/fm-backlog-handoff-body-b3

Conversation

@kunchenguid

Copy link
Copy Markdown
Owner

Intent

Fix bin/fm-backlog-handoff.sh so secondmate backlog handoffs move the full item block, not just the checklist header line.

Bug (confirmed live 2026-07-09): handing ha-codex-fast-default-4e to a secondmate only moved the - [ ] <id> ... header; the item's indented multi-line body stayed in the source data/backlog.md and visually attached to the preceding item. The secondmate worked from the title alone and the spec had to be re-delivered by hand.

Required behavior:

  1. Move header plus every following indented body line up to the next item line or section heading, atomically and byte-exact, preserving existing destination section placement.
  2. Idempotence for body-carrying items: re-run skips when already in destination (no duplicate body, no partial moves).
  3. Keep existing safety: ## In flight refusal, destination validation (seeded secondmate home with .fm-secondmate-home), byte-exact preservation of untouched lines.
  4. Body membership is by indentation, not content - indented lines beginning with ## (e.g. ## Intent) must NOT be treated as section boundaries (the tokenizer trap that caused the incident).
  5. Update the script header comment; add regression tests covering body followed by another item, by a section heading, as last lines of file, indented ## headings inside body, and idempotent re-run.

Prior pipeline run completed intent/rebase/review/test; review auto-fixed EOF terminator preservation (commit 8c9276c on this branch). Document step failed only because of a Codex usage limit; the gate daemon now runs Claude. Re-validate the full branch including that review fix through to a green PR.

Deliberate scope: only bin/fm-backlog-handoff.sh and tests/fm-backlog-handoff.test.sh. Sibling crews own other files; do not expand scope.

What Changed

  • Rewrote the move logic in bin/fm-backlog-handoff.sh so a handoff carries the - [ ] <id> header plus every following indented body line - including internal blank lines and indented ## lines - up to the next item line or section heading, atomically and byte-exact, instead of moving only the header and orphaning the body in the source.
  • Determined body membership strictly by indentation rather than content, so indented ## markers (e.g. ## Intent) are no longer misread as section boundaries, and preserved existing safeguards (## In flight refusal, seeded-secondmate-home destination validation, idempotent re-run, untouched-line preservation) plus EOF handoff terminators.
  • Added tests/fm-backlog-handoff.test.sh covering body-followed-by-item, body-followed-by-section-heading, multi-paragraph internal blanks, EOF last lines, indented ## tokenizer trap, and idempotent re-run; updated the script header comment, CONTRIBUTING.md, and the secondmate-provisioning skill to describe the full-block move behavior.

Risk Assessment

✅ Low: The change is well-bounded to two files, correctly fixes the prior round's body-orphaning finding, carefully preserves byte-exact EOF terminators, and is backed by thorough regression tests covering item/section/EOF boundaries, indented headings, internal blanks, and idempotence; I found no correctness bugs.

Testing

Baseline test command had already passed; I additionally ran the colocated tests/fm-backlog-handoff.test.sh (8 passing regression cases covering all five required scenarios) plus the two related secondmate suites (safety and lifecycle-e2e), all green. To demonstrate the intent as an end user experiences it, I built an E2E reproduction of the exact 2026-07-09 incident: the base-commit script moved only the - [ ] header and orphaned the indented body (## Intent / spec / ## Acceptance) onto the preceding item, while the fixed branch moved the entire block atomically to the secondmate backlog with neighbors untouched and the source clean. I also confirmed the retained safety behavior (in-flight refusal, unseeded-destination refusal) and idempotent re-run. This is a CLI/data-file change with no rendered UI surface, so evidence is the before/after backlog transcripts rather than screenshots. Working tree left clean.

Evidence: E2E before/after backlog transcript: base (buggy) vs fixed script on the ha-codex-fast-default-4e incident, plus idempotence re-run
### CONTRAST 1/2 - BASE COMMIT (buggy: single-line mover) ###

========== OLD: MAIN backlog BEFORE handoff ==========
## In flight

## Queued
- [ ] warm-cache-fix - keep the caches warm (repo: firstmate)
  Preceding item body stays put.
- [ ] ha-codex-fast-default-4e - harness default work (repo: firstmate)
  Context for the secondmate.
  ## Intent
  Deliver the full spec, not the title alone.
  ## Acceptance
  - body survives handoff
  - ## headings inside body stay body
- [ ] next-cleanup - after the trap (repo: firstmate)
  Following item body stays put.

## Done

========== OLD: running fm-backlog-handoff.sh design ha-codex-fast-default-4e ==========
handed off 1 item(s) to design: ha-codex-fast-default-4e
  into /private/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/tmp.Z9eChYtSGA/OLD-sub/data/backlog.md
(exit code: 0)

========== OLD: MAIN backlog AFTER handoff (source) ==========
## In flight

## Queued
- [ ] warm-cache-fix - keep the caches warm (repo: firstmate)
  Preceding item body stays put.
  Context for the secondmate.
  ## Intent
  Deliver the full spec, not the title alone.
  ## Acceptance
  - body survives handoff
  - ## headings inside body stay body
- [ ] next-cleanup - after the trap (repo: firstmate)
  Following item body stays put.

## Done

========== OLD: SECONDMATE backlog AFTER handoff (destination) ==========
## In flight

## Queued

- [ ] ha-codex-fast-default-4e - harness default work (repo: firstmate)
## Done

========== OLD: VERDICT ==========
  BUG: item body 'Deliver the full spec' ORPHANED in the source backlog
  BUG: item body never arrived at the secondmate backlog
  BUG: indented '## Intent' body line missing from destination

### CONTRAST 2/2 - FIXED BRANCH (full-block mover) ###

========== NEW: MAIN backlog BEFORE handoff ==========
## In flight

## Queued
- [ ] warm-cache-fix - keep the caches warm (repo: firstmate)
  Preceding item body stays put.
- [ ] ha-codex-fast-default-4e - harness default work (repo: firstmate)
  Context for the secondmate.
  ## Intent
  Deliver the full spec, not the title alone.
  ## Acceptance
  - body survives handoff
  - ## headings inside body stay body
- [ ] next-cleanup - after the trap (repo: firstmate)
  Following item body stays put.

## Done

========== NEW: running fm-backlog-handoff.sh design ha-codex-fast-default-4e ==========
handed off 1 item(s) to design: ha-codex-fast-default-4e
  into /private/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/tmp.Z9eChYtSGA/NEW-sub/data/backlog.md
(exit code: 0)

========== NEW: MAIN backlog AFTER handoff (source) ==========
## In flight

## Queued
- [ ] warm-cache-fix - keep the caches warm (repo: firstmate)
  Preceding item body stays put.
- [ ] next-cleanup - after the trap (repo: firstmate)
  Following item body stays put.

## Done

========== NEW: SECONDMATE backlog AFTER handoff (destination) ==========
## In flight

## Queued

- [ ] ha-codex-fast-default-4e - harness default work (repo: firstmate)
  Context for the secondmate.
  ## Intent
  Deliver the full spec, not the title alone.
  ## Acceptance
  - body survives handoff
  - ## headings inside body stay body
## Done

========== NEW: VERDICT ==========
  OK: full block moved atomically; header + body (incl. indented ## lines) landed; nothing orphaned

========== IDEMPOTENCE re-run on FIXED branch ==========
Second run output:
nothing to move: ha-codex-fast-default-4e already present in /private/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/tmp.Z9eChYtSGA/IDEM-sub/data/backlog.md
  OK: re-run reported skip and changed nothing (destination header count=1, no duplicate body)
Evidence: Safety refusals transcript: ## In flight handoff refused (source unchanged) and unseeded-destination-home refused
=== SAFETY A: refuse handing off an ## In flight item ===
error: refusing to hand off in-flight backlog items: live-task
       nothing was moved.
(exit: 1)

MAIN backlog is unchanged (in-flight item still present, nothing moved):
## In flight
- [ ] live-task - already running (repo: firstmate)
  do not hand off in-flight work

## Queued
- [ ] queued-task - fine to move (repo: firstmate)

## Done

=== SAFETY B: refuse a destination that is NOT a seeded secondmate home ===
error: firstmate home /private/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/tmp.J4rpUw9wsW/not-a-home is not a seeded secondmate home
(exit: 1)
Evidence: Base-commit (pre-fix) copy of fm-backlog-handoff.sh used for the buggy-vs-fixed contrast
#!/usr/bin/env bash
# Hand already-identified, in-scope backlog items off from the main firstmate
# backlog to a secondmate's own home backlog. Use this when a secondmate is
# created (or whenever an existing queued item should become its domain's work)
# so the secondmate owns its queue from day one instead of the item staying
# stranded in the main backlog.
#
# Scope-matching is firstmate's JUDGMENT: you pass the task-id keys you have
# already judged in-scope for the secondmate. This script performs only the
# mechanical move - it removes each matched line from data/backlog.md under the
# active firstmate home and appends it, under the same section heading, to the
# secondmate home's data/backlog.md (home resolved from data/secondmates.md). It
# never changes a line's text, never writes into a project (it refuses a home
# that is not a firstmate home), and is idempotent: a key already present in the
# secondmate backlog is reported and skipped, so re-running converges. If any key
# matches neither backlog, nothing is moved. See AGENTS.md project management
# and task lifecycle.
# Usage: fm-backlog-handoff.sh <secondmate-id> <item-key>...
set -eu

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
FM_ROOT="${FM_ROOT_OVERRIDE:-$(cd "$SCRIPT_DIR/.." && pwd)}"
FM_HOME="${FM_HOME:-${FM_ROOT_OVERRIDE:-$FM_ROOT}}"
DATA="${FM_DATA_OVERRIDE:-$FM_HOME/data}"
REG="$DATA/secondmates.md"
MAIN_BACKLOG="$DATA/backlog.md"

[ $# -ge 2 ] || { echo "usage: fm-backlog-handoff.sh <secondmate-id> <item-key>..." >&2; exit 1; }
ID=$1
shift

secondmate_home() {
  local id=$1 line
  [ -f "$REG" ] || { echo "error: no secondmate registry at $REG" >&2; return 1; }
  line=$(grep -E "^- $id( |$)" "$REG" | tail -1 || true)
  [ -n "$line" ] || { echo "error: secondmate $id is not registered in $REG" >&2; return 1; }
  printf '%s\n' "$line" | sed -n 's/^[^(]*(home: \([^;)]*\);.*/\1/p'
}

path_is_ancestor_of() {
  local ancestor=$1 path=$2
  [ -n "$ancestor" ] || return 1
  [ -n "$path" ] || return 1
  [ "$ancestor" != "$path" ] || return 1
  case "$path" in
    "$ancestor"/*) return 0 ;;
  esac
  return 1
}

resolved_existing_dir() {
  local path=$1
  [ -d "$path" ] || { echo "error: firstmate home does not exist or is not a directory: $path" >&2; return 1; }
  cd "$path" && pwd -P
}

validate_operational_dirs() {
  local abs_home=$1 abs_active_home=$2 abs_root=$3 name dir abs_dir
  for name in data state config projects; do
    dir="$abs_home/$name"
    if [ -L "$dir" ] && [ ! -e "$dir" ]; then
      echo "error: secondmate $name directory must resolve inside the secondmate home: $dir" >&2
      return 1
    fi
    if [ -d "$dir" ]; then
      abs_dir=$(cd "$dir" && pwd -P)
    elif [ -e "$dir" ]; then
      echo "error: secondmate $name path is not a directory: $dir" >&2
      return 1
    else
      abs_dir="$abs_home/$name"
    fi
    if ! path_is_ancestor_of "$abs_home" "$abs_dir"; then
      echo "error: secondmate $name directory must resolve inside the secondmate home: $dir" >&2
      return 1
    fi
    if [ "$abs_dir" = "$abs_active_home" ] || path_is_ancestor_of "$abs_active_home" "$abs_dir"; then
      echo "error: secondmate $name directory cannot be inside the active firstmate home: $dir" >&2
      return 1
    fi
    if [ "$abs_dir" = "$abs_root" ] || path_is_ancestor_of "$abs_root" "$abs_dir"; then
      echo "error: secondmate $name directory cannot be inside the firstmate repo: $dir" >&2
      return 1
    fi
  done
}

validate_secondmate_home() {
  local id=$1 home=$2 abs_home abs_active_home abs_root marker_id
  abs_home=$(resolved_existing_dir "$home") || return 1
  abs_active_home=$(resolved_existing_dir "$FM_HOME")
  abs_root=$(resolved_existing_dir "$FM_ROOT")
  if [ "$abs_home" = "/" ]; then
    echo "error: secondmate home cannot be the filesystem root: $home" >&2
    return 1
  fi
  if [ "$abs_home" = "$abs_active_home" ]; then
    echo "error: secondmate home cannot be the active firstmate home: $home" >&2
    return 1
  fi
  if [ "$abs_home" = "$abs_root" ]; then
    echo "error: secondmate home cannot be the firstmate repo: $home" >&2
    return 1
  fi
  if path_is_ancestor_of "$abs_active_home" "$abs_home"; then
    echo "error: secondmate home cannot be inside the active firstmate home: $home" >&2
    return 1
  fi
  if path_is_ancestor_of "$abs_root" "$abs_home"; then
    echo "error: secondmate home cannot be inside the firstmate repo: $home" >&2
    return 1
  fi
  if path_is_ancestor_of "$abs_home" "$abs_active_home"; then
    echo "error: secondmate home cannot be an ancestor of the active firstmate home: $home" >&2
    return 1
  fi
  if path_is_ancestor_of "$abs_home" "$abs_root"; then
    echo "error: secondmate home cannot be an ancestor of the firstmate repo: $home" >&2
    return 1
  fi
  validate_operational_dirs "$abs_home" "$abs_active_home" "$abs_root" || return 1
  if [ ! -f "$abs_home/.fm-secondmate-home" ]; then
    echo "error: firstmate home $home is not a seeded secondmate home" >&2
    return 1
  fi
  marker_id=$(cat "$abs_home/.fm-secondmate-home" 2>/dev/null || true)
  if [ "$marker_id" != "$id" ]; then
    echo "error: firstmate home $home is marked for secondmate ${marker_id:-unknown}, expected $id" >&2
    return 1
  fi
  if [ ! -f "$abs_home/AGENTS.md" ]; then
    echo "error: $home is not a firstmate home (missing AGENTS.md)" >&2
    return 1
  fi
  if [ ! -d "$abs_home/bin" ]; then
    echo "error: $home is not a firstmate home (missing bin/)" >&2
    return 1
  fi
  printf '%s\n' "$abs_home"
}

validate_backlog_file() {
  local label=$1 path=$2
  if [ -L "$path" ]; then
    echo "error: $label must not be a symlink: $path" >&2
    return 1
  fi
  if [ -e "$path" ] && [ ! -f "$path" ]; then
    echo "error: $label is not a regular file: $path" >&2
    return 1
  fi
}

backlog_key_section() {
  local file=$1 key=$2
  [ -f "$file" ] || return 1
  awk -v key="$key" '
    BEGIN { section = "## Queued" }
    /^## / { section = $0; next }
    /^- \[[ x]\] / {
      rest = $0
      sub(/^- \[[ x]\] +/, "", rest)
      id = rest
      sub(/[ \t].*/, "", id)
      if (id == key) { print section; found = 1; exit }
    }
    END { exit found ? 0 : 1 }
  ' "$file"
}

RAW_HOME=$(secondmate_home "$ID") || exit 1
[ -n "$RAW_HOME" ] || { echo "error: secondmate $ID has no home in $REG" >&2; exit 1; }
SUB_HOME=$(validate_secondmate_home "$ID" "$RAW_HOME") || exit 1
SUB_BACKLOG="$SUB_HOME/data/backlog.md"
validate_backlog_file "main backlog" "$MAIN_BACKLOG" || exit 1
validate_backlog_file "secondmate backlog" "$SUB_BACKLOG" || exit 1

# Classify every key before changing anything: move-from-main, already-in-sub, or
# missing. Abort with no changes if any key matches neither backlog.
TO_MOVE=()
ALREADY=()
MISSING=()
IN_FLIGHT=()
for key in "$@"; do
  if backlog_key_section "$SUB_BACKLOG" "$key" >/dev/null; then
    ALREADY+=("$key")
  elif section=$(backlog_key_section "$MAIN_BACKLOG" "$key"); then
    if [ "$section" = "## In flight" ]; then
      IN_FLIGHT+=("$key")
    else
      TO_MOVE+=("$key")
    fi
  else
    MISSING+=("$key")
  fi
done

FAILED=0
if [ "${#IN_FLIGHT[@]}" -gt 0 ]; then
  echo "error: refusing to hand off in-flight backlog items: ${IN_FLIGHT[*]}" >&2
  FAILED=1
fi
if [ "${#MISSING[@]}" -gt 0 ]; then
  echo "error: no backlog item matched these keys in $MAIN_BACKLOG: ${MISSING[*]}" >&2
  FAILED=1
fi
if [ "$FAILED" -ne 0 ]; then
  echo "       nothing was moved." >&2
  exit 1
fi

if [ "${#TO_MOVE[@]}" -eq 0 ]; then
  echo "nothing to move: ${ALREADY[*]:-no keys} already present in $SUB_BACKLOG"
  exit 0
fi

mkdir -p "$SUB_HOME/data"
SUB_EXISTED=0
if [ ! -f "$SUB_BACKLOG" ]; then
  printf '## In flight\n\n## Queued\n\n## Done\n' > "$SUB_BACKLOG"
else
  SUB_EXISTED=1
fi

MAIN_DIR=$(dirname "$MAIN_BACKLOG")
SUB_DIR=$(dirname "$SUB_BACKLOG")
KEYS_FILE=$(mktemp "$MAIN_DIR/.fm-handoff-keys.XXXXXX")
MOVED_FILE=$(mktemp "$MAIN_DIR/.fm-handoff-moved.XXXXXX")
KEPT_FILE=$(mktemp "$MAIN_DIR/.fm-handoff-kept.XXXXXX")
SUB_TMP=$(mktemp "$SUB_DIR/.fm-handoff-sub.XXXXXX")
MAIN_BAK=$(mktemp "$MAIN_DIR/.fm-handoff-main-bak.XXXXXX")
SUB_BAK=$(mktemp "$SUB_DIR/.fm-handoff-sub-bak.XXXXXX")
CHANGES_STARTED=0
COMMITTED=0
cleanup() {
  if [ "$CHANGES_STARTED" -eq 1 ] && [ "$COMMITTED" -eq 0 ]; then
    cp "$MAIN_BAK" "$MAIN_BACKLOG" 2>/dev/null || true
    if [ "$SUB_EXISTED" -eq 1 ]; then
      cp "$SUB_BAK" "$SUB_BACKLOG" 2>/dev/null || true
    else
      rm -f "$SUB_BACKLOG"
    fi
  fi
  rm -f "$KEYS_FILE" "$MOVED_FILE" "$KEPT_FILE" "$SUB_TMP" "$MAIN_BAK" "$SUB_BAK"
}
trap cleanup EXIT
printf '%s\n' "${TO_MOVE[@]}" > "$KEYS_FILE"
cp "$MAIN_BACKLOG" "$MAIN_BAK"
if [ "$SUB_EXISTED" -eq 1 ]; then
  cp "$SUB_BACKLOG" "$SUB_BAK"
fi

# Pass 1: drop the matched lines from the main backlog, capturing each removed
# line tagged with the "## " section heading it lived under.
: > "$MOVED_FILE"
awk -v keysfile="$KEYS_FILE" -v movedfile="$MOVED_FILE" '
  BEGIN {
    while ((getline k < keysfile) > 0) { if (k != "") want[k] = 1 }
    section = "## Queued"
  }
  /^## / { section = $0; print; next }
  /^- \[[ x]\] / {
    rest = $0
    sub(/^- \[[ x]\] +/, "", rest)
    id = rest
    sub(/[ \t].*/, "", id)
    if (id in want) { print section "\t" $0 > movedfile; next }
  }
  { print }
' "$MAIN_BACKLOG" > "$KEPT_FILE"

# Pass 2: insert each moved line at the end of its section in the sub backlog,
# creating the section heading if the sub backlog lacks it.
awk -v movedfile="$MOVED_FILE" '
  function flush(sec) {
    if (sec != "" && (sec in items) && !(sec in flushed)) {
      printf "%s", items[sec]
      flushed[sec] = 1
    }
  }
  BEGIN {
    nsec = 0
    while ((getline rec < movedfile) > 0) {
      tab = index(rec, "\t")
      if (tab == 0) continue
      sec = substr(rec, 1, tab - 1)
      line = substr(rec, tab + 1)
      if (!(sec in items)) { order[++nsec] = sec }
      items[sec] = items[sec] line "\n"
    }
    cur = ""
  }
  /^## / { flush(cur); cur = $0; print; next }
  { print }
  END {
    flush(cur)
    for (i = 1; i <= nsec; i++) {
      s = order[i]
      if (!(s in flushed)) {
        print ""
        print s
        printf "%s", items[s]
        flushed[s] = 1
      }
    }
  }
' "$SUB_BACKLOG" > "$SUB_TMP"

CHANGES_STARTED=1
mv "$SUB_TMP" "$SUB_BACKLOG"
mv "$KEPT_FILE" "$MAIN_BACKLOG"
COMMITTED=1

echo "handed off ${#TO_MOVE[@]} item(s) to $ID: ${TO_MOVE[*]}"
echo "  into $SUB_BACKLOG"
if [ "${#ALREADY[@]}" -gt 0 ]; then
  echo "  already present (skipped): ${ALREADY[*]}"
fi
Evidence: Key contrast excerpt (source backlog after handoff)
OLD (base, BUGGY) source after handoff -- body orphaned onto preceding item:
- [ ] warm-cache-fix - keep the caches warm (repo: firstmate)
Preceding item body stays put.
Context for the secondmate.
## Intent
Deliver the full spec, not the title alone.
...
OLD destination: only the header arrived:
- [ ] ha-codex-fast-default-4e - harness default work (repo: firstmate)

NEW (fixed) source after handoff -- clean, nothing orphaned:
- [ ] warm-cache-fix - keep the caches warm (repo: firstmate)
Preceding item body stays put.
- [ ] next-cleanup - after the trap (repo: firstmate)
Following item body stays put.
NEW destination: full block landed (header + indented ## body lines).

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ⚠️ bin/fm-backlog-handoff.sh:316 - A body block stops at the first blank line, which contradicts the documented contract and can re-orphan body lines. The header comment (lines 10-12) and pass-1 comment (lines 264-267) both state the block runs "up to the next item line or section heading." But a blank line is not indented, so it fails the moving &amp;&amp; /^[ \t]/ continuation rule and falls through to the catch-all (line 322), which sets moving = 0. Any indented lines AFTER an internal blank line are then no longer moving, so they are left (orphaned) in the source and never reach the destination. Multi-paragraph markdown item bodies with a blank line between paragraphs (e.g. - [ ] x\n para one\n\n para two\n- [ ] next) split: only para one moves, para two stays orphaned in data/backlog.md attached to nothing - the same failure mode this change fixes. No test covers an internal-blank body (the reference extract_item_block in the test also treats blank as a terminator, so the suite shares the blind spot). Either treat blank lines inside a body as part of the block (match the documented "up to the next item line or section heading" semantics) or document explicitly that a blank line terminates a body block and rely on the firstmate convention that bodies are contiguous indented lines.

🔧 Fix: treat blank lines inside item bodies as movable body
1 info still open:

  • ℹ️ bin/fm-backlog-handoff.sh:320 - Consistent-with-intent side effect (not a defect): under the new blank-is-body rule, a blank line between a moved item's body and the following column-0 section heading is captured as trailing body and moves with the item. For blank-separated items this keeps the source well-formed, but handing off the last item in a section consumes that section's trailing blank separator, leaving two ## headings adjacent in the source. Purely cosmetic, valid backlog, and re-normalized on the next tasks-axi mutation; noted only so the behavior is on record.
✅ **Test** - passed

✅ No issues found.

  • command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"
  • bash tests/fm-backlog-handoff.test.sh (8 tests: body followed by item, by section heading, multi-paragraph internal blanks, EOF last-lines, seeded-destination boundary, untouched-EOF terminator, idempotent re-run, indented ## tokenizer trap) - exit 0
  • bash tests/fm-secondmate-safety.test.sh - exit 0 (includes handoff atomic-abort and unsafe-home refusal)
  • bash tests/fm-secondmate-lifecycle-e2e.test.sh - exit 0 (includes single-line handoff happy path)
  • E2E contrast: ran base-commit script (80ecc8d copy) vs fixed bin/fm-backlog-handoff.sh on the ha-codex-fast-default-4e incident scenario, capturing before/after of both source and destination backlog.md
  • Manual safety checks: verified ## In flight handoff refusal leaves source unchanged, and refusal of a destination that is not a seeded secondmate home
  • Verified idempotence: second handoff run reports 'already present' and mutates neither backlog (destination header count stays 1)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

fm-backlog-handoff only moved the checklist header line, so multi-line
item bodies were left orphaned in the source backlog and never reached
the secondmate. Move the full block (header plus indented body lines)
atomically, treating body membership by indentation so lines like
## Intent stay with the item, and add regression coverage.
@kunchenguid
kunchenguid merged commit 600075e into main Jul 10, 2026
4 checks passed
@kunchenguid
kunchenguid deleted the fm/fm-backlog-handoff-body-b3 branch July 10, 2026 02:52
kunchenguid added a commit that referenced this pull request Jul 10, 2026
fm-backlog-handoff.sh's two-pass awk was a second parser of the backlog
format and the source of the PR #401 body-orphaning drift. Delete it and
delegate the move to `tasks-axi mv <id>... --to <dest>` (v0.2.2 atomic
multi-id), the single owner of the format: a connected set (blocker plus
dependents) moves together with blocked-by preserved, item blocks stay
byte-exact, and destination section placement holds. The helper keeps only
the fleet-level validation tasks-axi cannot know - secondmate-home
resolution, the seeded-home safety checks, the In-flight refusal, and
idempotent per-key reporting - and is atomic: on any move failure nothing
moves.

Tests: fm-backlog-handoff.test.sh keeps PR #401's regression matrix but now
exercises the delegated path and skips cleanly when tasks-axi is absent; the
two whole-file fixtures move to tasks-axi's canonical whitespace. The
lifecycle-e2e and safety move-cases gain the same skip guard. CI installs
tasks-axi so the delegated path is exercised. Docs state that
config/backlog-backend=manual governs firstmate's own hand-editing, not this
validated helper, which delegates fleet-wide because bootstrap requires
tasks-axi on PATH.

Remove the now-redundant WIP design note.
kunchenguid added a commit that referenced this pull request Jul 10, 2026
* wip(handoff): record verified delegation design + tasks-axi mv blocker

No production code changed yet. tasks-axi mv (v0.2.1) cannot atomically
move a blocked-by-linked item set across backlogs (deadlocks both orders,
no batch/--force), which fm-secondmate-lifecycle-e2e requires. Parked
pending a tasks-axi connected-set mv enhancement; note captures the
verified design, semantics, test/CI/doc changes, and resume checklist.

* refactor(handoff): delegate the item move to tasks-axi mv

fm-backlog-handoff.sh's two-pass awk was a second parser of the backlog
format and the source of the PR #401 body-orphaning drift. Delete it and
delegate the move to `tasks-axi mv <id>... --to <dest>` (v0.2.2 atomic
multi-id), the single owner of the format: a connected set (blocker plus
dependents) moves together with blocked-by preserved, item blocks stay
byte-exact, and destination section placement holds. The helper keeps only
the fleet-level validation tasks-axi cannot know - secondmate-home
resolution, the seeded-home safety checks, the In-flight refusal, and
idempotent per-key reporting - and is atomic: on any move failure nothing
moves.

Tests: fm-backlog-handoff.test.sh keeps PR #401's regression matrix but now
exercises the delegated path and skips cleanly when tasks-axi is absent; the
two whole-file fixtures move to tasks-axi's canonical whitespace. The
lifecycle-e2e and safety move-cases gain the same skip guard. CI installs
tasks-axi so the delegated path is exercised. Docs state that
config/backlog-backend=manual governs firstmate's own hand-editing, not this
validated helper, which delegates fleet-wide because bootstrap requires
tasks-axi on PATH.

Remove the now-redundant WIP design note.

* no-mistakes(review): Captain: harden atomic backlog handoffs

* no-mistakes(review): Captain: enforce queued-only backlog handoffs

* no-mistakes(review): Captain: harden handoff section parsing

* no-mistakes(document): Document delegated backlog handoffs

* no-mistakes(lint): Silence ShellCheck source diagnostics
Keigyoku pushed a commit to Keigyoku/firstmate that referenced this pull request Jul 11, 2026
…kunchenguid#401)

* fix(backlog-handoff): move full item blocks including indented bodies

fm-backlog-handoff only moved the checklist header line, so multi-line
item bodies were left orphaned in the source backlog and never reached
the secondmate. Move the full block (header plus indented body lines)
atomically, treating body membership by indentation so lines like
## Intent stay with the item, and add regression coverage.

* no-mistakes(review): Captain: preserve EOF handoff terminators

* no-mistakes(review): treat blank lines inside item bodies as movable body

* no-mistakes(document): sync backlog-handoff docs with full-block move behavior

(cherry picked from commit 600075e)
Keigyoku pushed a commit to Keigyoku/firstmate that referenced this pull request Jul 11, 2026
* wip(handoff): record verified delegation design + tasks-axi mv blocker

No production code changed yet. tasks-axi mv (v0.2.1) cannot atomically
move a blocked-by-linked item set across backlogs (deadlocks both orders,
no batch/--force), which fm-secondmate-lifecycle-e2e requires. Parked
pending a tasks-axi connected-set mv enhancement; note captures the
verified design, semantics, test/CI/doc changes, and resume checklist.

* refactor(handoff): delegate the item move to tasks-axi mv

fm-backlog-handoff.sh's two-pass awk was a second parser of the backlog
format and the source of the PR kunchenguid#401 body-orphaning drift. Delete it and
delegate the move to `tasks-axi mv <id>... --to <dest>` (v0.2.2 atomic
multi-id), the single owner of the format: a connected set (blocker plus
dependents) moves together with blocked-by preserved, item blocks stay
byte-exact, and destination section placement holds. The helper keeps only
the fleet-level validation tasks-axi cannot know - secondmate-home
resolution, the seeded-home safety checks, the In-flight refusal, and
idempotent per-key reporting - and is atomic: on any move failure nothing
moves.

Tests: fm-backlog-handoff.test.sh keeps PR kunchenguid#401's regression matrix but now
exercises the delegated path and skips cleanly when tasks-axi is absent; the
two whole-file fixtures move to tasks-axi's canonical whitespace. The
lifecycle-e2e and safety move-cases gain the same skip guard. CI installs
tasks-axi so the delegated path is exercised. Docs state that
config/backlog-backend=manual governs firstmate's own hand-editing, not this
validated helper, which delegates fleet-wide because bootstrap requires
tasks-axi on PATH.

Remove the now-redundant WIP design note.

* no-mistakes(review): Captain: harden atomic backlog handoffs

* no-mistakes(review): Captain: enforce queued-only backlog handoffs

* no-mistakes(review): Captain: harden handoff section parsing

* no-mistakes(document): Document delegated backlog handoffs

* no-mistakes(lint): Silence ShellCheck source diagnostics

(cherry picked from commit 31afb8c)
Keigyoku added a commit to Keigyoku/firstmate that referenced this pull request Jul 11, 2026