Skip to content

fix(monitoring): scale agent CPU alerts to the container limit - #4530

Merged
vybe merged 2 commits into
Abilityai:devfrom
pcbeingused333:fix/4529-cpu-percent-of-limit
Nov 17, 2026
Merged

vybe merged 2 commits into
Abilityai:devfrom
pcbeingused333:fix/4529-cpu-percent-of-limit

Conversation

@pcbeingused333

@pcbeingused333 pcbeingused333 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4529

Description

Agent CPU alerts compared a host-core reading with a 0–100 threshold. check_docker_health used Docker's stats formula (cpu_delta / system_delta) * online_cpus * 100, where 100 means one busy core and the ceiling is online_cpus × 100. MonitoringConfig still defaults cpu_warning_percent to 80 and cpu_critical_percent to 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 / 1e9 when that is set, otherwise CFS CpuQuota / CpuPeriod when both are positive (CpuQuota of 0 or -1 is Docker's "not throttled"), otherwise every online host core. Alerts, the stored docker health metric, and aggregate_health all 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, matching docker 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

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Testing

  • I have tested this locally
  • New tests added (if applicable)
  • All existing tests pass
  • Every new test executes the changed path

tests/unit/test_4529_cpu_percent_of_limit.py calls check_docker_health with a stats sample and the container's HostConfig, then feeds that result to aggregate_health. One busy core (cpu_delta / system_delta = 1/24, online_cpus = 24) under NanoCpus of 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, CpuQuota of -1 treated as no limit, a 1.5 CPU cap (66.67), and an idle sample (cpu_percent stays unset). Memory on the same sample stays 20% / 200 MB.

Mutation: putting the host-core formula back at the check_docker_health call 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 database and the docker helpers only while monitoring_service.py is imported by path, then puts sys.modules back. Those names are a top-level _STUBBED_MODULE_NAMES list with an autouse _restore_sys_modules fixture, the pair tests/lint_sys_modules.py exempts, so the lint-sys-modules job stays green. python tests/lint_sys_modules.py exits 0.

Checklist

  • My code follows the project's style guidelines
  • I have updated the documentation (if applicable)
  • I have not committed any sensitive data (API keys, credentials, etc.)
  • I have added appropriate logging for new functionality

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_percent thresholds 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_percent rows recorded before this change stay on the old scale.

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

@vybe vybe left a comment

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.

merge-train: batch validated on train/20261117-1746 (#4626)

@vybe
vybe merged commit 7d64a39 into Abilityai:dev Nov 17, 2026
24 checks passed
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.

2 participants