Agent in Production
ResilienceLong read

Post-Mortem Templates for Failed Coding Agent Sessions

Coding agents need post-mortems designed for behavioral failures, not just operational outages.

· 9 min read
Cover illustration for “Post-Mortem Templates for Failed Coding Agent Sessions”
Resilience · October 29, 2026 · 9 min read · 2,096 words

Post-mortem templates for failed coding agent sessions must record behavioral evidence, version lineage, and session cost as well as how service was restored. To prevent unexpected API bills, enforcement must stop execution before the next API call when a session budget is reached. Layered controls include per-request token limits, per-session rolling budgets, per-key monthly caps, model-tier routing, and spend-rate circuit breakers. Monitoring alone reports the loss after it happens.

Why standard SRE post-mortems leave coding agent failures unresolved

Filling out a standard SRE post-mortem after an agent incident exposes the mismatch immediately. The form asks what broke, when requests failed, and how service was restored. Yet the agent may have returned HTTP 200 throughout the incident while choosing the wrong path, citing stale context, or misusing a tool. There may be no outage to explain. The investigation instead needs to locate the first step where behavior diverged from the task.

CPU, latency, exceptions, and uptime may look normal after a prompt edit, a stale retrieval index, or an upstream model change quietly reduces output quality. The incident comes to light later through a billing spike, support queue, or compliance audit, after the state at the time of failure has changed. A report that concludes “the model behaved unexpectedly” records the symptom without identifying its cause. Getting service back up still leaves the cause unknown.

The five failure modes a coding agent post-mortem must be able to name

The taxonomy serves as a lookup between a failure mode, its place in the session lifecycle, and the evidence that can expose it. Context bleed occurs when information from one task or turn contaminates another, making the accumulated context the relevant record. Anthropic’s Apr 23 postmortem documented a related context-management failure in Claude Code. A Mar 26 caching bug turned a one-time clearing of “older thinking” into repeated clearing on every turn after a session had been idle for over an hour. The agent intermittently forgot information across the session.

Scope creep occurs when the agent expands its actions beyond the original task. Its intervention point is before tool execution, where a PreToolUse hook can block unauthorized calls. PostToolUse cannot undo an action already executed. Silent completion belongs at the other end of the lifecycle, when the agent declares success without completing the required work. In the PR-review example, pre-merge runs reported “review complete” with zero MCP tool calls because normal loop termination passed for success. An acceptance eval at completion can expose that gap.

Cascade error starts with an unexpected, partial, or corrupted tool response that poisons later context. PreToolUse and SubagentStop hooks provide inspection points for downstream actions built on that response, although a hook alone does not establish the diagnosis. Model drift is a change in how the agent behaves across sessions or deploys after a model, prompt, or retrieval corpus changes. It requires a golden eval tracked across deploys.

What makes an agent incident genuinely hard to reconstruct after the fact

The investigation asks which step was the last one where the agent remained on track. Answering it may require reconstructing 14 turns of accumulated context beyond the single failed request. At the divergence point, state includes the system prompt, conversation history, appended tool results, and available intermediate reasoning traces. Standard application logs do not preserve that whole state. When an action is syntactically valid but semantically wrong, a search through exception logs offers nothing useful.

Two evidence planes therefore have to survive the incident. The operational record contains availability, latency, exceptions, deployment and configuration events, infrastructure logs, and the alert and recovery timeline. The behavioral record contains the user goal, governing policy, observed outcome, messages, decisions, handoffs, tool calls, and side effects. It also preserves evaluator versions, human evidence, fix identity, and fresh production results. Neither plane substitutes for the other.

Version lineage connects those records to the system that actually ran. The same visible answer can depend on different prompts, model parameters, tool definitions, retrieved documents, routing paths, permissions, or policy versions. Without their identities, a later reproduction may test a different system. The post-mortem then appears specific while its causal claim remains unsupported.

The minimum telemetry that must be logged before an incident occurs

The preparation step is to instrument model calls before an incident occurs. Each structured event needs request_id, session_id, a timestamp, the model’s exact snapshot identifier, and the prompt template ID and hash. It also needs input tokens, output tokens, computed call cost, and latency. Retrieval document IDs belong in the event when retrieval is used. Tool calls and outcomes, finish reason, any error field, and a user-input hash complete the minimum record, with raw input retained only when policy allows.

Two omissions are especially damaging to later reconstruction. Without a prompt template hash, a quality shift cannot be correlated reliably with a template edit. Without retrieval document IDs, investigators cannot tell whether the model changed or the context it was given changed. A family name also fails to show which model snapshot ran. Readable labels are not version evidence on their own.

Structured events make these records usable after the fact. JSON to stdout is sufficient if a collector parses it into a queryable store that supports grouping by session and filtering by template hash and model version. The cost of each session must also be tracked by adding up its call costs. Per-call averages can conceal runaway fan-out within a session. Without that aggregation, the bill can reveal a failure that the telemetry obscures.

The fields a purpose-built agent post-mortem template must contain

Each section of the template below lists what to record and the evidence needed to back it up. One accountable owner should maintain it and write UNOBSERVED wherever a measurement was not collected. Zero and an estimate are not substitutes. Version drift, eval gap, and behavioral evidence extend the familiar blameless SRE structure.

Identity and ownership. Record the incident ID, behavior-and-impact title, status, owner, technical reviewer, severity rule, and durable record URL. Required evidence is the durable incident record and its ownership. Executive summary. Record three to five factual sentences covering user experience, affected workflow, mitigation, and what remains unverified. Required evidence comes from the supporting fields below.

Expected and observed behavior. Record what the agent should have done beside what it actually did, naming the failure mode and violated policy or product contract. Required evidence is a representative trace and the owning rule. Exact execution lineage and version drift. Record trace and run IDs, agent path, prompt hash, model snapshot, tool schema versions, permissions, retrieval document IDs, conversation history length, deployment identifier, and feature flags. Required evidence includes immutable identifiers for model, prompt, tools, platform, eval set, and guardrails, with deployment and last-validation times.

UTC timeline. Record timestamps, events, evidence, and decision owners from the first agent action through detection, containment, mitigation, candidate fix, deployment, and post-change observation. Required evidence is the corresponding event record. Detection and first causal step. Record the first signal, monitoring or eval gap, evaluator version, threshold, evaluator concerns, last correct step, first divergent step, and causal edge. Required evidence is the supporting trace, with failure category, fix type, owner, confidence, and counterevidence or an unresolved label.

Blast radius. Record affected systems, data, users, bad outcomes, impact window, privacy or safety implications, financial impact, and irreversible effects. Required evidence includes numerators, denominators, and source references for counts. Cost impact. Record total session cost and whether each of the five controls was present and fired, namely per-request token limits, per-session rolling budgets, per-key monthly caps, model-tier routing, and spend-rate circuit breakers. Required evidence distinguishes retrospective monitoring from enforcement that intercepted execution before the next API call.

Mitigation, corrective change, validation, and production verdict. Record these as four separate artifacts. Required evidence includes a mitigation receipt, reviewable change identity and exact diff with rollback target, a frozen reproduction compared against baseline, and a fresh-traffic result. Label validation Verified, Confounded, or UNOBSERVED, since getting service back up does not prove the fault was fixed. Follow-up actions. Record owners, due dates, and verifiable completion criteria, with evidence of completion.

How to use the template to trace a real failure from billing spike to root cause

A billing spike begins the investigation in the cost-impact field, where session totals expose which runs deserve inspection. The support-ticket example shows how to trace the failure from there, though it was detected when a support lead noticed longer, more hedged replies, with no measured billing increase. No alert had fired.

First, populate the timeline in a common time zone by querying per-call events grouped by hour over the preceding days, filtering on model_version and prompt_template_hash. The hash changes at a specific timestamp, and output length begins rising in the same window. That establishes a candidate relationship. Second, check the inputs by grouping events into coarse input categories. A shift across categories rules out the input-distribution explanation in this example and implicates the template change.

Third, retrieve the before-and-after templates using their stored hashes. The diff reveals an added hedging instruction that explains the changed replies. Fourth, fill in version drift to show that the model version stayed the same, the prompt hash changed, and the retrieval corpus stayed the same. The causal edge now has concrete supporting evidence. Fifth, revert the template and record a separate production verdict only after fresh traffic shows the quality signal returning to the reference window.

The n8n February 2026 incident illustrates why tool lineage belongs in the same investigation. Users upgrading from v2.4.7 to v2.6.3 encountered invalid function-calling JSON schemas from the Vector Store Question Answer Tool, which OpenAI and Anthropic both rejected. Enterprise production workflows stopped, and the fix was a version rollback. Tool schema versions were needed to find that failure.

Governance and compliance fields the template must carry in 2026

The governance requirement is traceability. An investigation must establish why an agent acted, what data it used, and which policies applied at execution time. The EU AI Act’s Article 12 requires automatic event logging for high-risk systems over their lifetime to support risk identification and post-market monitoring. The high-risk obligations originally scheduled for August 2, 2026 were deferred to December 2, 2027 for standalone Annex III systems. That distinction prevents a future obligation from being presented as universally operative in 2026.

The Singapore IMDA Model AI Governance Framework for Agentic AI, issued in January 2026, recommends verifiable agent identities and an audit trail linking actions to authorization. Compliance with the framework is voluntary, unlike applicable statutory duties. NIST’s Center for AI Standards and Innovation started an AI Agent Standards Initiative in February 2026. The NCCoE concept paper tied to the initiative points out what is missing when agents run as generic service accounts without their own identity, authorization, or accountability controls.

The practical template extension records agent identity, the authorizing human or trigger and permitted scope, governance interventions with timestamps and outcomes, and regulated-data lineage, including retrieval document IDs. Hard and soft gates belong in that intervention record, although Article 12 does not prescribe those categories. Fragmented logs leave cross-channel actions difficult to reconstruct. Google Threat Intelligence Group’s account of UNC6780 supply-chain compromises also connects this evidence to credential risk, making session identity and authorization security fields as well as governance fields.

Running agents on infrastructure that makes post-mortem fields collectable by default

The infrastructure must make the required evidence available without someone having to piece it together by hand. Local execution or a bare CI runner does not, by itself, provide session-scoped credentials, per-session cost enforcement, an immutable audit trail, or a sandbox boundary separating the agent from its host. A completed form cannot compensate for those omissions. The platform must create the record as the agent runs.

A managed platform should attribute every tool call, diff, and token to a session and a person or trigger. It should mint fresh session credentials and revoke them on completion, capture immutable prompt and model identifiers at session start, and expose an audit log queryable by session, template hash, model version, and time window. These are concrete selection criteria. They make the template fillable without relying on memory.

For budget cap enforcement and graceful shutdown, the supported requirement is a halt before the next API call once the session limit is reached, with a hard record that the control fired. A cost dashboard alone does not meet it. Agent configuration stored as YAML in the repository adds versioned commits for behavioral changes, preserving prompt and tool-schema lineage. Infrastructure that captures these identities and enforces these boundaries gives the post-mortem evidence to test recurrence and resolve a field marked UNOBSERVED.

Filed underResilience

More in Resilience