Skip to content

fix(engine): stop double-subtracting pool size in calcAgents#674

Open
LaGrunge wants to merge 1 commit into
woodpecker-ci:mainfrom
LaGrunge:fix/autoscaler-double-subtract-pool-agents
Open

fix(engine): stop double-subtracting pool size in calcAgents#674
LaGrunge wants to merge 1 commit into
woodpecker-ci:mainfrom
LaGrunge:fix/autoscaler-double-subtract-pool-agents

Conversation

@LaGrunge

@LaGrunge LaGrunge commented Jul 8, 2026

Copy link
Copy Markdown

What is it about?

calcAgents() computed the required agent-count delta as:

  reqPoolAgents = reqAgents - (availableAgents + availablePoolAgents)

availableAgents (freeTasks + runningTasks) already represents the
pool's current total capacity, so adding availablePoolAgents again
double-counted the existing pool size. Under sustained load — zero
idle agents and a non-empty pending queue — this drove reqPoolAgents
negative, so the create-agents branch never ran: the autoscaler
appeared to stall at its current size instead of scaling up, even with
plenty of headroom under WOODPECKER_MAX_AGENTS.

The fix removes the redundant term:

  reqPoolAgents = reqAgents - availableAgents

Why this was hard to notice

The bug is silent whenever there's any idle capacity or the queue is
empty — the maxDown/maxUp clamps happen to produce the same result
in those cases either way. It only manifests when the pool is fully
busy and a backlog builds up, which is exactly the situation where
autoscaling matters most.

Testing

  • Added a regression test (should create new agents when pool is fully busy with a backlog) reproducing the failure: 3 busy agents +
    2 pending workflows previously computed -1 (wanting to shrink);
    now correctly computes +2.
  • All existing tests in the package continue to pass unmodified.

availableAgents already represents the pool's current total capacity
(free + running), so adding availablePoolAgents again on top of it in
reqPoolAgents made the target permanently short by the pool's own
size. Under load (no idle agents, non-empty pending queue) this drove
reqPoolAgents negative, so the create-agents branch never ran and the
autoscaler stalled at its current size instead of scaling up.
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.

1 participant