Repository navigation
fix(bin): keep unbounded fleet-snapshot payloads off exec argv - #4206
neilwashere wants to merge 7 commits into
Conversation
2a3c06c to
57e41f5
Compare
57e41f5 to
3cb2730
Compare
|
Speaking as Kun's firstmate: First look on HEAD Contract-class: restore. Fleet snapshot already owed readable Bearings/home summaries; oversized status/open-decision payloads on exec argv hit Linux VISION.md per-rule (inspected
Attestation: MISMATCH — body marker waiting-author: please re-run Non-blocking review notes already in the PR body (fallback write / remaining |
A task's whole-status-log open-decision fold (status_open_decisions) has no size bound: it keeps every still-open needs-decision/blocked note, however long, until resolved. task_json_lines() embedded that fold through jq's --argjson, a single exec argument, so a task with many long-held decisions could exceed Linux's 128 KiB MAX_ARG_STRLEN and fail with "Argument list too long". The failure was swallowed by the unchecked "done | jq -s" pipe, so the affected task silently vanished from the snapshot instead of loudly failing, turning its home summary invalid (orphan_in_flight) and making it unreadable to Bearings. The originally suspected cause - the whole backlog JSON riding --argjson - was already fixed for both fleet-snapshot assembly points in kunchenguid#3677; this is a second, narrower survivor of the same argv-limit class that kunchenguid#3677's large-backlog fixtures never exercised, because they carry no task metadata and so never reach task_json_lines()'s per-task fold. File-back the fold the same way kunchenguid#3677 file-backed the larger payloads, via a private per-task temp file and --slurpfile.
…per-task snapshot failures
…unknown agent_alive
…t-snapshot header
…ile-back activity scan
…et-snapshot comment
3cb2730 to
0b30058
Compare
|
Closing in favor of a fresh PR from the same branch rebased onto current main; no code change. |
What Changed
bin/fm-fleet-snapshot.shnow routes every potentially unbounded snapshot payload through files instead of exec arguments: crew-state raw/detail lines, status-event raw/note, the per-task open-decision fold, and the secondmate aggregation's mirrored event line, activity scan, decision fold, and reconciliation now usejq --rawfile/--slurpfilerather than--arg/--argjson, so a single status line or accumulated fold above Linux's 128 KiBMAX_ARG_STRLENno longer breaks the composingjq.state unknown, a failed status-event transport reports no last event while still reporting the contract path, an unreadable endpoint observation reportsagent_alive=unknownwithexists null, and a failed open-decision write falls back to argv only when the fold provably fits a new 16 KiB character bound, otherwise reporting no open decisions - each case emitting a named stderr diagnostic. Collection-stage write failures still fail the whole command loudly, and the header comment block documents this boundary.tests/fm-home-summary-refresh.test.shadds four cases: many long never-resolved decisions on one task, a single >128 KiB status line asserted back untruncated through both home-summary and--jsonmodes, mirrored oversized lines through local and remote parent secondmate aggregation alongside an unrelated task that must survive, and a realENAMETOOLONGopen-decision write failure exercising both the small-fold argv fallback and the oversized-fold degradation (skipped where the filesystem name limit cannot isolate it).Risk Assessment
✅ Low: The change is a well-bounded transport swap (argv to files) plus per-task degradation defaults in one script, matches the recorded user authorizations from earlier rounds, is disclosed in the file's own header contract, and is covered by new behavioral regression fixtures that would fail before the fix; only informational residuals remain (a missing
// []default, one narrow--arg prargv path, one redundant per-task jq exec, and one vacuously-passable test assertion).Testing
I reproduced the reported end-user symptom against the base snapshot script and then showed it gone at the target, using the real publisher and the real captain-facing renderers rather than unit assertions alone: with 60 still-open decisions on one task, the base writer exited 0 while jq reported "Argument list too long", the task vanished from the published state/home-summary.json, the summary went invalid with orphan_in_flight, and Bearings showed the home as "structured home state invalid ... has no child metadata" with zero of the 60 captain decisions; with the fix the same fixture publishes valid:true, both tasks present, 60 decisions counted, no reconcile row, and the parent aggregation reports captain_decision. A second scenario with one 186,155-byte mirrored status line went from "summary producer failed with exit 1" and no home-summary.json at all (Bearings: "structured home ledger is missing, unreadable, or invalid", empty in_flight) to a published valid summary carrying the open decision and the child's live work. On the automated side the branch's own suite fails at the first new case when run against the base snapshot script and passes fully against the target, and the two nearest consumer suites (fleet-snapshot view and bearings snapshot) pass, with the single unrelated bearings case that requires the absent
tasks-axiCLI as the only failure. The change is CLI/JSON-surface only, so the reviewer-visible evidence is command transcripts and published JSON ledgers rather than screenshots; no rendered UI is involved.Evidence: Evidence index: before/after comparison tables, reproduction instructions
Source: Evidence index: before/after comparison tables, reproduction instructions
Evidence: Scenario A diff - what the captain sees before vs after (60 open decisions, 152,451-byte fold)
Source: Scenario A diff - what the captain sees before vs after (60 open decisions, 152,451-byte fold)
# "<" = base 2da3c5e ">" = fix d46f31f < "valid": false, < "invalidity_kind": "orphan_in_flight", < "invalidity_ids": [ "migration-run" ], < "reason": "in-flight backlog item has no child metadata: migration-run", < "tasks_seen": [ "docs-pass" ], < "decisions_open_count": 0 > "valid": true, > "invalidity_kind": null, > "invalidity_ids": [], > "reason": null, > "tasks_seen": [ "docs-pass", "migration-run" ], > "decisions_open_count": 60 < producer stderr: .../bin/fm-fleet-snapshot.sh: line 833: /usr/bin/jq: Argument list too long > producer stderr: # Bearings secondmate row < portal-mate,...,"structured home state invalid: in-flight backlog item has no child metadata: migration-run" > portal-mate,...,"-" # Bearings secondmate_reconcile row < portal-mate,null,null,orphan_in_flight,"["migration-run"]" > portal-mate,null,null,null,"[]" # parent aggregation of that home < "state": "active_child_work", "child_open_decisions": 0 > "state": "captain_decision", "child_open_decisions": 20Evidence: Scenario A transcript - BEFORE (base 2da3c5e): writer exits 0, task silently dropped, summary invalid
Source: Scenario A transcript - BEFORE (base 2da3c5e): writer exits 0, task silently dropped, summary invalid
Evidence: Scenario A transcript - AFTER (fix d46f31f): summary valid, both tasks present, 60 decisions surfaced
Source: Scenario A transcript - AFTER (fix d46f31f): summary valid, both tasks present, 60 decisions surfaced
Evidence: Scenario B transcript - BEFORE (base): one 186,155-byte status line, no home-summary.json published, Bearings blind
Source: Scenario B transcript - BEFORE (base): one 186,155-byte status line, no home-summary.json published, Bearings blind
Evidence: Scenario B transcript - AFTER (fix): summary published valid, decision and child work visible in Bearings and fleet view
Source: Scenario B transcript - AFTER (fix): summary published valid, decision and child work visible in Bearings and fleet view
Evidence: Regression proof - branch tests fail at the base snapshot script
Source: Regression proof - branch tests fail at the base snapshot script
$ bash tests/fm-home-summary-refresh.test.sh # bin/fm-fleet-snapshot.sh from BASE 2da3c5e ok - large backlog snapshots and home-summary publication stay within exec limits ok - parent snapshot consumes large child ledgers without argument transport not ok - secondmate home-summary mode reported an error for many long held decisions: bin/fm-fleet-snapshot.sh: line 833: /usr/bin/jq: Argument list too long exit=1Evidence: Regression proof - the same suite passes at the target commit
Source: Regression proof - the same suite passes at the target commit
ok - many long held decisions on one task publish without exec argument transport ok - one oversized status line publishes a readable home summary untruncated ok - mirrored oversized status lines survive the parent secondmate aggregation ok - a failed open-decision write keeps every task row and never hands an oversized fold to exec exit=0Evidence: Reproduction script - scenario A (folded open decisions, silent task drop)
Source: Reproduction script - scenario A (folded open decisions, silent task drop)
Evidence: Reproduction script - scenario B (one oversized mirrored status line)
Source: Reproduction script - scenario B (one oversized mirrored status line)
Pipeline
Updates from git push no-mistakes
⏭️ **intent** - skipped
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-fleet-snapshot.sh:946-($open_decisions_file[0]) as $open_decisionsis the only one of the three new transport reads in this composing jq without a//fallback: its siblings at lines 944-945 both supply a bounded default object. Verified with jq 1.7 that--slurpfileon an empty or whitespace-only file yields[], so[0]isnulland the row publisheshints.open_decisions: nullinstead of an array. Two writers can produce that shape: the success path at line 869 writesprintf '%s\n' "$open_decisions_json", which is a bare newline whenopen_decisions_jsonis empty, and the argv fallback at line 878 becomes--argjson open_decisions_file "[]"in the same case. Reaching an emptyopen_decisions_jsonrequires the producingjq -R -sat line 855 to emit nothing, so this is defensive rather than routine, and both current consumers (bin/fm-fleet-snapshot.sh:1120and:1849) read it as.hints.open_decisions // [], so nothing downstream breaks today. It still contradicts the contract sentence added at line 59 ("hints.open_decisions can be empty" - empty, not null). Remedy is the one-token// []to match the siblings; no new state, schema, or failure policy.bin/fm-fleet-snapshot.sh:927- After this change--arg pr "$pr"is the last status-log-derived value in the per-task composing jq that still rides an exec argument, so the invariant this commit documents at line 63 ("The row itself is never dropped") has one remaining source-verifiable hole.prcomes fromfirst_pr_url_in_file "$status_log"(line 389), which isgrep -Eo 'https?://[^[:space:])"]+/pull/[0-9]+' | head -1; the character class is greedy and excludes only whitespace,)and", so on one line the match spans from the firsthttps://to the LAST/pull/<digits>. Nothing bounds one status line:bin/fm-procevent-remote-reply.shverifiespayload_bytesagainst its digest (lines 336-354) but never caps it, and appends each normalized payload line straight into the status stream (line 402). A mirrored payload line above MAX_ARG_STRLEN whose bytes contain no whitespace,)or"between a URL prefix and a trailing/pull/N(for example a comma-joined PR/URL list) makes--arg prexceed the 128 KiB per-argument limit; the composing jq then fails to exec, and because the loop body is the left side ofdone | jq -sat line 981 with nopipefail,TASKS_JSON=$(task_json_lines) || ...at line 2062 never fires and the task row silently vanishes - the exact symptom this branch exists to remove. The shape requirement makes this much narrower than the raw/note/detail/fold paths already fixed, hence info rather than a blocker. Earliest correction at the shared boundary is mechanical and local: bound the extractor's output infirst_pr_url_in_file(a real PR URL has a practical length limit) so no status-derived value can reach exec, rather than adding a fourth per-payload transport later.bin/fm-fleet-snapshot.sh:811- The new readability gate runsjq -e 'type == "object"' "$current_file"and then, on success, a secondjq -r '[.state // "", .source // ""] | @tsv' "$current_file"(line 813) over the same file, where the base revision used one$(<"$current_file")plus one jq. That is one extra process per task in the sequentialtask_json_linesloop, and the|| printf '\t\n'guard on line 813 is now dead because the gate already proved the file parses. Both the gate and the read collapse into a single invocation whose exit status carries the verdict, e.g.if state_tsv=$(jq -er 'select(type == "object") | [.state // "", .source // ""] | @tsv' "$current_file" 2>/dev/null); then read -r current_state current_source <<<"$state_tsv"; else <degrade>; fi- same degradation semantics, one fewer exec per task, and no dead fallback. Non-functional; no user-visible output changes.tests/fm-home-summary-refresh.test.sh:506- The write-failure test isolates the failing write purely by filename length: it probes that<236-char-id>.crew-state-detail(254 bytes) fits and<id>.open-decisions.json(256 bytes) does not. Those suffixes are internal transport names, not a declared contract, and the small-fold case that follows (line 528) asserts onlyopen_decisions | length == 1 and open_decisions[0].key == "transport"- which holds identically when the write SUCCEEDS. So if a future rename or a different NAME_MAX changes which write fails, that case passes vacuously and the newly added argv-fallback branch at line 878 loses its only coverage without any failure (theelsebranch just prints skip). The oversized sibling at line 541 is non-vacuous (length == 0would fail if the write succeeded), so the mechanism is not uncovered today. Mechanical tightening that stays behavioral: the snapshot's degradation line on stderr is an explicitly documented output surface (header line 56: "reports the degradation on stderr"), so assert that$TMP_ROOT/write-fail-small.errcontains theopen-decision transport write failed; passing the fold on argvline, which proves the intended write actually failed instead of inferring it from a filesystem probe.tests/fm-bearings-snapshot.test.sh:1623- Unrelated to this change: the final case in tests/fm-bearings-snapshot.test.sh ("landed accepts only kind-owned delivery artifacts") fails immediately on this host because its guard[ -n "$TASKS_AXI_BIN" ]finds notasks-axibinary on PATH (TASKS_AXI_BIN is a plaincommand -v tasks-axilookup at line 17). It is a host prerequisite, not a product failure, and installing system packages is outside this run's allowed boundary. Every other case in that file passes against the target commit. Remote CI, which owns broad regression, needs the tasks-axi CLI available for that case to run at all.bin/fm-fleet-snapshot.sh:810- Coverage disclosure for this test phase: the open-decision write-failure degradation is genuinely exercised (the suite injects a real ENAMETOOLONG write failure with a 236-character task id and proves both the small-fold argv path and the oversized-fold degradation keep every row), but the two sibling degradations added in the same round - unreadable per-task current-state observation (line ~810) and failed status-event transport (line ~828) - cannot be triggered through any public interface. Their transport filenames are shorter than the crew-state files written earlier in the same loop (<id>.json+5 and<id>.event-raw+10 versus<id>.crew-state-raw+16), so any filesystem-name or write failure that would reach them aborts the snapshot earlier by the accepted crew-state policy, and the observation directory is private to the process. They remain untested defensive fallbacks; no test was added rather than one that could only assert on source text.bash tests/fm-home-summary-refresh.test.sh(target d46f31f) - all cases pass, including the four new argv-transport cases (60 long held decisions, one 200,000-char status line, mirrored parent aggregation, and a real ENAMETOOLONG open-decision write failure)bash tests/fm-home-summary-refresh.test.shrun against a root whosebin/fm-fleet-snapshot.shis the BASE 2da3c5e file - fails at the first new case withjq: Argument list too long(regression reproduced before the fix)bash tests/fm-fleet-snapshot-view.test.sh- snapshot/fleet-view contract consumers of the changed composition, all passbash tests/fm-bearings-snapshot.test.sh- heaviest consumer of the changed secondmate aggregation; all cases pass except thetasks-axi-gated landed case (host prerequisite missing)Manual end-to-end, scenario A (silent task drop):bash repro-silent-task-drop.sh <root> <label>run against base and target - seeds a real secondmate home whose long-lived task holds 60 still-open needs-decision notes (152,451-byte fold), publishes withbin/fm-home-summary-refresh.sh, then rendersbin/fm-bearings-snapshot.shand the parentbin/fm-fleet-snapshot.sh --jsonaggregation from a captain home that registers itManual end-to-end, scenario B (one oversized line):bash repro-home-summary-argv-overflow.sh <root> <label>run against base and target - one 186,155-byte mirroredneeds-decisionstatus line, same writer plusbin/fm-bearings-snapshot.shandbin/fm-fleet-view.shcaptain surfacesConfirmed the worktree is clean (git status --porcelainempty) and removed the throwaway base-root used for the before/after comparisonbin/fm-fleet-snapshot.sh:244- Judgment call, deliberately not changed: the new per-task degradation behavior (a snapshot that reports an unreadable observation on stderr and still exits 0 with a degraded row) is stated only in the script header, which is the output contract's single owner. The --help text was left alone rather than carrying a second copy: it already restates bounds facts the header owns, and adding the degradation contract there would create a second full copy that drifts, against the repo's one-owner rule and the mechanics tier in .agents/skills/firstmate-coding-guidelines/SKILL.md. If maintainers prefer --help to disclose the exit-zero-with-degradation case, the smallest safe form is a one-line pointer to the header rather than a restatement.✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.