Repository navigation
fix: avoid jq argument overflow in fleet snapshots - #148
Merged
Merged
Conversation
…guid#3677) A backlog above Linux's per-argument limit (~128 KiB) made jq fail with "Argument list too long" before it started: BACKLOG_JSON, TASKS_JSON, each sampled secondmate summary (up to FM_SNAPSHOT_SECONDMATE_MAX_BYTES), and the accumulated records all traveled through --argjson. Port of upstream 31cba0d to the fork's direct-sampling collector: a private mktemp transport dir (EXIT-trap recursive cleanup) carries backlog, tasks, main_inventory, scout_reports, secondmate_current, and secondmate_landed to jq via --slurpfile; each secondmate summary is captured to a transport file and records append to a JSONL file, so no exec argument holds a fleet-sized blob. Verified: 213726-byte backlog fails on the pre-fix script at line 625 (jq: Argument list too long) and produces a valid fm-fleet-snapshot.v1 on this one; bin/fm-lint.sh clean; tests/fm-fleet-snapshot-view.test.sh and tests/fm-bearings-snapshot.test.sh all green including the new >128KiB-transport regression.
…ot/fleet-view tests (the PR added the 17th regression test). Verified the snapshot suite passes with 17 tests and git diff checks clean
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 the fm-fleet-snapshot jq ARG_MAX overflow per upstream 31cba0d (kunchenguid#3677), adapted to the fork. Failure: bin/fm-fleet-snapshot.sh:625 /usr/bin/jq: Argument list too long; BACKLOG_JSON 134346 bytes exceeds MAX_ARG_STRLEN ~131072. Observed 2026-09-16 during bearings snapshot; main inventory summary failed. Convert main_inventory_json/secondmate_home_summary_json blob passing from jq -n --argjson over argv to --slurpfile over temp files with a mktemp transport dir + recursive cleanup, at the large-blob call sites (:624, :652, :1428 and the inline assembly at :1413). Keep the fork's observational-caching layer intact; port the technique, not the file verbatim. Add the tests/fm-home-summary-refresh.test.sh equivalent covering the overflow path. AC1: Bearings snapshot succeeds with a 134KB+ backlog blob where it previously failed with Argument list too long - receipt with exact byte counts and command output. AC2: bin/fm-lint.sh shellcheck-clean; colocated regression test exercises the slurpfile transport through the executable interface (large blob in, valid snapshot out), never source-byte assertions.
Firstmate-Validation-Generation: 7ee1e7dda7438c1452c51ee2a91a1db2
What Changed
--slurpfile, with cleanup, for backlog, task, inventory, and secondmate data.Risk Assessment
✅ Low: The change consistently moves fleet-sized JSON through securely created temporary files and slurpfile inputs, preserves the existing observational-caching flow, and adds executable-interface regression coverage for oversized backlog and child-summary data without source-content assertions.
Testing
The focused regression suite drove the real snapshot executable through both overflow paths and passed. Evidence records exact input/output byte counts and valid snapshot fields. Full lint completion remains untested because the prior run was interrupted before completion.
bash tests/fm-fleet-snapshot-view.test.sh;ok - fleet snapshot transports >128KiB blobs through files, not argvbash tests/fm-fleet-snapshot-view.test.sh; large child summary and parent aggregation assertionsEvidence: fm-fleet-snapshot overflow receipt
command: PATH=<fakebin>:$PATH FM_HOME=<fixture> bin/fm-fleet-snapshot.sh --json backlog_bytes=213726 output_bytes=1604193 exit_code=0 schema=fm-fleet-snapshot.v1 orphan_in_flight=1200 stderr=Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
bash tests/fm-fleet-snapshot-view.test.sh;ok - fleet snapshot transports >128KiB blobs through files, not argvbash tests/fm-fleet-snapshot-view.test.sh; large child summary and parent aggregation assertionsbash tests/fm-fleet-snapshot-view.test.shManualbin/fm-fleet-snapshot.sh --jsonwith 213,726-byte backlogshellcheck --norc --external-sources bin/fm-fleet-snapshot.sh tests/fm-fleet-snapshot-view.test.shbin/fm-lint.sh(started, interrupted after >10 minutes)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.