Skip to content

Simulation and Replay Testing for Agent Verification

Replay recorded tasks to collect regression evidence; a matching past result does not establish readiness for new tasks.

The problem

When you change an agent's instructions, how do you know the change improves output? Intuition and manual testing on new tasks are unreliable. New tasks have different context, different difficulty, and different success criteria. You cannot compare them cleanly to the previous agent's performance.

Simulation and replay testing uses recorded tasks as fixtures for bounded comparisons.

Why it works

Replay testing can hold recorded task inputs fixed for comparison. The merged output supplies a comparison artifact. Instructions are not necessarily the only variable: leftover files, caches, and resource conditions can affect trials (Anthropic's evaluation guidance).

Checking out a recorded commit restores recorded repository files (Git checkout). External task state needs separate capture; a completed tracker item differs from its original state (Warp). Environment state also needs separate treatment. Identical model inputs can still produce different outputs (Claude glossary). Use reconstructable factory run records to declare captured boundaries, missing evidence, and replay authority.

The technique

The core loop:

  1. Identify a task that was previously completed and merged — a recorded comparison artifact with known acceptance evidence.
  2. Roll back to the git state just before that task was completed (the "before" state).
  3. Replay the task using the updated agent instructions.
  4. Diff the agent's output against what was actually merged.

A matching result supplies regression evidence for this task. Require repeated trials and broader cases before promotion, following controlled factory experiments. Define acceptable differences before comparing outputs.

graph TD
    A[Identify past merged task] --> B[Checkout pre-merge git state]
    B --> C[Replay task with updated prompts]
    C --> D[Diff output vs merged solution]
    D -->|Matches or better| E[Collect regression evidence]
    D -->|Regression| F[Reject change / iterate]

Using worktrees for isolation

Git worktrees let you check out multiple working trees from one repository (git worktree add is a standard git feature since Git 2.5). A simulation runs in an isolated worktree, so it does not interfere with the main working directory or other parallel simulations.

# Create an isolated worktree at the pre-merge commit
git worktree add ../sim-test <pre-merge-commit-sha>

# Run the task in the isolated worktree
cd ../sim-test
# ... invoke agent with updated prompts ...

# Record the replay output in its own commit before this comparison
git diff <expected-output-commit-sha> <replay-output-commit-sha> -- <target-files>

Multiple simulations can run in parallel across separate worktrees — one for each prompt variant you evaluate.

What "better" means

Define success criteria before you run the simulation, not after:

  • Structural match — the output follows the same shape as the merged solution
  • Content match — key claims, code paths, or decisions align
  • Regression check — the updated agent does not omit things the original agent got right
  • Improvement — the updated agent catches something the original missed

Automated diff scoring (line count, structural similarity) is a starting point for flagging obvious regressions. You still need human judgment on the diff for qualitative assessment.

Regression testing agent behavior

Simulation replay is most valuable for regression testing:

  • After a prompt change that fixes a known failure, verify it does not break passing cases
  • After updating a skill file, replay several past tasks that used the skill
  • After tool configuration changes, verify the agent still reaches the correct outcome

A library of "golden" past tasks — completed, merged, and known-good — forms a regression suite for agent behavior, much like snapshot testing in software.

Integration with the content pipeline

In a content pipeline (research → draft → review → publish), simulation replay lets you test individual stage prompts:

  • Change the researcher's instructions → replay a past research task → compare findings against what was merged
  • Change the reviewer's format → replay a past review → compare structured output against the previous review

Each stage has an independently testable input/output boundary.

Limitations

  • Simulation tests past conditions, not future ones — novel task types may not be represented in the golden library
  • Replay is not deterministic: the same agent instructions on the same task may produce different output on each run. Even at temperature 0, outputs remain only "mostly deterministic" because floating-point non-associativity on parallel GPU kernels shifts logits across runs (Feng et al., 2025, Get Experience from Practice: LLM Agents with Record & Replay; OpenAI Developer Community: Clarifications on temperature = 0)
  • A "better" output is easier to define for structured tasks (code, structured documents) than for open-ended ones
  • Naive record-and-replay of agent executions has its own failure modes: too-concrete replays break on minor context drift, while too-abstract replays lose task-specific detail. AgentRR (Feng et al. 2025) argues that reliable replay needs a trust-anchor check function to verify preconditions before replay is allowed to apply — prompt-diff replay as described here is a lightweight analogue and carries the same risk when the upstream context (tools, skills, repo state) has shifted since the golden run was recorded

Key Takeaways

  • Use past merged tasks as test fixtures — check the merged solution against current acceptance criteria
  • Worktrees provide isolation for replay runs without affecting the main working directory
  • Define success criteria before running the simulation to avoid post-hoc rationalization
  • Parallel simulations across worktrees let you test multiple prompt variants simultaneously
  • Build a library of golden past tasks to form a regression suite for agent behavior

Comparing recorded outputs

Keep the expected-output commit and the new replay-output commit as separate identifiers. Comparing the pre-task commit with the historical merge only displays the old patch. It does not inspect the replay result. Record new files in the replay commit too; a comparison that omits them cannot assess the full output.