Skip to content

fix: pass backlog-sized JSON to jq through files in the fleet snapshot contribution input - #62

Merged
doitdigital0495 merged 1 commit into
mainfrom
fm/firstmate-fleet-snapshot-jq-arglist
Oct 11, 2026
Merged

doitdigital0495 merged 1 commit into
mainfrom
fm/firstmate-fleet-snapshot-jq-arglist

Conversation

@doitdigital0495

Copy link
Copy Markdown
Owner

Intent

The fleet snapshot script (bin/fm-fleet-snapshot.sh) fails with a jq "Argument list too long" error when the backlog is large (about 200 tasks), so the fleet view and the live board built from it can break.
The secondmate that found it (backlog-closer) could not dispatch it because firstmate is not registered in its home; the captain's standing instruction is to dispatch ready queued work.

What Changed

  • bin/fm-fleet-snapshot.sh --contribution-input no longer hands the backlog and contribution task JSON to jq as --argjson command-line arguments, where a single argument is capped near 128 KiB and a large backlog failed with "Argument list too long". It now writes both to files in a mktemp -d transport directory and loads them with --slurpfile, producing the same {backlog, tasks} output shape.
  • The contribution-input path now exits with jq's own status instead of an unconditional exit 0, and reports a specific error if the transport directory or either temporary file cannot be created.
  • Added test_large_backlog_reaches_jq_through_files to tests/fm-fleet-snapshot-view.test.sh: it builds a 700-task queued backlog, asserts the output exceeds 131072 bytes (one argv entry), and checks that all 700 backlog records survive on the contribution input.

Risk Assessment

✅ Low: The change replaces the only backlog-sized jq argv argument in the script (base line 2043) with the file transport the --json and --live-board-input paths already use, the temp dir is removed by the existing EXIT trap, and the new test drives the real script with a backlog over 128 KiB.

Testing

Drove the real bin/fm-fleet-snapshot.sh at base 8793116 and target cfcab60 against throwaway FM_HOME directories with generated backlogs (200 realistic tasks, 2000 tasks, 300 shell-hostile titles, 5 tasks), with tmux, no-mistakes and herdr stubbed on PATH so nothing touched the live fleet. The base reproduced the reported jq failure and the target fixed it; a small backlog gives the same JSON value on both commits; the default, live-board-input and secondmate-home-summary modes and fm-fleet-view.sh all succeed on the 200-task home; an unwritable TMPDIR fails loudly with exit 1; no temp directories leak. The existing regression test in tests/fm-fleet-snapshot-view.test.sh also passes. No visual artifact: the change is a CLI JSON emitter, and the live board HTML render was not driven. The base script was placed in bin/ temporarily for the comparison and removed; the worktree is clean.

  • Live validation: ✅ go - 6 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Operator runs fm-fleet-snapshot.sh --contribution-input on a home with about 200 queued tasks and gets the full backlog/tasks JSON instead of a jq 'Argument list too long' error ✅ pass live drive-transcript.txt S1: base prints /usr/bin/jq: Argument list too long, exit=0, 0 stdout bytes; target exit=0, 452187 bytes, 200 backlog records from task-0001 to task-0200
Small backlog: the contribution input carries the same data before and after the change ✅ pass live drive-transcript.txt S2: base and target outputs are the same JSON value after jq -S (8266 bytes); raw bytes differ only in nested object key order
Fleet view and the other snapshot modes work on the same 200-task home ✅ pass live drive-transcript.txt S3: default JSON exit=0 with 200 records, --live-board-input exit=0 (452822 bytes), --secondmate-home-summary exit=0, fm-fleet-view.sh exit=0 with 217 lines including task-0…
fm-contributions.sh poll on a 200-task home receives a usable contribution input ⏸️ untested no The generated backlog has no pull request URLs, so poll has nothing to act on and its result is the same either way. Proving the consumer end-to-end needs a backlog with contribution URLs and a gh l…
Adversarial: a 2000-task backlog and titles with quotes, $(...), backticks, backslashes and UTF-8 pass through intact ✅ pass live drive-transcript.txt S4: 2000 tasks exit=0, 5288181 bytes, 2000 records; hostile titles exit=0, 300 records, sample title round-trips verbatim
Adversarial: when the temp directory cannot be created the script fails loudly instead of emitting an empty or partial document ✅ pass live drive-transcript.txt S4: read-only TMPDIR gives exit=1, 0 stdout bytes, stderr fm-fleet-snapshot: temporary transport directory creation failed
The new temp transport directory is removed after each run ✅ pass live drive-transcript.txt S1 and S4: 0 directories left by the target run; 28 fm-fleet-snapshot.* directories in the temp dir before and after the whole driver
Captain opens the live board page built from a 200-task home and it renders ⏸️ untested no Rendering the board goes through fm-live-board.sh and Lavish, which serve against the operator's real Lavish sessions; no isolated lab recipe for the board is in the runbook. The change does not tou…
Evidence: Base-vs-target CLI transcript

Source: Base-vs-target CLI transcript

== S1: realistic backlog, 200 queued tasks with detail lines backlog.md bytes: 173093 -- base 8793116 base --contribution-input exit=0 stdout_bytes=0 stderr: .../bin/fm-fleet-snapshot.base.sh: line 2043: /usr/bin/jq: Argument list too long -- target cfcab60 target --contribution-input exit=0 stdout_bytes=452187 payload: {"backlog_records":200,"tasks":0,"first":"task-0001","last":"task-0200"} temp dirs left behind by target run: 0 == S2: small backlog byte-identical: no (object key order differs) same JSON value after key sort (jq -S): yes (8266 bytes) == S3: 200-task home, target target (default fleet JSON) exit=0 stdout_bytes=454150 target --live-board-input exit=0 stdout_bytes=452822 target --secondmate-home-summary exit=0 stdout_bytes=11888 fm-fleet-view.sh exit=0 stdout_bytes=27374 view lines: 217, mentions task-0200: 1 == S4: adversarial target --contribution-input, 2000 tasks exit=0 stdout_bytes=5288181 payload: {"backlog_records":2000,"tasks":0} target --contribution-input, shell-hostile titles exit=0 stdout_bytes=407821 target --contribution-input, TMPDIR read-only exit=1 stdout_bytes=0 stderr: fm-fleet-snapshot: temporary transport directory creation failed -- no temp dirs leaked across the whole run: 28 present now vs 28 at start

== jq: jq-1.6, ARG_MAX=2097152, single argv cap=131072 bytes

== S1: realistic backlog, 200 queued tasks with detail lines
backlog.md bytes: 173093
-- base 8793116
base   --contribution-input                          exit=0 stdout_bytes=0
    stderr: ~/.no-mistakes/worktrees/cf62ac6bfd91/01M4KZSHTDPVDYFB3WZ61FH23S/bin/fm-fleet-snapshot.base.sh: line 2043: /usr/bin/jq: Argument list too long
-- target cfcab60
target --contribution-input                          exit=0 stdout_bytes=452187
   payload: {"backlog_records":200,"tasks":0,"first":"task-0001","last":"task-0200"}
   temp dirs left behind by target run: 0

== S2: small backlog, base and target must emit identical JSON
base exit=0
target exit=0
byte-identical: no (object key order differs)
same JSON value after key sort (jq -S): yes (8266 bytes)
top-level key order base:   ["backlog","tasks"]
top-level key order target: ["backlog","tasks"]

== S3: every snapshot mode and the views built from it, 200-task home, target
target (default fleet JSON)                          exit=0 stdout_bytes=454150
   payload: {"backlog_records":200}
target --live-board-input                            exit=0 stdout_bytes=452822
target --secondmate-home-summary                     exit=0 stdout_bytes=11888
fm-fleet-view.sh                                     exit=0 stdout_bytes=27374
   view lines: 217, mentions task-0200: 1
fm-contributions.sh poll (consumer of the fixed mode) exit=0 stdout_bytes=0
-- same consumer wired to the base snapshot (temp copy of bin/ with the base script swapped in)
base   fm-contributions.sh poll                      exit=0 stdout_bytes=0
    stderr: /tmp/fm-snap-drive.jGL5Eg/basebin/fm-fleet-snapshot.sh: line 2043: /usr/bin/jq: Argument list too long

== S4: adversarial
backlog.md bytes (2000 tasks): 2450284
target --contribution-input, 2000 tasks              exit=0 stdout_bytes=5288181
   payload: {"backlog_records":2000,"tasks":0}
target --contribution-input, shell-hostile titles    exit=0 stdout_bytes=407821
   payload: {"backlog_records":300,"sample":"Title with \"quotes\", $(subshell), `ticks`, backslash \\ and unicode e-acute é %s number 1 padded to make the record long enough to matter for the size"}
-- unwritable TMPDIR must fail loudly, not emit a partial document
target --contribution-input, TMPDIR read-only        exit=1 stdout_bytes=0
    stderr: mktemp: failed to create directory via template ‘/tmp/fm-snap-drive.jGL5Eg/ro/fm-fleet-snapshot.XXXXXX’: Permission denied
    stderr: fm-fleet-snapshot: temporary transport directory creation failed
-- no temp dirs leaked across the whole run: 28 present now vs 28 at start
Evidence: Driver script used for the run

Source: Driver script used for the run

#!/usr/bin/env bash
# Drives bin/fm-fleet-snapshot.sh (base vs target) against an isolated home with a large backlog.
# usage: drive.sh <worktree> <base-script-name>
set -u
WT=$1
BASE_NAME=$2
WORK=$(mktemp -d "${TMPDIR:-/tmp}/fm-snap-drive.XXXXXX")
trap 'rm -rf "$WORK"' EXIT

unset NO_MISTAKES_GATE FM_GATE_REFUSE_BYPASS FM_ROOT_OVERRIDE FM_STATE_OVERRIDE FM_DATA_OVERRIDE FM_CONFIG_OVERRIDE FM_PROJECTS_OVERRIDE FM_HOME

# Keep the run off the live tmux server and the real no-mistakes daemon.
FAKEBIN=$WORK/fakebin
mkdir -p "$FAKEBIN"
for tool in tmux no-mistakes herdr; do
  printf '#!/usr/bin/env bash\nexit 0\n' > "$FAKEBIN/$tool"
  chmod +x "$FAKEBIN/$tool"
done
export PATH="$FAKEBIN:$PATH"

make_home() {  # <name> <count> <detail-lines>
  local home=$WORK/$1 count=$2 detail=$3 i d
  mkdir -p "$home/state" "$home/data" "$home/projects" "$home/config"
  {
    printf '## In flight\n\n## Queued\n'
    for i in $(seq 1 "$count"); do
      printf -- '- [ ] task-%04d - Queued task %d: tighten the retry path of the ingest worker so a dropped lease is retried once (repo: alpha) (kind: ship) (since 2026-10-01)\n' "$i" "$i"
      for d in $(seq 1 "$detail"); do
        printf '  Detail %d for task %d: the captain asked for the full acceptance criteria to stay with the backlog entry, including the reproduction steps and the expected observable result.\n' "$d" "$i"
      done
    done
    printf '\n## Done\n'
  } > "$home/data/backlog.md"
  printf '%s\n' "$home"
}

run() {  # <label> <home> <script> [args...]
  local label=$1 home=$2 script=$3 rc bytes
  shift 3
  FM_HOME="$home" "$script" "$@" > "$WORK/out" 2> "$WORK/err"
  rc=$?
  bytes=$(wc -c < "$WORK/out")
  printf '%-52s exit=%s stdout_bytes=%s\n' "$label" "$rc" "$bytes"
  [ ! -s "$WORK/err" ] || sed 's/^/    stderr: /' "$WORK/err" | cut -c1-240
  return "$rc"
}

leftovers() { find "${TMPDIR:-/tmp}" -maxdepth 1 -name 'fm-fleet-snapshot.*' 2>/dev/null | wc -l; }

BASE=$WT/bin/$BASE_NAME
TARGET=$WT/bin/fm-fleet-snapshot.sh

echo "== jq: $(jq --version), ARG_MAX=$(getconf ARG_MAX), single argv cap=131072 bytes"
echo
echo "== S1: realistic backlog, 200 queued tasks with detail lines"
H200=$(make_home h200 200 4)
echo "backlog.md bytes: $(wc -c < "$H200/data/backlog.md")"
echo "-- base 8793116"
run 'base   --contribution-input' "$H200" "$BASE" --contribution-input
echo "-- target cfcab60"
before=$(leftovers)
run 'target --contribution-input' "$H200" "$TARGET" --contribution-input
cp "$WORK/out" "$WORK/h200.json"
echo "   payload: $(jq -c '{backlog_records:(.backlog.records|length), tasks:(.tasks|length), first:.backlog.records[0].id, last:.backlog.records[-1].id}' "$WORK/h200.json")"
echo "   temp dirs left behind by target run: $(( $(leftovers) - before ))"

echo
echo "== S2: small backlog, base and target must emit identical JSON"
H5=$(make_home h5 5 1)
FM_HOME="$H5" FM_SNAPSHOT_NOW=2026-10-11T00:00:00Z "$BASE" --contribution-input > "$WORK/small-base.json" 2>"$WORK/err"; echo "base exit=$?"
FM_HOME="$H5" FM_SNAPSHOT_NOW=2026-10-11T00:00:00Z "$TARGET" --contribution-input > "$WORK/small-target.json" 2>"$WORK/err"; echo "target exit=$?"
cmp -s "$WORK/small-base.json" "$WORK/small-target.json" && echo "byte-identical: yes" || echo "byte-identical: no (object key order differs)"
jq -S . "$WORK/small-base.json" > "$WORK/small-base.sorted.json"
jq -S . "$WORK/small-target.json" > "$WORK/small-target.sorted.json"
if cmp -s "$WORK/small-base.sorted.json" "$WORK/small-target.sorted.json"; then echo "same JSON value after key sort (jq -S): yes ($(wc -c < "$WORK/small-target.sorted.json") bytes)"; else echo "same JSON value after key sort (jq -S): NO"; diff "$WORK/small-base.sorted.json" "$WORK/small-target.sorted.json" | cut -c1-300; fi
echo "top-level key order base:   $(jq -c 'keys_unsorted' "$WORK/small-base.json")"
echo "top-level key order target: $(jq -c 'keys_unsorted' "$WORK/small-target.json")"

echo
echo "== S3: every snapshot mode and the views built from it, 200-task home, target"
run 'target (default fleet JSON)' "$H200" "$TARGET"
echo "   payload: $(jq -c '{backlog_records:(.backlog.records|length)}' "$WORK/out" 2>&1 | cut -c1-200)"
run 'target --live-board-input' "$H200" "$TARGET" --live-board-input
run 'target --secondmate-home-summary' "$H200" "$TARGET" --secondmate-home-summary
run 'fm-fleet-view.sh' "$H200" "$WT/bin/fm-fleet-view.sh"
echo "   view lines: $(wc -l < "$WORK/out"), mentions task-0200: $(grep -c 'task-0200' "$WORK/out")"
run 'fm-contributions.sh poll (consumer of the fixed mode)' "$H200" "$WT/bin/fm-contributions.sh" poll
echo "-- same consumer wired to the base snapshot (temp copy of bin/ with the base script swapped in)"
cp -r "$WT/bin" "$WORK/basebin"
cp "$BASE" "$WORK/basebin/fm-fleet-snapshot.sh"
rm -f "$WORK/basebin/$BASE_NAME"
H200B=$(make_home h200b 200 4)
run 'base   fm-contributions.sh poll' "$H200B" "$WORK/basebin/fm-contributions.sh" poll

echo
echo "== S4: adversarial"
H2000=$(make_home h2000 2000 6)
echo "backlog.md bytes (2000 tasks): $(wc -c < "$H2000/data/backlog.md")"
run 'target --contribution-input, 2000 tasks' "$H2000" "$TARGET" --contribution-input
echo "   payload: $(jq -c '{backlog_records:(.backlog.records|length), tasks:(.tasks|length)}' "$WORK/out" 2>&1 | cut -c1-200)"
HQ=$WORK/hquote
mkdir -p "$HQ/state" "$HQ/data" "$HQ/projects" "$HQ/config"
{
  printf '## In flight\n\n## Queued\n'
  for i in $(seq 1 300); do
    printf -- '- [ ] odd-%04d - Title with "quotes", $(subshell), `ticks`, backslash \\ and unicode e-acute \303\251 %%s number %d padded to make the record long enough to matter for the size (repo: alpha) (kind: ship)\n' "$i" "$i"
  done
  printf '\n## Done\n'
} > "$HQ/data/backlog.md"
run 'target --contribution-input, shell-hostile titles' "$HQ" "$TARGET" --contribution-input
echo "   payload: $(jq -c '{backlog_records:(.backlog.records|length), sample:.backlog.records[0].title}' "$WORK/out" 2>&1 | cut -c1-260)"
echo "-- unwritable TMPDIR must fail loudly, not emit a partial document"
RO=$WORK/ro; mkdir -p "$RO"; chmod 555 "$RO"
TMPDIR="$RO" run 'target --contribution-input, TMPDIR read-only' "$H200" "$TARGET" --contribution-input
chmod 755 "$RO"
echo "-- no temp dirs leaked across the whole run: $(leftovers) present now vs $before at start"
- Outcome: ⚠️ 2 infos across 1 run (6m18s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ℹ️ bin/fm-fleet-snapshot.sh:2044 - The contribution-input branch repeats the transport setup the full path already does at bin/fm-fleet-snapshot.sh:2057-2068 and the same jq projection at :2098-2099 (mktemp, backlog file write, {backlog:$backlog[0],tasks:$tasks[0]}). Hoisting the mktemp and backlog write above the branch would remove about four lines. Behaviour is correct as written and cleanup is covered by the existing trap snapshot_cleanup EXIT (:1550), so no action is needed.
⚠️ **Test** - 2 infos
  • ℹ️ bin/fm-fleet-snapshot.sh:2050 - Nested object key order in --contribution-input output differs between base and target under jq 1.6 (--slurpfile vs --argjson). The JSON value is identical after jq -S. Only a consumer that compares the raw bytes or hashes the output would notice; none was found among the callers (fm-contributions.sh reads it with jq).
  • ℹ️ bin/fm-fleet-snapshot.sh:2052 - The base failure was silent: jq failed but the script ended with exit 0 and empty stdout, so fm-contributions.sh poll continued on an empty input file. The target's exit $? now propagates a jq failure.
  • Live validation: ✅ go - 6 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Operator runs fm-fleet-snapshot.sh --contribution-input on a home with about 200 queued tasks and gets the full backlog/tasks JSON instead of a jq 'Argument list too long' error ✅ pass live drive-transcript.txt S1: base prints /usr/bin/jq: Argument list too long, exit=0, 0 stdout bytes; target exit=0, 452187 bytes, 200 backlog records from task-0001 to task-0200
Small backlog: the contribution input carries the same data before and after the change ✅ pass live drive-transcript.txt S2: base and target outputs are the same JSON value after jq -S (8266 bytes); raw bytes differ only in nested object key order
Fleet view and the other snapshot modes work on the same 200-task home ✅ pass live drive-transcript.txt S3: default JSON exit=0 with 200 records, --live-board-input exit=0 (452822 bytes), --secondmate-home-summary exit=0, fm-fleet-view.sh exit=0 with 217 lines including task-0…
fm-contributions.sh poll on a 200-task home receives a usable contribution input ⏸️ untested no The generated backlog has no pull request URLs, so poll has nothing to act on and its result is the same either way. Proving the consumer end-to-end needs a backlog with contribution URLs and a gh l…
Adversarial: a 2000-task backlog and titles with quotes, $(...), backticks, backslashes and UTF-8 pass through intact ✅ pass live drive-transcript.txt S4: 2000 tasks exit=0, 5288181 bytes, 2000 records; hostile titles exit=0, 300 records, sample title round-trips verbatim
Adversarial: when the temp directory cannot be created the script fails loudly instead of emitting an empty or partial document ✅ pass live drive-transcript.txt S4: read-only TMPDIR gives exit=1, 0 stdout bytes, stderr fm-fleet-snapshot: temporary transport directory creation failed
The new temp transport directory is removed after each run ✅ pass live drive-transcript.txt S1 and S4: 0 directories left by the target run; 28 fm-fleet-snapshot.* directories in the temp dir before and after the whole driver
Captain opens the live board page built from a 200-task home and it renders ⏸️ untested no Rendering the board goes through fm-live-board.sh and Lavish, which serve against the operator's real Lavish sessions; no isolated lab recipe for the board is in the runbook. The change does not tou…
  • bash ~/.no-mistakes/evidence/01M4KZSHTDPVDYFB3WZ61FH23S/drive.sh &#34;$PWD&#34; fm-fleet-snapshot.base.sh - base-vs-target driver against isolated homes; base script extracted with git show 8793116:bin/fm-fleet-snapshot.sh
  • fm-fleet-snapshot.sh --contribution-input on a 200-task backlog (173 KB backlog.md), base and target
  • fm-fleet-snapshot.sh --contribution-input on a 5-task backlog, base vs target compared with jq -S
  • fm-fleet-snapshot.sh (default), --live-board-input, --secondmate-home-summary and fm-fleet-view.sh on the 200-task home, target
  • fm-contributions.sh poll on a 200-task home, target and a temp copy of bin/ with the base snapshot script swapped in
  • fm-fleet-snapshot.sh --contribution-input on 2000 tasks (2.4 MB backlog.md) and on 300 titles containing quotes, $(...), backticks, backslashes and UTF-8
  • TMPDIR=<read-only dir> fm-fleet-snapshot.sh --contribution-input
  • Count of fm-fleet-snapshot.* directories in the temp dir before and after the runs
  • bash tests/fm-fleet-snapshot-view.test.sh - includes test_large_backlog_reaches_jq_through_files
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@doitdigital0495
doitdigital0495 merged commit 810e7b3 into main Oct 11, 2026
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