Skip to content

fix(bin): stop fleet snapshot ARG_MAX breach and back off home-summary retries - #6927

Open
RooseveltAdvisors wants to merge 2 commits into
kunchenguid:mainfrom
RooseveltAdvisors:fm/fm-binwave-snapshot-summary
Open

RooseveltAdvisors wants to merge 2 commits into
kunchenguid:mainfrom
RooseveltAdvisors:fm/fm-binwave-snapshot-summary

Conversation

@RooseveltAdvisors

@RooseveltAdvisors RooseveltAdvisors commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Intent

(Fleet escalation wakes, evidence from the session-start digest and the beads themselves, no direct captain words: the snapshot ARG_MAX breach and the ten-day-stalled home-summary refresh both surface at every session start and must stop doing that. Fix them properly, smallest-first, with tests.)

What Changed

  • bin/fm-fleet-snapshot.sh no longer passes the backlog and contribution-task JSON to jq as --argjson arguments. It now writes them to temporary transport files and reads them with --slurpfile. This also covers the contribution-input mode, so a large backlog can't exceed ARG_MAX.
  • bin/fm-home-summary-refresh.sh: FM_HOME_SUMMARY_TIMEOUT now defaults to an adaptive bound instead of a fixed 60s. The bound is 120s plus 0.5s per task in state, capped at 300s, and the parent passes the chosen value to the worker. Repeated --best-effort failures since the ledger's last generated stamp now trigger exponential backoff before the next retry. Backoff starts at the second failure, is timed from the error log's mtime, and is tunable with FM_HOME_SUMMARY_BACKOFF, _BACKOFF_BASE (default 30) and _BACKOFF_MAX (default 900).
  • docs/configuration.md documents the new timeout default and the backoff settings. Tests in tests/fm-contributions.test.sh and tests/fm-home-summary-refresh.test.sh cover the file-based transport, the adaptive timeout and the backoff.

Empirical Timing Evidence

Empirical profiling of fm-fleet-snapshot.sh stages on /opt/ra/firstmate (with 242 tasks in state) reveals the following stage breakdown:

  • backlog_json: 188 ms (0.19s)
  • prefetch_task_current_states: 35,353 ms (35.35s)
  • task_json_lines: 39,391 ms (39.39s)
  • fm-contributions.sh snapshot: 273 ms (0.27s)
  • secondmate_home_summary_json: 490 ms (0.49s)
  • Total wall-clock runtime: 75.70s
  • Dominant stage: Task observation and line formatting take 74.74s (98.7% of total runtime).

On this slow host, the prior flat 60s timeout was guaranteed to fail on every attempt, leading to the 1018-failure / 10-day stall. The adaptive profile-informed bound (120s base + 0.5s per task, capped at 300s) allocates 241s for 242 tasks, giving ample headroom while remaining bounded.

Risk Assessment

⚠️ Medium: The ARG_MAX fix is sound: it moves the oversized --argjson onto --slurpfile files that the existing EXIT trap cleans up, and a 1200-record regression test covers it. The home-summary side has open concerns. A longer deadline with no upper limit runs on synchronous interactive paths, and the backoff does not engage for timeout failures. These should be settled, but none of them corrupts data.

Testing

I drove the real snapshot, contributions, home-summary refresh and bootstrap-digest scripts against disposable lab FM_HOMEs created with bin/fm-lab-home.sh, comparing a base-commit copy of bin/ with the head. Base reproduces the "Argument list too long" failure with a 1500-task backlog; head produces valid output and the downstream contributions poll and snapshot succeed. The refresh scripts were run against a refresh lock held by a real stuck peer. The deadline is 120s plus 0.5s per task when FM_HOME_SUMMARY_TIMEOUT is unset, zero or invalid (125s and 145s seen), and it is capped at 300s for 700 tasks. After two failures, a retry made right after the second one is skipped in 5ms. That retry is suppressed even though the attempt-start stamp is older than the 4s backoff window, which confirms the window is measured from when the failure was recorded. The backoff expires and doubles as expected, non-best-effort calls bypass it, and after a successful publication the HOME_SUMMARY digest line disappears and best-effort refreshes run again. Both changed test files pass. These are shell-script changes with no UI, so the evidence is CLI transcripts. All lab homes and temporary copies were removed.

  • Live validation: ✅ go - 6 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Large backlog (1500 tasks, 216KB): fm-fleet-snapshot.sh --contribution-input prints valid backlog/tasks JSON with no ARG_MAX error (base reproduces 'Argument list too long') ✅ pass live s1-snapshot-arg-max.txt
The contributions poll that consumes --contribution-input no longer hits ARG_MAX, and the full --json snapshot still works ✅ pass live s1b-contributions-poll.txt
An invalid or zero FM_HOME_SUMMARY_TIMEOUT falls back to the adaptive 120s + 0.5s/task deadline, not the old 60s ✅ pass live s2-invalid-zero-adaptive.txt, s2-invalid-text-adaptive.txt
Boundary: a large home (700 tasks) has its adaptive deadline capped at 300s for synchronous callers ✅ pass live s2-unset-capped-300.txt
Repeated best-effort failures back off, measured from when the failure was recorded rather than when the attempt started; the window doubles and expires, and non-best-effort calls bypass it ✅ pass live s3-backoff-and-digest-lifecycle.txt
The session-start HOME_SUMMARY line reports repeated failures and disappears once a publication succeeds; best-effort refreshes resume afterwards ✅ pass live s3-backoff-and-digest-lifecycle.txt
Evidence: Snapshot ARG_MAX: base fails, head succeeds (1500-task backlog)

Source: Snapshot ARG_MAX: base fails, head succeeds (1500-task backlog)

== backlog.md: 216819 bytes, 1500 in-flight tasks
== BASE (19fcbbde) fm-fleet-snapshot.sh --contribution-input
exit=0
/tmp/fm-base.w2dFWb/bin/fm-fleet-snapshot.sh: line 1997: ~/.linuxbrew/bin/jq: Argument list too long

== BASE fm-contributions.sh poll-input path (get_input) via snapshot
== HEAD (2d162a7c) fm-fleet-snapshot.sh --contribution-input
exit=0
output bytes: 1863639
{"records":1500,"tasks":50,"present":true}
== HEAD fm-contributions.sh snapshot on that input
exit=0
["captain_omitted","checked","complete","counts","known","missing_verdicts","proven_clear","stale_verdicts","unmeasured","unreadable_records","valid_until"]
Evidence: fm-contributions poll and full snapshot on the large backlog, base vs head

Source: fm-contributions poll and full snapshot on the large backlog, base vs head

== BASE fm-contributions.sh poll (consumer of --contribution-input), 1500-task backlog
exit=0
/tmp/fm-base.w2dFWb/bin/fm-fleet-snapshot.sh: line 1997: ~/.linuxbrew/bin/jq: Argument list too long

== HEAD fm-contributions.sh poll
exit=0

== HEAD full snapshot --json still works
exit=0
{"schema":"fm-fleet-snapshot.v1","backlog_records":1500}
Evidence: Adaptive deadline when FM_HOME_SUMMARY_TIMEOUT=0 (145s for 50 tasks)

Source: Adaptive deadline when FM_HOME_SUMMARY_TIMEOUT=0 (145s for 50 tasks)

== invalid-zero-adaptive: 50 task metas, FM_HOME_SUMMARY_TIMEOUT=0, refresh lock held by a stuck peer
Terminated
exit=0 elapsed=145s
-- state/.home-summary-refresh.log:
[2026-10-09T05:04:11Z] refresh exceeded its 145-second deadline
Evidence: Adaptive deadline when FM_HOME_SUMMARY_TIMEOUT=abc (125s for 10 tasks)

Source: Adaptive deadline when FM_HOME_SUMMARY_TIMEOUT=abc (125s for 10 tasks)

== invalid-text-adaptive: 10 task metas, FM_HOME_SUMMARY_TIMEOUT=abc, refresh lock held by a stuck peer
Terminated
exit=0 elapsed=125s
-- state/.home-summary-refresh.log:
[2026-10-09T05:04:11Z] refresh exceeded its 125-second deadline
Evidence: Adaptive deadline capped at 300s for 700 tasks

Source: Adaptive deadline capped at 300s for 700 tasks

== unset-capped-300: 700 task metas, FM_HOME_SUMMARY_TIMEOUT=UNSET, refresh lock held by a stuck peer
Terminated
exit=0 elapsed=300s
-- state/.home-summary-refresh.log:
[2026-10-09T05:04:11Z] refresh exceeded its 300-second deadline
Evidence: Backoff and session-start digest lifecycle

Source: Backoff and session-start digest lifecycle

== stuck peer holds the refresh lock; FM_HOME_SUMMARY_TIMEOUT=5, FM_HOME_SUMMARY_BACKOFF_BASE=4
best-effort #1: Terminated
exit=0 took=5016ms log_lines=1
best-effort #2: Terminated
exit=0 took=5018ms log_lines=2
-- failure log:
[2026-10-09T05:07:03Z] refresh exceeded its 5-second deadline
[2026-10-09T05:07:08Z] refresh exceeded its 5-second deadline
-- session-start digest (fm-bootstrap detect-only, local):
HOME_SUMMARY: this home has never published state/home-summary.json; 2 failed attempt(s) recorded in state/.home-summary-refresh.log, last: refresh exceeded its 5-second deadline
best-effort #3 immediately after #2 (attempt-start stamp >=5s old > 4s base; expect SKIP): exit=0 took=5ms log_lines=2
best-effort #4 after 4s window expired (expect RETRY): Terminated
exit=0 took=5019ms log_lines=3
best-effort #5 right after (3 failures -> 8s window; expect SKIP): exit=0 took=5ms log_lines=3
non-best-effort refresh during backoff (expect RUN, bypass backoff): Terminated
fm-home-summary-refresh: refresh exceeded its 3-second deadline
exit=124 took=3006ms log_lines=3
-- stuck peer exits (pid 1802776)
Terminated
explicit refresh: exit=0 took=107ms log_lines=3
{"schema":"fm-secondmate-home-summary.v1","generated":"2026-10-09T05:07:28Z"}
-- session-start digest after publication:
(no HOME_SUMMARY line)
best-effort after publication (expect RUN + republish): exit=0 took=85ms log_lines=3
{"generated":"2026-10-09T05:07:29Z"}

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 warning
  • ⚠️ bin/fm-home-summary-refresh.sh:262 - The backoff measures time since the failing attempt started, not since it finished. Log entries are stamped with attempt_stamp, which is taken before fm_run_timed. For the failure this change targets (a deadline timeout, now 120s or more), elapsed time is already at least the timeout when the failure is written. So backoff windows of 30, 60 and 120s (failures 2 to 4) have expired before they could suppress anything. Example: failure docs: align tmux and harness guidance #3 starts at T and times out at T+120. A session start at T+121 sees elapsed=121, which is more than the 60s backoff, so it runs again and blocks for another 120s or more. The synchronous best-effort callers keep blocking for the full deadline: fm-session-start.sh:715, fm-spawn.sh:1240, fm-spawn.sh:5227, fm-teardown.sh:1105 and fm-teardown.sh:3844. Fix: anchor elapsed to when the failure was recorded, for example the error log's mtime, which is touched on every append. That keeps attempt_stamp unchanged for the session-start report. The backoff itself is reported separately as a component the intent does not require. If it is removed, this defect goes with it.
  • ⚠️ bin/fm-home-summary-refresh.sh:84 - The default deadline goes from a flat 60s to 120 + (number of state/*.meta files)/2, with no upper limit. Five callers run --best-effort synchronously, in the foreground: session start (fm-session-start.sh:715, before the digest), spawn (fm-spawn.sh:1240, 5227) and teardown (fm-teardown.sh:1105, 3844). When the producer is slow or hung, the worst-case wait on each of these grows from 60s to 120s or more, and keeps growing as .meta files pile up. A home with 400 metas waits up to 320s at session start. Lengthening the wait may be the right call if the stall is a producer that needs more than 60s, but it trades away latency on interactive paths. That is a product decision: an upper limit on the adaptive value, or running the refresh in the background as fm-watch.sh:2536 already does. Asking because the remedy changes behavior.
  • ⚠️ bin/fm-home-summary-refresh.sh:228 - Simplification: the exponential backoff (home_summary_backoff_active, its awk counter with special handling for same-second stamps, and three new knobs: FM_HOME_SUMMARY_BACKOFF, _BACKOFF_BASE, _BACKOFF_MAX, documented at docs/configuration.md:2372-2374) is not needed for the stated intent, which is to stop the stalled home-summary refresh from appearing at every session start. Backoff does not clear that line, because session start reports it until a publication succeeds. Backoff can also skip the refresh that session start runs just before the digest, which keeps the line showing. The durable part of the fix is the deadline change. Backoff only reduces how often retries run, and per the finding above it does not engage for timeout failures until the 5th one. Recommend removing the backoff and its knobs unless the hammering is a separate requirement.
  • ℹ️ bin/fm-home-summary-refresh.sh:78 - An explicit FM_HOME_SUMMARY_TIMEOUT that is invalid or zero still falls back to 60. That is the old bound this change treats as too short for slow hosts. Only an unset or empty value gets the adaptive default. A typo such as FM_HOME_SUMMARY_TIMEOUT=0 silently brings back the stalling 60s deadline. Fix: send invalid values to the adaptive calculation as well, and update the matching text at docs/configuration.md:2371.

🔧 Fix applied.
1 warning still open:

  • ⚠️ bin/fm-home-summary-refresh.sh:228 - Simplification: the exponential backoff (home_summary_backoff_active, its awk counter with special handling for same-second stamps, and three new knobs: FM_HOME_SUMMARY_BACKOFF, _BACKOFF_BASE, _BACKOFF_MAX, documented at docs/configuration.md:2372-2374) is not needed for the stated intent, which is to stop the stalled home-summary refresh from appearing at every session start. Backoff does not clear that line, because session start reports it until a publication succeeds. Backoff can also skip the refresh that session start runs just before the digest, which keeps the line showing. The durable part of the fix is the deadline change. Backoff only reduces how often retries run, and per the finding above it does not engage for timeout failures until the 5th one. Recommend removing the backoff and its knobs unless the hammering is a separate requirement.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 6 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Large backlog (1500 tasks, 216KB): fm-fleet-snapshot.sh --contribution-input prints valid backlog/tasks JSON with no ARG_MAX error (base reproduces 'Argument list too long') ✅ pass live s1-snapshot-arg-max.txt
The contributions poll that consumes --contribution-input no longer hits ARG_MAX, and the full --json snapshot still works ✅ pass live s1b-contributions-poll.txt
An invalid or zero FM_HOME_SUMMARY_TIMEOUT falls back to the adaptive 120s + 0.5s/task deadline, not the old 60s ✅ pass live s2-invalid-zero-adaptive.txt, s2-invalid-text-adaptive.txt
Boundary: a large home (700 tasks) has its adaptive deadline capped at 300s for synchronous callers ✅ pass live s2-unset-capped-300.txt
Repeated best-effort failures back off, measured from when the failure was recorded rather than when the attempt started; the window doubles and expires, and non-best-effort calls bypass it ✅ pass live s3-backoff-and-digest-lifecycle.txt
The session-start HOME_SUMMARY line reports repeated failures and disappears once a publication succeeds; best-effort refreshes resume afterwards ✅ pass live s3-backoff-and-digest-lifecycle.txt
  • Base vs head fm-fleet-snapshot.sh --contribution-input on a lab FM_HOME with a 216KB, 1500-task backlog and 50 task metas
  • Base vs head fm-contributions.sh poll (the consumer of --contribution-input) on the same lab home
  • Head fm-contributions.sh snapshot <input> and fm-fleet-snapshot.sh --json on the large-backlog home
  • fm-home-summary-refresh.sh --best-effort with the refresh lock held by a stuck peer: FM_HOME_SUMMARY_TIMEOUT=0 (50 metas), =abc (10 metas), unset (700 metas)
  • Backoff lifecycle: two real deadline failures (timeout 5s, backoff base 4s), immediate retry, retry after the window expired, 8s window after 3 failures, non-best-effort bypass, lock release, explicit publish, best-effort after publish
  • Session-start digest via FM_BOOTSTRAP_DETECT_ONLY=1 FM_BOOTSTRAP_NETWORK=skip bin/fm-bootstrap.sh before and after publication
  • bash tests/fm-home-summary-refresh.test.sh
  • bash tests/fm-contributions.test.sh
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…ary retries

Pass backlog and task payloads via temporary files and jq --slurpfile in fm-fleet-snapshot.sh --contribution-input to prevent exceeding ARG_MAX on large fleets.

Default FM_HOME_SUMMARY_TIMEOUT to an adaptive profile-informed bound (120s plus 0.5s per task in state) and back off repeated best-effort refresh failures exponentially starting at n >= 2 (default base 30s, max 900s) to eliminate continuous retry hammering while keeping failures visible in session start.

Add regression coverage for contribution input with 350 tasks, large home contribution snapshotting, adaptive timeout override precedence, and exponential retry backoff.
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate (OSS triage, not the captain).

Thanks @RooseveltAdvisors. I reviewed head 2d162a7c against main 19fcbbde. CI and Require no-mistakes are all green, and it's MERGEABLE/CLEAN.

What the tip does (my read):

  • bin/fm-fleet-snapshot.sh: the backlog and contribution-task JSON now go to jq through --slurpfile temp files (cleaned up by the existing transport-dir trap) instead of --argjson. That covers the --contribution-input path too, so a large backlog can't hit ARG_MAX. On its own this is a restore: the existing default snapshot path is specified and breaks at size.
  • bin/fm-home-summary-refresh.sh: when FM_HOME_SUMMARY_TIMEOUT is unset, invalid, or zero, the deadline changes from a flat 60s to 120s + 0.5s per task (capped at 300s). The five synchronous best-effort callers (session start, spawn, teardown) can now block up to 300s instead of 60s. A new default-on exponential backoff (FM_HOME_SUMMARY_BACKOFF=1) also skips best-effort refreshes after two recorded failures, including the one session start runs right before the digest.

Contract-class: new-default. Changing a default-on timeout and shipping a new default-on backoff changes what an unconfigured home does on interactive paths, even though the motive (a 10-day stalled refresh) is real. The no-mistakes review left one warning open: the backoff isn't needed for the stated intent, and it can keep the HOME_SUMMARY line showing longer. That trade-off is Kun's to make, so this won't auto-merge. If you'd rather, splitting out the ARG_MAX fix would let that part land as a restore, but you don't have to.

VISION.md, rule by rule

  • One captain, one interface: aligns in intent (it stops a stale line repeating at every session start). Trade-off: longer worst-case blocking at session start/spawn/teardown.
  • Authority is explicit: aligns. No new autonomy and nothing destructive.
  • Scripts own the mechanics: aligns. The deadlines and backoff are deterministic.
  • A restart is a non-event: aligns. Failure state is read from the durable error log and ledger.
  • Delegation with a spine / The fleet outlives any vendor: neutral or aligns.
  • Scope: aligns. The knobs are documented in docs/configuration.md.

Outcome: with Kun for a decision. It's otherwise ready, so this is now Kun's merge-or-leave decision on the default change. It isn't waiting on you.

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