fix: correct CPU capacity defaults and cluster-wide scaling logic#13
Merged
Conversation
Three root-cause fixes for autoscale misbehavior in cluster mode: 1. CPU defaults were too aggressive for containerized workloads: - reserve_cpu_cores: 1 → 0.2 (int → float) - worker_cpu_core_estimate: 1.0 → 0.2 - max(..., 1) usable cores guard → max(..., 0) for fractional cores 2. Cluster leader applied local-host capacity to cluster-wide targets, strangling per-queue demand (e.g. fast queue capped to 1 worker despite needing 12). Added evaluateDemand() for unconstrained strategy + config bounds; distributeClusterTarget() now respects per-host maxWorkers. 3. clusterScaleSignal() recommended scale_down at 100% utilization because it only checked bin-packing. Now blocks scale-down when utilization ≥ 80% or any workload has pending jobs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Finding 1: clusterScaleSignal action-check used the raw spaceship int which happened to work at this call site, but was fragile. Replaced with direct target_workers > current_workers comparison — works regardless of whether action is int or string. Finding 3: Added 16 unit tests for new code paths: - evaluateDemand: config bounds respected, capacity ignored - clusterScaleSignal: hold at ≥80% util, hold with pending, boundary at 79% - distributeClusterTarget: per-host maxWorkers cap, skip full hosts, preserve existing Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Two CapacityCalculator tests compared maxWorkersByCpu across separate CPU measurements. On small CI runners the second measurement could spike, yielding 0 available cores and failing the comparison. Fixed by reusing the cached metrics snapshot — only the estimate changes between calls, making the comparison deterministic. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Set max_cpu_percent=100 in the two comparison tests so that even saturated CI runners (>85% CPU) have non-zero available headroom. Without this, availableCpuPercent=0 makes both estimates yield 0 workers and the comparison is meaningless. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
CI runners in cgroup containers without explicit CPU limits report 0 cores via system-metrics. With reserve_cpu_cores > 0, usableCores becomes 0 regardless of config, making both estimate comparisons yield 0 workers. Fix: set reserve_cpu_cores=0 in comparison tests and guard the worker-count comparison behind a capacity check. When system-metrics reports 0 cores (CI), verify the estimate value is correctly applied instead of comparing worker counts. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
Fixes three root-cause bugs causing autoscale to recommend scale-down at 100% utilization with pending SLA breaches in cluster mode.
1. CPU defaults too aggressive for containers
reserve_cpu_cores:1→0.2(typeint→floatthroughout)worker_cpu_core_estimate:1.0→0.2max(..., 1)→max(..., 0)for fractional cores2. Cluster leader applied local-host capacity to cluster-wide targets
clusterTargetWorkers()calledScalingEngine::evaluate()which uses local CPU/memory capacity against cluster-wide pool workers — scope mismatchScalingEngine::evaluateDemand(): strategy + config bounds only, no system capacity constraintdistributeClusterTarget()now respects per-hostmaxWorkers, skipping hosts at capacityrequired_workersreflects actual demand, not capacity-capped values3.
clusterScaleSignal()ignored utilization and backlogTest plan
holdorscale_upunder load, neverscale_downrequired_workersreflects actual demand, not capped values