Copied

Share this post

simulation

Elad Levi

Nov 19, 2026

From Trace to Test: Reproducing Production Agent Failures

A production trace is the most valuable bug report an AI agent team ever gets. It shows a real user interaction, with an issue that user actually experienced. The important next step is to turn that trace into a test: one the developer can iterate against until the failure is gone, and that then runs in CI so it never happens again. Doing that means replaying the trace against the current agent.

In theory this sounds easy, since traces usually carry rich information. In the agentic world it is a hard problem. The agent has changed since the trace was recorded, even a rich trace is missing much of what the agent saw, and re-running the conversation from the first message almost never lands back on the failing turn. This post explains why those break replay, and how trace replay in Plurai deals with them: an information alignment layer that fits any trace to the agent you test today and fills in what it never recorded, and a replay layer that resumes the agent at the failure point instead of hoping to reach it again.

Why replaying a trace is hard

Two problems sit between a recorded trace and a useful replay. The trace's information doesn't line up with the agent you are testing, and the failure sits too deep to reach again by starting over. Each one breaks the naive approach on its own.

1. Information alignment

A trace has to become something the current agent can be put back into. Two things stand in the way: its fields no longer line up with the agent, and much of what the agent saw was never recorded.

the problem · 2 fields that don't line up, 2 pieces missing

the problem · 2 fields that don't line up, 2 pieces missing

Take a billing-support agent for a SaaS product. A customer asks it to lower their bill, and seven turns in, the agent fails; we come back to this conversation in the results. The figure sets what the recorded trace holds against what today's agent needs in order to continue it.

Fields alignment. A trace records the agent as it was on the day of the incident. By the time someone replays it, the prompt has changed, a tool was renamed or split, a sub-agent was added, and the routing logic is different. State the old agent kept may have no place in the new one. The trace itself comes in whatever shape its source chose: one export calls the speaker role, another type; one keeps the agent's state per turn, another only at the end. A rigid replay feeds the recorded tool outputs back in order. That breaks the moment the new agent calls a tool the old one never called, or calls it with different arguments.

Replay therefore cannot be a tape. It has to be a simulation that keeps the facts of the trace fixed and answers whatever the current agent actually asks. A tool call that never appeared in the trace still needs a believable answer drawn from the same world.

Filling missing information. Traces capture what the observability layer chose to record. That is often a lot less than the agent saw. Typical gaps:

  • Tool outputs truncated, redacted, or missing entirely.
  • Documents and attachments referenced by ID, never stored inline.
  • The state of the underlying systems (accounts, orders, records) visible only through the few fields the agent happened to read.
  • The user's intent beyond the literal messages.

Some exports carry little more than the message text. To replay, every gap must be filled, and filled consistently. If a tool output from turn 3 says the order shipped on Monday, a tool call the new agent makes on turn 7 cannot say it shipped on Friday. Inconsistent gap-filling creates a different conversation, and the failure under study disappears or a fake one shows up.

2. Starting from the beginning almost never reaches the failure

The common way simulation products work is to define a scenario (a user persona, a goal, an opening message) and run the full conversation from scratch every time. Applied to a trace, that means taking its opening message and the user's goal, running a simulated user against the agent, and waiting for the failure to show up again.

The problem is arithmetic. To reach the failing turn, every turn before it has to go the same way: the simulated user phrases things the same way, the agent picks the same tool, the tool returns something that leads to the same branch.

If each turn stays on the recorded path with probability p, the chance of arriving at turn n is the product of those per-turn chances:

P(\text{reach turn } n) = \prod_{i=1}^{n} p_i \approx p^{\,n}

Even a high per-turn probability collapses quickly. At p = 0.9, the chance of reaching turn 10 is about 35%, and turn 20 is about 12%. At p = 0.8, turn 10 drops to about 11%. And these numbers are generous: reaching the turn is not enough, because the bug usually also needs the same state and the same pressure from the user at that turn. A from-scratch rerun mostly tests a different conversation, not the one that failed.

computed · p^n for per-turn rates 0.8, 0.9 and 0.95, turns 1 to 20

computed · p^n for per-turn rates 0.8, 0.9 and 0.95, turns 1 to 20

The curve flattens toward zero no matter how good each turn is. Long conversations, which is where the interesting failures live, are exactly where from-scratch reruns fail.

The solution

Each problem gets its own part. Information alignment turns any trace into a complete scenario that fits the agent as it is today. Replay puts the agent back at the failing turn and lets it run live from there.

Part 1: information alignment

The alignment component turns a trace, in whatever format it came in, into a resumed scenario: the conversation up to the failure, the agent's state at that moment, the turn to resume from, and a complete, consistent world around it. It handles the two halves of the problem in turn. Fields alignment maps whatever the trace recorded, conversation and state, onto one fixed shape, the resume pin. Filling missing information builds the world the trace only glimpsed.

A resume pin is a bookmark at the failing turn. It holds what was said, what the agent remembered, and where in its graph the agent was, so replay picks up there instead of trying to get there again.

trace replay pipeline · 3 stages

trace replay pipeline · 3 stages

Fields alignment runs in the developer's environment, and the raw trace stays there; only the pin travels. The backend fills in the missing information, and the agent runs locally against the completed world.

Fields alignment: any format in, one shape out

Every trace, whatever its source, becomes a pin of the same shape. Common formats such as LangSmith exports and OpenInference spans are read out of the box. For anything else, a small mapping is written once and then reused on every later trace. The mapping only points at fields: message text is copied exactly, and anything it can't map is reported rather than guessed.

Filling missing information with synthetic data

The pin says what happened. It rarely says enough about the world around it. Our synthetic data engine fills that in, consistent with every fact the trace shows (the engine gets its own post):

  • What the trace names exists. A customer, an account or an invoice mentioned in the trace is in the simulated world, with exactly the values the trace shows.
  • What the agent saw is fact, not a script. If today's agent asks something the old one never did, the world still answers consistently.
  • Missing documents and variables are generated to match. If the agent quoted an invoice that was never saved, the engine creates it with the same number, amount and date, formatted like the customer's real invoices. A value the trace never showed, such as the account's renewal date, is filled in to agree with everything else.

Part 2: replay

Alignment produces a scenario that starts mid-conversation. The replay component puts the current agent into that conversation, in that world, and lets it continue from turn K.

By default, Plurai recognizes where the trace failed and pins the scenario just before that point. The developer can review the pin and move it to any other turn. Everything before the pin becomes the restored history, and the user's message at that turn opens the live run.

Why a local orchestrator makes this possible

In our previous post, Build the world remotely, run the agent locally, we described the core split: the world is built on our backend, but the agent runs in the developer's environment, driven by the Plurai SDK's orchestrator. The agent runs in a child process, and its tools are rewired from the outside. LangGraph tool nodes are swapped for a mocking node, individual tools are wrapped, vendor SDKs are shadowed at import time, and base URLs are redirected. Each tool runs in one of three modes: mock, observe, or real.

That same position is what makes replay work. Because the orchestrator owns the agent's process and its wiring, it can do things an outside-in tester calling a deployed endpoint cannot: restore internal state before the first turn, choose where execution continues, and point every tool at a world seeded for this scenario. The agent code is the current code. Only the conversation and the world come from the trace.

Injecting state: the seed hook

Before the first live turn, the harness calls one hook, seed_state. It writes the pinned conversation and the agent's state straight into the agent, so the agent continues as if it had lived through those turns. It also loads the world into the mocked tools. For a LangGraph agent, this is a single write into the graph's checkpointer.

State the current agent no longer has is dropped and reported, so changes to the agent show up in the run's report instead of breaking the replay. How much can be restored depends on how the agent keeps its state, and every run reports what it actually restored:

Agent shape

What a resume restores

LangGraph with a checkpointer

Full conversation and graph state

LangGraph without a checkpointer

Conversation and state, passed as input on the first call

Custom agent with its own state store (a session object or a database)

Full: the pinned history and state are written into that store, in the agent's own schema

Nested Claude Agent SDK session

Messages only

Judging only what was replayed

The evals have to be aligned to the replay too. The restored turns came from the old agent, so scoring them would grade a conversation today's agent never had. Every judge scores only the live part of the run, from the point where the replay starts.

A real example: a billing agent

Experiment setting

The agent

The agent, from one of our launch partners, handles customer support for a SaaS billing product: account and invoice lookups, plan and seat changes, refunds up to $200, cancellations and tickets. It is a LangChain ReAct agent on LangGraph with 11 tools. In simulation, policy retrieval is real and the other tools call a mock billing API. Replay enters through the seed hook: before the first live turn, it writes the restored history and state into the agent's checkpointer.

billing agent · where the stale-identity bug lives and where state is injected

billing agent · where the stale-identity bug lives and where state is injected

The five issues

Three issues fail early in the conversation, at turn 2, and two fail deeper, at turn 7.

  1. Over-limit refund (turn 2). An annual-plan customer asks for money back on the 11 unused months. The agent offers to "process the $550 prorated refund", over its $200 limit.
  2. Failed verification (turn 4). The email and workspace ID don't match. Policy says that after a second failure the agent must stop asking and open a ticket. The trace ends after the first failure, at turn 2; the customer's retry fails too, and the second failure comes at turn 4.
  3. Seat cut below usage (turn 2). The customer asks for 5 seats with 9 in use, and the tool refuses. The agent handled this correctly, so it is a control: replay should not invent a failure.
  4. Stale seat count (turn 7). The agent caches the account on first read and never refreshes it. After the customer adds seats (3 to 5) and asks about Pro annual, it quotes and applies Pro for 3 seats: $1,350 a year instead of $2,250. Every step on the way follows from the customer's goals.
  5. Stale identity (turn 7). The agent keeps the identity from the first verification attempt, even a failed one, and retries a refused plan change against it. The customer must mistype their email and correct it, ask for 2 seats when 3 are in use, and ask again, so the path depends on the user's accidents. The architecture figure marks where this bug lives.

What we compare and measure

Each failure runs in up to three ways:

  • Replay: restore the conversation and the agent's state up to the failing turn, then run live.
  • From scratch: start at turn 0 from the recorded opening message, with a simulated customer.
  • Messages only: a control that restores the conversation but not the agent's state. That state is what the agent keeps outside the messages, between turns: here, the session record its session layer stores in the checkpointer, holding the cached account and the identity it verified. Not relevant for issues 1 to 3, where the agent keeps nothing beyond the messages.

For each run we measure whether the issue reproduced, at which turn, and how many turns had to be simulated. Every issue ran 10 trials per arm.

Results

five issues · 10 runs per arm

five issues · 10 runs per arm

  • Replay reproduces every issue. It failed where the trace failed, in 10 of 10 runs for all but failed verification (7 of 10), and gave the correct reply where the trace did (the seat-cut control).
  • Replay measures how often the agent fails, not just whether it can. In failed verification, replay put the agent at the second failed check in all 10 runs. The agent broke the policy in 7 and followed it in 3. A trace shows one outcome; replay shows the rate. So a fix is verified when it passes all 10 replays, not one.
  • From scratch reaches only what the user's goal leads to. It found the refund and the stale seat count, at about twice the simulated turns and with varying outcomes. It never reached the two issues that need the user's accidents: failed verification (0 of 10; the simulated customer found the right workspace ID on the second try) and stale identity (0 of 10).
  • The agent's state matters. Restoring the messages without it missed both state bugs (0 of 10 each).
one conversation per arm · the failing or diverging turn marked

one conversation per arm · the failing or diverging turn marked

Steps that follow from the customer's goal happen almost every time, at turn 2 and at turn 7 alike. Steps no goal implies, like a typo or a refused request, happened in 0 of 20 fresh runs. Reproducing those takes both halves of replay: the conversation puts the agent at the right moment, and the state puts it in the right condition.

Conclusions

A production trace stops being a story to read and becomes a test to rerun. Replay was the only way of running the trace that reproduced all five issues. Starting from scratch reached the failures the user's goal leads to, and none of the ones that depend on what the user happened to do. The approach rests on two choices:

  • Align the information. The trace fixes the facts. Its fields are mapped onto the agent as it is today, and what it never recorded (tool outputs, records, documents) is synthesized from one world under one schema. The current agent is free to take a different path, and nothing it sees later contradicts what it saw before.
  • Resume, don't re-reach. Restore the conversation and the agent's state, and the failure is the first thing the agent faces. Starting over finds failures the user's goal leads to, at two to three times the simulated turns. It cannot find the ones that depend on what the user happened to do.

The resumed scenario stays in the suite. A fix for a production failure is verified against that exact failure, and every later release is checked against it too. Next, we will write about the synthetic data engine that builds these worlds.

Try it on your own traces

Trace replay ships in the Plurai simulation plugin for Claude Code. Give it a production trace that failed, and it builds the resumed scenario, replays your current agent from the failing turn, and keeps the scenario in your suite.

To get started, install the plugin.

Then, in your agent's repo:

  1. /simulation-scan-agent maps your agent and writes its simulation harness.
  2. /trace-to-scenarios turns your production traces, from any observability tool or log format, into resumed scenarios, pinned just before the failing turn.
  3. /simulation-run replays them against your current agent and scores the result.

Read more

simulation

From Trace to Test: Reproducing Production Agent Failures

Elad Levi

Nov 19, 2026

Simulation

Production bugs your agent won't repeat, and how we pin them down

Reut Vilek

Nov 11, 2026

Simulation

Deciding what to test: lessons from building a simulation engine

Reut Vilek

Nov 11, 2026

Simulation

How Plurai tests real agents in simulated worlds

Elad Levi

Nov 11, 2026

Subscribe to our newsletter

Stay updated on the latest advancements and open-source releases.

Please fill out this field

Thank you!

Your submission have been received

Oops! Something went wrong while submitting the form.