Skip to content

fix(bin): stage contribution-input backlog through --slurpfile - #4861

Closed
haroarthur wants to merge 2 commits into
kunchenguid:mainfrom
haroarthur:fm/fix-fleet-snapshot-argjson-overflow
Closed

haroarthur wants to merge 2 commits into
kunchenguid:mainfrom
haroarthur:fm/fix-fleet-snapshot-argjson-overflow

Conversation

@haroarthur

Copy link
Copy Markdown
Contributor

Intent

The captain, 2026-09-18, ruling D6 on the fleet backlog triage board: "Ship the fix now - it is small and it fires every session".

Context needed to read it: bin/fm-fleet-snapshot.sh has one remaining call site that passes a whole backlog JSON document to jq through --argjson on argv: the contribution-input output mode near the end of the script (jq -n --argjson backlog "$BACKLOG_JSON" --argjson tasks "$contribution_tasks" ...). Linux limits one argv string to 128 KiB (MAX_ARG_STRLEN), so on the analytics home, whose backlog is about 85 KB in markdown and larger once structured, the read dies with "jq: Argument list too long" and the contribution-input read fails at every analytics session start. The earlier fix fix-fleet-snapshot-argjson-limit (done 2026-09-03) moved the other three call sites to a temporary transport directory and --slurpfile; this site was missed. The verified line is reported in data/fleet-backlog-triage-board/report.md: the remaining --argjson backlog pass is that contribution-input jq invocation near the end of bin/fm-fleet-snapshot.sh.

What Changed

  • Moved the --contribution-input output mode in bin/fm-fleet-snapshot.sh off the jq -n --argjson backlog "$BACKLOG_JSON" ... argv pass, the last call site still doing so. It now stages the backlog and contribution-tasks documents into the shared temporary transport directory and assembles them with jq --slurpfile, so a backlog larger than Linux's 128 KiB single-argv limit (MAX_ARG_STRLEN) no longer aborts the read with "jq: Argument list too long". The transport-directory creation and backlog staging were reordered ahead of the contribution-input branch so it can reuse them.
  • Added a regression test in tests/fm-contributions.test.sh that builds a backlog whose structured form exceeds 128 KiB and asserts --contribution-input returns all 400 records intact through to the consumer.
  • Extended tests/fm-home-summary-refresh.test.sh to exercise --contribution-input in the large-backlog scenario, asserting the backlog records and tasks array survive alongside the existing json and secondmate-home-summary mode checks.

Risk Assessment

✅ Low: A small, well-bounded fix that moves the one remaining contribution-input jq call from --argjson to the established temp-transport --slurpfile pattern with byte-identical output, correct branch ordering, trap-based cleanup, and a behavioral large-backlog regression test.

Testing

I derived the scenarios from the intent (large-backlog argv overflow at the contribution-input jq site) and drove them live against the real script and its consumer. On the base script a 229 KB backlog (~1 MB structured, far over the 128 KiB argv limit) reproduces exactly jq: Argument list too long at line 1978 and silently emits nothing, causing the consumer to report all contributions as vanished (known:0, unreadable_records:1). On the fixed script the same backlog produces a valid 900-record document that the consumer reads intact (known:900). The existing contribution-input test suite stays green, confirming the small-backlog happy path is preserved, and I added a durable regression test that fails before the fix and passes after. Evidence is a CLI transcript artifact; there is no UI surface for this CLI/JSON change.

  • Live validation: ✅ go - 4 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Large analytics-home backlog: --contribution-input emits every record instead of overflowing argv ✅ pass live Ran bin/fm-fleet-snapshot.sh --contribution-input with a 229 KB / ~1 MB-structured backlog; exit 0, 900 records emitted, structured backlog 1,005,853 bytes (>131072 argv limit). Artifact: contributi…
Adversarial/regression: base --argjson path dies with 'Argument list too long' and emits nothing ✅ pass live Base commit script run from bin/ with libs loaded reproduced jq: Argument list too long at line 1978 with 0 bytes of output - the exact reported failure the fix removes.
Downstream consumer reads the large contribution input intact ✅ pass live bin/fm-contributions.sh snapshot input.json --all on the fixed output reports known:900; on the base empty output reports known:0 / unreadable_records:1, showing the real end-user damage the fix pre…
Small-backlog happy path (existing behavior) preserved after the slurpfile change ✅ pass live bash tests/fm-contributions.test.sh full suite exits 0, including all pre-existing --contribution-input scenarios (unobserved-head, away-yolo, etc.).
Evidence: contribution-input argv-overflow before/after transcript

Source: contribution-input argv-overflow before/after transcript

# Evidence: contribution-input survives the 128 KiB argv limit

Change: `fm/fix-fleet-snapshot-argjson-overflow` (target 57bd5dc, base daaffdb).
Moves the `--contribution-input` mode of `bin/fm-fleet-snapshot.sh` off
`jq --argjson backlog "$BACKLOG_JSON"` (argv) onto a staged temp file read with
`--slurpfile`.

## Fixture
A large analytics-style backlog: 900 Queued task lines, `backlog.md` = 229,413 bytes,
which parses to a structured backlog JSON of ~1,005,853 bytes - far over Linux's
128 KiB (131,072) MAX_ARG_STRLEN single-argv limit.

## Base script (before fix) - reported failure reproduced
Run from `bin/` so sibling libs load, isolating the argv failure:

`` `
bin/fm-fleet-snapshot.basecheck.sh: line 1978: jq: Argument list too long
stdout bytes: 0
`` `

Line 1978 is the `jq -n --argjson backlog "$BACKLOG_JSON" ...` contribution site.
It dies, then the script hits `exit 0` - a silent break emitting no output.

Fed that empty output to the real consumer `fm-contributions.sh snapshot ... --all`:

`` `
{ "known": 0, "checked": 0, ... "unreadable_records": 1, "rows": [] }
`` `

All 900 contributions silently vanish - "the read fails at every analytics session start".

## Target script (with fix) - works
`` `
exit=0
stdout bytes: 1372211
.backlog.records | length  => 900
structured backlog JSON bytes: 1005853
`` `

Fed to the same consumer:

`` `
{ "known": 900, "checked": 0 }
`` `

Every record reaches the consumer intact.

## Durable regression test
Added `test_large_backlog_contribution_input_survives_argv_limit` to
`tests/fm-contributions.test.sh` (400-record backlog, asserts structured backlog
> 131072 bytes, 400 records read, consumer reports `known == 400` and
`unreadable_records == 0`).

- On the fixed tree: `ok - a backlog exceeding the argv limit is staged and read with every record intact`
- On the base script: `not ok - structured backlog only 0 bytes; too small to exercise the argv limit`
  (preceded by `jq: Argument list too long`) - fails before the fix, passes after.
Evidence: Base script fails at the argjson site
bin/fm-fleet-snapshot.sh: line 1978: jq: Argument list too long
stdout bytes: 0
# then downstream consumer on that empty output:
{ "known": 0, "checked": 0, ..., "unreadable_records": 1, "rows": [] }
Evidence: Fixed script succeeds over the argv limit
exit=0
stdout bytes: 1372211
.backlog.records | length => 900
structured backlog JSON bytes: 1005853
# downstream consumer: { "known": 900, "checked": 0 }

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
Large analytics-home backlog: --contribution-input emits every record instead of overflowing argv ✅ pass live Ran bin/fm-fleet-snapshot.sh --contribution-input with a 229 KB / ~1 MB-structured backlog; exit 0, 900 records emitted, structured backlog 1,005,853 bytes (>131072 argv limit). Artifact: contributi…
Adversarial/regression: base --argjson path dies with 'Argument list too long' and emits nothing ✅ pass live Base commit script run from bin/ with libs loaded reproduced jq: Argument list too long at line 1978 with 0 bytes of output - the exact reported failure the fix removes.
Downstream consumer reads the large contribution input intact ✅ pass live bin/fm-contributions.sh snapshot input.json --all on the fixed output reports known:900; on the base empty output reports known:0 / unreadable_records:1, showing the real end-user damage the fix pre…
Small-backlog happy path (existing behavior) preserved after the slurpfile change ✅ pass live bash tests/fm-contributions.test.sh full suite exits 0, including all pre-existing --contribution-input scenarios (unobserved-head, away-yolo, etc.).
  • bash tests/fm-contributions.test.sh (full suite, exit 0 - all existing --contribution-input scenarios still pass)
  • Manual E2E: 900-record / 229 KB backlog (~1 MB structured) run through bin/fm-fleet-snapshot.sh --contribution-input on the target script -> exit 0, 900 records emitted
  • Manual E2E on base commit script (daaffdb) run from bin/ with libs loaded -> jq: Argument list too long at line 1978, 0 bytes emitted
  • Downstream consumer bin/fm-contributions.sh snapshot input.json --all on fixed output -> known:900; on base empty output -> known:0, unreadable_records:1
  • Added and ran test_large_backlog_contribution_input_survives_argv_limit; passes on the fix, fails on the base script (true regression guard)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

The missed --argjson backlog pass overflowed Linux MAX_ARG_STRLEN on homes whose structured backlog exceeds 128 KiB, so reuse the existing slurpfile transport for that mode too.
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @haroarthur. The diagnosis was right and the before/after evidence is thorough. This is my first look.

The fix has already landed on main another way. #6830 (merged 2026-10-10) moved the --contribution-input assembly in bin/fm-fleet-snapshot.sh off --argjson backlog "$BACKLOG_JSON", and #5359 then made that path propagate assembly failures. On current main 427056c4, both documents are staged to a per-invocation temp dir with trap cleanup and read through jq --slurpfile (around lines 2016-2029). No --argjson pass of the backlog is left on that path. The branch also conflicts with those changes. Since what this PR set out to fix is solved on main, I'm closing it as superseded by #6830.

One part isn't on main: a regression test that pushes a backlog over 128 KiB through --contribution-input and checks every record arrives (tests/fm-fleet-snapshot-contribution-input.test.sh only covers the failure-propagation case). If you'd like to land your test_large_backlog_contribution_input_survives_argv_limit on its own, a small test-only PR against current main would be welcome. Or reopen this and tell me what I've missed.

contract-class: restore (the default contribution read was broken on large backlogs, and main has since restored it).
VISION.md, rule by rule: one captain, one interface: aligns (a silent empty contribution read is a hidden failure). Authority explicit: neutral. Scripts own mechanics: aligns. Restart is a non-event: neutral. Delegation with a spine: aligns. Fleet outlives any vendor: neutral. Scope: aligns. Closing because it's superseded, not because of any VISION concern.

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.

2 participants