Skip to content

fix(bin): pass unbounded snapshot documents to jq through files, not argv - #3418

Open
rrecheve wants to merge 9 commits into
kunchenguid:mainfrom
rrecheve:fm/fm-fleet-reader-argv-limite
Open

rrecheve wants to merge 9 commits into
kunchenguid:mainfrom
rrecheve:fm/fm-fleet-reader-argv-limite

Conversation

@rrecheve

@rrecheve rrecheve commented Aug 31, 2026 •

Copy link
Copy Markdown

Intent

Get the existing upstream pull request #3418 green on every check. This is not a fresh implementation: six commits already exist and the PR is already open, and the work must be continued rather than restarted, rewritten, or squashed, because those commits carry the evidence the PR body cites.

The underlying change: bin/fm-fleet-snapshot.sh and neighbours built JSON by handing whole unbounded documents to jq as single command-line arguments (--argjson backlog "$1" and similar). Linux caps a single argv entry at MAX_ARG_STRLEN = 128 KiB, independent of ARG_MAX, so once one document crosses it exec fails with E2BIG and jq never runs. Those values now reach jq through files (--slurpfile/--rawfile via process substitution) instead. It also fixes a neighbouring script (bin/fm-bearings-snapshot.sh) that a first audit wrongly reported clean, moves unbounded status-line and outcome-text values in bin/fm-public-followup-emit.sh off jq argv, and adds a guard refusing multi-document slurps in the fleet snapshot JQ_DOC path.

Two checks were failing and this run must clear both.

Failure 1, "Stock macOS Bash snapshot compatibility" (job macos-stock-bash in .github/workflows/ci.yml). Diagnosed from the real failing job log, not assumed: the job runs on stock Bash 3.2.57, parses every file from bin/fm-lint.sh --list-files with /bin/bash -n, then runs the snapshot and Bearings suites and asserts an EXACT count of "ok - " lines. The log shows the parse sweep clean and all tests passing under real Bash 3.2.57, failing only on "expected 15 snapshot/fleet-view tests, got 18". The regressions this change added moved the totals, so the hardcoded literals were stale: the snapshot suite gained three cases (oversized backlog, oversized status line, unusable secondmate home summary) so 15 becomes 18, and the Bearings suite gained one case (oversized candidate PR set) so 42 becomes 43. The Bearings literal was a latent second failure that the job never reached. Only the two stale literals were changed; the job's real assertions are untouched, and it still requires every listed file to parse under /bin/bash 3.2.57 and every test in both suites to pass there. Do not weaken, skip or disable this gate.

Failure 2, "PR must be raised via no-mistakes". PR 3418 was opened by hand with gh because at the time the pipeline had no write access anywhere and the fork did not exist. The captain authorised the fork https://github.com/rrecheve/firstmate on 2026-08-31 and it now has write access, so the gate must be satisfied the legitimate way: by having this pipeline push the branch to that fork and raise or re-raise the PR against kunchenguid/firstmate, producing a genuine attestation bound to the current head SHA. The gate is deliberately not forgery-proof, but hand-writing the signature or attestation into the PR body is explicitly out of scope and must not be done. The pipeline push target was configured with no-mistakes init --fork-url for exactly this reason. Prefer bringing the existing PR 3418 into compliance over closing and re-raising it.

Rebase context: upstream main moved to a5f3cbe "fix: support first public-followup registration on Bash 3.2 (#3420)", which touches the same file family and the same Bash 3.2 theme. Their fix is a different bug in a different file (empty array under set -u in bin/fm-public-followup.sh) from ours (argv size limits in bin/fm-public-followup-emit.sh), so the two are complementary and neither supersedes the other. The branch has been rebased onto their main; the one conflict, in docs/verification/public-followup.md, was purely additive and both sides were kept, theirs first. Their bin/fm-public-followup.sh and tests/fm-pr-check-security.test.sh changes are untouched by us. Never resolve a conflict by discarding their work; we are guests in their repository and if their approach supersedes ours we adopt theirs.

Constraints: bin/*.sh must pass shellcheck and bin/fm-lint.sh must be clean (both verified green locally, including actionlint on the edited workflow). Tracked Markdown uses one sentence per line and a plain dash, never an em dash. Never add an agent name as a commit co-author. This is somebody else's repository and their gates are not ours to lower: if a check cannot be made to pass for a reason outside our control, stop and report it with evidence rather than disabling, skipping or weakening the check.

What Changed

  • bin/fm-fleet-snapshot.sh, bin/fm-bearings-snapshot.sh, and bin/fm-public-followup-emit.sh now hand every value whose length has no producer bound (backlog and task documents, secondmate home summaries and reconciliations, status-log lines and PR URLs, candidate PR rows, composed deliverables, and outcome text) to jq through --slurpfile/--rawfile process substitution instead of --argjson/--arg. Previously a single document past Linux's 128 KiB MAX_ARG_STRLEN made the exec fail with E2BIG so jq never ran. Bounded values (ids, kinds, counts, timestamps, single paths, fixed state words) stay on argv.
  • A shared JQ_DOC doc($d; $name) helper unwraps each slurped document and errors unless exactly one arrived, so a producer that emits nothing or concatenates multiple documents fails closed rather than binding null or silently keeping the first value; fm-public-followup-emit.sh applies the same length guard inline for deliverables.
  • An unusable secondmate home summary (failed, timed out, oversized, malformed, or stale) now resets to {} and degrades to its own unknown-state record instead of cascading into a whole-snapshot exit 1, and its schema check runs under jq -s with length == 1 so concatenated documents are rejected too.
  • Added regressions for oversized backlogs, status lines, status-log PR URLs, unusable home summaries, oversized candidate PR sets, and oversized outcome text (file and stdin); updated the stock macOS Bash lane's exact ok - counts to 19 snapshot/fleet-view and 43 Bearings tests, and recorded the new argv-size guarantee in docs/verification/public-followup.md.

Risk Assessment

✅ Low: The change is a mechanical, hunk-by-hunk semantics-preserving move of unbounded values from jq argv onto --slurpfile/--rawfile with a shared one-document guard, backed by real fail-before/pass-after regressions and CI count literals I independently recounted as correct (19 and 43); the single warning is a pre-existing fail-open pipeline boundary with no realistically reachable trigger left after this change.

Testing

Ran the three suites that own the changed scripts (19 snapshot, 43 Bearings, 54 public-followup ok lines, no failures) plus two consumer suites, then went past pass/fail for product evidence: with only the three fixed scripts reverted to base, an operator running fm-fleet-view.sh, fm-bearings-snapshot.sh and fm-public-followup-emit.sh on oversized-but-ordinary inputs gets "Argument list too long" and no output at all, while the target commit renders the fleet view, the Bearings board and the published terminal event with the long values intact; a two-document remote summary likewise degrades to one unknown-state record instead of killing the whole snapshot. For the failing CI check I extracted the macos-stock-bash job script and ran it verbatim (exit 0, no ::error::, correct 19/43/1 counts) and reproduced the original failure by running the base version of that script against the current suites. Stock Bash 3.2.57 is unavailable on this Linux runner, so the job's parse sweep ran under 5.2.21 and the 3.2-specific half is left to the macOS lane in remote CI; the "PR must be raised via no-mistakes" check is a pipeline action outside this phase. One consumer suite, fm-bearings-board.test.sh, fails identically on base and target from a sandbox-level process-event source claim, so it is environmental rather than a regression. Evidence transcripts are in /tmp/no-mistakes-evidence/01M1E9Z2JZ2H9T9ABV54TBPXST.

Evidence: Operator CLI transcript: oversized backlog and status line, before vs after
FM_HOME                  : /tmp/fm-argv-demo.HJkh6N
backlog.md size          : 107159 bytes
ship-task.status line    : 180010 bytes
MAX_ARG_STRLEN (one argv): 131072 bytes

==================================================================
BEFORE  (/tmp/fm-argv-baseline)
==================================================================
$ FM_HOME=$HOME_DIR bin/fm-fleet-view.sh 
/tmp/fm-argv-baseline/bin/fm-fleet-snapshot.sh: line 277: /usr/bin/jq: Argument list too long
jq: invalid JSON text passed to --argjson
Use jq --help for help with command-line options,
or see the jq manpage, or online docs  at https://jqlang.github.io/jq
/tmp/fm-argv-baseline/bin/fm-fleet-snapshot.sh: line 657: /usr/bin/jq: Argument list too long
fm-fleet-snapshot: main inventory summary failed
-> exit 1

$ FM_HOME=$HOME_DIR bin/fm-bearings-snapshot.sh 
/tmp/fm-argv-baseline/bin/fm-fleet-snapshot.sh: line 277: /usr/bin/jq: Argument list too long
jq: invalid JSON text passed to --argjson
Use jq --help for help with command-line options,
or see the jq manpage, or online docs  at https://jqlang.github.io/jq
/tmp/fm-argv-baseline/bin/fm-fleet-snapshot.sh: line 657: /usr/bin/jq: Argument list too long
fm-fleet-snapshot: main inventory summary failed
-> exit 1

$ FM_HOME=$HOME_DIR bin/fm-fleet-snapshot.sh --json | jq '.tasks[0] | ...'

==================================================================
AFTER  (/home/vscode/.no-mistakes/worktrees/c52ddf65534b/01M1E9Z2JZ2H9T9ABV54TBPXST)
==================================================================
$ FM_HOME=$HOME_DIR bin/fm-fleet-view.sh 
# Fleet View

Schema: fm-fleet-snapshot.v1
Home: /tmp/fm-argv-demo.HJkh6N

## Under Way
| ID | Current | Kind | Repo/Project | Backend | Endpoint | Artifact | Path | Watch / return channel |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| ship-task | unknown / none | ship | alpha | tmux | absent | - | /tmp/fm-argv-demo.HJkh6N/projects/alpha-worktree | bin/fm-peek.sh fm-ship-task |

## Queued
| ID | Title | Repo | Kind | Blocked By | Artifact |
| --- | --- | --- | --- | --- | --- |
| big-queued-001 | Big Queued 1 | alpha | ship | - | - |
| big-queued-002 | Big Queued 2 | alpha | ship | - | - |
| big-queued-003 | Big Queued 3 | alpha | ship | - | - |
| big-queued-004 | Big Queued 4 | alpha | ship | - | - |
| big-queued-005 | Big Queued 5 | alpha | ship | - | - |
| big-queued-006 | Big Queued 6 | alpha | ship | - | - |
| big-queued-007 | Big Queued 7 | alpha | ship | - | - |
| big-queued-008 | Big Queued 8 | alpha | ship | - | - |
| big-queued-009 | Big Queued 9 | alpha | ship | - | - |
  ... (100 lines total)
-> exit 0

$ FM_HOME=$HOME_DIR bin/fm-bearings-snapshot.sh 
schema: fm-bearings.v1
home: tmp/fm-argv-demo.HJkh6N
generated: "2026-09-01T11:41:24Z"
prs: "not_requested (run: /bearings include PRs)"
in_flight[1]{id,kind,state,doing}:
  ship-task,ship,unknown,"backend target gone: firstmate:fm-ship-task"
secondmates: []
secondmate_reconcile: []
decisions_open: []
landed[6]{id,what,artifact,owner}:
  big-done-040,Big Done 40,"https://github.com/kunchenguid/firstmate/pull/40",(main)
  big-done-039,Big Done 39,"https://github.com/kunchenguid/firstmate/pull/39",(main)
  ... (52 lines total)
-> exit 0

$ FM_HOME=$HOME_DIR bin/fm-fleet-snapshot.sh --json | jq '.tasks[0] | ...'
{
  "task": "ship-task",
  "state": "working",
  "note_chars": 180000,
  "note_head": "rebasing onto main and re-running the suite; rebasing onto m",
  "backlog_records": 121,
  "main_inventory_orphans": 40
}
Evidence: Public-followup emit with a 176 KB outcome text, before vs after

=== BEFORE (base a5f3cbe) === outcome text file: 176059 bytes (one argv entry is capped at 131072) $ bin/fm-public-followup-emit.sh --home $HOME --obligation pf-demo --outcome pr-merged --outcome-text-file outcome.txt fm-public-followup-emit.sh: line 247: /usr/bin/jq: Argument list too long fm-public-followup-emit: could not build the typed terminal event -> exit 1 no terminal event was published - the promised public reply never happens === AFTER (target 7a9c65a) === -> exit 0 published terminal event: 51221036412dfdcc11284f409b66ce772e8238a5dfca3a2733e09f5765562206.json { "schema_version": 1, "obligation_id": "pf-demo", "outcome_type": "pr-merged", "deliverables": { "pr_url": "https://github.com/example/repo/pull/5" }, "public_safe_outcome_chars": 600, "public_safe_outcome_head": "Shipped the café fix, and here is the rest of the report: a very long " }

=== BEFORE (bin/fm-public-followup-emit.sh at base a5f3cbe) ===
outcome text file: 176059 bytes (one argv entry is capped at 131072)
$ bin/fm-public-followup-emit.sh --home $HOME --obligation pf-demo --outcome pr-merged --outcome-text-file outcome.txt
/tmp/fm-argv-baseline/bin/fm-public-followup-emit.sh: line 247: /usr/bin/jq: Argument list too long
fm-public-followup-emit: could not build the typed terminal event
-> exit 1
no terminal event was published - the promised public reply never happens

=== AFTER (bin/fm-public-followup-emit.sh at target 7a9c65a) ===
outcome text file: 176059 bytes (one argv entry is capped at 131072)
$ bin/fm-public-followup-emit.sh --home $HOME --obligation pf-demo --outcome pr-merged --outcome-text-file outcome.txt
51221036412dfdcc11284f409b66ce772e8238a5dfca3a2733e09f5765562206
-> exit 0
published terminal event: 51221036412dfdcc11284f409b66ce772e8238a5dfca3a2733e09f5765562206.json
{
  "schema_version": 1,
  "obligation_id": "pf-demo",
  "outcome_type": "pr-merged",
  "deliverables": {
    "pr_url": "https://github.com/example/repo/pull/5"
  },
  "public_safe_outcome_chars": 600,
  "public_safe_outcome_head": "Shipped the café fix, and here is the rest of the report: a very long "
}
Evidence: Multi-document slurp guard: whole-snapshot failure becomes one degraded record

=== BEFORE (base a5f3cbe) === remote home summary emits: 2 JSON documents $ FM_HOME=$HOME_DIR bin/fm-fleet-snapshot.sh --json -> exit 1 stderr: jq: invalid JSON text passed to --argjson (no snapshot output at all - every fleet read in this home is dead) === AFTER (target 7a9c65a) === remote home summary emits: 2 JSON documents -> exit 0 { "secondmate_records": 1, "id": "twodocs", "state": "unknown", "reason": "structured home snapshot was malformed or stale", "reconcile_inventory": null }

=== BEFORE (bin/fm-fleet-snapshot.sh at base a5f3cbe) ===
remote home summary emits: 2 JSON documents
$ FM_HOME=$HOME_DIR bin/fm-fleet-snapshot.sh --json
-> exit 1
stderr:
jq: invalid JSON text passed to --argjson
Use jq --help for help with command-line options,
or see the jq manpage, or online docs  at https://jqlang.github.io/jq
jq: invalid JSON text passed to --argjson
(no snapshot output at all - every fleet read in this home is dead)

=== AFTER (bin/fm-fleet-snapshot.sh at target 7a9c65a) ===
remote home summary emits: 2 JSON documents
$ FM_HOME=$HOME_DIR bin/fm-fleet-snapshot.sh --json
-> exit 0
{
  "secondmate_records": 1,
  "id": "twodocs",
  "state": "unknown",
  "reason": "structured home snapshot was malformed or stale",
  "reconcile_inventory": null
}
Evidence: macos-stock-bash job script run verbatim on the target: exit 0, no ::error::
LOCAL EMULATION: stock macOS Bash 3.2.57 is unavailable on this Linux runner; running the rest of the job verbatim under 5.2.21(1)-release
GNU bash, version 5.2.21(1)-release (aarch64-unknown-linux-gnu)
ok - empty fleet snapshot and view use explicit absence markers
ok - fixture snapshot covers task rows, backlog rows, pointers, and stable ordering
ok - main_inventory discloses orphan/unstructured and clears when inventory is consistent
ok - backlog normalization preserves strict roles and resolves every blocker compatibly
ok - snapshot event hints follow reconciled current state
ok - durable fold keeps an open decision past a later unrelated event
ok - a live secondmate endpoint preserves unrelated open decisions
ok - durable captain-held transfer closes the duplicate live status decision
ok - durable fold clears a decision only on a keyed resolution
ok - a completed scout's stale decision surfaces as a report pointer, not pending
ok - a scout still parked at a decision stays pending (terminal clear does not over-fire)
ok - a backlog past the single-argument size cap still reads through snapshot, home summary, and bearings
ok - a status line past the single-argument size cap keeps its task instead of dropping it
ok - a status-log PR URL past the single-argument size cap keeps its task instead of dropping it
ok - an unusable secondmate home summary degrades to an unknown record instead of failing the snapshot
ok - snapshot includes durable scout reports after teardown
ok - snapshot parses tasks-axi rows and respects operational overrides
ok - fleet view renders the snapshot without secondmate peek guidance
ok - fleet view renders secondmate agent liveness
ok - Domain Alpha structured state overrides a stale parent Phase 7 event
ok - GNU stat file reads select -c without BSD filesystem-report pollution
ok - parent activity evidence is bounded and disclosed
ok - Bearings excludes a status-only child decision
ok - a structured child captain hold reaches Captain's Call
ok - missing, invalid, unreadable, malformed, and timed-out homes stay explicit unknowns
ok - an oversized secondmate summary retains the strict empty unknown fallback
ok - secondmate and per-home child counts are bounded, disclosed, and explicitly expandable
ok - parent decisions remain untrusted contradiction evidence
ok - parent evidence reconciliation distinguishes matching holds, blocks, and decisions
ok - nonprogressing child states are explicit and inconsistent terminal rows invalidate
ok - registry unavailability and bounded truncation remain explicit
ok - repeated snapshots keep the same current landed baseline and ignore prior reports
ok - default output is bounded, local-only, and marks omitted surfaces
ok - TOON and JSON are parity representations of the same model
ok - landed includes secondmate-managed merges alongside main-home merges
ok - default landed selection balances one dominant home with sparse homes
ok - landed selection refills capacity after sparse homes exhaust
ok - landed selection uses deterministic home order when homes exceed the cap
ok - landed selection preserves deterministic home and internal tie ordering
ok - landed selection handles no landed items
ok - --all-landed keeps the complete global landed output
ok - landed stays bounded with per-home + overall caps and omitted[] disclosure
ok - Bearings keeps a live blocker in structured live state and never converts it to Charted Next queue work
ok - action-free items (working/done/queued/landed) do not leak into Captain's Call
ok - main orphan in-flight stays out of Underway and is disclosed in omitted/gates
ok - main unstructured current is disclosed while structured siblings still project
ok - counterfactual meta clears main inventory warning and projects the live task
ok - mixed secondmate roles, partial state, and captain readiness project independently
ok - main and secondmate captain actionability use the same blocker readiness
ok - a completed scout with decision-like report prose is a pointer, not pending
ok - an authoritative captain hold surfaces end-to-end
ok - current report pointers surface
ok - superseded queued items are dropped by default and restored with --all-queued
ok - --include-prs is the only path that fetches, and it enriches correctly
ok - a partial GitHub failure degrades gracefully
ok - Perl fallback bounds stalled GitHub calls without coreutils timeout
ok - all fleet-sized sections are capped with counted opt-in expansion
ok - captain-held tasks of any kind reach Captain's Call, deferral is honored, and landed excludes answered calls
ok - live PR enrichment caps repositories with counted expansion
ok - per-repository open-PR caps are disclosed with an expansion knob
ok - a candidate PR set past the single-argument size cap still projects
ok - projection and TOON rendering failures exit nonzero with diagnostics
LOCAL EMULATION: skipping global npm install; tasks-axi 0.2.5 is already present
ok - first register succeeds with an empty lock list under /bin/bash
Evidence: Reported CI failure reproduced with the pre-fix literals

=== the base a5f3cbe job script against the current suites === ok - fleet view renders secondmate agent liveness ::error::expected 15 snapshot/fleet-view tests, got 19 job exit=1 === the same script at target 7a9c65a === job exit=0 (19 snapshot + 43 Bearings + 1 public-followup ok lines, no ::error::)

LOCAL EMULATION: stock macOS Bash 3.2.57 unavailable; running the rest verbatim under 5.2.21(1)-release
GNU bash, version 5.2.21(1)-release (aarch64-unknown-linux-gnu)
ok - empty fleet snapshot and view use explicit absence markers
ok - fixture snapshot covers task rows, backlog rows, pointers, and stable ordering
ok - main_inventory discloses orphan/unstructured and clears when inventory is consistent
ok - backlog normalization preserves strict roles and resolves every blocker compatibly
ok - snapshot event hints follow reconciled current state
ok - durable fold keeps an open decision past a later unrelated event
ok - a live secondmate endpoint preserves unrelated open decisions
ok - durable captain-held transfer closes the duplicate live status decision
ok - durable fold clears a decision only on a keyed resolution
ok - a completed scout's stale decision surfaces as a report pointer, not pending
ok - a scout still parked at a decision stays pending (terminal clear does not over-fire)
ok - a backlog past the single-argument size cap still reads through snapshot, home summary, and bearings
ok - a status line past the single-argument size cap keeps its task instead of dropping it
ok - a status-log PR URL past the single-argument size cap keeps its task instead of dropping it
ok - an unusable secondmate home summary degrades to an unknown record instead of failing the snapshot
ok - snapshot includes durable scout reports after teardown
ok - snapshot parses tasks-axi rows and respects operational overrides
ok - fleet view renders the snapshot without secondmate peek guidance
ok - fleet view renders secondmate agent liveness
::error::expected 15 snapshot/fleet-view tests, got 19
job exit=1
Evidence: All six new regressions failing against the pre-fix scripts
### BASELINE: post-fix regression tests against pre-fix bin/*.sh (base a5f3cbe) ###
### baseline tree is a real git checkout so fm-on.sh route resolution matches ###
--- test_oversized_backlog_still_reads ---
not ok - snapshot must survive a backlog larger than one argv entry
    /tmp/fm-argv-baseline/bin/fm-fleet-snapshot.sh: line 657: /usr/bin/jq: Argument list too long
  exit=1
--- test_oversized_status_line_keeps_the_task ---
not ok - an oversized status line must not drop the task or invent an orphan
    /tmp/fm-argv-baseline/bin/fm-fleet-snapshot.sh: line 277: /usr/bin/jq: Argument list too long
    jq: invalid JSON text passed to --argjson
  exit=1
--- test_oversized_status_pr_url_keeps_the_task ---
not ok - an oversized status PR URL must not drop the task or invent an orphan
    /tmp/fm-argv-baseline/bin/fm-fleet-snapshot.sh: line 277: /usr/bin/jq: Argument list too long
    /tmp/fm-argv-baseline/bin/fm-fleet-snapshot.sh: line 575: /usr/bin/jq: Argument list too long
  exit=1
--- test_unusable_secondmate_summary_degrades_to_unknown_record ---
not ok - one unusable secondmate home summary must not fail the whole snapshot: jq: invalid JSON text passed to --argjson
    not ok - one unusable secondmate home summary must not fail the whole snapshot: jq: invalid JSON text passed to --argjson
    jq: invalid JSON text passed to --argjson
    jq: invalid JSON text passed to --argjson
  exit=1
--- bearings: test_oversized_candidate_pr_set_still_projects ---
not ok - bearings must survive a candidate PR set larger than one argv entry
    /tmp/fm-argv-baseline/bin/fm-bearings-snapshot.sh: line 262: /usr/bin/jq: Argument list too long
    fm-bearings-snapshot: projection failed
  exit=1
--- public-followup: test_oversized_outcome_text_file_still_emits ---
not ok - emit must survive an outcome text larger than one argv entry (176059 bytes)
    /tmp/fm-argv-baseline/bin/fm-public-followup-emit.sh: line 247: /usr/bin/jq: Argument list too long
    fm-public-followup-emit: could not build the typed terminal event
  exit=1
Evidence: Suite runs on the target: snapshot (19), Bearings (43), public-followup (54)
ok - empty fleet snapshot and view use explicit absence markers
ok - fixture snapshot covers task rows, backlog rows, pointers, and stable ordering
ok - main_inventory discloses orphan/unstructured and clears when inventory is consistent
ok - backlog normalization preserves strict roles and resolves every blocker compatibly
ok - snapshot event hints follow reconciled current state
ok - durable fold keeps an open decision past a later unrelated event
ok - a live secondmate endpoint preserves unrelated open decisions
ok - durable captain-held transfer closes the duplicate live status decision
ok - durable fold clears a decision only on a keyed resolution
ok - a completed scout's stale decision surfaces as a report pointer, not pending
ok - a scout still parked at a decision stays pending (terminal clear does not over-fire)
ok - a backlog past the single-argument size cap still reads through snapshot, home summary, and bearings
ok - a status line past the single-argument size cap keeps its task instead of dropping it
ok - a status-log PR URL past the single-argument size cap keeps its task instead of dropping it
ok - an unusable secondmate home summary degrades to an unknown record instead of failing the snapshot
ok - snapshot includes durable scout reports after teardown
ok - snapshot parses tasks-axi rows and respects operational overrides
ok - fleet view renders the snapshot without secondmate peek guidance
ok - fleet view renders secondmate agent liveness
Evidence: docs/verification/public-followup.md transcript matches the live suite output

doc lines: 54 run lines: 54 IDENTICAL: docs/verification/public-followup.md transcript matches this run line for line

doc lines: 54  run lines: 54
IDENTICAL: docs/verification/public-followup.md transcript matches this run line for line
Evidence: Evidence index with baseline-tree reconstruction steps
# Evidence: argv-size (E2BIG) fix on fm/fm-fleet-reader-argv-limite

base a5f3cbe -> target 7a9c65a

The baseline tree used for every BEFORE column is a checkout of the target tree with only
bin/fm-fleet-snapshot.sh, bin/fm-bearings-snapshot.sh and bin/fm-public-followup-emit.sh
reverted to base a5f3cbe, so the sole difference is the fix itself.
Recreate it with:

    mkdir /tmp/fm-argv-baseline && git archive 7a9c65a | tar -x -C /tmp/fm-argv-baseline
    for f in bin/fm-fleet-snapshot.sh bin/fm-bearings-snapshot.sh bin/fm-public-followup-emit.sh; do
      git show a5f3cbe:"$f" > /tmp/fm-argv-baseline/$f; chmod +x /tmp/fm-argv-baseline/$f
    done
    cd /tmp/fm-argv-baseline && git init -q && git add -A && git commit -qm baseline   # fm-on.sh needs a tracked checkout

| file | what it shows |
| --- | --- |
| cli-transcript-before-after.txt | An operator runs `fm-fleet-view.sh` and `fm-bearings-snapshot.sh` on a home with a 107 KB backlog and a 180 KB status line. Before: both die with "Argument list too long", exit 1, no fleet read at all. After: the view and the Bearings board render, and the 180 000-character status note survives whole. |
| cli-transcript-public-followup-emit.txt | `fm-public-followup-emit.sh --outcome-text-file` with a 176 KB report body. Before: exit 1, no terminal event, the promised public reply never happens. After: the typed event is published and the outcome is still bounded at 600 codepoints without splitting the multi-byte "café". |
| cli-transcript-multidoc-guard.txt | A remote secondmate whose home-summary command emits two concatenated JSON documents. Before: the whole snapshot exits 1 with no output. After: that one mate degrades to an unknown-state record ("structured home snapshot was malformed or stale") and the rest of the fleet still reads. |
| macos-stock-bash-job-local-run.txt | The `macos-stock-bash` job script extracted from .github/workflows/ci.yml and executed verbatim (minus the Bash 3.2.57 gate, unavailable on this Linux runner, and the global npm install). Exit 0, no `::error::`, 19 + 43 + 1 ok lines. |
| macos-stock-bash-job-prefix-literals.txt | The same job script taken from base a5f3cbe, i.e. the stale literals, run against the current suites: `::error::expected 15 snapshot/fleet-view tests, got 19`, exit 1. This is the reported failing check reproduced. |
| baseline-regressions.txt | All six new regression tests run against the pre-fix scripts. Every one fails with the exact reported symptom (E2BIG / "invalid JSON text passed to --argjson"). They all pass on the target tree. |
| snapshot-suite.txt, bearings-suite.txt, public-followup-suite.txt | Full runs of the three owning suites on the target tree: 19, 43 and 54 ok lines, no failures. |
| doc-transcript-match.txt | The transcript recorded in docs/verification/public-followup.md matches the live suite output line for line, all 54 lines. |
| fm-home-summary-refresh.txt, fm-bearings-board-render.txt | Consumer suites of the changed scripts, both clean. |
| demo-oversized-fleet.sh, demo-multidoc-guard.sh | The manual reproductions used above, re-runnable as `<script> <fixed-tree> <baseline-tree>`. |
| fm-bearings-board.txt | Pre-existing environment failure, not caused by this change: `fm-procevent.sh` cannot claim a `lavish-*` process-event source in this sandbox. It fails identically on the base commit. |
- Outcome: ⚠️ 1 info across 1 run (12m36s)

Note for maintainers: a pre-existing issue this change deliberately leaves alone

While working in bin/fm-fleet-snapshot.sh I noticed that a per-task read failure can discard a live worker silently instead of surfacing an error.
task_json_lines (line 469) ends its loop with done | jq -s 'sort_by(.id)' at line 676, and the script sets set -u at line 73 without pipefail, so the function's exit status is the one from jq -s and never from the per-task jq.
The caller's guard at line 1506 therefore does not see that failure: the affected task emits no line, the loop continues, the snapshot exits 0, the task disappears from .tasks, and its still-live in-flight backlog row is then reported under orphan_in_flight.
The earliest place the invariant could be enforced is the loop itself, around line 676, either with a per-task status check or a local set -o pipefail.

This predates this branch, and the change here does not touch that construct, so I have left it exactly as it is rather than widening a pull request that is about the single-argument size limit.
Whether a lost task should fail the read or degrade to a disclosed record looks like a design call for this repository's maintainers, and the same trade-off appears in this branch's own handling of an unusable secondmate home summary, so I am reporting it here instead of choosing on your behalf.

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 2 issues (1 warning, 1 info)
  • ⚠️ bin/fm-fleet-snapshot.sh:613 - --arg pr &#34;$pr&#34; is the one remaining task-level argv value the script itself derives from status-log text, which the change's own rule at lines 221-226 declares unbounded ("A status log line has no producer bound at all"). At lines 505-507 pr falls back to first_pr_url_in_file &#34;$status_log&#34;, i.e. grep -Eo &#39;https?://[^[:space:])&#34;]+/pull/[0-9]+&#39;; POSIX ERE takes the longest leftmost match, so a status line of the form https://x/ + >128 KiB of non-space, non-), non-&#34; bytes + /pull/1 yields a single argv entry past MAX_ARG_STRLEN. That per-task jq -n then fails with E2BIG, task_json_lines's done | jq -s silently drops the task's line while still exiting 0, and main_inventory reports the still-live backlog row as orphan_in_flight - the exact "a supervisor would be told a live worker does not exist" failure test_oversized_status_line_keeps_the_task was added to close, reachable through a sibling field in the same jq invocation that was just fixed. Every neighbouring status-derived value (raw, note, verb, detail, last_event_raw) was moved to --rawfile; pr was not. Fix at the same boundary: --rawfile pr &lt;(printf &#39;%s&#39; &#34;$pr&#34;). Reachability is low (it needs a pathological unbroken URL-shaped token in a status log), which is why this is a follow-up rather than a merge blocker.
  • ℹ️ bin/fm-bearings-snapshot.sh:268 - The "exactly one slurped document" invariant is open-coded twice in this file with two independently written implementations and two divergent error strings - the accumulator at line 268 (if (($a | length) == 1) and (($b | length) == 1) ... error(&#34;...for each candidate PR row set...&#34;)) and the projection at line 332 (if length == 1 then .[0] else error(&#34;...for $candidate_prs...&#34;)). The sibling script factored the identical invariant into the reusable JQ_DOC helper (bin/fm-fleet-snapshot.sh:234), which yields one uniform, self-naming message. Defining the same one-line def doc($d; $name) constant here and calling doc($a; &#34;a&#34;) + doc($b; &#34;b&#34;) and doc($candidate_prs; &#34;candidate_prs&#34;) removes both hand-rolled copies with no behavior change. Non-functional cleanup only.

🔧 Fix: move PR URL off jq argv and share bearings doc guard
2 issues (1 warning, 1 info) still open:

  • ⚠️ bin/fm-fleet-snapshot.sh:676 - The guards this change adds inside the per-task jq fail OPEN, not closed. task_json_lines ends done | jq -s &#39;sort_by(.id)&#39; with no pipefail (the script sets only set -u at line 73), so the function's exit status is jq -s's, never the per-task jq's. The caller's guard at line 1506, TASKS_JSON=$(task_json_lines) || { echo &#34;task snapshot failed&#34;; exit 1; }, is therefore dead for the dominant failure mode: a per-task jq that dies emits no line, the loop continues, the snapshot exits 0, the task vanishes from .tasks, and main_inventory_json (line 685) reports its still-live in-flight backlog row under orphan_in_flight with reason "in-flight backlog item has no child metadata". That is verbatim the failure test_oversized_status_line_keeps_the_task was added to close ("A supervisor reading that would be told a live worker does not exist"). This change adds three NEW error() sites into exactly that jq - doc($open_decisions), doc($current_state), doc($status_log) at lines 630-632 - each of which, when it fires, silently deletes a live worker and manufactures a false orphan instead of failing the read. The two named triggers are now closed, and the one residual argv path I can name is contrived (path_present_json at line 239 still uses --arg path, so a hand-edited worktree= value past MAX_ARG_STRLEN would E2BIG, yield an empty worktree_json, and break --argjson worktree_path; real writers set WT to a created git worktree, so PATH_MAX bounds it in practice). The defect is the boundary itself, not a specific trigger: the earliest place the invariant can be made to hold is line 676, by giving the loop a per-task status check (or a local set -o pipefail) so a lost task surfaces instead of degrading into a false orphan. Which remedy is right is a product call - commit 5494ad4 chose "degrade to a disclosed unknown record" for an unusable secondmate home rather than hard-failing, and the same choice applies here - so this needs the author's decision rather than a mechanical fix.
  • ℹ️ tests/fm-fleet-snapshot-view.test.sh:850 - All five new regressions gate their fixtures on a hardcoded 131072 (here and at lines 915 and 988, plus tests/fm-bearings-snapshot.test.sh:1187 and tests/fm-public-followup.test.sh:291), but that number is not a constant: Linux computes MAX_ARG_STRLEN as PAGE_SIZE * 32, so it is 131072 only on 4 KiB-page hosts (verified 4096 here, so these tests genuinely fail-before/pass-after in this environment), 524288 on a 16 KiB-page aarch64 kernel, and 2 MiB on a 64 KiB-page one. Darwin has no per-argument cap at all - only the ~1 MiB total ARG_MAX - so on the macos-stock-bash lane, which is the very job this change exists to green and which runs both of these suites in full, a ~136 KiB single argv entry execs fine and every one of these cases passes with the --arg/--argjson bug fully restored. The fixture guards cannot detect this: -gt 131072 still succeeds while the fixture sits below the host's real cap, so the case degrades from a regression proof into a plain happy-path assertion without any signal. The assertions themselves are correct behavior checks on every platform, and the x86-64 Linux lane still provides the fail-before proof, so nothing here is wrong or flaky - noting it so the durability limit is on the record rather than proposing a change.
⚠️ **Test** - 1 info
  • ℹ️ tests/fm-bearings-board.test.sh - tests/fm-bearings-board.test.sh fails in this sandbox at "the order-proof board build failed" because bin/fm-procevent.sh cannot claim a lavish-* process-event source here. It is not caused by this change: the identical failure reproduces on the base commit a5f3cbe with the pre-fix scripts. Recorded only so the failing line in the evidence directory is not mistaken for a regression; remote CI owns this lane.
  • /bin/bash tests/fm-fleet-snapshot-view.test.sh - 19 ok lines, matches the CI literal
  • /bin/bash tests/fm-bearings-snapshot.test.sh - 43 ok lines, matches the CI literal
  • /bin/bash tests/fm-public-followup.test.sh - full owner suite of the changed emit script, 54 ok lines
  • FM_TEST_ONLY=test_first_register_succeeds_with_empty_lock_list_under_bash32 /bin/bash tests/fm-public-followup.test.sh - the third count the CI job asserts
  • Extracted the macos-stock-bash job's run script from .github/workflows/ci.yml and executed it verbatim (Bash 3.2.57 gate and global npm install substituted): exit 0, no ::error::, 63 ok lines
  • Ran the same job script taken from base a5f3cbe against the current suites to reproduce the reported failure: ::error::expected 15 snapshot/fleet-view tests, got 19, exit 1
  • Ran all six new regressions against a tree with only the three fixed scripts reverted to a5f3cbe: every one fails with E2BIG / invalid JSON text passed to --argjson
  • Manual before/after: FM_HOME=&lt;big-home&gt; bin/fm-fleet-view.sh and bin/fm-bearings-snapshot.sh with a 107 KB backlog and a 180 KB status line
  • Manual before/after: bin/fm-public-followup-emit.sh --outcome-text-file with a 176 KB outcome body, checking the published event JSON
  • Manual before/after: remote secondmate whose home-summary command emits two concatenated JSON documents, checking the multi-document slurp guard
  • /bin/bash tests/fm-home-summary-refresh.test.sh and /bin/bash tests/fm-bearings-board-render.test.sh - consumer suites of the changed scripts, clean
  • Compared the recorded transcript in docs/verification/public-followup.md against the live suite output - identical, all 54 lines
⚠️ **Document** - 1 info
  • ℹ️ bin/fm-bearings-snapshot.sh:109 - The JQ_DOC single-document guard is defined three times in executable code - bin/fm-fleet-snapshot.sh:234, bin/fm-bearings-snapshot.sh:109, and a hand-inlined variant inside the event builder in bin/fm-public-followup-emit.sh - differing only in the error prefix. I reduced the duplicated prose to a pointer, but the definition itself is code, so consolidating it (both scripts already source shared libs such as bin/fm-timeout-lib.sh, so a lib-owned helper is feasible) would change executable behavior and is outside this documentation phase. Proposed as a follow-up, not needed for this change.
✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (3): Last reviewed commit: "no-mistakes(document): record argv-size ..." | Re-trigger Greptile

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: full diff review of HEAD ef98f7ae762be6ce401bf9bd48a99747520b8e33 (fork). No workflows, secrets, pull_request_target, sudo, eval, or moving URLs. Greptile 5/5 noted as data only.

VISION (per-rule): One captain / honest interface — aligns (oversized backlog/status/PR/outcome no longer erase the whole fleet read; one bad secondmate no longer blanks every read). Authority explicit — aligns (scripts-only plumbing; no autonomy/consent change). Scripts own mechanics — aligns (--slurpfile/--rawfile + doc() fail-closed single-document guard restores --argjson contract). Restart non-event — aligns (snapshot/emit keep producing durable JSON under load). Delegation with a spine — cannot tell / n/a (no task-contract change). Fleet outlives vendor — aligns (jq argv bound is OS-level, not vendor-coupled). Scope — aligns (bin + tests + verification transcript; forge/CI untouched).

Contract-class: restore. Snapshot/bearings/emit were already supposed to produce JSON; the argv MAX_ARG_STRLEN/E2BIG hole made that fail. Status-line drop→orphan was a quiet wrong answer on an exit-0 path — restore. Callout on unusable secondmate home: on main, timeout/fail already reset summary='{}' and degraded to the unknown-state record; oversized/malformed set the same reason strings but left unusable bytes in summary, so --argjson cascaded into whole-snapshot exit 1. This PR resets summary='{}' on those branches so the already-specified unknown-record path is reachable. Observable change (exit-1-nothing → exit-0 unknown) matches timeout/fail, not a new policy — still restore, not new-default. Multi-doc -s length==1 tightens the same gate.

Approved fork CI for this HEAD only: CI 33445612893, Require no-mistakes 33445612915. Attestation: MISSING (no no-mistakes-pipeline-attestation:v1 in body). MERGEABLE/UNSTABLE; CI not green yet.

Waiting on author for a no-mistakes pipeline attestation that MATCHES this HEAD. Do not merge this pass. No Firstmate flag (author/CI blockers).

A single argv entry is capped at MAX_ARG_STRLEN (128 KiB on Linux),
independently of the far larger ARG_MAX, so every jq call that handed a
whole fleet document to --argjson failed with E2BIG once the home grew.
This home's real backlog (108333 bytes) renders to 153355 bytes of JSON,
which broke fm-fleet-snapshot.sh --json, its secondmate-home-summary
mode, and fm-bearings-snapshot.sh --json outright, and left the home
summary unpublished.

Convert every unbounded document in bin/fm-fleet-snapshot.sh to
--slurpfile through process substitution: the main inventory, the
secondmate home summary, the parent-evidence reconciliation, the
secondmate union, both per-record assemblies, the record accumulator,
the landed projection, the per-task open-decision fold, and the final
assembly. A shared jq def unwraps each slurped document and refuses an
empty one, so a producer that returned nothing still fails closed
instead of binding null. Counts, booleans, timestamps, single paths, and
single status lines stay on argv.

bin/fm-bearings-snapshot.sh already piped the snapshot on stdin, but its
accumulated candidate PR rows had the same shape and the same failure:
900 open PRs made the projection exec fail. Convert those two sites too.

Output is byte-identical for every input that fits under the cap.
The review round that made an unusable secondmate home summary degrade
to the unknown-state record left no explanation in the file, so the
reason for the four summary='{}' resets and the length == 1 schema check
lived only in the commit history. Put it where the next reader of that
sampling block will meet it.

This records one deliberate observable-output change, the only exception
to this change's byte-identical-output requirement.

The input class is a sampled secondmate home summary that is unusable:
it exits 0 but is not valid JSON, is two concatenated documents, or
exceeds FM_SNAPSHOT_SECONDMATE_MAX_BYTES. That unparseable value used to
reach the record assembly and cascade through the empty record, the
accumulator's doc() guard, and the final assembly, so the whole snapshot
exited 1 with "registered secondmate aggregation failed" and emitted
nothing. It now degrades to the unknown-state record the surrounding
code was already written to produce, and the snapshot exits 0.

The reason is that one bad input must not break every fleet read in the
home, which is the same failure class this whole change targets. The
fallback record already existed and was simply unreachable.

Every other path stays byte-identical, verified base against HEAD.
The stock macOS Bash lane asserts an exact count of `ok -` lines from the
snapshot and Bearings suites, so it fails whenever either suite legitimately
grows. This branch adds four regressions that pin the argv-size fix, and the
lane still expected the pre-change totals.

The snapshot suite gains three cases (oversized backlog, oversized status
line, and unusable secondmate home summary), so 15 becomes 18. The Bearings
suite gains one case (oversized candidate PR set), so 42 becomes 43.

The numbers move only because tests were added. The lane's real assertions are
unchanged: it still requires every listed file to parse under /bin/bash 3.2.57
and every test in both suites to pass there. The failing run already proved
both halves hold, printing 18 passing snapshot tests with no parse error and
failing only on the stale literal.
@rrecheve
rrecheve force-pushed the fm/fm-fleet-reader-argv-limite branch from ef98f7a to 17634dd Compare September 1, 2026 10:58
@rrecheve rrecheve changed the title fix(bin): pass unbounded values to jq as files, not as single argv entries fix(bin): pass unbounded snapshot documents to jq through files, not argv Sep 1, 2026
@rrecheve

rrecheve commented Sep 3, 2026

Copy link
Copy Markdown
Author

Following up on the 2026-08-31 triage, which was waiting on the author for a no-mistakes pipeline attestation matching the head.

That attestation is now in the PR body, and its head_sha is 2fe8ac90364fc55b3cc64b12fad6a4db1532423e, which is the current head of this PR.

The remaining blocker is on your side rather than ours: this is a fork PR, so its workflow runs sit at action_required until a maintainer releases them. The CI approval recorded in that triage was for the earlier head ef98f7ae, and pushing the attestation commit moved the head, so the runs need approving again for 2fe8ac90. Right now the only check that has executed is Greptile, so the "1 passed" this PR shows is not a real green.

Could a maintainer approve the workflow runs for this head when convenient? Happy to rebase or supply anything else that would help.

For context on the urgency, with no wish to rush anyone: the argv bound this fixes is now breaking fleet snapshots in day-to-day use once a backlog crosses the single-argument limit, so the fix is doing real work while it waits.

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