Skip to content

Reserve host memory for the CI runner agent in the fuzzer jobs - #116782

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:ci-fuzzer-container-memory-reserve
Sep 3, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:ci-fuzzer-container-memory-reserve

Conversation

@groeneai

@groeneai groeneai commented Aug 27, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Bound the AST fuzzer and BuzzHouse containers so a fuzz run cannot exhaust the CI runner host.

Description

Related: #111892
Related: #115915
Related: #116666

AST fuzzer (amd_debug, targeted) on #116666 reported failure having published nothing: the
Run step was cancelled after the runner agent lost communication, so CI DB has 0 rows for
it. The twin arm and four more passed on it.
Report,
job log.

Nothing bounds the job's share of the host: get_run_command passes no --memory, and inside the
container max_server_memory_usage stays 0 with only the 0.75 ratio set, so the server sized
itself at 46.33 of the runner's 61.78 GiB. The container then reached current RSS: 57.14 GiB
against maximum: 46.18 GiB with every query refused. That RSS is the container cgroup's anon and
charges the client and two gdb processes too, so the server's ratio cannot bound it; 4.6 GiB was
left for the agent.

I add --memory=Utils.physical_memory() - RUNNER_MEMORY_RESERVE to that docker run, in the shape
ci/defs/job_configs.py already uses; 8 GiB because 4.6 was not enough. A kernel bound holds
whatever the server, gdb and the client do, and the launcher stays on the host, so an
in-container kill still publishes a result.

The 0.75 ratio is unchanged and becomes the inner margin: on that runner the cap is 53.78 GiB and
the server's ceiling 40.33 instead of 46.33 GiB. Lowering that ratio on the stateless jobs was
tried and reverted the same day (#110293, #110572) for flooding master with
MEMORY_LIMIT_EXCEEDED, by a different mechanism (below).

Validated with this job's exact flags including --privileged: the cap binds and ClickHouse
reports the container size. All 10 fuzzer job digests change; 164 others do not.

Known and unchanged: a cap trip that kills clickhouse-client instead of the server is still
reported OK with no artifacts; the 10.81 GiB overshoot is one sample; the stress and libFuzzer
jobs have their own uncapped containers, untouched here.

Memory envelope before and after, on a 61.78 GiB *-medium runner
before after
container unbounded 53.78 GiB, kernel-enforced
server ceiling (0.75 ratio, unchanged) 46.33 GiB 40.33 GiB
room for what the server does not track (client, two gdb, shell) 15.45 GiB 13.45 GiB
left outside the container, shared by the agent, dockerd and the kernel whatever is spare: 4.6 GiB when the agent lost communication 8.00 GiB, kernel-enforced

The overshoot on #116666 was 10.81 GiB, so a run of that shape keeps ~2.6 GiB of container slack. A
larger overshoot becomes an in-container OOM kill, which the job reports, instead of a lost runner,
which it cannot.

Fuzzed queries therefore meet MEMORY_LIMIT_EXCEEDED sooner. Three existing paths already absorb
that: the client clears a server-side 241 and keeps fuzzing (FuzzLoop.cpp), the post-fuzz liveness
probe treats 241 as alive-and-busy (run-fuzzer.sh), and a terminal server-survived 241 is reported
OK (ast_fuzzer_job.py). The reverted stateless change is not the same mechanism: the comment at
ci/jobs/functional_tests.py:909-927 describes that flood as the aggregate RSS of dozens of
concurrent clickhouse-client processes, whereas the fuzzer drives one client at a time
(run-fuzzer.sh:274) under a max_memory_usage of 10G from its own profile.

The server sees the cap because these runners are cgroups v1 and the reader is scoped to the
container, not to the controller root: a retained fuzzer server log on the same runner class
(#111394) shows Will create cgroup reader from '/sys/fs/cgroup/memory' (cgroups version: v1) and
then resident: 156.19 MiB from that same reader at server startup, which the controller root could
not report while the runner agent alone holds ~2.4 GiB. --memory is enforced by the kernel either
way, so the 8 GiB reserve does not depend on this.


Workflow [PR]
Sync PR [sync-upstream/pr/116782]


Workflow [PR]
Sync PR [sync-upstream/pr/116782]

Version info

  • Merged into: 26.9.1.610 (included in 26.9 and later)

The fuzzer jobs give one unbounded container a whole shared runner:
get_run_command passes no --memory, and inside the container only
max_server_memory_usage_to_ram_ratio is set while max_server_memory_usage stays
0, so the server sizes itself from the host (46.33 of 61.78 GiB). On PR ClickHouse#116666
the container reached "current RSS: 57.14 GiB" against "maximum: 46.18 GiB"
while every query was refused with Code 241. That RSS is the container cgroup's
anon, so it charges clickhouse-client and two gdb processes as well, and the
server's own ratio cannot bound it. About 4.6 GiB was left for the runner agent;
it lost communication, the Run step concluded cancelled, and since upload
happens after Run the job published nothing. CI DB has 0 rows for
AST fuzzer (amd_debug, targeted) at that commit, while the twin
old_compatibility arm fuzzed the same two query files against the same diff at
the same commit and passed.

--memory is a kernel bound on the whole container, so the reserve holds whatever
the server, gdb and the client do. The launcher stays outside the container, so
an in-container kill leaves it alive to publish a result. The derived form
follows ci/defs/job_configs.py and adapts to both runner classes; 8 GiB rather
than that file's 2 GiB because the agent lost communication with 4.64 GiB still
available, and the runner's at-rest footprint is already about 2.4 GiB.

max_server_memory_usage_to_ram_ratio is deliberately unchanged and becomes an
inner margin: the container cap is 53.78 GiB and the server ceiling 40.33
instead of 46.33 GiB. Lowering that ratio was tried and reverted before
(ClickHouse#110293, reverted by ClickHouse#110572) for flooding unrelated tests with
MEMORY_LIMIT_EXCEEDED.

Validated locally: the flag binds a container carrying this job's exact flags
including --privileged, and ClickHouse then reports the container size rather
than the host's (8.00, 4.00 and 16.00 GiB as the cap varies, 755.49 GiB with no
flag, and 8.00 down to 3.00 GiB through the cgroups v1 code path); 2 GiB of anon
in a 512 MiB container of this shape is killed by the kernel and succeeds
uncapped; all 10 fuzzer job digests change while 164 other PR jobs do not; and
pytest ci/tests/ has identical pass/fail sets with and without the change.

Related: ClickHouse#111892

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect labels Aug 27, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (click to expand)

An independent model reviewed this diff cold over three rounds. Everything it raised is below with
the verdict and the evidence. The diff is unchanged since the first round; two of the corrections
are to the description.

❌ Fixed

  • The envelope table said 8 GiB was "left for the runner agent". --memory bounds the container; it
    does not reserve anything for the agent specifically. Reworded to host-side headroom shared by the
    agent, dockerd and the kernel.
  • The relationship line combined three shorthand references. Now three full URLs, one per line.

⚠️ Disagreed, with evidence

  • "On cgroups v1 ClickHouse reads the controller root, so it still sizes itself from host RAM." A
    retained fuzzer server log from the same runner class (Fsync backup files and directories when writing a backup to local disk #111394) shows that reader created from
    /sys/fs/cgroup/memory as v1 and then reporting resident: 156.19 MiB at server startup. The
    controller root cannot report 156 MiB while the runner agent alone holds ~2.4 GiB, so the reading
    is container-scoped, and memory.limit_in_bytes is read from that same directory. The description
    now carries this evidence and its exact reach. The host reserve does not depend on it: --memory
    is enforced by the kernel.
  • "No evidence that the lower ceiling preserves useful fuzzing." The fact is right and is in the
    description. The requested paired CI runs would be less discriminating than the control already
    has: all 20 MEMORY_LIMIT_EXCEEDED lines in that log come from one fuzzed query attempting a
    1.00 GiB chunk at would use 44.60 GiB against maximum: 44.56 GiB, i.e. a query refused at
    whatever ceiling exists. The band that changes is 40.33-46.33 GiB of total server usage, and the
    profile caps a single query at 10G. The reverted stateless change was an aggregate of dozens of
    concurrent clients (ci/jobs/functional_tests.py:909-927); this job runs one at a time.
  • "Prove docker enforces the computed limit and the launcher survives." Already measured: the
    verbatim flag set at --memory 4/8/16 GiB, with ClickHouse inside reporting 4.00/8.00/16.00 GiB
    and 755.49 GiB with no flag; the production command rendered from the module reporting exactly
    physical - 8 GiB; 2 GiB of anon in a 512 MiB container of this shape SIGKILLed at exit 137 and
    succeeding uncapped; and run_in_docker empty on all 18 fuzzer job entries, so the reporter runs
    on the host. The third round returned no findings.

💡 Noted, not blocking

  • A bounded kill is a memcg kill, and the non-sanitized dmesg needles in this file match only the
    global-OOM wording, so such a kill keeps its artifacts and its CI DB row but loses the "OOM in
    dmesg" label. Report the fuzzer jobs' host OOM as a named result again #116359 already owns that grep and its fixture, so the needle belongs there rather
    than putting two open PRs in one hunk.
  • physical_memory() - 8 GiB has no floor. Measured: at exactly 8 GiB docker reads 0 as unlimited
    (today's behaviour) and below that it refuses with rc=125, so the job fails loudly. Every consumer
    runs on a 61.78 GiB *-medium runner, and LIMITED_MEM in ci/defs/job_configs.py has the same
    shape.

Session id: cron:clickhouse-review-slot-8:20260827-184502

@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Aug 27, 2026
@clickhouse-gh clickhouse-gh Bot closed this Aug 27, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Aug 27, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Split, deliberately. The runner reclaim itself needs a 61.78 GiB runner with a GitHub Actions agent on it and is established from CI evidence (job object, check annotation, the retained job log, CI DB with the five sibling arms as controls), not from a local run. The mechanism and the fix's effect are deterministic and on demand: a container carrying this job's exact flags, with and without --memory, 100% repeatable. Nothing here rests on a low-rate observation.
b Root cause explained? The job hands one unbounded container a whole shared runner. get_run_command passes no --memory, and inside the container only max_server_memory_usage_to_ram_ratio is set while max_server_memory_usage stays 0, so the server sized itself at 46.33 of 61.78 GiB. The container reached current RSS: 57.14 GiB against maximum: 46.18 GiB while every query was refused; that RSS is the container cgroup's anon and charges clickhouse-client and two gdb processes as well, so the server's ratio structurally cannot bound it. About 4.6 GiB was left for the runner agent, which lost communication; the Run step was cancelled, and upload happens after Run.
c Fix matches root cause? Yes. The missing thing is a boundary, and the boundary is added at the layer that owns it. No bound widened, no test weakened, no dataset reduced, no defensive check masking anything. The server ratio is deliberately left at 0.75: it cannot bound the 10.96 GiB that sits outside the server's own limit, and the same ratio drop on the sanitizer stateless runs was tried and reverted the same day (#110293, #110572) for flooding master with MEMORY_LIMIT_EXCEEDED.
d Test intent preserved / new tests added? No test committed, deliberately: .claude/CLAUDE.md:190 says a throwaway test for a CI-script change need not be committed, and the same commit deleted 70 of 71 ci/tests/test_*.py. Nothing weakened either: pytest ci/tests/ gives identical pass/fail sets with and without the change (14 pre-existing failures, 1156 passing, both arms; the 14 are proven pre-existing by the base arm rather than assumed from their names), and the two files that read this module pass 32/32.
e Both directions demonstrated? Yes, on the production command. get_run_command was rendered by importing the module from the pristine file and from the fixed file, and each rendered command was then executed with only the image and payload substituted: pristine renders no --memory and ClickHouse inside reports 755.49 GiB (the whole host); fixed renders --memory=802616041472 and ClickHouse reports 747.49 GiB, exactly physical - 8 GiB. Separately, 2 GiB of anon inside a 512 MiB container of this shape is SIGKILLed by the kernel (exit 137) and the same allocation succeeds with no cap.
f Fix is general across code paths? Yes. get_run_command is the single docker run for all ten jobs, six AST fuzzer parametrizations plus four BuzzHouse ones, which share it because buzzhouse_job.py imports run_fuzz_job from this module. It has exactly one caller and no test asserts on it. Measured rather than inferred: all 10 job digests change and 164 other jobs do not, so every arm actually re-runs. The sibling ratio carriers are left alone with reasons recorded.
g Fix generalizes across inputs (params/datatypes/wrappers)? The input is host size and runner class. The derived form adapts with no per-class constant, measured to track the cap at 4, 8 and 16 GiB and to fall back to the host only when the flag is absent. Both cgroup code paths are exercised: v2 natively, and the v1 branch (which is what the CI runners use) through a synthetic view that tracks at 8 and 3 GiB. Boundary values measured: at exactly 8 GiB of physical memory the expression is 0, which docker reads as unlimited, that is today's behaviour; below that it is negative and docker refuses with rc=125 and a clear message, so the job fails loudly. No conditional and no silent fallback, per .claude/CLAUDE.md:157; the smallest runner class in use has 61.78 GiB.
h Backward compatible? (maintainer-approved exception only) N/A. These are a CI job's container arguments: no setting default, no SettingsChangesHistory.cpp entry, no serialization or format change, no experimental gate, no deletion logging, no user-visible surface.
i Invariants and contracts preserved? The invariant added is that the fuzzer job must leave the runner host a reserve it cannot consume. Each carrier checked by measurement: the launcher stays outside the container (run_in_docker is empty on all 18 fuzzer job entries), so an in-container kill leaves the reporter alive to publish; --privileged does not defeat --memory; nothing else in the container competes for the cap, since the --tmpfs mount is unused by this job and the server's --path is the disk-backed overlay; the sanitizer arms keep classifying an in-container kill as an OOM. No error or early-return path is touched: the diff adds one constant and one token to a string, with no new branch, no new call and no changed control flow.

Session id: cron:clickhouse-impl-slot-7:20260827-174900

@clickhouse-gh

clickhouse-gh Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2931d8b]

Summary: ✅


AI Review

Summary

This PR adds a host-side --memory= cap to the docker run command shared by the AST fuzzer and BuzzHouse jobs so those containers cannot consume the entire *-medium runner. The cap is wired through the only launcher path for the affected jobs and the current PR CI is green, but I still see one unresolved evidence gap before approval.

Findings

⚠️ Majors

  • [dismissed by author -- https://github.com/Reserve host memory for the CI runner agent in the fuzzer jobs #116782#discussion_r3875426727] [ci/jobs/ast_fuzzer_job.py:248] The entire behavioral contract of this PR is the rendered docker run string, yet none of the committed CI Tests assertions exercise get_run_command. Manual validation in the description does not protect future refactors, so a later drop or miscompute of --memory= would reintroduce the runner-starvation failure while the in-tree suite stays green.
    Suggested fix: extend ci/tests/test_ast_fuzzer_memory_limit.py (or add a sibling source-level test) to stub Utils.physical_memory() and assert that get_run_command emits the expected --memory= value for both the AST fuzzer and BuzzHouse call paths.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: add a focused automated guard for the new --memory= emission in get_run_command.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 27, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @maxknv, could you review this? The fuzzer jobs pass no --memory, so one container sizes ClickHouse from the whole runner and can starve the agent, which is how AST fuzzer (amd_debug, targeted) on #116666 finished with 0 CI DB rows. It caps the container at physical memory minus 8 GiB, and the 0.75 ratio is untouched.

Comment thread ci/jobs/ast_fuzzer_job.py
# For sysctl
"--privileged "
"--network=host "
f"--memory={Utils.physical_memory() - RUNNER_MEMORY_RESERVE} "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This adds a memcg cap to the fuzzer container, but the post-run classifier still treats any fuzzer_exit_code == 137 with a live server as success (ci/jobs/ast_fuzzer_job.py:451-458). If the kernel kills clickhouse-client or the timeout wrapper instead of clickhouse-server, run-fuzzer.sh writes server_died=0 / fuzzer_exit_code=137 to status.tsv (ci/jobs/scripts/fuzzer/run-fuzzer.sh:315-428), and we now return OK with no artifacts even though the fuzz run was cut short by the new cap. That means this change can trade the current "runner lost communication" failure for a false green that silently loses fuzz coverage.

Can we disambiguate "budget expired and timeout had to SIGKILL" from "memcg OOM killed the client" before treating 137 as benign here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Verified, and the mapping is as you describe: ast_fuzzer_job.py:451-458 returns OK for fuzzer_exit_code 137 with a live server. That arm predates this PR and is deliberate, its own comment reading "normal exit with timeout or OOM kill", and run-fuzzer.sh:274 produces it through timeout --signal TERM --kill-after=5m.

What I disagree with is that the cap makes that the likely outcome, because a memcg OOM kills the largest task in the cgroup rather than the one that allocates. Measured in the clickhouse/fuzzer image with this job's flags (--privileged --memory=512m): a 400 MiB process was SIGKILLed while a second one bounded at 140 MiB, whose allocation is what crossed the cap, exited 0. The fuzzer client is bounded at 1 GB by --max_memory_usage_in_client (run-fuzzer.sh:275) against a 53.78 GiB container cap, so the server is the victim, and a dead server sets server_died=1 (run-fuzzer.sh:410) and takes the named-failure branch instead of the 137 arm.

The gap is inside that branch: its dmesg grep only matches global-OOM text. A memcg kill prints Memory cgroup out of memory: Killed process and oom-kill:constraint=CONSTRAINT_MEMCG, and the three needles at ast_fuzzer_job.py:521 match 0 lines of captured kernel output while those two match all of it. #116359 already rewrites that exact grep, so the memcg needle belongs there rather than in a second hunk here. The client-killed variant stays disclosed in the description.

Comment thread ci/jobs/ast_fuzzer_job.py
# For sysctl
"--privileged "
"--network=host "
f"--memory={Utils.physical_memory() - RUNNER_MEMORY_RESERVE} "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This PR's new contract lives entirely in the rendered docker run string, but there is no committed ci/tests guard that asserts get_run_command actually emits this --memory= cap. The existing test_ast_fuzzer_memory_limit.py coverage is all about 241 classification, so a later refactor that drops or miscomputes this flag would keep the committed suite green while reintroducing the lost-runner failure this patch is fixing.

Please add a focused unit or source-level test that stubs Utils.physical_memory() and checks the generated command for both buzzhouse=False and buzzhouse=True.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The risk is real, nothing committed asserts the flag.

I am not adding it, on the in-tree rulebook. .claude/CLAUDE.md: "When you want to test changes in the CI scripts, you can write and run a throwaway test, but you don't need to commit it to the repository, because we don't have automated CI tests" (added 2026-08-13 in ee29730735613f4). The same author has PR 114675 merged, removing the CI-script unit tests, and PR 115650 "Remove ci/tests (attempt 2)" open. test_ast_fuzzer_memory_limit.py is a file I added in July, before that line landed, so I would not cite it as precedent for adding more arms beside it.

What I ran instead: the command get_run_command renders was executed in both arms, and ClickHouse inside the container reads 755.49 GiB with no flag against 747.49 GiB with it, exactly physical minus the 8 GiB reserve; all 10 fuzzer job digests change while 164 other jobs do not. CI Tests passes on this change.

If a maintainer wants a committed guard here anyway, I will add it.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 2931d8b

CI is fully finished at this commit. One check failed, and it has an owner.

Check / test Reason Owner / fixing PR
AST fuzzer (amd_debug, targeted) Two PR workflow runs were dispatched at this one commit (33110944888 and 33110955304, both run_attempt = 1, the second from a reopened event). praktika keys artifacts by (PR, sha) and never by run id, so both runs wrote PRs/116782/2931d8b4.../build_amd_debug/clickhouse. Run 33110955304's fuzzer leg downloaded that key at 20:34:59Z while run 33110944888's Build (amd_debug) was still writing it (that build finished at 20:35:07Z), so the job's pre-run step died with S3DownloadFailedError: Contents of stored object ... did not match expected ETag and published an ERROR with no result, which is why CIDB holds 0 rows for this check name. Not caused by this diff: the same check on this identical tree is success in the sibling run, at 20:37:09Z, once that run's own build had settled #116701 (ours, open)

Everything else at this commit is green. Across all 7 workflow runs at this head, that one fuzzer leg is the only job that is neither success nor skipped, and Config Workflow, Style check, Mergeable Check and Finish Workflow all pass in both PR runs.

Report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=116782&sha=2931d8b4b138ec5c552e231da645f31c44c8725f&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%29

Session id: cron:our-pr-ci-monitor:20260827-213000

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good.

@alexey-milovidov alexey-milovidov self-assigned this Sep 3, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 3, 2026
Merged via the queue into ClickHouse:master with commit f311601 Sep 3, 2026
536 of 537 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants