trim_serve_processes
Close leftover Kiln servers from ended agent sessions to free memory. Confirms before closing, preserves your open sessions, and refuses if a print is in flight.
Instructions
Close leftover Kiln servers left behind by closed sessions.
Every agent session spawns its own background Kiln server;
client apps don't reliably close them when a session ends, so
they accumulate and quietly hold memory. This is the cleanup
the pile-up warning (health_check / kiln_health / get_started)
offers.
WHY THIS IS SAFE: closing a server never stops a physical
print — the printer keeps going regardless. What a close can
end is MONITORING (a running watch loop). So this refuses to
act while any printer has a job in flight, and otherwise the
worst case is that a still-open session reconnects. This
session's own server is never closed.
AGENT CONTRACT (important):
* ASK THE USER how many agent sessions they actually have
open right now and pass it as open_sessions — they are
the one source of truth for that, and it beats guessing
from process age. Never ask them for a PID.
* Confirm before acting. Called without confirm, this
returns the plan (how many would close, how many stay)
to show the user; pass confirm=True once they agree.
* If it comes back blocked because something is printing,
tell the user what's printing and leave it alone — offer
to clean up after the print finishes rather than
reaching for force.
Args:
confirm: Set True to actually close the leftovers.
open_sessions: The user's own count of agent sessions
currently open. Keeps that many most-recently-started
servers and proposes the rest.
force: Proceed even though a printer has a job in flight.
Only when the user explicitly insists, knowing that
monitoring for that job may stop.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| force | No | ||
| confirm | No | ||
| open_sessions | No |