pks agentics runner cleanup

stable

Find and remove Docker containers left behind by a previous Agentics runner process, with a dry run first and a confirmation before anything is deleted.

Author: Poul Kjeldager
Usage: pks agentics runner cleanup [options]
Platform: linuxmacoswindows
Category: infrastructure

Examples

$ pks agentics runner cleanup --dry-run

List removal candidates without removing them

$ pks agentics runner cleanup

Remove orphans after a confirmation prompt

$ pks agentics runner cleanup --yes

Remove orphans without prompting

$ pks agentics runner cleanup --all

Remove every pks.agentics container, live or not

Restarting the runner strands its containers. Each spawned container is bound to the runner process that created it through a pks.agentics.runner-instance label, and its bind mounts point at temp directories the new process does not share — so the old containers can never be reused. runner cleanup finds them and removes them.

1. Prerequisites

  • The docker CLI on PATH with a reachable daemon. If listing containers fails, the command aborts with exit code 1 rather than reporting zero containers.
  • No confusion about scope. This removes containers, not volumes and not remote containers. A runner handed off over SSH keeps its containers on the remote machine.

2. See what would go

Always start with a dry run.

pks agentics runner cleanup --dry-run

The command lists every container carrying the pks.agentics.fingerprint label, running or stopped, and marks which ones it considers orphaned.

3. Understand the liveness heuristic

There is no out-of-band registry of live runner-instance ids, so liveness is approximated: the command looks for a running pks-cli agentics runner start process with pgrep.

  • No runner process running — every labelled container is treated as an orphan and becomes a removal candidate.
  • A runner process running — the check cannot tell which instance it belongs to, so it stays conservative: only label-less containers are treated as orphans, and anything carrying a runner-instance label is left alone even if it is stale.

4. Remove the orphans

pks agentics runner cleanup

You are asked Remove N container(s)?, defaulting to No, then each candidate is removed with docker rm -f. To skip the prompt in a script:

pks agentics runner cleanup --yes

5. Remove everything, deliberately

--all bypasses the liveness heuristic and removes every pks.agentics.* container regardless of whether a runner is using it — including a container a running runner may reuse for a warm or in-flight job.

pks agentics runner cleanup --all --dry-run

Confirm the list first, then re-run without --dry-run.

6. Verify

docker ps -a --filter label=pks.agentics.fingerprint

You should see only containers belonging to a runner you intend to keep.

Options

FlagDescription
-n, --dry-runShow what would be removed without removing anything.
-y, --yesSkip the confirmation prompt.
--allRemove all pks.agentics.* containers, including those of currently-running runners.
-v, --verboseEnable verbose output.

Troubleshooting

  • Exit code 1 with a listing failure. Docker is not installed or the daemon is down. Fix Docker, then re-run.
  • Nothing is removed while a runner is running. That is the conservative branch of the heuristic. Stop the runner and re-run, or use --all after checking a dry run.
  • A stale container survives repeated cleanups. It carries a runner-instance label and a runner process is live. Stop the runner first.
  • Containers reappear after every restart. Expected — each restart orphans the previous instance's containers. Add a cleanup to your restart routine.

See also