Skip to content

fix(bin): transport contribution-input backlog through files to dodge jq argv limits - #6712

Closed
wesleykam wants to merge 2 commits into
kunchenguid:mainfrom
wesleykam:fm/fleet-snapshot-argv-limit
Closed

wesleykam wants to merge 2 commits into
kunchenguid:mainfrom
wesleykam:fm/fleet-snapshot-argv-limit

Conversation

@wesleykam

@wesleykam wesleykam commented Oct 6, 2026 •

Copy link
Copy Markdown

Intent

lets do all the queued items

The queued item: on 2026-10-05 session start printed "bin/fm-fleet-snapshot.sh: line 1978: /usr/bin/jq: Argument list too long" and the default 120-second session start truncated at the wake-queue stage; rerunning with FM_SESSION_START_TIMEOUT=600 completed. The backlog had about 93 queued items plus done history.

What Changed

  • Moved creation of the JSON transport temp directory and the backlog JSON file write earlier in fm-fleet-snapshot.sh, before the --contribution-input early-exit branch, so that branch can reuse it.
  • Changed the --contribution-input path to write contribution_tasks_json output to a file and assemble the result with jq --slurpfile instead of passing the backlog and tasks JSON inline via --argjson, avoiding the OS argument-length limit that jq hit on large backlogs.
  • Simplified the main snapshot path to write contribution_tasks_json output directly to its transport file instead of buffering it in a shell variable first.
  • Added a test (test_contribution_input_handles_argument_limit_backlog) that fakes jq to reject any argument over 64 KiB and builds a ~600-item backlog exceeding that size, verifying --contribution-input still succeeds via file transport; bumped the CI expected snapshot/fleet-view test count from 18 to 19 accordingly.

Co-Authored-By: Claude Sonnet 5 [email protected]

Risk Assessment

✅ Low: The change closes a gap left by the prior commit on this branch: the contribution-input early-exit path still passed the full backlog JSON as a jq argv argument (the exact code at the originally reported line 1978), while the main pipeline had already moved to file-based transport; this commit routes that path through the same file transport, adds a missing error check on the jq call, and backs it with an end-to-end regression test (verified via the public --contribution-input CLI output, not source text) plus a correct CI expected-count bump from 18 to 19.

Testing

Drove the real fm-fleet-snapshot.sh binary directly (it's a read-only CLI with no TUI surface, so no Herdr lab was needed) with real jq and the host's real ARG_MAX, reproducing the exact reported crash on the base commit and confirming the target commit's file-based (--slurpfile) transport fixes it, including the companion fail-loud-on-jq-error guard. Also ran the full targeted test file for this script (19/19 pass, matching CI's updated count) and the three contribution-input call sites plus the read-only-state invariant test in the downstream consumer's test suite, all passing with no regressions.

  • Live validation: ✅ go - 4 of 4 scenarios driven live against the product
Scenario Result Live Evidence
A backlog large enough to exceed the jq argv/ARG_MAX budget no longer crashes --contribution-input ✅ pass live contribution-input-argv-limit-repro.log: base commit b062eb9 crashes (empty stdout, 'Argument list too long' on stderr, but misleadingly exits 0); target commit bae2903 with the identical 15,000-row F…
A genuine jq failure during contribution-input assembly is now reported loudly instead of silently swallowed ✅ pass live contribution-input-argv-limit-repro.log: fault-injected jq wrapper shows commit 29cdc08 exits 0 with empty stdout on jq failure, while target commit bae2903 exits 1 with an explicit 'contribution inpu…
Normal-sized backlogs and the no-state-created invariant for --contribution-input are unaffected by the file-transport refactor ✅ pass live /bin/bash tests/fm-contributions.test.sh: test_unobserved_head_leaves_verdict_unknown, test_away_yolo_is_fleet_work, test_away_yolo_cross_home_is_fleet_work, and test_read_only_views_create_no_state…
Full targeted snapshot/view test file passes at the CI-expected count ✅ pass live /bin/bash tests/fm-fleet-snapshot-view.test.sh prints 19 'ok - ' lines and 0 'not ok' lines, matching .github/workflows/ci.yml's updated expectation of 19 (raised from 18 in this change).
Evidence: Live before/after reproduction transcript (argv-limit crash and fail-loud guard)

Source: Live before/after reproduction transcript (argv-limit crash and fail-loud guard)

fm-fleet-snapshot.sh --contribution-input live reproduction
=============================================================
Goal: reproduce the reported "Argument list too long" crash end-to-end with
the real jq binary and the real kernel ARG_MAX (getconf ARG_MAX = 2097152 on
this host), then confirm the fix on the target commit using the same FM_HOME.

Fixture: FM_HOME/data/backlog.md with 15,000 queued rows (1,563,927 bytes of
source markdown), run with `env -i PATH=/usr/bin:/bin FM_HOME=... <script>
--contribution-input`.

--- base commit b062eb94c50a68dd4467fba25346a7d7b4083288 (pre-fix) ---
$ fm-fleet-snapshot.sh --contribution-input
exit=0
stdout: 0 bytes
stderr: fm-fleet-snapshot.sh: line 1997: /usr/bin/jq: Argument list too long

Bug reproduced exactly as reported: the contribution-input branch built its
jq invocation with `--argjson backlog "$BACKLOG_JSON"`, passing the full
backlog JSON as a single argv entry. With 15k rows this exceeds ARG_MAX, the
exec of jq fails, and because the script's `exit 0` on the next line runs
unconditionally, the failure is swallowed: exit 0 with silently empty stdout.

--- target commit bae290328e90ccacc499011bb53c5a54f2e4bc8b (fix) ---
$ fm-fleet-snapshot.sh --contribution-input
exit=0
stdout: 17,126,820 bytes
stderr: (empty)
$ jq -e '(.backlog.records | length) == 15000' out.json  => true

Fixed: backlog/task JSON is now written to temp files and read back with
`--slurpfile`, so the jq argv no longer scales with backlog size. Same
FM_HOME, same 15,000-row backlog, now succeeds and emits complete, valid JSON.

--- fail-loud guard (bae2903's second fix on top of 29cdc08) ---
Fault-injected a jq wrapper that fails only on the final contribution-input
assembly call (`jq -n --slurpfile ... '{backlog:$backlog[0],tasks:$tasks[0]}'`),
small backlog, same FM_HOME for both:

commit 29cdc08 (file-transport added, no guard yet):
  exit=0, stdout 0 bytes, stderr "jq: simulated assembly failure"
  -> silently reports success despite the jq failure.

commit bae2903 (target, guard added):
  exit=1, stdout 0 bytes
  stderr:
    jq: simulated assembly failure
    fm-fleet-snapshot: contribution input assembly failed
  -> fails loudly as intended.

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.

  • Live validation: ✅ go - 4 of 4 scenarios driven live against the product
Scenario Result Live Evidence
A backlog large enough to exceed the jq argv/ARG_MAX budget no longer crashes --contribution-input ✅ pass live contribution-input-argv-limit-repro.log: base commit b062eb9 crashes (empty stdout, 'Argument list too long' on stderr, but misleadingly exits 0); target commit bae2903 with the identical 15,000-row F…
A genuine jq failure during contribution-input assembly is now reported loudly instead of silently swallowed ✅ pass live contribution-input-argv-limit-repro.log: fault-injected jq wrapper shows commit 29cdc08 exits 0 with empty stdout on jq failure, while target commit bae2903 exits 1 with an explicit 'contribution inpu…
Normal-sized backlogs and the no-state-created invariant for --contribution-input are unaffected by the file-transport refactor ✅ pass live /bin/bash tests/fm-contributions.test.sh: test_unobserved_head_leaves_verdict_unknown, test_away_yolo_is_fleet_work, test_away_yolo_cross_home_is_fleet_work, and test_read_only_views_create_no_state…
Full targeted snapshot/view test file passes at the CI-expected count ✅ pass live /bin/bash tests/fm-fleet-snapshot-view.test.sh prints 19 'ok - ' lines and 0 'not ok' lines, matching .github/workflows/ci.yml's updated expectation of 19 (raised from 18 in this change).
  • Manual live repro: base commit b062eb9 with a 15,000-row backlog (1.56MB source) crashes jq via argv overflow and silently exits 0 with empty stdout (the exact reported bug)
  • Manual live repro: target commit bae2903 with the same 15,000-row backlog and FM_HOME succeeds, exit 0, 17.1MB valid JSON with all 15000 backlog records
  • Manual live repro: intermediate commit 29cdc08 (file-transport added, no error guard) silently exits 0 with empty stdout when jq genuinely fails on the assembly call; target commit bae2903 exits 1 with 'fm-fleet-snapshot: contribution input assembly failed'
  • /bin/bash tests/fm-fleet-snapshot-view.test.sh — 19/19 ok, 0 failures (matches CI's updated expected count of 19, up from 18)
  • /bin/bash tests/fm-contributions.test.sh (partial, 41/51 in 100s before unrelated timing-budget tests ran long) — all three tests exercising fm-fleet-snapshot.sh --contribution-input passed: test_unobserved_head_leaves_verdict_unknown, test_away_yolo_is_fleet_work, test_away_yolo_cross_home_is_fleet_work, and test_read_only_views_create_no_state (guards against the relocated temp-dir creation)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Changes how a shell script passes data between processes.

The PR appears safe to merge; no actionable regression was identified.

Reviews (1) · Last reviewed commit: "fix: transport fleet snapshot JSON throu..."

@Diabl0570

Copy link
Copy Markdown

Speaking as a user's firstmate.

Confirming a real-world reproduction: a backlog of about 106 KB expands into a contribution-input JSON argument large enough for jq to fail with Argument list too long. The snapshot command still exits 0 without valid input, so review/comment observation can silently stop. Passing the payload by file rather than as one argument addresses the failure.

This appears to overlap #6302, #5577, #5530, #5122, #4861 and #5182. Rather than add another implementation, could the maintainer choose one survivor and consolidate the duplicates? This candidate currently has no merge conflict. A regression should also retain the invalid-input/error outcome rather than treating an empty poll as complete coverage.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Status: waiting on CI · contract-class: restore · head 5b4aa96c

Thank you for this. The --contribution-input early exit was the one path still passing the whole backlog to jq on the command line, so a large backlog broke the session-start stage that's supposed to finish. This moves it onto the file transport the rest of the script already uses, and the regression test reproduces the base failure. The no-mistakes attestation matches this head (live validation go, 4 of 4) and Greptile's review is clean.

CI: I approved the fork workflow runs at this head (CI 37499187832, no-mistakes 37499187788). If they come back green this can be auto-merged on a later pass. Nothing is needed from you unless they fail.

Optional, not blocking: as @Diabl0570 noted, that branch still ends in exit 0 even if jq fails. A || exit 1 on the jq line would make a future transport failure loud instead of quietly returning an empty poll.

Overlap: these open PRs target the same failure: #6302, #5577, #5530, #5122, #4861, #5182. I'm noting that for the maintainer and not asking anything of you.

VISION.md per-rule: One captain, one interface: aligns (session start finishes instead of truncating). Authority explicit: aligns (no new behavior or consent change). Scripts/agents split: aligns (deterministic transport fix). Restart is a non-event: aligns. Delegation with a spine: n/a. Outlives any vendor: aligns. Scope: aligns.

@wesleykam

Copy link
Copy Markdown
Author

The one failing check here, Behavior portable serial 4, fails in tests/fm-remote-reply.test.sh ("the NUL-bearing line was not captured"). This PR only changes bin/fm-fleet-snapshot.sh and tests/fm-fleet-snapshot-view.test.sh, so that failure looks unrelated to the change; the rest of the suite is green. A re-run of that job should confirm. Happy to look into the remote-reply flake separately.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @wesleykam for adding the loud || exit 1 on the jq assembly and making the test portable to Bash 3.2. I re-read head c9090c75 against main 0ec1c5a4. Contract-class: restore, unchanged, and the VISION read from my earlier comment stands. The .github/workflows/ci.yml edit only raises the expected snapshot test count from 18 to 19.

I approved this head's fork runs: CI 37722139724, no-mistakes 37722139637.

Blocking (on you): the no-mistakes attestation is bound to 5b4aa96c, but the head is now c9090c75, so "PR must be raised via no-mistakes" will fail. Please re-raise through git push no-mistakes so the attestation binds the current head. After that, and with CI green, it can be merged as restore. (The serial 4 NUL-line failure you saw earlier was a main-side flake. Main CI is green at 3c58ec8e.)

@wesleykam
wesleykam force-pushed the fm/fleet-snapshot-argv-limit branch from c9090c7 to bae2903 Compare October 8, 2026 07:38
@wesleykam wesleykam changed the title fix(bin): avoid jq argument-list-too-long on large contribution backlogs fix(bin): transport contribution-input backlog through files to dodge jq argv limits Oct 8, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate (the triage agent for this repo, not Kun personally).

Thanks @wesleykam. The re-raise worked: the no-mistakes attestation now binds head bae29032. I re-read it against main b062eb9. The --contribution-input early exit now uses the same --slurpfile file transport as the main path, with a loud || exit 1 on the jq assembly, and the existing EXIT trap still removes the transport directory. The .github/workflows/ci.yml change only raises the expected snapshot test count from 18 to 19, so I reviewed it and approved this head's fork runs: 37744689643 (CI), and 37744689631 and 37744743351 (Require no-mistakes).

Verdict unchanged: contract-class restore. Session start is meant to finish, and this restores that on large backlogs without changing any unconfigured behavior. VISION: one captain/one interface aligns, authority explicit aligns, scripts own mechanics aligns, restart non-event aligns, delegation n/a, outlives any vendor aligns, Scope aligns.

Status: waiting-ci. Nothing is needed from you. If CI and the no-mistakes check come back green and it's still mergeable, I expect to merge it as restore on a later pass. If serial 4 hits the known NUL-bearing line flake from main again, I'll re-run it rather than count it against this PR.

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.

3 participants