CPU is the wrong signal to autoscale agents. Agent Substrate workers are slot-bound, one actor per worker, and an LLM session is mostly I/O wait, so workers hosting active sessions measured at single-digit mCPU. A CPU HPA looks at a full pool, sees a quiet cluster, and will not scale up, so scale on sustained rejections and occupancy instead.
Lesson two from the talk. If you remember one thing from this series, make it this one, because it is the mistake a sensible platform team makes on day one.
Why is CPU the wrong signal to autoscale agents?
Somebody sees a WorkerPool with a scale subresource and reaches for a standard HPA on CPU. That is how we scale everything else. The documented scaling path even looks like Kubernetes:
kubectl scale workerpools.ate.dev kagent-default -n kagent --replicas=4
The CR will grow. The signal you used to decide 4 is the part that is wrong.
Substrate workers are slot-bound. One actor per worker, no matter what. What is Agent Substrate is time-multiplexing, not packing. Density comes from parking idle agents as snapshots and restoring them onto a small pool. Simultaneous sessions equal worker count. CPU on the worker does not tell you how many sessions are waiting. It tells you how hard this one sandbox is computing while it waits on a model.
An LLM turn is mostly I/O wait on the model provider. I measured workers hosting active sessions at single-digit mCPU. Memory is not better, since restored snapshots have nearly constant footprints. The always-on comparison on this laptop cluster was about 204 MiB resident and 50m CPU requested while doing nothing. Substrate’s win is that you stop reserving that per agent. The worker that is actually in a turn still does not look busy on a CPU graph.
So picture a full pool. Every slot busy, every worker near idle on CPU, new sessions bouncing off. A CPU autoscaler looks at that and sees a quiet cluster. It will not scale up. It might scale down.
That is the lie kubectl is lying to you from the autoscaler side. Two worker pods, a few MiB each, Running. Eighteen agents on the talk setup, nine on the first lab, over a thousand real sessions, reserved capacity about 4.5x lower than always-on pods. None of those facts show up as CPU pressure. If you scale on CPU, you will not keep them.
Where does demand actually live when the pool is full?
Substrate rejects when the pool is full instead of queueing. The caller gets substrate worker pool has no free workers. So the queue is not gone. It just lives in your callers’ retry loops, outside the runtime, where your autoscaler cannot see it.
That is the signal. Sustained rejections are the purest statement of unmet demand you will get. The catch is that today you have to collect it at the caller. Substrate Scope does this for the stimulator: the restore queue on the board is client-side retries, not a scheduler. The runtime does not hold a pending-restore queue you can scrape as a Prometheus metric. Not in what I have run.
This is the same gap as agent runtimes have an autoscaler, not a scheduler. Scaling answers how many workers exist. Rejection-plus-retry answers who gets the next freed slot, by accident: the client that retries into the window wins. An HPA on CPU sees none of that. An HPA on occupancy plus queued work at least sees the count.
Where to count, in order of honesty:
- Caller retries. Your load generator, gateway, or agent client already knows it was rejected. Increment there. This is what I actually have.
- Board queue depth. Scope renders client-reported retries. Useful for a demo. Not a cluster-wide metric unless every caller reports in.
- Runtime export. A rejections/sec or pending-restore gauge from
ateapiis the cleaner fix. I have not seen that ship. Until it does, do not pretend CPU is a stand-in.
Do not count Suspended actors and call it demand. That list grows because sessions finished. Lesson one: the actors list lies. Demand is people who cannot get a slot now.
What autoscaling policy did you ship?
From notes/autoscaling.md in the demo repo, the policy running behind Scope’s AUTOSCALE toggle:
target = busy + queued, clamped to [2, 8]
scale UP straight to target when queued > 0 for 2 samples (6s), cooldown 8s
scale DOWN straight to max(demand over last 30s window) when that peak < slots
for 6 samples (~18s), cooldown 20s
Four choices in that box, each load-bearing:
- Up on queue depth. Queued work is user-visible latency, so move fast. Two samples, about 6 seconds, then jump straight to
busy + queued. Stepping by one with a long cooldown just makes users wait through several cycles. - Down on occupancy. Queue depth is about zero whenever capacity is fine, so it cannot tell you how much spare you have. Busy versus total slots can. Sustained
busy < slotsmeans paid-for warm workers doing nothing. - Window peak, not instant demand. A gap between sessions should not slash the pool. The down-target is the max demand over the last 30 seconds, held for about 18 seconds, with a 20 second cooldown. A genuinely idle pool still drops to the floor in one step.
- Floor of two. With one worker, any long session blocks every other agent. Two is the floor so a demo never looks frozen. The clamp’s ceiling of 8 is a laptop bound, not a production law.
The production shape is probably KEDA on an external metric fed by rejections, aimed at the WorkerPool’s scale subresource. The cleaner fix is for the runtime to export a rejection or pending-restore metric itself.
One more trap: anything that scales through kubectl scale takes field ownership of spec.replicas, and later helm upgrades need --force-conflicts. I hit that after scaling the live kagent-default pool. Put it in the runbook next to the scaler, not in the incident doc after the chart fails.
And even a good signal has limits. The next post is about the night the autoscaler did exactly what I told it to and made things worse: the autoscaler made it worse. Slot count is not model throughput.
How do you test that a CPU HPA would sleep through saturation?
A test plan, using the cluster you already have. No new telemetry numbers. You are checking shape, not chasing a benchmark.
- Baseline the slot model. Read the workers list, not the pod CPU. Two workers means two live actors. Confirm one actor per worker while a session is in flight. Commands are in the lab post and in lesson one.
- Measure CPU during a live turn. Watch a worker that is hosting an active session. I measured single-digit mCPU. If you see the same shape, a CPU threshold that would fire on a typical web Deployment will not fire here. If you see something else, you have a different workload than chat-against-a-provider, and you should write that down before you copy my policy.
- Fill the pool. Start enough concurrent sessions to occupy every slot. On two workers, that is two in-flight turns. New sessions should fail with
substrate worker pool has no free workers. - Watch CPU while rejections happen. This is the picture: every slot busy, workers near idle, callers retrying. A CPU HPA looking at that window has no reason to scale up. If you already have one attached, this is the moment it sleeps. If it scales down because utilization is low, that is the worse case from the notes: it sheds capacity under peak load.
- Count rejections at the caller. Same string, same window. That counter should rise while CPU does not. If your autoscaler cannot see that counter, it cannot see demand.
- Scale on the policy above, not on CPU. Turn on AUTOSCALE in Scope, or drive
kubectl scalefrombusy + queued. Confirm the pool grows while rejections are sustained, and that it does not collapse on a brief gap between sessions. The 30 second peak window is there for that. - Do not forget the floor. Drain to one worker on purpose once. Put a long session on it. Everything else rejects until that session ends. That is why the clamp starts at 2.
- Record the helm conflict. After a scale, run a helm upgrade the way you usually do. If it fails on field ownership of
spec.replicas, you have reproduced the--force-conflictstrap. Fix the runbook.
Pass condition: you can show a full pool, rising rejections, and CPU that would not have added a replica. Fail condition: you add an HPA on CPU anyway because “that is how we scale everything else.”
What should you put on the Monday dashboard?
Three numbers, all cheaper than a new platform:
- Occupancy: busy / total, from the workers list. Down-signal. Also how you notice a ghost actor later: a busy bay with no live session.
- Rejections:
substrate worker pool has no free workers, counted at the caller. Up-signal. - Target versus slots:
busy + queuedagainst current replicas, clamped to whatever floor and ceiling you actually chose. The laptop clamp was[2, 8]. Yours should be “sessions that must be live at once,” not “number of agents you defined.”
Leave CPU on the dashboard if you want. Do not page on it. Do not scale on it. Compare reservation when you tell the density story: about 4.5x lower reserved capacity than always-on pods on this cluster, because idle agents stopped holding 204 MiB and 50m CPU each. That ratio is reservation. It will not appear as a CPU graph going up.
The field guide index is Agent Substrate. The visualizer is Substrate Scope. If you landed on this post first, the talk recap is the hub.