Skip to content

fix(bin): retry ShellCheck roots that hit the memory ceiling without --external-sources - #6443

Merged
kunchenguid merged 8 commits into
kunchenguid:mainfrom
tiago-peixoto:fm/fm5620-shellcheck-oom
Oct 2, 2026
Merged

kunchenguid merged 8 commits into
kunchenguid:mainfrom
tiago-peixoto:fm/fm5620-shellcheck-oom

Conversation

@tiago-peixoto

@tiago-peixoto tiago-peixoto commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Fixes #5620.

Prepare the fix for #5620: CI lint runs ShellCheck with --external-sources per root, and on current main bin/fm-teardown.sh already peaks at about 8,382,364 KB against the CI runner's 8 GiB (8,388,608 KB) per-root memory ceiling, so any change touching the libraries teardown reaches fails Lint with reason=memory rc=251 (open PRs #4893 and #5598 both cross it by about 1 MB with no ShellCheck findings). The maintainer earlier pointed to #3973's fix shape (one file at a time under a per-file timeout and memory ceiling, with a named fallback without --external-sources); #3973 was closed unmerged. A question asking which direction the maintainer prefers is open on the issue.

The issue is not yet labeled ready-for-pr, and firstmate only accepts a PR after that invitation.

What Changed

  • bin/fm-lint.sh now retries a root once without --external-sources if it fails with a memory reason while following sources. The retry runs under the same per-root timeout and address-space bounds, and it excludes only the cross-file codes that local no-source lint already skips (SC1091,SC2034,SC2153,SC2329). If the retry is clean, the root passes with a new memory-fallback reason and a warning line in the shard output. Retry findings or a failed retry still fail lint, and the retry's diagnostics replace those of the failed attempt.
  • Per-root evidence now records whether the final attempt followed sources, as a new column in the roots log. Peak RSS for a retried root is the larger value of the two attempts. The telemetry source_followed_directives count includes only roots whose final attempt followed sources.
  • tests/fm-lint.test.sh covers the fallback path in bounded and unbounded runs, including RSS reporting, using disposable test roots. The script header and docs/fm-test-portable-shards.md now describe the fallback and its reporting.

Fixes #5620.

Risk Assessment

✅ Low: The change adds one bounded retry, and only for roots already classified as memory failures (rc=251 or GHC heap exhaustion), so the existing failure modes stay intact: the retry drops only --external-sources and excludes only the four cross-file codes that local lint already excludes. Fallback findings and failed retries still fail lint, and the roots log and telemetry index mapping (1-based ROOTS order, field 12) are consistent with how both are produced and read; the tests run the real lint entry point in bounded and unbounded modes.

Testing

I ran the real bin/fm-lint.sh and the real ShellCheck 0.11.0 against bin/fm-teardown.sh under enforced per-root bounds. The baseline run reproduced the issue's footprint: about 8,381,404 KB resident with sources followed. With an 8 GiB ceiling, the source-following attempt ran out of memory (rc=251). The retry without --external-sources then passed at about 5.6 GB. Lint exited 0, printed the disclosure line, recorded reason memory-fallback in the roots log, and reported telemetry source_followed_directives=0. Three adversarial runs behaved correctly. An injected SC2086 finding still failed lint (rc=1, reason findings). A 1 GiB or 512 MiB ceiling made the retry run out of memory too, and lint failed with reason=memory rc=251. A 5-second deadline failed with reason=timeout and no retry. I did not run CI partition mode (--partition), but it uses the same per-root function. The temporary probe script and scratch files were removed. The transcripts are in the evidence directory.

  • Live validation: ✅ go - 6 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Teardown lint under an 8 GiB per-root ceiling passes through the disclosed no-source retry instead of failing with memory rc=251 ✅ pass live fm-lint-fb.txt: exit 0, disclosure line, roots log reason memory-fallback, rc 0, RSS 5594212, follow 0
Telemetry counts zero followed source directives when the root passed only the no-source retry ✅ pass live fm-lint-fb.txt: source_followed_directives 0 vs 16 in fm-lint-base.txt
Adversarial: a real ShellCheck finding in the no-source retry still fails lint ✅ pass live fm-lint-find.txt: 'fallback reason=findings rc=1', SC2086 shown, exit 1
Adversarial: if the no-source retry also runs out of memory, lint fails with reason=memory ✅ pass live fm-lint-low1048576.txt: 'fallback reason=memory rc=251', exit 251
Adversarial: non-memory failures such as a timeout are not retried ✅ pass live fm-lint-to.txt: reason=timeout rc=124, no retry line, follow flag 1
Healthy run below the ceiling keeps full --external-sources analysis with no retry ✅ pass live fm-lint-base.txt: reason ok, follow 1, source_followed_directives 16
Evidence: Baseline: teardown peaks ~8.38 GB RSS with sources followed

Source: Baseline: teardown peaks ~8.38 GB RSS with sources followed

\### base output
fm-lint.sh: ShellCheck 0.11.0 (pinned 0.11.0)
fm-lint.sh: full ShellCheck extended analysis enabled

real	1m25.771s
user	1m18.025s
sys	0m5.813s
\### base roots log end record
end	1	bin/fm-teardown.sh	0	full	1790974662853	1790974746187	83334	0	ok	8381404	1
\### base telemetry source/rss
source_followed_directives	16
max_worker_rss_kib	8381404
Evidence: 8 GiB ceiling: memory failure, then the no-source retry passes (memory-fallback, source_followed_directives 0)

Source: 8 GiB ceiling: memory failure, then the no-source retry passes (memory-fallback, source_followed_directives 0)

fm-lint: bin/fm-teardown.sh hit the memory ceiling with --external-sources (reason=memory rc=251); retried without it; fallback passed with cross-file codes excluded (SC1091,SC2034,SC2153,SC2329) end 1 bin/fm-teardown.sh 0 full ... 0 memory-fallback 5594212 0

\### fb output
fm-lint.sh: ShellCheck 0.11.0 (pinned 0.11.0)
fm-lint.sh: full ShellCheck extended analysis enabled
fm-lint: bin/fm-teardown.sh hit the memory ceiling with --external-sources (reason=memory rc=251); retried without it; fallback passed with cross-file codes excluded (SC1091,SC2034,SC2153,SC2329)

real	1m11.719s
user	1m5.768s
sys	0m3.976s
\### fb roots log end record
end	1	bin/fm-teardown.sh	0	full	1790974755665	1790974824944	69279	0	memory-fallback	5594212	0
\### fb telemetry source/rss
source_followed_directives	0
max_worker_rss_kib	5594212
Evidence: Retry with an injected SC2086 finding fails lint

Source: Retry with an injected SC2086 finding fails lint

\### find output
fm-lint.sh: ShellCheck 0.11.0 (pinned 0.11.0)
fm-lint.sh: full ShellCheck extended analysis enabled
fm-lint: bin/fm-zz-probe-finding.sh hit the memory ceiling with --external-sources (reason=memory rc=251); retried without it; fallback reason=findings rc=1

In bin/fm-zz-probe-finding.sh line 3858:
fm_probe_unquoted() { local x=$1; printf "%s\n" $x; }
                                                ^-- SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
fm_probe_unquoted() { local x=$1; printf "%s\n" "$x"; }

For more information:
  https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ...
rc=1
\### find roots log end record
end	1	bin/fm-zz-probe-finding.sh	0	full	1790974839685	1790974906084	66399	1	findings	5594148	0
\### find telemetry source/rss
source_followed_directives	0
max_worker_rss_kib	5594148
Evidence: 2 GiB ceiling: the retry still passes

Source: 2 GiB ceiling: the retry still passes

\### low output
fm-lint.sh: ShellCheck 0.11.0 (pinned 0.11.0)
fm-lint.sh: full ShellCheck extended analysis enabled
fm-lint: bin/fm-teardown.sh hit the memory ceiling with --external-sources (reason=memory rc=251); retried without it; fallback passed with cross-file codes excluded (SC1091,SC2034,SC2153,SC2329)
rc=0
\### low roots log end record
end	1	bin/fm-teardown.sh	0	full	1790974839682	1790974863343	23661	0	memory-fallback	1403364	0
\### low telemetry source/rss
source_followed_directives	0
max_worker_rss_kib	1403364
Evidence: 1 GiB ceiling: the retry also runs out of memory and lint fails with memory rc=251

Source: 1 GiB ceiling: the retry also runs out of memory and lint fails with memory rc=251

\### low1048576 output
fm-lint.sh: ShellCheck 0.11.0 (pinned 0.11.0)
fm-lint.sh: full ShellCheck extended analysis enabled
fm-lint: end bin/fm-teardown.sh reason=memory rc=251 duration_ms=19433 rss_kib=705892
fm-lint: bin/fm-teardown.sh hit the memory ceiling with --external-sources (reason=memory rc=251); retried without it; fallback reason=memory rc=251
shellcheck: out of memory
rc=251
\### low1048576 roots log end record
end	1	bin/fm-teardown.sh	0	full	1790974914949	1790974934382	19433	251	memory	705892	0
\### low1048576 telemetry source/rss
source_followed_directives	0
max_worker_rss_kib	705892
Evidence: Timeout is not retried

Source: Timeout is not retried

\### to output
fm-lint.sh: ShellCheck 0.11.0 (pinned 0.11.0)
fm-lint.sh: full ShellCheck extended analysis enabled
fm-lint: end bin/fm-teardown.sh reason=timeout rc=124 duration_ms=5096 rss_kib=unavailable
rc=124
\### to roots log end record
end	1	bin/fm-teardown.sh	0	full	1790974839683	1790974844779	5096	124	timeout	unavailable	1
\### to telemetry source/rss
source_followed_directives	16
max_worker_rss_kib	8404

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 6 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Teardown lint under an 8 GiB per-root ceiling passes through the disclosed no-source retry instead of failing with memory rc=251 ✅ pass live fm-lint-fb.txt: exit 0, disclosure line, roots log reason memory-fallback, rc 0, RSS 5594212, follow 0
Telemetry counts zero followed source directives when the root passed only the no-source retry ✅ pass live fm-lint-fb.txt: source_followed_directives 0 vs 16 in fm-lint-base.txt
Adversarial: a real ShellCheck finding in the no-source retry still fails lint ✅ pass live fm-lint-find.txt: 'fallback reason=findings rc=1', SC2086 shown, exit 1
Adversarial: if the no-source retry also runs out of memory, lint fails with reason=memory ✅ pass live fm-lint-low1048576.txt: 'fallback reason=memory rc=251', exit 251
Adversarial: non-memory failures such as a timeout are not retried ✅ pass live fm-lint-to.txt: reason=timeout rc=124, no retry line, follow flag 1
Healthy run below the ceiling keeps full --external-sources analysis with no retry ✅ pass live fm-lint-base.txt: reason ok, follow 1, source_followed_directives 16
  • FM_LINT_JOBS=1 FM_LINT_REQUIRE_BOUNDS=1 bin/fm-lint.sh --telemetry ... bin/fm-teardown.sh (baseline, default 12 GiB address-space limit)
  • FM_LINT_ROOT_MEMORY_KIB=8388608 FM_LINT_REQUIRE_BOUNDS=1 bin/fm-lint.sh --telemetry ... bin/fm-teardown.sh (CI-sized 8 GiB ceiling)
  • FM_LINT_ROOT_MEMORY_KIB=8388608 ... bin/fm-lint.sh bin/fm-zz-probe-finding.sh (temporary copy of teardown with an injected SC2086 finding, deleted afterwards)
  • FM_LINT_ROOT_MEMORY_KIB=2097152 / 1048576 / 524288 ... bin/fm-lint.sh bin/fm-teardown.sh (ceilings low enough that the retry also runs out of memory)
  • FM_LINT_ROOT_SECONDS=5 FM_LINT_REQUIRE_BOUNDS=1 bin/fm-lint.sh bin/fm-teardown.sh (timeout is not retried)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@greptile-apps

ghost commented Oct 2, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Adds memory fallback retry logic to the linting script.

The PR appears safe to merge, though the new deadline test could fail intermittently on a delayed runner.

Reviews (2) · Last reviewed commit: "no-mistakes(ci): The memory fallback (th..."

Comment thread bin/fm-lint.sh Resolved
…urces) now gets only the time left in its root's original deadline, so it can no longer outlast the CI job. Invariant: one root's first attempt plus its fallback must fit inside a single FM_LINT_ROOT_SECONDS deadline, plus the cleanup grace. Only one site started a new deadline: the fallback call in fm_lint_run_root. The deadline is the only budget involved, because the memory limit already applies to each process separately. Changes in bin/fm-lint.sh: - fm_lint_exec_root now takes a <seconds> argument instead of always reading FM_LINT_INTERNAL_ROOT_SECS. - The first attempt passes the full deadline. - The fallback passes floor((start + deadline - now) / 1000) seconds. - When bounds are enforced and less than 1 second is left, no retry starts. fm_exec_timed rejects 0 seconds, so the retry cannot run with no time. The root keeps reason=memory, and the shard output says "no time left in its Ns deadline to retry without it". - Unbounded local runs have no deadline and behave as before. - The header comment now describes the shared deadline. Changes in tests/fm-lint.test.sh: a new test, test_memory_fallback_spends_only_the_remaining_root_deadline, runs only on hosts that can enforce bounds. It uses a 6 s deadline and 1 s grace. - Case 1: the first attempt runs 3 s and then fails with memory status 251. The test asserts one fallback ran, reported reason=timeout, and the root's recorded duration is under 7000 ms. - Case 2: the first attempt runs 5.2 s. The test asserts no fallback starts, the skip is explained, and the sidecar records memory with source-following 1. Verification: - Full `nice -n 10 bash tests/fm-lint.test.sh` passed, including the new test, in about 5 minutes. - Case 1 run against the HEAD script: the root took 9168 ms, so the under-7000 ms check fails before the fix. - `bin/fm-lint.sh bin/fm-lint.sh tests/fm-lint.test.sh` reported no findings. - The CI workflow is unchanged, so the Test step still runs only tests/fm-lint.test.sh with nice -n 10 and the 12 GiB ShellCheck limit
Comment thread tests/fm-lint.test.sh
Comment on lines +1686 to +1689
out=$(PATH="$fakebin:$PATH" FM_LINT_JOBS=1 FM_LINT_REQUIRE_BOUNDS=1 \
FM_LINT_ROOT_SECONDS=6 FM_LINT_ROOT_GRACE=1 \
FM_TEST_ATTEMPT_LOG="$log" FM_TEST_FIRST_SECS=5.2 \
"$LINT" --telemetry "$tmp/spent.tsv" "$fixture" 2>&1) || rc=$?

ghost Oct 2, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Deadline test can fail under load

The fake first attempt sleeps for 5.2 seconds under a 6-second watchdog, leaving less than 0.8 seconds for startup and scheduling delays. If those delays exceed the remaining time, the watchdog reports a timeout before the fake ShellCheck emits its memory failure. The test then fails its memory-reason and no-retry assertions even though the fallback behaves correctly, making this CI check timing-sensitive.

ghost commented Oct 2, 2026

Copy link
Copy Markdown
Owner

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

Verdict: waiting-ci. Contract-class restore (my judgment): CI already promised per-root ShellCheck with --external-sources under a memory envelope (#5620 / prior #3973 shape). Tip keeps that first attempt and adds a disclosed one-shot retry without --external-sources that spends only the remaining root deadline — restoring a completed lint result when the runner hits the ceiling, not a new default-on surface.

Attestation: MATCH f73bc945 (body pipeline attestation head_sha equals HEAD).
CI/NM: CI 37069189086 in progress (Lint 2 + Behavior portable serial 2 still running; others SUCCESS). NM 37069189055 SUCCESS. Mergeable MERGEABLE / UNSTABLE.
Closes: body has Fixes #5620 — verified against issue #5620 (ShellCheck --external-sources OOM on CI runner).

VISION: One captain one interface — aligns (CI forge mechanics). Authority explicit — aligns. Scripts vs agents — aligns (deterministic lint envelope). Restart non-event — aligns. Delegation with spine — aligns. Fleet outlives vendor — aligns. Scope — aligns (validation belongs to lint/CI, not workshop).

Greptile: SUCCESS; prior P1 "Retry can outlast CI" is resolved/outdated (fallback now uses remaining deadline; under 1s left skips retry). Outstanding P2 only (deadline-test timing under load) — not a merge gate.

This pass: no new workflow approvals (fork CI already running). No auto-merge until full green + CLEAN. No Firstmate flag.

@kunchenguid
kunchenguid merged commit d719ef3 into kunchenguid:main Oct 2, 2026

ghost commented Oct 2, 2026

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @tiago-peixoto — really appreciate you taking the time on this.

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.

fm-lint: ShellCheck --external-sources in one process per shard runs out of memory on the CI runner

2 participants