Repository navigation
fix(bin): pass fleet-sized JSON to jq on stdin so large homes stop failing bearings snapshots - #30
Merged
Merged
Conversation
added 3 commits
September 13, 2026 22:20
A home with a ~72KB backlog.md derives more than 128KB of backlog JSON, past the kernel's per-argument limit, so fm-fleet-snapshot.sh died with "Argument list too long" and /bearings produced nothing. Add bin/fm-jq-lib.sh with fm_jq: any --argjson/--arg value above FM_JQ_INLINE_MAX (8192 chars) travels on jq's stdin and is bound with `input as $name`, so no temp files or extra tools are needed and output stays byte-identical. Route every data-sized jq call in fm-fleet-snapshot.sh and fm-bearings-snapshot.sh through it. Claude-Session: https://claude.ai/code/session_011RUQ7zuDDvfQLVcGh8Sh7b
The argv-limit fix adds two Bearings regression tests. Claude-Session: https://claude.ai/code/session_011RUQ7zuDDvfQLVcGh8Sh7b
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-bearings-snapshot.sh failing on a large home: it died with 'bin/fm-fleet-snapshot.sh: line 635: /usr/bin/jq: Argument list too long' then 'fm-fleet-snapshot: main inventory summary failed', so /bearings and the bearings board produced nothing. Cause: bin/fm-fleet-snapshot.sh passed whole JSON documents to jq via --argjson (main_inventory_json with BACKLOG_JSON/TASKS_JSON, the final assembly --argjson backlog, etc.); the captain's data/backlog.md is ~72KB so the derived JSON exceeds the kernel per-argument limit MAX_ARG_STRLEN (128KB). Required: pass every potentially unbounded JSON value (backlog, tasks, secondmate summaries, anything sized by fleet data) to jq without argv - --slurpfile/--rawfile from a private temp file, or stdin; audit all --argjson/--arg sites in bin/fm-fleet-snapshot.sh and bin/fm-bearings-snapshot.sh (and direct helpers) for data-sized values; small scalars may stay. Output must be byte-identical for inputs that worked before. Add a colocated regression test that builds a backlog large enough to exceed 128KB of JSON and proves the snapshot succeeds. Temp files, if used, must be private and cleaned up on exit. Acceptance: bin/fm-bearings-snapshot.sh succeeds against the real home ~/firstmate (read-only run), existing snapshot tests pass, shellcheck clean; follow firstmate-coding-guidelines. Decisions made: chose the stdin option instead of temp files - a first temp-file version broke the existing test_perl_fallback_bounds_github_call, which deliberately runs with a minimal PATH lacking mktemp/rm, and bash process substitution stored in an arg array is closed before jq opens it. New sourced bin/fm-jq-lib.sh (one owner) provides fm_jq: with -n, any --argjson/--arg value above FM_JQ_INLINE_MAX chars (default 8192) is streamed on jq stdin (--arg strings JSON-encoded via jq -Rs .) and bound by prefixing the filter with 'input as $name |'; small values stay inline so the common case costs nothing; without -n values stay inline. The bearings projection, which used to read the snapshot on stdin, now uses fm_jq -n --argjson canonical_snapshot and starts its filter with '$canonical_snapshot |' (name chosen because $snap is already used inside the filter). Per-call '# shellcheck disable=SC2016' comments were added because shellcheck only exempts jq program quoting for a command literally named jq. Tests added in tests/fm-bearings-snapshot.test.sh: a 1500-row backlog proving >128KB backlog JSON (asserted non-vacuous) still snapshots and renders bearings (fails on the old code with the original error), and a parity test that FM_JQ_INLINE_MAX=0 (everything on stdin) yields byte-identical bearings output vs everything inline. Verified old-vs-new output byte-identical on fixtures.
What Changed
bin/fm-jq-lib.sh, which providesfm_jq. When called with-n, it sends any--argjson/--argvalue longer thanFM_JQ_INLINE_MAX(default 8192 chars) to jq on stdin instead of argv. It binds those values withinput as $name |at the start of the filter, and--argstrings are JSON-encoded first. Smaller values stay inline, and calls without-npass their values through inline as before. Large homes (for example a ~72KBdata/backlog.md) no longer hit the kernelArgument list too longlimit. That error was killing the fleet snapshot, which left/bearingsand the bearings board empty.bin/fm-fleet-snapshot.shandbin/fm-bearings-snapshot.shnow callfm_jqat every jq site that can receive data-sized values: backlog/tasks inventory, secondmate summaries and records, evidence reconciliation, and PR row merging. The bearings projection no longer reads the snapshot on stdin. It now receives it through--argjson canonical_snapshot, and the filter starts with$canonical_snapshot |. Each converted call has a# shellcheck disable=SC2016comment, anddocs/scripts.mdlists the new lib.tests/fm-bearings-snapshot.test.sh. One builds a 1500-row backlog, checks that its JSON is over 128KB, and confirms the snapshot still renders bearings. The other checks that bearings output withFM_JQ_INLINE_MAX=0(every value on stdin) is byte-identical to output with every value inline.🤖 Generated with Claude Code
Risk Assessment
✅ Low: The change is well-bounded: one new helper,
fm_jq, sends large jq--arg/--argjsonvalues through stdin, and every call site that can carry fleet-sized JSON uses it. I checked that jq accepts theinput as $x |prefix (including when the filter starts withdef) and that spilled and inline runs give byte-identical output, even for a string with tabs, quotes and invalid UTF-8.$SNAPis still validated before the bearings step, and the remaining plain--arg/--argjsoncalls pass only small values: counts, timestamps, paths, short reasons.Testing
I ran both snapshot test files on the target and they pass, including the two new tests. I also ran the new test file against the base code, where the 1500-row backlog test fails with the original 'Argument list too long' error. Against the real home, read-only, the base commit's bearings and fleet snapshot both fail with that error, while the target renders full TOON and JSON bearings and exits 0. I couldn't compare base and target output byte-for-byte on the real home because the base produces no output there. The parity test (everything inline vs everything on stdin) and the old-vs-new fixture check reported in the intent cover that requirement. The evidence transcripts are in the evidence directory, and the worktree is clean.
Evidence: Real home: base fails with argv error, target succeeds
Source: Real home: base fails with argv error, target succeeds
Evidence: Target bearings TOON output against ~/firstmate
Source: Target bearings TOON output against ~/firstmate
Evidence: New regression test fails on base code (reproduces original bug)
Source: New regression test fails on base code (reproduces original bug)
Evidence: fm-bearings-snapshot test run on target
Source: fm-bearings-snapshot test run on target
Evidence: fm-fleet-snapshot-view test run on target
Source: fm-fleet-snapshot-view test run on target
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.
bash tests/fm-bearings-snapshot.test.sh(all tests pass, including new test_backlog_beyond_argv_string_limit and test_stdin_spill_is_byte_identical)bash tests/fm-fleet-snapshot-view.test.sh(all pass)New test file run against base cf5bed9 bin/ (via git archive into /tmp): fails withfm-fleet-snapshot.sh: line 635: /usr/bin/jq: Argument list too long/main inventory summary failedFM_HOME=~/firstmate bin/fm-bearings-snapshot.sh(TOON) and--jsonon the target: exit 0, full bearings rendered; real home's git status was the same before and after (read-only)Base cf5bed9fm-bearings-snapshot.shandfm-fleet-snapshot.sh --jsonagainst the real home: both fail with the original argv error, so the bug reproduces on real dataFM_HOME=~/firstmate bin/fm-fleet-snapshot.sh --json | jq -c .backlog | wc -c: about 125KB of backlog JSON; the full snapshot is about 222KB✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.