Repository navigation
fix(bin): stop fleet snapshot ARG_MAX breach and back off home-summary retries - #6927
RooseveltAdvisors wants to merge 2 commits into
Conversation
…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.
|
Speaking as Kun's firstmate (OSS triage, not the captain). Thanks @RooseveltAdvisors. I reviewed head What the tip does (my read):
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
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. |
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.shno longer passes the backlog and contribution-task JSON tojqas--argjsonarguments. It now writes them to temporary transport files and reads them with--slurpfile. This also covers thecontribution-inputmode, so a large backlog can't exceed ARG_MAX.bin/fm-home-summary-refresh.sh:FM_HOME_SUMMARY_TIMEOUTnow 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-effortfailures since the ledger's lastgeneratedstamp 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 withFM_HOME_SUMMARY_BACKOFF,_BACKOFF_BASE(default 30) and_BACKOFF_MAX(default 900).docs/configuration.mddocuments the new timeout default and the backoff settings. Tests intests/fm-contributions.test.shandtests/fm-home-summary-refresh.test.shcover the file-based transport, the adaptive timeout and the backoff.Empirical Timing Evidence
Empirical profiling of
fm-fleet-snapshot.shstages 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)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
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.
Evidence: Snapshot ARG_MAX: base fails, head succeeds (1500-task backlog)
Source: Snapshot ARG_MAX: base fails, head succeeds (1500-task backlog)
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
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)
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)
Evidence: Adaptive deadline capped at 300s for 700 tasks
Source: Adaptive deadline capped at 300s for 700 tasks
Evidence: Backoff and session-start digest lifecycle
Source: Backoff and session-start digest lifecycle
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
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-effortsynchronously, 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.
Base vs headfm-fleet-snapshot.sh --contribution-inputon a lab FM_HOME with a 216KB, 1500-task backlog and 50 task metasBase vs headfm-contributions.sh poll(the consumer of --contribution-input) on the same lab homeHeadfm-contributions.sh snapshot <input>andfm-fleet-snapshot.sh --jsonon the large-backlog homefm-home-summary-refresh.sh --best-effortwith 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 publishSession-start digest viaFM_BOOTSTRAP_DETECT_ONLY=1 FM_BOOTSTRAP_NETWORK=skip bin/fm-bootstrap.shbefore and after publicationbash tests/fm-home-summary-refresh.test.shbash tests/fm-contributions.test.sh✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.