Skip to content

Reserve host memory for the CI runner agent in the stress and upgrade jobs - #118057

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/stress-job-runner-memory-reserve
Sep 13, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/stress-job-runner-memory-reserve

Conversation

@groeneai

@groeneai groeneai commented Sep 4, 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 stress test and upgrade check containers so a run cannot exhaust the CI runner host.

Description

Related: #116782
Related: #111892

Stress test (arm_asan_ubsan) on #116485 published nothing: praktika reported ERROR with
links=[], and CI DB holds 0 rows for it while the same commit carries 258,113 rows and nine
sibling variants that each reported.
Report,
job log.

get_run_command passes no --memory, and common_stress_job_config has no run_in_docker, so the
container is bounded only by the host. configure_limits sets
max_server_memory_usage_to_ram_ratio=0.8 and calls that safe because "the total server memory usage
is capped to the memory usage of the whole cgroup", a cap this call site never creates. Its log shows
total_mem=66198712320 (61.65 GiB of host RAM), so the server's ceiling was 49.32 GiB on a host that
also runs the agent. From 00:15:52Z its own trivial statements were refused with 241
(SYSTEM STOP VIEWS, a LIMIT 1 read of system.mutations). Runner timestamps then jump 19m44s
while the lines arriving at the far end carry inner stamps from inside that gap: the process was
alive and only its output was not drained. GitHub then cancelled the job.

I add --memory=Utils.physical_memory() - RUNNER_MEMORY_RESERVE, in the shape and with the 8 GiB of
#116782. A kernel bound holds whatever the server, gdb and the clients do, and the launcher stays
on the host, so an in-container kill still publishes a result.

This is the single container call site for Stress test (*), Stress test (amd_cfi) and
Upgrade check (*): 35 job instances across five workflows.

Validated with these exact flags including --privileged, against a control with the cap removed and
nothing else changed; both arms are below. No ci/defs/ change, so praktika yaml leaves
.github/workflows/ unchanged.

Known and unchanged: max_memory_usage_for_user stays host-derived at 18.50 GiB, below the new
ceiling. The libFuzzer and vector-search containers are also uncapped, but I have no runner-loss
observation for either.

Memory envelope before and after, on the measured 61.65 GiB *-medium runner
before after
container unbounded (memory.max reads max) 53.65 GiB, kernel-enforced
server ceiling (0.8 ratio, unchanged) 49.32 GiB 42.92 GiB
room for what the server does not track (gdb, clients, page tables) whatever is spare 10.73 GiB
left outside the container for the agent, dockerd and the kernel whatever is spare, and the agent lost communication 8.00 GiB, kernel-enforced

The reserve is 8 GiB because #116782 measured 4.6 GiB of host headroom left at failure, and 4.6 was
not enough. The server's ceiling therefore drops 12.98%, so stress runs meet
MEMORY_LIMIT_EXCEEDED a little sooner, and an overshoot becomes an in-container kill: the job still
publishes its result, logs and cores instead of losing the runner and publishing nothing, and an OOM
is already an allowed outcome there (stress_job.py:441). Lowering the harness ratio instead was
tried on the stateless jobs and reverted the same day (#110293, #110572); that is a different
mechanism, and it would bound only the server rather than gdb and the clients sharing this cgroup.

Measured in the clickhouse/stress-test image with the job's own flags, differing only in
--memory. With the cap: memory.max reads the exact byte value passed, a plain 12 GiB allocation
is SIGKILLed by the kernel, and a query the server refuses reports a maximum: scaled from the cap
rather than from the host. Control, cap removed and nothing else changed: memory.max reads max,
the same 12 GiB allocation completes, and the same query passes a host-derived ceiling.


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

Version info

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

… jobs

get_run_command builds the stress container with no --memory, and
common_stress_job_config has no run_in_docker, so the job script runs on the
runner host and launches a container that only the host bounds. Inside,
configure_limits sets max_server_memory_usage_to_ram_ratio=0.8 and states that
this is safe because "the total server memory usage is capped to the memory
usage of the whole cgroup", a cap this call site never creates.
getMemoryAmountOrZero takes min(physical RAM, cgroups v2 limit), so with no
--memory the server sizes itself from the whole host, and its runtime dynamic
limit tracks host availability rather than a leaf.

The starved process is then the runner agent, which lives outside the
container, so GitHub tears the job down before praktika can write a result:
status ERROR, empty info, links=[], and no CI DB rows at all. A real crash or
sanitizer report in such a run is lost, which is why this is worth fixing.

Measured on Stress test (arm_asan_ubsan), job 100462891406, where
configure_limits runs under set -x and prints its own inputs:
total_mem=66198712320 (61.65 GiB of host RAM) with ratio 0.8, so the server
ceiling was 49.32 GiB on a host that also had to run the agent. From 00:15:52Z
the harness's own trivial statements were refused with 241, including bare
SYSTEM STOP VIEWS and a LIMIT 1 read of system.mutations, which no per-query or
per-user limit can explain. Runner timestamps then jump 19m44s while the lines
arriving at the far end carry inner harness stamps from inside that gap, so the
process was alive and only its output was not being drained. CI DB holds 0 rows
for that check while the same commit carries 258,113 rows and nine sibling
stress variants that each reported.

I add --memory=Utils.physical_memory() - RUNNER_MEMORY_RESERVE, reusing the
shape, the constant name and the 8 GiB of the merged fuzzer fix in
ci/jobs/ast_fuzzer_job.py: that change measured 4.6 GiB of host headroom left at
failure and chose 8 GiB because 4.6 was not enough. A kernel bound holds
whatever the server, gdb and the clients do, and the launcher stays on the host,
so an in-container kill still publishes a result. The value is computed at
runtime, so it adapts per runner pool with nothing hard-coded.

get_run_command is the single container call site for three job families, all of
which gain the bound: Stress test (*), Stress test (amd_cfi) via cfi_stress_job,
and Upgrade check (*), whose upgrade_job.py imports run_stress_test and only
swaps the run script. That is 35 job instances across MasterCI, PR,
ReleaseBranchCI and WeeklyCFI.

Validated in the clickhouse/stress-test image with this job's exact flags,
including --privileged, against a control that removes only --memory. With the
cap, the container's memory.max equals the byte value passed, a plain 12 GiB
allocation is SIGKILLed by the kernel, and a query the server refuses reports a
maximum: scaled from the cap rather than from the host. Without it, memory.max
reads max, the same allocation completes, and the same query passes a
host-derived ceiling. No ci/defs/ change is needed, and praktika yaml leaves
.github/workflows/ unchanged; stress_job.py is already in the digest
include_paths of both affected job configs.

The server ceiling drops 49.32 to 42.92 GiB on that runner, 12.98%, while the
container keeps about 10.73 GiB inside for gdb and clients and 8 GiB is reserved
outside for the agent. So stress runs meet MEMORY_LIMIT_EXCEEDED slightly
sooner, and an overshoot becomes an in-container OOM kill, which the job
reports, instead of a lost runner, which it cannot. max_memory_usage_for_user is
read from /proc/meminfo, which Docker does not namespace, so it stays 18.50 GiB
and remains below the new ceiling.

keeper_stress_job was already capped with KEEPER_DIND_MEM and is untouched. The
libFuzzer and vector-search containers are also uncapped, but I have no
runner-loss observation for either, so they are left alone here.

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 Sep 4, 2026
@groeneai

groeneai commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review

An independent cold review plus a second-model gate ran over this diff before publishing.
The gate returned 0 findings. My own review returned three nits, all in the PR text rather
than the code, so the diff is unchanged from the one that was measured.

💡 The blast radius line now reads five workflows, not four: backport_branches.yml also carries
stress_test_amd_tsan, so the 35 instances span MasterCI, PR, ReleaseBranchCI, WeeklyCFI and
BackportPR.

⚠️ Self-correction to my own commit message, which says the 241 statements are ones "no per-query
or per-user limit can explain". max_memory_usage_for_user (18.50 GiB here) is cumulative across a
user's concurrent queries, so it can refuse a trivial statement too, and the harness discards
stderr, so the (total) vs (for user) label is not recoverable from that log. Both ceilings are
derived from host RAM, so the conclusion stands either way.

💡 An overshoot after this change lands as an in-container kill, and stress_job.py:441 already
treats an OOM as an allowed outcome, so what the job gains is a published result with its logs and
cores rather than a red.

@clickhouse-gh

clickhouse-gh Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6b10e20]

Summary: ✅


AI Review

Summary

This PR adds a shared container_memory_limit helper in ci/jobs/stress_job.py and feeds its result into the docker run command used by both the stress and upgrade jobs. The previously reported Utils.physical_memory() - RUNNER_MEMORY_RESERVE underflow is fixed: on hosts at or below the 8 GiB reserve, the launcher now fails explicitly instead of handing Docker a negative or zero --memory value, and I found no remaining correctness or rollout issues in the current diff.

Final Verdict

✅ No new findings in the current diff.

@groeneai

groeneai commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator Author

cc @leshikus, could you review this? get_run_command in ci/jobs/stress_job.py launches the stress container with no --memory, so it is bounded only by the host and the starved process is the runner agent outside it, which is why those jobs publish no result at all. It adds the same Utils.physical_memory() - RUNNER_MEMORY_RESERVE bound #116782 merged for the fuzzer jobs, and reaches Stress test (*), Stress test (amd_cfi) and Upgrade check (*) through that one call site.

Comment thread ci/jobs/stress_job.py Resolved
…unner reserve

get_run_command subtracted RUNNER_MEMORY_RESERVE from the visible RAM and passed
the result straight to docker run --memory, with nothing checking the sign. The
CI pools these jobs run on are amd-medium and arm-medium, measured at 61.65 GiB,
so the subtraction is never near zero there, but the same file is a documented
local entrypoint (python -m ci.praktika run "<JOB_NAME>"), where a smaller host
reaches it.

Measured with docker 29.5.1 on cgroups v2: --memory=-401154048 is rejected with
exit 125 and "invalid size", while --memory=0 is accepted and the container's
memory.max reads "max", so a host at exactly the reserve silently produced the
uncapped container this change exists to prevent. Clamping at zero, as
INTEGRATION_NESTED_BUDGET does in ci/defs/job_configs.py, is wrong here: that
value is read by docker_in_docker.sh's validator, where zero is a refusal, not by
docker, where it means no limit. So this raises, naming the host figure and the
reserve.

The value emitted on an adequately sized host is unchanged. On a 755.49 GiB box
both code paths still carry exactly one --memory token holding
physical_memory() - RUNNER_MEMORY_RESERVE, and a pristine-tree control taken by
patch file agrees; at 7.63 GiB and at exactly 8 GiB that control emits
-401154048 and 0, where this raises instead.

Co-Authored-By: Claude Opus 5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added manual approve Manual approve required to run CI comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). labels Sep 4, 2026
@groeneai

groeneai commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator Author

Holding this one until the ceiling question is settled, because the fuzzer version of exactly this
change has now been measured and it regressed CI.

#116782 applied this same physical - 8 GiB reserve to the AST fuzzer container on 2026-09-03. It
dropped the server's derived ceiling from 46.33 to 40.33 GiB, and AST fuzzer (amd_debug%) went from
34 days at zero to 4-6 Server unresponsive: memory limit exceeded failures a day for seven days
running, 30 failing jobs across 27 distinct PRs, with job volume flat. Measurement and the proposed
remedy: #118365 (comment)

Here the arithmetic is the same shape and slightly worse: ratio 0.8 on the 61.65 GiB host takes the
ceiling from 49.32 to 0.8 * 53.65 = 42.92 GiB, a 6.4 GiB cut, and the stress amd_msan and
arm_msan servers already sit exactly at their current cap (53.29/53.29, 53.75/53.73, 53.81/53.81
GiB) with tracked usage of only 18-20 GiB. So this reserve on its own would very likely reproduce the
fuzzer regression on the stress and upgrade families.

The host reserve itself is still worth having; it is the uncompensated ceiling that is the problem.
Once it is decided how the fuzzer lane pays for its ceiling, this PR should carry the same
compensation rather than the bare reserve.

@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.

Ok, let's try.

@alexey-milovidov alexey-milovidov self-assigned this Sep 13, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 13, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

Thanks. The hold was mine, so your approval settles it: the hold is released, and CI is green on 6b10e203.

I will watch Stress test (*) and Upgrade check (*) for the Server unresponsive: memory limit exceeded signature after this lands, and send the ceiling compensation as a follow-up if the same shape appears there.

Merged via the queue into ClickHouse:master with commit c2006ad Sep 13, 2026
174 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 13, 2026
@groeneai

groeneai commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator Author

Closing the watch I promised above: the memory-cgroup kills that Stress test (*msan) showed after this merged are not a ceiling problem, so I am not sending a ceiling change. Of the 12 in the last 14 days, 9 were one fuzzed mergeTreeAnalyzeIndexes vector-search query that reserves 32 GiB (fixed by #122154) and 1 was the exponential planning of #123724. The server memory limit stops neither, so no ceiling would have prevented them. Details: #100173 (comment)

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 comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect manual approve Manual approve required to run CI 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.

3 participants