Skip to content

fix(fm-lint): bound per-file ShellCheck runs by timeout and memory ceiling - #3973

Closed
NewAiCoder-bot wants to merge 6 commits into
kunchenguid:mainfrom
NewAiCoder:up/fm-lint-per-file-bounds
Closed

NewAiCoder-bot wants to merge 6 commits into
kunchenguid:mainfrom
NewAiCoder:up/fm-lint-per-file-bounds

Conversation

@NewAiCoder-bot

@NewAiCoder-bot NewAiCoder-bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Opened from the reporter's secondary account (same person as the issue's reporter, not automation).
Closes #3925

What Changed

  • bin/fm-lint.sh now runs ShellCheck one file at a time under a per-file wall-clock timeout (FM_LINT_FILE_TIMEOUT, default 120s, enforced via a self-driven SIGALRM deadline) and, on hosts with a live systemd --user session, a per-file memory ceiling (FM_LINT_FILE_MEM_KB, default 6 GiB target capped by 70% of host MemTotal divided across FM_LINT_JOBS) enforced via a systemd-run --user --scope cgroup; a file that hits either bound retries once without --external-sources before being reported as a named lint failure, so one pathological file can no longer stall or exhaust the host.
  • Added docs/fm-lint-external-sources-fallback.md (registered in docs/documentation-audiences.json under maintainer-verification) tracking which files currently need the --external-sources fallback, and documented the new env vars, default-sizing formula, and rationale (including the rejected ulimit -v approach) in docs/configuration.md.
  • bin/fm-teardown.sh gets a shellcheck disable=SC2034 annotation for a variable only visible to ShellCheck under --external-sources.
  • Added test coverage in tests/fm-lint.test.sh for the new timeout/memory-ceiling and fallback behavior, and adjusted tests/fm-pending-reply.test.sh for the related change.

Risk Assessment

✅ Low: Both prior review findings (stale fallback wording, stale rc/output on double-ceiling-hit) are correctly fixed in the current code; independent tracing of the SIGALRM/zombie-reap logic, systemd-run scope PID semantics, and the memory-ceiling default formula found no further defects, and the change is well-covered by new tests plus extensive inline rationale.

Testing

Both no-mistakes review findings (review-1: fallback wording falsely claimed in local/no-external-sources mode; fallback-stale-rc-mismatch: final classification using stale first-attempt rc/timed_out instead of the fallback's real outcome) are now covered by targeted regression tests that execute bin/fm-lint.sh's real fm_lint_run_one_file logic end-to-end via fake shellcheck stubs (no source-text inspection). Each new test was confirmed to fail on the specific pre-fix commit it targets and pass on the target commit, and the full existing fm-lint.test.sh suite (41 tests) passes with no regressions. The worktree is clean except for the added tests.

Evidence: Full tests/fm-lint.test.sh run at target commit (41/41 ok)
ok - fm-lint.sh local changed-file mode reports a timeout without falsely claiming a fallback ran
ok - fm-lint.sh classifies a ceiling-failing fallback by its own outcome, not the first attempt's stale one
... (39 more ok lines) ...
EXIT=0
Evidence: Regression proof: new test fails pre-fix (commit 452d62f), review-1 defect reproduced
not ok - local mode never runs --external-sources, so no fallback ever ran, but the report falsely claimed one did (unexpected: 'external-sources fallback')
fm-lint.sh: bin/fm-afk-launch.sh exceeded the 2s per-file lint timeout (FM_LINT_FILE_TIMEOUT) even after the --external-sources fallback; reported as a lint failure, continuing with the next file.
Evidence: Regression proof: new test fails pre-fix (commit 5480950), fallback-stale-rc-mismatch defect reproduced
not ok - the fallback genuinely timed out, but the final report did not say so (missing: 'per-file lint timeout')
fm-lint.sh: .../fixture.sh hit the 6291456 KiB per-file memory ceiling (FM_LINT_FILE_MEM_KB), even after the --external-sources fallback; reported as a lint failure, continuing with the next file.

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found. Rebased onto upstream/main; one additive conflict in bin/fm-lint.sh resolved.

✅ **Review** - passed

✅ No issues found. Confirmed the pre-applied fix (bounding the fm_lint_resolve_mem_mechanism systemd-run probe itself with a timeout 5, so the probe cannot hang on a host where systemd-run misbehaves - every other systemd-run call in this file was already time-bounded) matches the recorded decision; no further issues found.

✅ **Test** - passed

✅ No issues found. Full tests/fm-lint.test.sh suite (41/41) passes at the rebased head.

✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found. ShellCheck 0.11.0.

⏭️ **Push** - skipped (author-pushed)

The daemon's push step failed repeatedly on this host: its attestation write (gh pr edit) authenticated as the personal reporter account, which lacks UpdatePullRequest permission on this bot-authored PR. The pipeline-validated head (this attestation's head_sha, fetched from the pipeline's own gate repo) was pushed to the fork branch and this PR body was edited by the bot account by hand instead, per the author-edited-attestation path no-mistakes's own verify step is built to accept. No step result is fabricated: only intent, rebase, review, test, document, and lint - which the pipeline actually ran to completion - are marked completed above.

⏭️ **PR** - skipped (author-edited, see Push)
⏭️ **CI** - skipped (author-pushed head; CI runs on GitHub against the pushed commit as usual)

@greptile-apps

greptile-apps Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (2): Last reviewed commit: "no-mistakes(ci): Fixed both Greptile Rev..." | Re-trigger Greptile

Comment thread bin/fm-lint.sh Resolved
Comment thread bin/fm-lint.sh Resolved
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

First look on main b84e0e362face25f3dd8945297a3df1320d7668c. Tip 138bad41216c. Attestation MATCH. Tip NM success present. CI still in progress. Greptile 4/5 with P1: memory mechanism enabled by a probe that does not prove transient scope/cgroup properties can be created (partially capable systemd user manager can fail every linted file); fallback output can mislabel nonzero results as clean. Workflows: none. Waiting on author for those findings. Not a merge vote. Do not auto-merge.

What I inspected

  • bin/fm-lint.sh always applies per-file wall timeout (default 120s) and, when systemd --user probe passes, a per-file memory ceiling via systemd-run --user --scope. That changes the unconfigured lint path on capable hosts.

VISION.md (each rule)

  • One captain, one interface: aligns — one pathological ShellCheck file taking the host down is a fleet-wide failure.
  • Authority is explicit: does not align as default — always-on timeout/memory ceiling on lint without an explicit captain grant; systemd wrap assumed from probe alone (Greptile P1).
  • Scripts own the mechanics: aligns — bounds are exact script work once the capability contract is sound.
  • A restart is a non-event: aligns — lint must not strand the host.
  • Delegation with a spine: aligns — host protection around an existing lint path.
  • The fleet outlives any vendor: aligns — non-systemd hosts keep the prior path; probe must fail closed.
  • Scope: aligns — maintainer lint / command-layer.

contract-class: new-default. No auto-merge. After Greptile P1s are cleared and CI is green, flag Firstmate for a captain card if still otherwise ready.

Security FYI (not waiting-captain): systemd-run scope wrap is host-local; tip only.

@NewAiCoder-bot

Copy link
Copy Markdown
Contributor Author

Posted from the reporter's secondary account (same person as the issue's reporter, not automation).

Both Greptile P1 findings from the earlier tip (138bad41) are fixed at the current tip (28f60b77):

  • Incomplete systemd capability probe: fm_lint_resolve_mem_mechanism (bin/fm-lint.sh) no longer stops at systemctl --user show-environment. It now launches a real trial scope with the same properties the actual per-file run uses (systemd-run --user --scope --quiet -p MemoryMax=64M -p MemorySwapMax=0 -- true) before selecting the systemd path. A user manager that responds but cannot actually create a transient scope with those cgroup properties now falls through to FM_LINT_MEM_MECHANISM=none (timeout-only linting) instead of failing every file.
  • Fallback failures claim clean completion: in fm_lint_run_one_file, the branch taken when the fallback attempt does not hit the ceiling now returns $fallback_rc (the fallback's real exit status) and appends the fallback's actual output (cat "$fallback_current" >> "$output"), so a fallback that finds a genuine ShellCheck issue is reported as that failure, not as clean. The message wording was also changed from claiming the file "finished cleanly" to "completed narrower analysis."

Greptile's latest pass on this tip reads 5/5 with no findings. Flagging so this gets a fresh look.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Re-eval after newer activity (Greptile P1 fixes at tip 28f60b77113970f6cfc09911767749fa80c280a9, author note 2026-09-12, Greptile 5/5 on tip, tip NM success). Main 0962d4a02375986894b45c366b36b452e1abc948. Attestation MATCH. Tip NM SUCCESS. CI SUCCESS on tip. Greptile 5/5, prior P1/P2 threads resolved. MERGEABLE / CLEAN (branch diverged: ahead 5 / behind 44; no conflict). Closes #3925 verified (author body Closes #3925; issue open ready-for-pr same surface/author lineage). Workflows: none. No auto-merge (new-default). Flagging Firstmate — otherwise ready except default-behavior. Do not merge/rebase from here.

What I inspected

  • Tip 28f60b77: fm_lint_resolve_mem_mechanism now trial-launches systemd-run --user --scope -p MemoryMax=64M -p MemorySwapMax=0 -- true before selecting systemd; partial user managers fall through to timeout-only.
  • Fallback path returns $fallback_rc / appends fallback output; wording is "completed narrower analysis"; classification uses fallback rc/timed_out; has_external gates fallback wording.
  • Always-on per-file wall timeout (default 120s) and, when the probe passes, always-on per-file memory ceiling on the unconfigured lint path — still a default-behavior change.

VISION.md (each rule)

  • One captain, one interface: aligns — one pathological ShellCheck file taking the host down is a fleet-wide failure.
  • Authority is explicit: does not align as default — always-on timeout/memory ceiling on lint without an explicit captain grant (even with a sound fail-closed probe).
  • Scripts own the mechanics: aligns — bounds are exact script work once the capability contract is sound.
  • A restart is a non-event: aligns — lint must not strand the host.
  • Delegation with a spine: aligns — host protection around an existing lint path.
  • The fleet outlives any vendor: aligns — non-systemd hosts keep timeout-only; probe fails closed.
  • Scope: aligns — maintainer lint / command-layer; field incident → regression coverage.

contract-class: new-default. Issue #3925 was pre-stamped restore for the defect shape; the shipped always-on unconfigured-path bounds keep this PR in new-default (same adjudication as the 2026-09-08 first look). No auto-merge. Captain card for default-behavior.

Security FYI (not waiting-captain): systemd-run scope wrap remains host-local resource bounding; tip only.

@NewAiCoder
NewAiCoder force-pushed the up/fm-lint-per-file-bounds branch from 28f60b7 to 83a44a0 Compare September 20, 2026 06:19
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Re-eval after tip move. Main a09090d13ef24ce3cf71d171ade119896d6db301. Tip 83a44a0b26b3. Attestation MISMATCH (body binds 28f60b771139; tip rebased). Tip NM FAIL (attestation head_sha mismatch). CI SUCCESS on tip. MERGEABLE / UNSTABLE. Greptile prior 5/5 was on old tip. Workflows: none needed. Closes #3925 verified (author body Closes #3925; issue open ready-for-pr, same lint-bound surface). Prior waiting-captain cleared — not otherwise ready while NM/attestation fail. No auto-merge. Waiting on author to re-run git push no-mistakes so attestation binds to current tip. Do not flag Firstmate until green NM + MATCH and still otherwise ready (class remains new-default).

What I inspected

  • Tip still ships always-on per-file wall timeout (default 120s) and, when the systemd probe passes, always-on per-file memory ceiling via systemd-run --user --scope on the unconfigured lint path.
  • Probe still trial-launches a real scope before selecting systemd; fallback classification still uses fallback rc/output.

VISION.md (each rule)

  • One captain, one interface: aligns — one pathological ShellCheck file taking the host down is a fleet-wide failure.
  • Authority is explicit: does not align as default — always-on timeout/memory ceiling without an explicit captain grant.
  • Scripts own the mechanics: aligns — bounds are exact script work.
  • A restart is a non-event: aligns — lint must not strand the host.
  • Delegation with a spine: aligns — host protection around an existing lint path.
  • The fleet outlives any vendor: aligns — non-systemd hosts keep timeout-only; probe fails closed.
  • Scope: aligns — maintainer lint / command-layer.

contract-class: new-default. No auto-merge.

Security FYI (not waiting-captain): systemd-run scope wrap remains host-local resource bounding; tip only.

NewAiCoder and others added 6 commits September 20, 2026 10:57
…st starvation

One fm-lint.sh run sat 21 minutes in disk sleep at 2.7 GB resident on a
single large script under concurrent shard load, and got an unrelated
production build killed by the host's memory guard four times.

fm-lint.sh now runs shellcheck one file at a time per shard, each under a
wall-clock timeout (FM_LINT_FILE_TIMEOUT, default 120s) and a `ulimit`-free
systemd-scope memory ceiling (FM_LINT_FILE_MEM_KB, default a 6 GiB target
capped by host memory divided across concurrent shards). A file that hits
either bound retries once without --external-sources before being reported
as a named lint failure, so one pathological file can no longer starve the
host or block the rest of the run.

Fixes #3925
…h: 1. (P1, line ~123) `fm_lint_resolve_mem_mechanism` only checked that `systemd-run` exists and `systemctl --user show-environment` succeeds - it didn't verify a transient scope with `MemoryMax`/`MemorySwapMax` can actually be created. On a host where the user manager responds but cgroup delegation/those properties are unavailable, every per-file `systemd-run` launch would fail before ShellCheck runs. Fixed by having the probe launch a real trivial scope (`systemd-run --user --scope --quiet -p MemoryMax=64M -p MemorySwapMax=0 -- true`) with the same properties used for real files, falling back to "none" (timeout-only) when that fails. Kept the existing user-facing message text unchanged so `test_mem_ceiling_probe_failure_falls_back_to_timeout_only` still matches. 2. (P2, line ~356) The `--external-sources` fallback success message said "finished cleanly" even when the fallback attempt returned a genuine ShellCheck finding or execution error (any non-ceiling-failure `fallback_rc`, including nonzero), which is then propagated via `return "$fallback_rc"` - contradicting the "cleanly" claim during failure triage. Reworded to "completed narrower analysis" per the reviewer's suggested fix, removing the false claim of clean completion without changing the classification/return logic. Verified: ran `bash bin/fm-lint.sh bin/fm-lint.sh` (clean, rc=0) and the full `tests/fm-lint.test.sh` suite (41/41 tests pass, including the two tests directly covering the touched code paths: the memory-ceiling probe fallback test and the fallback-classification test)
… 5s timeout

The probe itself could hang without a timeout on a host where systemd-run misbehaves; every other systemd-run invocation in this file is already time-bounded.
@NewAiCoder
NewAiCoder force-pushed the up/fm-lint-per-file-bounds branch from d5fcbaf to 34bc8ee Compare September 20, 2026 15:13
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Re-eval after tip move + attestation refresh. Main a09090d13ef24ce3cf71d171ade119896d6db301. Tip 34bc8eee03f74d3e194bd0f28d02fba7bd23d3e1. Attestation MATCH (body binds tip). Tip NM SUCCESS (edited run 35518940206; earlier synchronize FAIL superseded). CI SUCCESS on tip. MERGEABLE / CLEAN. Greptile prior 5/5 on earlier tip; probe now also timeout 5 wraps the systemd trial scope. Workflows: none needed. Closes #3925 verified (author body Closes #3925; issue open ready-for-pr, same lint-bound surface). No auto-merge (new-default). Otherwise ready except default-behavior — Firstmate flag needed for captain card (default-behavior). Do not merge/rebase from here. Not waiting on author/CI.

What I inspected

  • Tip still ships always-on per-file wall timeout (default 120s) and, when the systemd probe passes, always-on per-file memory ceiling via systemd-run --user --scope on the unconfigured lint path.
  • fm_lint_resolve_mem_mechanism trial-launches a real scope (MemoryMax=64M / MemorySwapMax=0) under timeout 5 before selecting systemd; partial managers fall through to timeout-only.
  • Fallback classification uses fallback rc/output; has_external gates fallback wording.

VISION.md (each rule)

  • One captain, one interface: aligns — one pathological ShellCheck file taking the host down is a fleet-wide failure.
  • Authority is explicit: does not align as default — always-on timeout/memory ceiling on lint without an explicit captain grant (even with a sound fail-closed probe).
  • Scripts own the mechanics: aligns — bounds are exact script work once the capability contract is sound.
  • A restart is a non-event: aligns — lint must not strand the host.
  • Delegation with a spine: aligns — host protection around an existing lint path.
  • The fleet outlives any vendor: aligns — non-systemd hosts keep timeout-only; probe fails closed.
  • Scope: aligns — maintainer lint / command-layer; field incident → regression coverage.

contract-class: new-default. Issue #3925 was pre-stamped restore for the defect shape; the shipped always-on unconfigured-path bounds keep this PR in new-default (same adjudication as 2026-09-08 / 2026-09-13). No auto-merge. Captain card for default-behavior.

Security FYI (not waiting-captain): systemd-run scope wrap remains host-local resource bounding; tip only.

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.

fix(fm-lint): bound each file's shellcheck by time and memory so one pathological file cannot starve the host

3 participants