Repository navigation
fix(bin): keep fleet-sized snapshot documents out of jq's argv - #15
Merged
Merged
Conversation
A 152KB data/backlog.md renders to a JSON document larger than Linux's MAX_ARG_STRLEN (128KB per argv string), so passing it as a single --argjson value died with 'jq: Argument list too long' (E2BIG), taking down fm-fleet-snapshot.sh and with it fm-bearings-snapshot.sh, /bearings, and /ahoy for that home. Stage every document that grows with backlog, task, or secondmate volume (backlog, tasks, per-home summaries, their aggregates, and the open-decision fold) into a private mktemp directory and hand it to jq with --slurpfile; the secondmate record aggregation appends records to a staging file and slurps them instead of re-parsing a growing argv string per record. fm-bearings-snapshot.sh slurps the snapshot and candidate_prs from stdin. Output is byte-identical for small inputs; no bounds, fields, or defaults change. The regression guard generates a backlog whose rendered JSON provably crosses the 128KB limit and asserts the snapshot and the secondmate home summary both survive with complete records; it fails on the previous code with the production error.
digbycampbell
pushed a commit
that referenced
this pull request
Aug 22, 2026
Takes the 10 genuinely-missing upstream commits through kunchenguid#2764: the captain-hold rework (kunchenguid#2707/kunchenguid#2728/kunchenguid#2744/kunchenguid#2748), watcher robustness (kunchenguid#2524/kunchenguid#2733), ask-user/yolo decouple (kunchenguid#2764), tool-update watch (kunchenguid#2684), and CI/lint (kunchenguid#2710/kunchenguid#2758). Stops at 52d20f1 per the divergence assessment: voice (fbe37e9) is deliberately skipped, and Relay follow-up preservation (dc0172c) cannot be merged without it since fbe37e9 is its ancestor. Resolution stance: fork deviations preserved throughout - the slim AGENTS.md (upstream hunks hand-ported, including the 'gh-axi for all GitHub operations' wording), the jq argv-limit staged-file fix in fm-fleet-snapshot.sh/fm-bearings-snapshot.sh (upstream's kunchenguid#2728 hold-until/captain_actionable hunks threaded onto it), worktree-claim and git-identity hooks, the brief's verification and isolation clauses, and the fork's PR-#15 polling fixes in fm-pi-watch-extension.test.sh. decision-hold-lifecycle ripples hand-ported to captain-hold-lifecycle.
digbycampbell
pushed a commit
that referenced
this pull request
Aug 22, 2026
The serial lane fails intermittently on CI with a different shard each run: the fixtures race their deadlines under load. Following the PR #15 pattern, each fix polls the condition actually being waited for with a ceiling calibrated to the fixture's real cost; no assertion weakened, no retries, no skips. - fm-remote-job: the worker's execution deadline used SECONDS whole- second arithmetic that could fire up to ~1s early (a nominal 3s window could deliver ~1-2s real time); measure against EPOCHREALTIME instead, record the claim deadline as the first whole second after intended expiry, and give the readiness probe a 60s ceiling for loaded starts. Fixture: crash-recovery mutation delay outlasts legitimate recovery latency; the symlinked-argv case stages with a queue window that outlasts a loaded fresh-worker startup. - fm-watch-triage: watcher-written .stale-since marker waits get the file's documented 100-tick budget (3s cannot cover a full fm-watch.sh boot plus one poll under load). - fm-secondmate-harness: the first-config-push marker wait polls the same condition with a 60s ceiling (the push's real work costs ~6-8s unloaded, more under load; old ceiling was 2s). - fm-tool-update-check: the sweep-budget case uses a budget the 30s probe stall still fully consumes (1s could be spent before the probe started, yielding a different report); the watcher checkpoint ceiling rises past FM_CHECK_TIMEOUT for loaded watcher startup. Each fix proven: failing under induced load before, passing under the same load after (3/3) and unloaded.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Fix bin/fm-fleet-snapshot.sh: it died with 'jq: Argument list too long' and produced no snapshot at all, which took down bin/fm-bearings-snapshot.sh and therefore /bearings and /ahoy for this home. Root cause (confirmed by reproduction): the home's real data/backlog.md is 152KB and renders to a JSON document larger than Linux's MAX_ARG_STRLEN (the 128KB per-argument limit, much smaller than the 2MB ARG_MAX total), so passing it as a single --argjson value fails with E2BIG at main_inventory_json (formerly line 1358/610). Scope requirement: main_inventory_json was only the first casualty - every place in that script where a value that can grow with backlog, task, or secondmate volume was passed through --argjson had to be routed through a file-based mechanism (--slurpfile, --rawfile, or stdin) with a properly cleaned-up temp file, otherwise the failure just moves. Explicit constraints: do NOT fix this by truncating, capping, or summarising the backlog before it reaches jq - the projection-layer bounds are deliberate and the fleet reader must stay correct at the real size of the home's data; do not change the snapshot's output contract, field names, bounds, or defaults (plumbing fix, not a redesign); keep bin/ POSIX-ish bash consistent with surrounding style and match existing temp-file/cleanup idioms. Acceptance criteria: (1) ./bin/fm-bearings-snapshot.sh succeeds against the real 152KB backlog with normal TOON output, proven red first; (2) ./bin/fm-fleet-snapshot.sh --json succeeds and emits valid JSON against the same data; (3) ./bin/fm-bearings-snapshot.sh --json --all-in-flight --all-decisions --all-queued --all-landed succeeds (the opt-in surfaces widen the payload and are the real stress case); (4) ./bin/fm-fleet-snapshot.sh --secondmate-home-summary still works; (5) a regression guard exists that actually fails on the old code - a synthetic backlog exceeding the 128KB per-argument limit - wired into the existing test entry point (a small fixture guards nothing since the defect is size-dependent); (6) output is unchanged for a small backlog, shown by before/after capture; (7) bin/fm-session-start.sh still renders its fleet-state section correctly. Implementation decisions made: growable documents are staged into a private mktemp -d directory (umask 077) removed by an EXIT trap, with HUP/INT/TERM routed through exit so a timed-out child summary TERMed by fm_run_timed still cleans up; jq receives them via --slurpfile with a '$x_docs[0] as $x' binding prefix so jq program bodies stay unchanged; the secondmate aggregation loop appends each record to a staging file and slurps once at the end instead of re-parsing a growing argv string per record; bash-builtin printf-to-stdin pipes were left as-is since they never exec and cannot hit E2BIG. fm-bearings-snapshot.sh was also hardened in the two spots that grow with repo/PR volume under --include-prs: the PR-row accumulation and candidate_prs now arrive via stdin slurp (jq -s), deliberately avoiding mktemp there because tests/fm-bearings-snapshot.test.sh exercises bearings under a minimal restricted PATH; that test's tool whitelist gained mktemp and rm because the fleet snapshot (which bearings shells out to) now legitimately needs them - the test's actual discriminator (bounding a stalled gh call) is unchanged. The regression test in tests/fm-fleet-snapshot-view.test.sh generates a 1400-row Done backlog, asserts the rendered backlog JSON actually exceeds 131072 bytes so the fixture cannot silently shrink below the limit, asserts records are complete (not truncated), and covers both --json and --secondmate-home-summary; it was proven to fail on the previous code with the exact production error and pass on the fix. Output was verified byte-identical before/after on a small fixture for --json, --secondmate-home-summary, and bearings TOON with pinned timestamps. Known pre-existing, unrelated: tests/fm-session-start.test.sh fails one assertion ('MISSING diagnostic did not appear at all') identically on pristine HEAD in this environment; actionlint is not installed locally so fm-lint.sh exits 127 at its workflow step (no workflow files changed).
What Changed
bin/fm-fleet-snapshot.sh: reworked every jq invocation that could grow with backlog/task/secondmate volume to stop passing large JSON through--argjsonon the command line. Growable documents are now staged into a privatemktemp -ddirectory (umask 077, removed via anEXIT/HUP/INT/TERMtrap) and handed to jq via--slurpfilewith a$x_docs[0] as $xbinding prefix, keeping jq program bodies unchanged. The secondmate aggregation loop now appends each record to a staging file and slurps once at the end instead of re-parsing a growing argv string per record.bin/fm-bearings-snapshot.sh: the two spots that grow with repo/PR volume under--include-prs(PR-row accumulation andcandidate_prs) now stream through stdin viajq -sinstead of argv, avoiding the E2BIG failure without needingmktempin that path.tests/fm-bearings-snapshot.test.sh: widened the restricted-PATH tool whitelist to includemktempandrm, since bearings shells out to the fleet snapshot which now legitimately needs them; the test's actual discriminator (bounding a stalledghcall) is unchanged.tests/fm-fleet-snapshot-view.test.sh: added a regression test that generates a 1400-row Done backlog exceeding the 128KB--argjsonper-argument limit, asserts the rendered JSON exceeds 131072 bytes and that records are complete (not truncated), covering both--jsonand--secondmate-home-summary.Risk Assessment
✅ Low: Mechanical plumbing fix routing growable JSON through staged temp files with proper cleanup traps; sequential file reuse verified safe, callers check return codes, output contract unchanged, and a new regression test reproduces the original failure and passes on the fix.
Testing
Ran the targeted fleet-snapshot/bearings/session-start test suites and manually exercised all 7 acceptance criteria against the real 152KB firstmate home backlog; the new oversized-backlog regression test was verified to fail with the actual E2BIG production error on the base commit and pass on the fix, and all other suites pass except one pre-existing, unrelated session-start assertion already known-broken on HEAD.
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
./tests/fm-fleet-snapshot-view.test.sh (all pass, including new test_backlog_beyond_kernel_argv_limit_still_snapshots)Proved red: swapped in base-commit bin/fm-fleet-snapshot.sh and reran the suite — new oversized-backlog test failed with the exact production error ('jq: Argument list too long' at main_inventory_json), then restored the fixed file (worktree diff confirmed identical to pre-swap)FM_HOME=/home/digby/devs/firstmate ./bin/fm-bearings-snapshot.sh (real 152KB backlog, TOON output) — succeedsFM_HOME=/home/digby/devs/firstmate ./bin/fm-fleet-snapshot.sh --json — succeeds, valid JSONFM_HOME=/home/digby/devs/firstmate ./bin/fm-bearings-snapshot.sh --json --all-in-flight --all-decisions --all-queued --all-landed — succeeds, valid JSONFM_HOME=/home/digby/devs/firstmate ./bin/fm-fleet-snapshot.sh --secondmate-home-summary — succeeds, valid JSONFM_HOME=/home/digby/devs/firstmate ./bin/fm-session-start.sh — FLEET STATE section renders in_flight/decisions_open/queued rows correctly from real data./tests/fm-bearings-snapshot.test.sh (full suite, all pass)./tests/fm-session-start.test.sh (all pass except the pre-existing unrelated 'MISSING diagnostic did not appear at all' failure, consistent with the intent's noted pre-existing baseline failure)✅ **Document** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.