Coding Challenge on Debugging a Failing On-Call Agent
Explore how to debug a failing on-call agent by separating context rot, buried instructions, and conflicting runbooks. Use trace hooks, one-item ablations, repeated answer checks, and unit tests to identify the true cause and build a date-based filter for stale knowledge.
We'll cover the following...
In this chapter, we built a set of tools for understanding why a context goes wrong. We learned about context rot and the position debate, wrote four checks that label a failing trace, and built hooks and an ablation harness that prove which item caused a failure.
In this challenge, we’ll use all of them on one messy trace. The on-call assistant gave a wrong first step during a checkout incident. The trace contains three things that could each explain the mistake. Our job is to find out which one actually caused it, and then write a fix that a set of unit tests can confirm.
The failing incident
Here’s what happened. At 14:05, checkout latency spiked. The team’s incident channel filled up with alert messages, and partway through, the team lead posted a clear instruction: follow the May 2026 runbook (note-1) and don’t restart Redis today. Then someone asked the assistant our running question: “Checkout latency spiked at 14:05. What changed, and what should we roll back?”
The assistant answered: “Restart the Redis cache cluster first [note-4], then roll back the latest checkout deploy.” That’s the step the 2024 runbook recommends, and it’s exactly what the team lead said not to do.
The pre-inference snapshot for this call holds these parts:
Incident log: 16 channel messages. Fifteen are alert-bot lines about latency and error rates.
Buried instruction: The team lead’s message is entry 9 of 16, in the middle of the log.
Retrieved notes: The top five results from
search_documents(), including bothnote-1(May 2026) andnote-4(2024).Facts: The first two steps that
extract_facts()pulled from the notes.
Let’s rebuild this snapshot with the hook and pipeline code from the previous lesson, and run the classifier on it.
In the code above:
Line 6: We write the team lead’s instruction as one channel message.
Lines 7–8: We generate 15 alert-bot messages, first about latency and then about error rates.
Line 9: We build
INCIDENT_LOGby placing the instruction after the first eight alerts, so it lands at entry 9. ...