Ghost Actors Pin Your Workers

Part of: Agent Runtimes

Ghost actors pin your workers on Agent Substrate: a killed session can hold a slot while the pool looks idle and new chats still get rejected.

Ghost actors pin your workers. A session killed mid-flight can leave its actor holding a WorkerPool slot, sometimes after that actor has disappeared from inventory, so new chats fail with substrate worker pool has no free workers while the pool looks idle. Restarting the pool clears it, and it is cheap, because agent state lives in snapshots in object storage rather than in the pods.

Lesson four from the talk, and the creepiest one.

Why does Agent Substrate say no free workers when the pool looks empty?

New sessions failing with substrate worker pool has no free workers. The pool looks empty. Nothing is running. Nothing in the actor inventory claims the slot.

That rejection string is the same one CPU is the wrong signal treats as unmet demand. Here it is a lie about demand. Callers retry. An autoscaler that scales on sustained rejections will add workers. The ghost will not move. You now have more empty-looking bays and the same stuck assignment, or you have paid for extra slots so that one ghost is a smaller fraction of a larger pool. Neither is a diagnosis.

kubectl get pods is no help. The worker pods are Running. They look like the quiet pair from kubectl is lying to you. A few MiB, bored. On this laptop that pair hosted 18 agents for the talk setup and nine in the first lab, over a thousand real sessions, reserved capacity about 4.5x lower than always-on pods. A ghost does not show up as CPU, and it does not show up as a crash. It shows up as a reserved parking space with no car.

On a two worker pool, one ghost is half your capacity. Two is all of it. That is not a metaphor. Simultaneous sessions equal worker count. What is Agent Substrate gets its density by time-multiplexing those slots. Pin one and you have shrunk the multiplex.

What leaves a ghost actor pinning a worker?

A session got killed mid-flight. Timeout, cancelled chat, provider outage, take your pick. Its actor never released the worker. Sometimes it stopped showing up in the actor inventory entirely and kept holding the slot anyway. A ghost.

I am not adding a new failure mode on top of that. Those three kill paths are the ones I already named in the lab writeup. The important part is the release path: the slot is supposed to free when the session ends and the actor checkpoints back to object storage. A kill in the middle can skip the release and leave the assignment in place. If the actors list also drops the row, you have a slot that is taken for a reason nobody can look up.

This is not the same bug as the actors list lies. That lesson is partial results on an unbounded history, so a live session vanishes from a dashboard that joined the wrong list. The agent was fine. The board was not. Here the board that reads actors (or pods) shows idle, and the workers list shows taken. The agent is not fine. The slot is pinned.

Agent runtimes have an autoscaler, not a scheduler called this out as priority inversion’s ugly cousin: a wedged session can pin a slot indefinitely, and when the holder of a contended resource cannot be preempted, who gets capacity is a hope about arrival order. Ghosts are that pin. Reset is preemption you do by hand.

Do not confuse a ghost with a serial model wait either. The autoscaler made it worse is busy bays with live actors waiting on one cashier. Ghosts are busy bays with nobody home. Same occupancy number, opposite fix.

How do you clear a ghost actor without losing agent state?

Reset the pool. In my lab that meant restarting the worker pool, and Scope has a RESET POOL button for exactly this. The command from the lab post:

kubectl rollout restart deploy/kagent-default-deployment -n kagent

Only the wedged sessions die. Every agent’s snapshot survives. It is cheap, because agent state is not in the pods. It is in snapshots in object storage. Kill the workers and nothing is lost but warm-up time.

That is the density design paying you back at incident time. Always-on pods hold about 204 MiB and 50m CPU idle in the kagent default I measured. You would hesitate to bounce those if the process were the source of truth. Substrate parked the source of truth on the shelf. The worker is a bay. Bays can be rebuilt.

Substrate Scope exposes the same reset as a live control, next to workers plus and minus (kubectl scale against the WorkerPool) and AUTOSCALE. Use RESET POOL when the workers list says taken and nothing alive is using the bay. Do not use it as the fix for a disappearing chip that is actually the actors-list join. Bounce hardware for a display bug and you will teach yourself the wrong lesson.

After the restart, confirm:

  • workers list: assignments cleared, or only live sessions remain
  • callers: the substrate worker pool has no free workers stream stops for new chats that should fit
  • snapshots: the agents you care about still restore. They should. That is the point of the shelf.

If you scaled through kubectl scale earlier in the same incident, remember the field-ownership trap from lesson two: helm upgrades then need --force-conflicts. Reset and scale are different operations. They can show up in the same night.

How would you catch a ghost before the pool is stuck?

This is where lesson one pays off. The workers list knows a slot is taken even when the actors list has forgotten why. A board that reads workers shows a busy bay with nothing alive in it. That is your ghost. A board that reads actors, or a pod list, shows you a quiet cluster and a pile of rejections, and you go hunting in the wrong place.

So the check I would automate: a worker that has been assigned for longer than your longest plausible session, with no turn activity, gets flagged. Then decide if you trust it enough to reset automatically.

I am not giving you a timeout number I did not measure. Chat turns on this cluster were not a published SLO. “Longer than your longest plausible session” is the rule. Pick that bound from your own traces, not from mine. Flag on workers, not on actors. Actors going silent is how ghosts hide and also how a partial actors page looks. If you auto-reset from actors-list silence, you will bounce a healthy pool because you asked the unbounded list.

A detection checklist, in the order I would run it:

  1. Read workers, not pods. Port-forward the kagent controller and GET /api/substrate/status, same payload as lesson one. Each worker row names the assigned actor, or it does not.
  2. Compare actors. If a worker names an actor that is missing from the current actors page, do not stop at “partial list.” Check whether a session is actually in flight (chat I/O, restore, checkpoint). No activity plus a missing actor is ghost-shaped. Activity plus a missing actor is still lesson one.
  3. Watch rejections against occupancy. Rejections with a pod dashboard that looks empty, and a workers list that looks full, is the parking lot. Rejections with a full workers list and live turns waiting on a model is lesson three. Rejections with a full workers list and live turns that are fine is ordinary saturation. Scale that last one. Do not reset it.
  4. On two workers, count halves. One pinned slot is half the pool. Two is a full outage for live work, even if 18 agents still exist as snapshots. Treat two ghosts on a two-replica pool as an incident, not as a curiosity.
  5. Reset once, then re-read workers. If the assignment survives a restart, you have a different bug than the one I hit. I am not going to invent that bug. Write down what you saw.
  6. Put RESET POOL in the runbook before you need it. Practice the reset path before the first incident. The button in Scope is one implementation. kubectl rollout restart is the other. Both assume snapshots are the source of truth. Verify that assumption with a restore after the bounce, not with hope.

What should you instrument so ghosts do not look like demand?

Three signals, and they have to sit together or you will scale a pin:

  • Workers occupancy. Busy / total from the workers list. The only occupancy I trust.
  • Live turn activity. Chat I/O, restore, checkpoint. Scope’s per-agent drawer is one place that stream already exists. A busy bay with none of that is the ghost flag.
  • Rejections. Same string as lesson two. Demand if occupancy is full of live turns. A pin if occupancy is full of silence.

Do not page from CPU. Ghosts do not burn CPU. Live turns barely do either. Do not page from actors length. That list passed 900 in a day because sessions finished, which is the opposite of a pin.

The short version of the whole talk: the runtime tells the truth, but you have to ask the layer that knows. Pods do not. Workers do. Start with the hub if you landed here first. The field guide index is Agent Substrate. The board is themsquared/substrate-scope. The lab, including the restart command, is kagent Agent Substrate.

Frequently asked questions

Why does Agent Substrate say no free workers when the pool looks empty?

A session killed mid-flight by a timeout, a cancelled chat, or an API outage can leave its actor pinning a worker slot indefinitely, sometimes as a ghost that no longer appears in the actor inventory. New sessions then get rejected while the pool looks idle.

How do you clear a ghost actor?

In my lab, restarting the worker pool cleared it. kubectl rollout restart deploy/kagent-default-deployment -n kagent. It is cheap because agent state lives in snapshots in object storage, not in the worker pods. Only the wedged sessions die.

How do you see a ghost if the actors list has forgotten it?

Read the workers list. A worker that is assigned with no live turn, including an assignment whose actor is missing from inventory, is the ghost. A board that joins through actors, or a pod list, shows a quiet cluster and a pile of rejections.

Should you reset the pool automatically?

Flag first: a worker assigned longer than your longest plausible session, with no turn activity. Then decide if you trust that enough to reset automatically. I would not auto-reset from actors-list silence alone. That list already lies for a different reason.

Disagree or have a war story? Reply on X