Three months ago, we introduced AI Incident Commander (v0.1)—a Go service sitting inside our K3s system namespace that catches firing Grafana 11 alerts, inspects cluster state, and opens automated remediation pull requests via the Antigravity CLI (agy).
Running an autonomous SRE agent against a live production fleet for three months is the fastest way to learn where naive automation breaks. By v0.3.0, real alerts exposed nine subtle reliability, concurrency, and security bugs—and taught us a counterintuitive truth about incident response: the smartest thing an autonomous SRE can do during the first 60 seconds of an alert is nothing.
Across ADR-0056 (v0.4.0) and ADR-0057 (v0.5.0–v0.5.2), we hardened the commander’s runtime, isolated its credentials, embedded a pinned helm binary for drift-aware pre-diagnostics, added a cancellable 60s soak gate, replaced blind auto-merging with a human gate (AUTO_MERGE=false), and scheduled a daily 07:15 ICT fleet audit.
1. Post-Mortem: Nine Failure Modes From Three Months in Production
An operational audit of ai-incident-commander (v0.3.0) surfaced nine P0/P1 defects in how the agent interacted with Prometheus, Kubernetes, Git, and agy:
- Prometheus Scraper Label Shadowing: Alerts emitted from
kube-state-metricscarriedpod="fleet-kube-state-metrics-..."andservice="fleet-kube-state-metrics"scraper labels that shadowed the realdeployment,statefulset,job_name, orpersistentvolumeclaimtargets—poisoning PostgreSQL incident deduplication keys. - Dead-End
AppFixerRouting: Infrastructure alerts in namespaceapps(category: workload|storage|node|endpoint) fell into a dead-endAppFixerbranch instead of opening Helm remediation PRs against the fleet repository. - Pod-Restart Incident Amnesia: Keeping
ActiveIncidentssolely in Go memory meant a commander pod restart silently dropped incomingresolvedwebhooks, leaving stale incidents open in PostgreSQL and GitHub. - Concurrent Git Workspace Races: Simultaneous webhook goroutines ran
git checkoutandgit pullon the same local clone without a mutex. - Unverified Auto-Merges & Missing PR CI: Reviewer-approved PRs merged immediately without waiting for GitHub Actions (
WaitForPRChecks), while.github/workflows/deploy.yamloriginally ran only onpushtomain—leaving autonomous PRs with zero CI check runs. rootHost Auth Pollution & MCP OOMs: Mounting/home/opc/.geminiread-write asrootpolluted host CLI state and booted unrelated host MCP servers inside a512Mimemory limit, without--disable-slash-commandsor a validatedAGY_MODEL.- Unauthenticated
/webhook& Missing/healthz:/webhookaccepted unauthenticated requests, and probes checked TCP sockets instead of PostgreSQL readiness. - Broken OTLP Logging: Leaving
OTEL_EXPORTER_OTLP_ENDPOINTunset dumped verbose OpenTelemetry span JSON straight into stdout and VictoriaLogs. - Hair-Trigger PR Churn: Firing immediately on transient rollout blips—without waiting to see if Kubernetes self-healed or comparing live Pod specs against Git Helm templates—generated noisy PRs for self-resolving events.
2. Runtime Sandboxing & CI-Gated PRs (v0.4.0, ADR-0056)
In v0.4.0, we eliminated the concurrency, security, and isolation gaps before adding higher-level diagnostic intelligence:
- Read-Only Host Auth + Ephemeral
emptyDirIsolation:Deployment/ai-incident-commandernow mounts/home/opc/.gemini/antigravity-clistrictly read-only at/mnt/host-gemini-cli(AGY_HOST_AUTH_DIR=/mnt/host-gemini-cli), while/root/.geminiis an ephemeralemptyDir. Before eachagyinvocation, the commander copies onlyantigravity-oauth-token,installation_id, andsettings.json, and writes{"mcpServers":{}}to/root/.gemini/config/mcp_config.json. Combined with--disable-slash-commands,AGY_MODEL=gemini-3.8-flash-medium, and a raised1536Mimemory limit onarm10,agystarts fast, loads zero extraneous MCP tools, and never mutates host files asUID 0. - Grafana Bearer Auth & Retained Secrets (
ADR-0052): Grafana 11 now authenticates every webhook POST usingauthorization_scheme: Bearerbacked by retained Secretai-commander-webhook-secret("helm.sh/resource-policy": "keep",createWebhookSecret: falseby default). - Restart-Safe Reconciliation, Mutexes &
/healthz: Added workspace mutex locking around git/Fixer loops, idempotent scraper-label cleanup migrations, restart-safe debounced resolve locks, and a DB-aware HTTPGET /healthzprobe. - Pull Request CI Gates & Clean OTLP Export: Added
pull_request: branches: [ "main" ]to.github/workflows/deploy.yamlsoWaitForPRChecksblocks merges untilhelm lint,terraform fmt, andpytestarchitectural fitness gates turn green, and wiredOTEL_EXPORTER_OTLP_ENDPOINTtootel-collector.observability.svc.cluster.local:4317(passing barehost:portviaotlptracegrpc.WithEndpoint(...)inv0.5.0to silence DNS resolver warnings).
3. Diagnostic-First 60s Soak & Pinned Helm Pre-Diagnostics (v0.5.0–v0.5.2)
Hardening v0.4.0 stopped crashes and security leaks, but the commander still reacted too fast to transient noise and lacked Helm context during triage. ADR-0057 transformed the pipeline into a diagnostic-first, human-gated SRE state machine:
Grafana 11 Firing Webhook (Bearer Auth Verified)
│
▼
┌───────────────────────────────┐
│ SOAKING (SOAK_DURATION=60s) │◄─── Duplicate firing webhooks dropped
│ WaitForSoak │───► `resolved` webhook cancels soak!
└───────────────┬───────────────┘ (0 agy tokens, 0 GitHub issues)
│ 60s elapsed & still firing
▼
┌───────────────────────────────┐
│ CheckWorkloadStatus │───► Active rollout / already recovered?
│ + Open Issue/PR Dedup (v0.5.1)│ Defer or suppress cleanly!
└───────────────┬───────────────┘
│ Confirmed real incident
▼
┌───────────────────────────────┐
│ FetchDiagnosticBundle │ Read-only kubectl + pinned helm v3.21.4
│ (Zero Secret RBAC) │ Live Pods/Svcs/Endpoints vs Git values.yaml
└───────────────┬───────────────┘
│
▼
┌───────────────────────────────┐
│ agy Triage (AgyQueue, cap 1) │ 3-Way Verdict Gate:
│ gemini-3.8-flash-medium │ ├─ VERDICT: IGNORE -> close/no-op
└───────────────┬───────────────┘ ├─ VERDICT: ESCALATE_HUMAN -> issue only
│ └─ VERDICT: FIX_VIA_PR (requires HIGH conf)
▼
┌───────────────────────────────┐
│ Fixer -> PR -> CI + Reviewer │──► AUTO_MERGE=false: assigned to human owner
└───────────────────────────────┘
Three design choices in v0.5.x dramatically improved signal-to-noise:
- Cancellable
60sStabilization Soak: Rolling restarts, brief image pulls, or momentary scrape blips frequently self-recover inside a minute. EnteringSOAKINGforSOAK_DURATION=60sdrops duplicate firing payloads and aborts immediately if Grafana sends aresolvedwebhook—spending zeroagytokens and opening zero GitHub issues. - Pinned
helm v3.21.4+ Zero-Secret Read-Only RBAC: Installinghelm v3.21.4alongsidekubectlinside the container letsFetchDiagnosticBundlecompare live Deployments, StatefulSets, Services, Endpoints, Events, and PVCs directly against Gitcharts/vinhthang-fleet/values.yamland run realhelm lint/helm templatevalidation before invokingagy—whileClusterRole/ai-incident-commander-readerstrictly excludessecretsRBAC. - Strict 3-Way Verdict Gate &
AUTO_MERGE=false: Triage must emit an explicitVERDICT: IGNORE,VERDICT: ESCALATE_HUMAN, orVERDICT: FIX_VIA_PR. AnyFIX_VIA_PRbelowConfidence: HIGH—or anyagyexecution error—downgrades automatically toESCALATE_HUMANwithout invoking Fixer. Even when Fixer opens a PR and both GitHub Actions CI and the Reviewer pass it,AUTO_MERGE=falseleaves the final merge click to the human operator.
4. Scheduled 07:15 ICT Daily agy Fleet Audits
Reactive alerting only tells you what broke—not what is slowly drifting. In v0.5.0, we added an authenticated POST /daily-report endpoint guarded by single-flight execution and serialized through the same AgyQueue (async worker channel cap 1) so scheduled audits never contend with live incident triage.
Every morning at 07:15 AM ICT (15 0 * * * UTC), CronJob/ai-commander-daily-report triggers the endpoint using curlimages/curl:8.10.1:
curl -sS --fail-with-body --max-time 25 -X POST \
-H "Authorization: Bearer ${WEBHOOK_AUTH_TOKEN}" \
"http://ai-incident-commander.system.svc.cluster.local:8085/daily-report"
(A quick operational lesson captured in v0.5.2: omit -f when passing --fail-with-body in BusyBox/curl scripts so HTTP error bodies aren’t swallowed silently.)
The resulting read-only agy fleet health audit is published in two places simultaneously:
- Private Engineering Journal (Memos): Written directly into
MEMOS_DB_DSN(public.memo) so morning coffee starts with a concise cluster digest. - GitHub Issue Tracker: Filed as
[Daily Fleet Check] YYYY-MM-DD(labeleddaily-report), auto-closed immediately whenHEALTHY, or left open and assigned to the owner whenATTENTION_NEEDED.
Between v0.4.0 runtime sandboxing and v0.5.x diagnostic-first soaking, AI Incident Commander has matured from an eager PR generator into a disciplined, evidence-backed junior SRE that respects human sign-off and sleeps quietly through transient noise.