Repository navigation
fix(monitoring): scale agent CPU alerts to the container limit - #4530
Merged
vybe merged 2 commits intoNov 17, 2026
Merged
Conversation
Docker's host-core formula recorded one busy core as 100%, so the default 80/95 thresholds marked an ordinary capped agent critical. Record CPU as a percent of the container's own limit (NanoCpus, else quota/period, else the host). Fixes Abilityai#4529
…es lint lint_sys_modules only skips a file that declares a top-level _STUBBED_MODULE_NAMES list and an autouse _restore_sys_modules fixture. The CPU-limit test used a private name, so the CI job counted six new stub writes. Fixes Abilityai#4529
9 of 12 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4529
Description
Agent CPU alerts compared a host-core reading with a 0–100 threshold.
check_docker_healthused Docker's stats formula(cpu_delta / system_delta) * online_cpus * 100, where 100 means one busy core and the ceiling isonline_cpus × 100.MonitoringConfigstill defaultscpu_warning_percentto 80 andcpu_critical_percentto 95, so any agent that kept one core busy was reported critical, then degraded, then recovered. Memory in the same check was already a share of the container's own memory limit.The recorded CPU percent is now a share of the container's own limit, so 100 means it is using everything it is allowed. The limit is
HostConfig.NanoCpus / 1e9when that is set, otherwise CFSCpuQuota / CpuPeriodwhen both are positive (CpuQuotaof 0 or -1 is Docker's "not throttled"), otherwise every online host core. Alerts, the stored docker health metric, andaggregate_healthall read that one number, so the 80/95 defaults mean what they say. The live header chart (agent_service/stats.py) and the telemetry totals still use the docker-stats scale, matchingdocker stats; they are not what the alerts compare.Related Issue
Fixes #4529
Journey Impact
Journey Impact: none: monitoring arithmetic only; no journey promise changes
Type of Change
Testing
tests/unit/test_4529_cpu_percent_of_limit.pycallscheck_docker_healthwith a stats sample and the container'sHostConfig, then feeds that result toaggregate_health. One busy core (cpu_delta / system_delta = 1/24,online_cpus = 24) underNanoCpusof 4 CPUs is 25 and stays healthy; filling the cap is 100 and degraded ("High CPU usage (100.0%)"); 3.4 of 4 cores is 85 and healthy with "Elevated CPU usage (85.0%)". Also covered: no cap (one core of 24 is 4.17), quota/period of 2 CPUs (50), NanoCpus winning over a disagreeing quota,CpuQuotaof -1 treated as no limit, a 1.5 CPU cap (66.67), and an idle sample (cpu_percentstays unset). Memory on the same sample stays 20% / 200 MB.Mutation: putting the host-core formula back at the
check_docker_healthcall site turns 10 tests red (the idle case stays green). Restored, 11 passed. Neighboring monitoring unit tests (test_1439_clone_status_health.py,test_monitoring_dormant_skip.py,test_monitoring_health_check_classification.py) still pass. The full suite was not run.The loader stubs
databaseand the docker helpers only whilemonitoring_service.pyis imported by path, then putssys.modulesback. Those names are a top-level_STUBBED_MODULE_NAMESlist with an autouse_restore_sys_modulesfixture, the pairtests/lint_sys_modules.pyexempts, so thelint-sys-modulesjob stays green.python tests/lint_sys_modules.pyexits 0.Checklist
Prepared with AI assistance.
Release note (added by merge-train, 2026-11-17)
Agent CPU health checks and alerts now report percent of the container's CPU limit, so the
cpu_warning_percent/cpu_critical_percentthresholds mean "of the agent's own limit". An install that raised those thresholds above 100 as a workaround for #4529 (for example 395 / 795) must set them back to the defaults, or it will get no CPU alerts.agent_health_checks.cpu_percentrows recorded before this change stay on the old scale.