Deploying to Kubernetes
Run abt triggers on Kubernetes in one of two ways: standalone abt watch run, which listens and dispatches in one process, or the distributed split, abt watch produce and abt watch consume, with the trigger and execution planes on separate pods connected by a Redis Streams queue. Every flag is in the abt watch reference.
Which mode?
Start with standalone abt watch run --all at replicas: 1. It needs no broker or extra credentials, and Kubernetes restarts it within seconds after a crash. For a few Slack or GitHub triggers that one pod can dispatch, this is enough.
Move to abt watch produce and abt watch consume when either is true:
- Dispatch volume (LLM calls, not events) outgrows one pod. Consumers scale independently of your triggers. See Scaling consumers.
- The trigger side must survive a pod loss without a multi-second gap.
producesupportsreplicas: N(see Leader election).
Image and project source
Install abt from its git repository, with the extras your pods use: queue for produce and consume, serve for --serve-api, slack for Slack triggers. Python 3.12 or newer is required.
FROM python:3.12-slim
RUN apt-get update && apt-get install -y --no-install-recommends git \
&& rm -rf /var/lib/apt/lists/*
RUN pip install "abt-core[queue,serve,slack]"
WORKDIR /workspace/repo
COPY . .
COPY . . also copies profiles.yaml and .env, which hold credentials. List them in a .dockerignore and supply credentials when the pod starts: mount profiles.yaml from a Secret, or inject ABT_TARGET__<TARGET>__* env vars (see Env-var-only targets).
With a git-sync sidecar, abt keeps the project root path as given, with symlinks unresolved, so each reconcile and dispatch reads the revision the link points to. Point --project-root at the stable link, and set ABT_PACKAGES_DIR to a stable path so installed packages survive the rotation. See Environment variables. consume --serve-api also recompiles when the link is repointed. Set git-sync's GITSYNC_STALE_WORKTREE_TIMEOUT to at least --invoke-max-run-seconds, so a run in flight keeps its checkout (see New checkouts in the invoke API reference).
Standalone abt watch run
apiVersion: apps/v1
kind: Deployment
metadata:
name: abt-watch
spec:
replicas: 1 # keep at 1, see "Why not replicas: N" below
selector:
matchLabels:
app: abt-watch
strategy:
type: Recreate # RollingUpdate starts the new pod before the old one stops
template:
metadata:
labels:
app: abt-watch
spec:
terminationGracePeriodSeconds: 45 # --shutdown-timeout (30s) plus 15s, see "Shutdown" below
containers:
- name: abt-watch
image: registry.example.com/abt-project:1.0.0 # built from the Dockerfile above
command: ["abt", "watch", "run", "--all", "--health-port", "8080"]
livenessProbe:
httpGet: { path: /health, port: 8080 }
periodSeconds: 30
# Ready only once a source is listening; see "Readiness" below.
readinessProbe:
exec:
command:
- python3
- -c
- "import json,sys,urllib.request as u; sys.exit(json.load(u.build_opener(u.ProxyHandler({})).open('http://127.0.0.1:8080/health'))['sources'] < 1)"
periodSeconds: 10
timeoutSeconds: 5 # exec probes default to 1s, less than Python startup plus the request
Why not replicas: N. Slack Socket Mode load-balances events across every open socket that shares one app token. Two pods each open a socket and silently drop a random subset of events, with no error or log line. Leader election solves this for produce only. To run two standalone pods, split the triggers with --tags, one tag set per pod, such as --tags team:infra and --tags team:platform.
Why strategy.type: Recreate. RollingUpdate starts the replacement before it stops the old pod, so both pods hold a socket and split events during the overlap. Recreate trades that overlap for a short window with no listener. It governs rollouts. An eviction can still overlap briefly, because Kubernetes starts the replacement while the old pod terminates.
Readiness. /health answers 200 before the first reconcile starts any source, so an httpGet readiness probe marks a pod Ready while no trigger listens. The exec probe fails while sources is 0, so a rollout waits for a pod whose triggers did not start. The probe needs python3 and your --health-port. The empty ProxyHandler stops a proxy in the pod environment from intercepting it. The check counts started sources only, so one failing source among several passes. With no triggers in the selected entrypoints, use an httpGet probe instead, since the exec probe would never pass. Keep liveness on /health, so one failing trigger does not restart the pod. Only the run payload carries sources at its top level, so this probe fits run, not produce or consume.
Exposure. The health port has no authentication and binds all interfaces, which probes need. Its payload shows runner state, sink counters, and exception classes for the last error and any invoke refresh error. Messages stay in the log. Restrict it with a NetworkPolicy to the probe and monitoring sources you trust. With consume --serve-api, /health and /ready share the invoke API's port and stay unauthenticated, while the invoke, poll and cancel routes need the bearer token. The NetworkPolicy covers that port too.
Shutdown. On SIGTERM, run and consume wait up to --shutdown-timeout (default 30 seconds) for in-flight dispatches. Runs still in flight after that are abandoned. Set --shutdown-timeout above your slowest workflow run, and terminationGracePeriodSeconds to at least that value plus 15 seconds, as the manifests here do (45 for the default). Kubernetes kills the pod when the grace period ends, whatever the process is doing. produce has no in-flight runs and takes no --shutdown-timeout, so it keeps the default grace period.
Distributed mode
To embed either plane in your own process, see Using the Python SDK.
# Trigger plane: leader-elected, replicas: N is safe.
apiVersion: apps/v1
kind: Deployment
metadata:
name: abt-triggerer
spec:
replicas: 2 # one leader, N-1 hot standbys
selector:
matchLabels:
app: abt-triggerer
template:
metadata:
labels:
app: abt-triggerer
spec:
containers:
- name: abt-triggerer
image: registry.example.com/abt-project:1.0.0
command:
[
"abt", "watch", "produce", "--all",
"--queue", "redis://redis:6379",
"--health-port", "8080",
]
livenessProbe:
httpGet: { path: /health, port: 8080 }
periodSeconds: 15
---
# Execution plane: pure competing consumers, scale independently.
apiVersion: apps/v1
kind: Deployment
metadata:
name: abt-worker
spec:
replicas: 3
selector:
matchLabels:
app: abt-worker
template:
metadata:
labels:
app: abt-worker
spec:
terminationGracePeriodSeconds: 45 # --shutdown-timeout (30s) plus 15s
containers:
- name: abt-worker
image: registry.example.com/abt-project:1.0.0
command: ["abt", "watch", "consume", "--queue", "redis://redis:6379", "--health-port", "8080"]
livenessProbe:
httpGet: { path: /health, port: 8080 }
periodSeconds: 15
Both planes need Redis 7.0 or newer, or Valkey, at the URL in --queue or ABT_WATCH_QUEUE. You run Redis yourself, and abt only connects to it. An unreachable URL fails at startup with a docker run -p 6379:6379 redis:7 hint.
Both pods need credentials. The producer needs profiles.yaml (or equivalent env) for trigger credentials such as Slack and GitHub tokens. The consumer dispatches on a different pod, so it needs its own copy for execution credentials such as LLM and MCP keys. Without profile access, a consumer fails any agent that depends on profile-scoped env vars. To skip building profiles.yaml from a Secret, inject ABT_TARGET__<TARGET>__* env vars directly. See Env-var-only targets.
If a Slack trigger sets progress or progress_reaction, the consumer also needs that trigger's Slack bot token and the slack extra, because it clears the indicator when the run ends. See Progress UX.
Scaling consumers
Each consumer runs up to --max-concurrent agent runs (default 5). Runs spend most of their time waiting on model and tool calls, so CPU stays low, and a CPU-based HorizontalPodAutoscaler does not add consumers as the queue backs up. Scale on lag: entries no consumer has read yet, in consumer group workers on stream abt:dispatch (Redis ≥7.0, XINFO GROUPS).
Stream length measures history: the stream trims only at --stream-maxlen (default 10,000), so its length settles near that cap. Without --acks-late, the pending count stays near 0. Lag is the signal to scale on.
Workers sharing one provider quota also throttle each other. Declare the model_rate_limit middleware to cap model calls per minute across all of them.
Each consumer reports queue_lag in its health payload, refreshed every 15 seconds (null when Redis cannot say). An autoscaler cannot read a pod's health endpoint, so feed it lag from Redis: a Redis exporter with a Prometheus adapter, or KEDA's Redis Streams scaler on its lag setting. Without one, set a fixed replicas: sized from --max-concurrent and your peak dispatch rate. Consumers take no selectors, so shard by workflow on the producer with its entrypoints or --tags.
Leader election (replicas: N)
One produce replica holds a Redis-backed lease and runs event sources. The others stand by. A standby takes over within one --lease-seconds window (default 15) after the leader shuts down or crashes. A shorter window fails over faster at the cost of more Redis round-trips. Override --replica-group, the lease key, only to split one trigger selection into two leases.
Sizing --lease-seconds. Keep the lease well above your manifest compile time, which grows with project size and context or skill resolution. A compile that outlasts the lease makes leadership flap: acquire, start sources, lose the lease mid-compile, stop, reacquire. Repeated acquired leadership and stepping down log pairs are the symptom.
Failover. Only one replica listens, even with replicas: 5. To shard trigger count, run separate --tags groups. Each group gets its own lease and runs as its own replicas: N fleet.
Redelivery and dead-lettering
By default (--no-acks-late), a consumer that crashes mid-dispatch loses that job. Delivery is at-most-once: a rare run is lost, but an LLM call or Slack post never runs twice.
With --acks-late, the consumer acks after the run finishes. A crashed consumer's job stays pending until --reclaim-idle-seconds (default 300) passes, then a live consumer reclaims it through XAUTOCLAIM. A live consumer refreshes the claim on its running jobs every third of that window, so a run can outlast it without being redelivered or dead-lettered. Lower it to recover from a crash sooner, but keep it above 60 seconds.
The trade is possible duplicate runs: a crash between completion and ack re-runs the job. A completed-run marker keyed by dedup_key (agent, source, scope, thread) narrows that window. Distinct events sharing a key within --completed-ttl-seconds (default 600) collide, and the second is skipped. Keep the TTL just above the reclaim window. The CLI and RedisQueue refuse a TTL at or below it. Enable --acks-late only for agents that tolerate occasional duplicates.
A run paused for external approval returns a clean success, so --acks-late acks it without setting the marker. A later dispatch with the same dedup_key, such as a cron trigger polling the same approval thread, still resumes the agent.
After --max-deliveries attempts (default 5; 2-3 is typical), the job moves to abt:dispatch:dlq instead of retrying forever. Under --acks-late, each delivery runs the workflow once with no in-process retries, so --max-deliveries sets the total run budget. Alert on dlq_depth above 0 in the health payload, then list and replay from any pod or laptop that can reach Redis:
abt watch dlq list --queue redis://redis:6379
abt watch dlq replay --queue redis://redis:6379 --id 1700000000000-0 # or --all [--limit N]
A replayed job goes back onto the dispatch stream with a fresh delivery count and leaves the dead-letter stream. Fix the cause first, or it dead-letters again after --max-deliveries attempts. An invoke-API run stays parked, because its run is already marked failed: resubmit it to the API.
Keep --dispatch-retry-attempts at 3 for transient errors such as timeouts and rate limits. Under --acks-late it drops to 1, since queue redelivery replaces in-process retries. Every consume replica on one queue must use the same --acks-late setting. Redis stays silent when they differ.
Run result retention
Each job writes a directory under target/run_results/, and nothing else deletes them. Retention runs by default. It keeps the 20 most recent runs (--keep-runs), the 10 most recent failed runs (--keep-failed-runs), and anything under 24 hours old (--run-results-max-age-hours). It caps the total at 512 MB (--run-results-max-total-mb), evicting the oldest runs past the cap but never an in-flight run. Sweeps run every 60 seconds. Most space comes from --reclaim-repos-cache, which deletes each finished run's repos/ checkouts, gigabytes that can be cloned again. The run.log and run_results.json beside them are kilobytes of evidence.
run_results/ shares the worker's disk. With git-sync, that is usually one emptyDir that also holds the checkout and ABT_PACKAGES_DIR. Set the MB cap to a fraction of the volume's sizeLimit. The 512 MB default assumes a 2 Gi emptyDir shared three ways. Rollouts wipe an emptyDir, so a fill can stay hidden until a release freeze.
Each retention flag has a matching key under config.watch.retention in abt.yaml, so you can tune retention in the project without touching command: (see abt watch). A custom entrypoint that wraps abt.sdk.watch.worker(...) ignores these flags, and the SDK prunes nothing by default. Pass run_retention=RunRetentionPolicy(...), imported from abt.sdk.watch. See abt watch.
Confirm pruning with the run_results block of the health payload and the run_results_pruned and run_repos_reclaimed [WATCH_METRIC] events. In Datadog, query the @logger:abt.watch.metrics attribute.
Serving the invoke API from workers
abt watch consume --serve-api lets other services run an access: public agent over HTTP without a new workload. The worker answers POST /api/agents/{name}/invoke, GET .../runs/{run_id}, and POST .../runs/{run_id}/cancel. Any worker executes an enqueued run, and run state lives in Redis, so every replica answers polls. Install abt-core[queue,serve]. Details: abt watch.
Put a Service in front of the worker's health port:
apiVersion: v1
kind: Service
metadata:
name: abt-worker
spec:
selector:
app: abt-worker
ports:
- name: http
port: 8080
targetPort: 8080
Replace the abt-worker container in the worker Deployment above with this one:
- name: abt-worker
image: registry.example.com/abt-project:1.0.0
command: ["abt", "watch", "consume", "--queue", "redis://redis:6379", "--serve-api", "--health-port", "8080", "--acks-late"]
env:
- name: ABT_INVOKE_TOKEN
valueFrom: { secretKeyRef: { name: abt-invoke, key: token } }
livenessProbe:
httpGet: { path: /health, port: 8080 }
readinessProbe:
httpGet: { path: /ready, port: 8080 }
periodSeconds: 10
Run these workers with --acks-late, so a run survives its worker dying. Keep the terminationGracePeriodSeconds from the worker Deployment above: a draining worker keeps answering polls until its in-flight runs finish. Point the readiness probe at /ready, which stays 503 until the project compiles and while the worker is not consuming. /health means "the process is alive." Keep liveness on /health only if you accept a restart when Redis is unreachable for a few seconds. Five consecutive failed queue reads return 503, which restarts every replica at once and, without --acks-late, loses in-flight runs.
Roll out in two steps: upgrade every worker first, since older workers drop invoke requests as malformed, then add --serve-api to the pods that should serve HTTP. Workers without the flag still execute runs. Callers that send vars need the same order. An older worker skips those requests (malformed dispatch request, skipping) instead of running them on the agent's defaults. Under --acks-late, an upgraded worker picks them up.
Isolated tools
@isolated_tool tools need uv in the image. Point UV_CACHE_DIR at a persistent volume so a restart does not download again, and put TMPDIR on the same volume: each run's environment is built under it, and uv links files from its cache only within one filesystem (across two it copies them). A pod killed hard (SIGKILL, OOM) leaves its environment behind; the next run on that volume removes it.
Health probes
--health-port serves a plain HTTP endpoint on run, produce and consume. It answers 200 with a JSON payload when healthy and 503 when not, and the payload's healthy field matches the status. Without --serve-api it answers any path, so use /health. With consume --serve-api the port serves an HTTP app instead: /health (also /) answers the same payload, /ready answers readiness, and the invoke API paths sit beside them.
A liveness probe on /health restarts the pod once a 503 outlasts failureThreshold × periodSeconds. That helps when the fault is local. It does not help when Redis is down: consume turns 503 after 5 failed reads, every replica restarts at once, and without --acks-late the runs in flight are lost. If you do not accept that, use /health as a readiness probe or alert on the payload fields below.
run returns 503 when it is not running, when reconcile has failed --max-reconcile-failures times in a row (default 3), or when the last reconcile finished more than 2.5 × --reconcile-interval ago. Its payload:
| Field | Meaning |
|---|---|
healthy, running |
The status, and whether the runner loop is running |
sources |
Event sources listening, one per entrypoint workflow with an enabled trigger |
dispatched, ok, failed |
Dispatches started, succeeded and failed since the process started |
in_flight |
Dispatches running now |
last_reconcile_at, last_reconcile_ago_s |
Unix time of the last reconcile and seconds since. null before the first |
last_reconcile_ok, consecutive_reconcile_failures |
Outcome of the last reconcile, and failures in a row |
last_error |
null, or the class of the exception that stopped the last reconcile, such as ParserError. Trigger discovery failures read trigger discovery failed: ParserError. The message is in the log. A good reconcile clears it |
produce returns 503 when it is not running, or when the leader's runner crashed or failed to start (last_error is set). A standby is healthy: leader: false is the normal state for every replica but one, so do not gate traffic on leader: true. Its payload:
| Field | Meaning |
|---|---|
healthy, running |
The status, and whether the process is running |
leader |
true on the replica that holds the lease |
group, holder_id |
The lease key (--replica-group) and this pod's id, <hostname>-<pid> |
last_error |
null, or the class of the exception that stopped the leader's runner. Winning the lease again clears it |
inner |
Only while leading: the runner's own payload. It has the run fields above, except that published, publish_failed, consecutive_publish_failures and last_successful_publish_at replace dispatched, ok, failed and in_flight |
inner.healthy turns false after 5 failed publishes in a row, or when reconcile keeps failing. The producer's own status stays 200 in both cases, so alert on inner.healthy as well as on the probe.
consume returns 503 when it is not running, when the consume loop crashed (last_error is set), or after 5 failed queue reads in a row. A failed read retries about once a second, and a streak counts only while its latest failure is under a minute old. Its payload:
| Field | Meaning |
|---|---|
healthy, running |
The status, and whether the consume loop is running |
dispatched, ok, failed |
Jobs started, succeeded and failed on this worker since it started |
in_flight |
Jobs running now |
queue_lag |
Entries no consumer has read yet. null when Redis cannot say. Refreshed every 15 seconds |
dlq_depth |
Jobs parked in the dead-letter stream abt:dispatch:dlq. null when Redis cannot say. Refreshed every 15 seconds. Alert on any value above 0 |
queue_consecutive_read_failures |
Failed queue reads since the last success |
queue_last_successful_read_at |
Unix time of the last successful read. null until the first |
run_results |
The state of run result retention, below |
last_error |
null, or the class of the exception that crashed the consume loop |
invoke_ready |
Only with --serve-api: true once the project has compiled on this worker |
invoke_revision |
Only with --serve-api: digest of the checkout invoke is serving. null before the first compile |
invoke_refresh_error |
Only with --serve-api, and only while the live checkout fails to compile: the class of the exception that stopped it. The message is in the log. The previous checkout keeps serving |
The run_results block:
| Field | Meaning |
|---|---|
removed, kept |
Run directories the last sweep deleted and kept |
freed_bytes |
Bytes the last sweep freed |
skipped_active |
In-flight runs the last sweep left alone |
total_bytes, budget_bytes |
Size of target/run_results/ after the last sweep, and the --run-results-max-total-mb cap in bytes. budget_bytes is null when pruning is off |
repos_reclaimed |
Repo caches the last sweep deleted |
last_sweep_ts |
Unix time of the last sweep. null until the first |
boundary_repos_reclaimed, boundary_freed_bytes |
Repo caches and bytes reclaimed as jobs finished, summed since the worker started |
With --serve-api, GET /ready answers {"ready", "invoke_ready", "running", "invoke_revision"}, plus invoke_refresh_error while the live checkout fails to compile. It returns 200 once the worker is running, has no last_error and has compiled the project, and 503 otherwise.
Limitations
- GitHub triggers don't share a poll loop. Two workflows polling the same repo with one token each run a poller, doubling GitHub API quota use. Slack triggers share one socket per token pair. This asymmetry is a known gap.
- Dedup is best-effort. The cooldown key can be lost on Redis failover. It suppresses duplicates but cannot guarantee exactly-once handling.
--cooldownmust outlive the dispatch. If an agent'srun_timeoutexceeds--cooldown(default 30 seconds), a redelivery that arrives after the key expires and before the original dispatch finishes re-runs the agent.- The stream cap trades durability for memory. Entries older than
--stream-maxlenare trimmed even if unread, and Redis then counts them as read, so neitherqueue_lagnor the consumer can show the loss. The producer flags it: once--stream-maxlenentries wait unread, each publish emits thequeue_overflowmetric, and the producer logsunread entries reached the stream capat most once a minute. Alert on the metric, and size the cap against your worst realistic consumer downtime.