Cheat sheets

SRE, Incidents and Postmortems for AI

Triage LLM incidents with agents, gate every fix, write evidence-bound postmortems and compact logs for an assistant.

  • Concepts and terms
  • Tasks and commands
  • Annotated code
  • Diagrams
  • Comparisons
  • Defaults and numbers
  • Troubleshooting
  • Questions and tips

Source

Incident symptoms#

SymptomCauseFix
High error rate in checkoutvLLM OOM from KV cache spikeRestart pod. Lower --gpu-memory-utilization to 0.85
GPU memory at 98% before the spikeKV cache OOM under burst concurrencyApply runbook RB-017
Two models disagree on root causePossible hallucinated root causeEscalate with both hypotheses visible
Pod OOMKilled twice in 10mMemory request 256Mi too lowRequest 512Mi, limit 1Gi
CrashLoopBackOff on auth-svcProbe path changed to /readyRevert the probe path to /healthz
Image checkout-api:v2.41 fails /healthzBad rollout 14m agoRoll back to v2.40 after approval
blocked: no slack approvalDestructive tool with no approverGet the Slack card approved
Rare disk-full line lost from contextUniform sampling with budget 8Use the rarity policy

From 17.23 code/main.py, Lesson 17.23, 19.06 code/ts/src/agent.ts, Lesson 19.06, 19.06 code/main.py, log-volume-reduction-lab/README.md

Multi-agent triage#

1Supervisorbreaks the incident into sub-queries.2Log agentlog search. Finds the most common error pattern.3Metric agentPromQL. Finds the GPU memory spike before theerrors.4Runbook agentdoc retrieval. Matches a known runbook.5Supervisorgroups root causes. Two or more agents inagreement means confidence.6Humanapproves or redirects the hypothesis andevidence.7Actiona narrow safe action only, for example restartpod.

From Lesson 17.23, 17.23 code/main.py

K8s troubleshooting agent#

webhookalertwalklast 15mranked hypothesesapprovedappendclientAlert webhookPagerDuty orAlertmanagerprocessFastAPIreceiveraffected object,SLO breachmodelRoot-causeagentsample, walk,hypothesizestoreK8s knowledgegraphownership,schedulingstoreTelemetryslicesPrometheus,Loki, TempoclientSlack brieftop-3, approvalbuttonsprocessArgoCDrollback hookafter approvalstoreAudit logconsidered vsexecutedwebhookalertwalklast 15mranked hypothesesapprovedappendclientAlertwebhookPagerDutyorAlertmanagerprocessFastAPIreceiveraffectedobject,SLO breachmodelRoot-causeagentsample,walk,hypothesizestoreK8sknowledgegraphownership,schedulingstoreTelemetryslicesPrometheus,Loki,TempoclientSlackbrieftop-3,approvalbuttonsprocessArgoCDrollbackhookafterapprovalstoreAuditlogconsideredvsexecuted

From Lesson 19.06

Remediation scope#

FactorSafe, narrowNot safe, broad
Pods and codeRestart podDeploy new code
DeploysRevert a specific deployChange service topology
CapacityScale within pre-approved boundsModify resource limits
Config and accessEnable a pre-approved feature flagChange IAM, alter databases
RBAC verbsget, list, describedelete, exec, scale
Capstone toolskubectl_get, promql, logqlkubectl_delete, argocd_rollback
GateRuns at onceNeeds Slack approval

From Lesson 17.23, 19.06 code/main.py, Lesson 19.06

Postmortem packet rules#

Event
one JSONL row with id, second, kind and message.
Timeline
sort by second. Ties sort by ID.
Claim
nonblank text and at least one distinct known event ID.
Quote
each evidence ID needs an exact substring of its message.
Approval
approved needs a matching sourceSHA256 and a reviewer.
Action
state open, doing or done. Only open can have no owner.
Output
index.html, packet.json and packet.txt, written with 0600.

From solution/stage1.go, solution/stage2.go, solution/stage3.go, solution/integration.go, solution/main.go, postmortem-writer/README.md

Hypothesis score#

def score(self) -> float:
recency_w = max(0.0, 1.0 - self.recency_mins / 60.0)0 after 60 min
path_w = 1.0 / (1 + self.path_len)short graph path wins
return (recency_w * 0.35 +
self.specificity * 0.35 +0..1
min(len(self.citations), 5) / 5 * 0.2 +caps at 5 citations
path_w * 0.1)

From 19.06 code/main.py

Run the labs#

TaskCode
Multi-agent triage simulator, lesson 23code/main.py
K8s graph agent with approval gatepython main.py
Slack skeleton self-check, then testsnpm start and npm test
Slack interactive servernpm run serve
Postmortem packet from the examplesgo run . --events ../examples/events.jsonl --review ../examples/review.json --out /tmp/incident-packet
Build the log context toolrustc --edition 2021 main.rs -o /tmp/log-context
Compact logs, budget 8, rarity/tmp/log-context fixtures/burst.log 8 rarity /tmp/context.jsonl
Rare-template coverage reportpython3 main.py fixtures/burst.log /tmp/context.jsonl --out /tmp/coverage.json

From Lesson 17.23, 19.06 code/main.py, 19.06 code/ts/README.md, postmortem-writer/README.md, log-volume-reduction-lab/README.md

Limits in the code#

SettingDefaultNote
REPLAY_WINDOW_SECONDS60 * 5Older Slack requests are stale
SIGNATURE_VERSIONv0HMAC sha256 over v0:ts:body
rare_max2Rare template frequency
Log input size1_048_576Bytes, one MiB
Log records10_000Lines per input
Log line length4096Bytes per line
Event JSONL size2<<20Postmortem events
Claims and actions100Each, per review

From 19.06 code/ts/src/slack_verify.ts, solution/main.rs, solution/main.py, solution/integration.go

Error strings#

CommandWhat it does
review source changedReview hash differs from the events file
approval requires matching source and reviewerApproved claim with no hash or reviewer
quote for <id>Quote is blank or not in the message
budget exceededToo many events, claims or bytes
conflictDuplicate event ID or evidence ID
expected LEVEL<TAB>messageLog line has no tab
group count mismatchContext count differs from the source
invalid locatorfirstLine or lastLine is out of range

From solution/integration.go, solution/types.go, solution/main.rs, solution/main.py

Q&A#

What does the audit log record?
Every command considered, executed or approved, and who approved it.
What is the capstone bar?
At least 80% correct root cause on 20 synthetic incidents.
How fast is a hypothesis?
p50 under 5 minutes from alert to Slack brief.
Can prediction alone help?
No. Predictions without actuation are dashboards.
Does the packet prove the cause?
No. Provenance is checked. Causality requires review.
Uniform or rarity sampling?
Rarity. Uniform with budget 8 misses line 138.

From Lesson 17.23, Lesson 19.06, solution/stage4.go, log-volume-reduction-lab/README.md

Tips#

  • Write runbooks with symptom, hypothesis, verify and act sections.
  • Store runbooks and post-mortems in a vector DB for retrieval.
  • Before chaos, have SLI/SLO, observability, automated rollback, runbooks and on-call.
  • Hold a monthly game day. End it with a postmortem.
  • Pre-redact logs before you send context to an assistant.

From Lesson 17.23, Lesson 17.24, log-volume-reduction-lab/README.md