How to Catch and Replay Production Agent Failures: Trace-Native CI/CD in Practice
Why 100% CI Still Misses Agent Failures
Agent outages in production happen even with full test coverage, mocked APIs, and staged integration checks. We shipped a major outage past 100% CI, comprehensive Pytests, and simulated API responses. The reason: language agents break on scenarios that staged inputs and recorded mocks never exercise.
Case in point:
An e-commerce chatbot failed when a third-party inventory API returned a malformed response—but only for SKU-712, only outside working hours. The bot hallucinated "out of stock" on unrelated items. CI didn't catch it. Hours of lost revenue.
Static tests don’t simulate the real mix of user phrasing, API drift, or subtle agent prompt changes. Agents fail when a prompt changes tone, an endpoint adds a field, or a user typo slips through. Postmortems flag these failures days late—if users even report them.
Production Trace Dumps: The Only Reliable Black Box Evidence
Raw production traces are the only credible source for agent debugging. Here’s a real-world, sanitized trace from a travel assistant tasked to extract dates for flight search:
{
"input": "Book a flight to Paris leaving July 32",
"steps": [
{
"tool": "date_parser",
"input": "July 32",
"output": null,
"error": "date out of range"
},
{
"tool": "fallback_response",
"input": null,
"output": "Sorry, I couldn't find flights for that date."
}
],
"final_response": "Sorry, I couldn't find flights for that date.",
"expected_behavior": "Detect bad user input and suggest alternatives: e.g., 'There is no July 32. Did you mean July 31 or August 1?'"
}
All integration tests passed, but no test covered a typo like "July 32"—syntactically valid, semantically impossible. The fallback response silenced the real failure and eroded user trust. Only trace capture shows these edge failures. Attempting to postmortem after the fact results in partial reconstructions—too often missing prompt drift or hidden state.
Hermetic Regression: Tracely-ai Replays Real Failures End-to-End
Agent regression tests that just replay user messages quickly become brittle when prompts, APIs, or upstream models change. Tracely-ai solves this by replaying the full agent trace: every step, tool call, and token exchange, creating a hermetic environment that surfaces real regressions—not plausible ones.
Example using the trace above, runnable as an actual test:
tests/test_replay_production_failure.py:
from tracely_harness import TracelyReplay, assert_trace_matches
production_trace = {
"input": "Book a flight to Paris leaving July 32",
"steps": [
{
"tool": "date_parser",
"input": "July 32",
"output": None,
"error": "date out of range"
},
{
"tool": "fallback_response",
"input": None,
"output": "Sorry, I couldn't find flights for that date."
}
],
"final_response": "Sorry, I couldn't find flights for that date.",
"expected_behavior": "Detect bad user input and suggest alternatives: e.g., 'There is no July 32. Did you mean July 31 or August 1?'"
}
def test_july_32_trace_replay():
result_trace = TracelyReplay.run_from_trace(production_trace)
assert_trace_matches(result_trace, production_trace, strict=True)
assert "Did you mean" in result_trace["final_response"]
This does more than block reintroductions of old bugs. It can also assert forward progress—demanding that an improved fix lands before deploy, using the trace as the boundary of acceptance.
Enforce Trace Replays in CI/CD: Real Deploy Breaks Blocked, Not Documented
Trace-based regression is only valuable if enforced. Reviewing traces in incident postmortems doesn't protect future deploys. This is how to integrate trace-native regression in your CI/CD via GitHub Actions:
.github/workflows/trace-replay.yml:
name: Trace Regression Replay
on:
push:
branches: [main, release/*]
pull_request:
types: [opened, synchronize]
jobs:
trace-replay:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install tracely-harness
- name: Run Tracely regression tests
run: pytest tests/test_replay_production_failure.py
Any PR or deploy that regresses a real failure blocks immediately. Trace replays surface the changes no golden prompt set will catch—especially where agent logic, prompt churn, or dynamic tool routers rewrite experience on every deploy.
Trace Replay Surfaces Bugs Missed by Golden Prompts
Benchmarks show trace-native regression reveals breakage missed by input-only golden sets. The Apex Agent Reliability Benchmark found trace replay caught 37% more unique agent regressions across multiple agent frameworks. Emergent bugs from upstream LLM provider drift—like output schema changes—showed up in trace replays first because every tool call and intermediate state is covered, not just request/response boundaries.
Caveats:
- Data capture has real cost. You need to instrument trace capture on the critical path, handle PII scrubbing, and invest in secure trace transport.
- Replay isn't generative. It catches known failures, not theoretical futures. You'll still need input fuzzing and adversarial probes.
- Replay fidelity relies on complete state capture. If your trace misses latent context (prompt injections, external side effects), bugs can sneak by even with replay in place.
Despite these limits, trace-regression testing does what prompt sets and user-perceived QA cannot—defensively catching real-world breakage before customers do.
Conventional CI for agents is performative. Wire real production traces into trace-based regression tests with tools like Tracely-ai and close the reliability gap, fast. The overhead is minor compared to outage cost. If you run agents in production and want to actually retire root causes, route your next bug trace straight into CI.
Top comments (0)