Skip to content

fix: avoid jq argument overflow in fleet snapshots - #148

Merged
dnth merged 2 commits into
mainfrom
fm/fm-fleet-snapshot-jq-argmax
Sep 17, 2026
Merged

dnth merged 2 commits into
mainfrom
fm/fm-fleet-snapshot-jq-argmax

Conversation

@dnth

@dnth dnth commented Sep 17, 2026 •

Copy link
Copy Markdown
Owner

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

  • Reworked fleet snapshot JSON transport to use private temporary files and jq --slurpfile, with cleanup, for backlog, task, inventory, and secondmate data.
  • Added executable regression coverage proving snapshots and secondmate aggregation handle blobs larger than the per-argument limit.

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.

  • Live validation: ⚠️ inconclusive - 2 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Oversized backlog produces a valid fleet snapshot preserving orphan inventory ✅ pass live bash tests/fm-fleet-snapshot-view.test.sh; ok - fleet snapshot transports >128KiB blobs through files, not argv
Oversized secondmate summary remains valid and aggregates into parent snapshot ✅ pass live bash tests/fm-fleet-snapshot-view.test.sh; large child summary and parent aggregation assertions
Canonical lint command is shellcheck-clean ⏸️ untested no The prior payload only recorded that repository-wide lint was started and interrupted; it did not establish a live completion result.
Evidence: 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=

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=
- Outcome: ⚠️ 1 warning across 1 run (12m44s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

⚠️ **Test** - 1 warning
  • ⚠️ live validation verdict: inconclusive (2 of 3 scenarios were driven live against the product); untested: Canonical lint command is shellcheck-clean
  • Live validation: ⚠️ inconclusive - 2 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Oversized backlog produces a valid fleet snapshot preserving orphan inventory ✅ pass live bash tests/fm-fleet-snapshot-view.test.sh; ok - fleet snapshot transports &gt;128KiB blobs through files, not argv
Oversized secondmate summary remains valid and aggregates into parent snapshot ✅ pass live bash tests/fm-fleet-snapshot-view.test.sh; large child summary and parent aggregation assertions
Canonical lint command is shellcheck-clean ⏸️ untested no The prior payload only recorded that repository-wide lint was started and interrupted; it did not establish a live completion result.
  • bash tests/fm-fleet-snapshot-view.test.sh
  • Manual bin/fm-fleet-snapshot.sh --json with 213,726-byte backlog
  • shellcheck --norc --external-sources bin/fm-fleet-snapshot.sh tests/fm-fleet-snapshot-view.test.sh
  • bin/fm-lint.sh (started, interrupted after >10 minutes)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…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
@dnth
dnth merged commit 6f49b71 into main Sep 17, 2026
15 checks passed
@dnth
dnth deleted the fm/fm-fleet-snapshot-jq-argmax branch September 17, 2026 15:30
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.

1 participant