July 15, 2026
What to Log When an AI Test Agent Replays a Failed Run and Still Can’t Explain the Failure
A practical observability checklist for AI test agents, including run evidence, replay logs, failure triage artifacts, and logging patterns that help teams debug failures that survive retries.
AI test agents can reduce the effort required to create and maintain tests, but they do not remove the hardest debugging problem in Test automation: a failure that survives retries, reruns, and even a replay attempt, yet still refuses to explain itself. The agent sees a mismatch, or a timeout, or a visual change, but when you ask for the root cause, the answer is often incomplete. That is not a failure of the agent alone. It is usually a logging problem.
When teams ask what to log when an AI test agent fails, they are really asking how to make the failure reconstructable. The goal is not to produce a giant blob of text. The goal is to capture enough run evidence, state, and context that a human, or a later agent, can separate signal from noise. In practice, that means treating every failed run like a small incident, with evidence, timeline, environment, and decision trail.
This checklist is for QA engineers, DevOps, SREs, and test infrastructure owners who need an observability model for agentic test workflows. It is especially relevant when the agent is doing more than simple assertion checking, for example generating steps, choosing locators, adapting waits, recovering from flaky UI behavior, or replaying a run to infer what happened. The focus here is on the artifacts that make failure triage possible, not on the agent’s internal prompt logic.
If a failure cannot be reconstructed from logs and artifacts, it is not really triaged, it is only guessed at.
Start with the failure question you are trying to answer
Before adding more logs, define what kind of uncertainty you need to reduce. A replay that does not explain the failure is usually stuck on one of these questions:
- Did the app behave differently than expected?
- Did the test agent take a different path than the original run?
- Did timing, data, or environment change between runs?
- Was the failure caused by the test itself, the infrastructure, or the application under test?
- Was the agent uncertain, overconfident, or incorrectly recovering from an earlier issue?
If your logs do not help answer at least one of these questions, they are not sufficient.
A useful mental model is to capture the test like an execution trace, not just a pass or fail event. In Software testing terms, observability is about making the system understandable from the outside, similar to how application observability uses logs, metrics, traces, and artifacts to explain behavior in distributed systems. For test automation, that means preserving the state of the test, the environment, and the application at the time of each important decision.
The core observability checklist for AI test agent failures
Use this as the minimum evidence set for every failure that survives a replay.
1. Run identity and execution context
Log enough information to identify the exact run and distinguish it from every retry or replay.
Capture:
- Unique run ID
- Test suite, test case, and agent version
- Trigger source, such as CI, manual execution, scheduled run, or API trigger
- Retry count and replay count
- Timestamp in UTC, plus timezone if local time matters
- Branch, commit SHA, or release version under test
- Build number, pipeline ID, and job URL
- Test environment name, for example staging, preview, or production-like sandbox
Why this matters: if a failure only happens on one branch, one environment, or one agent version, you need to see that immediately. Without run identity, logs from the original attempt and replay can be misread as the same event.
2. Environment fingerprint
The application may not be deterministic because the environment is not deterministic. Capture the parts that commonly change behavior.
Capture:
- Browser or app runtime version
- Operating system and architecture
- Screen size, viewport, and device emulation settings
- Container image tag or VM image ID
- Network conditions, if simulated
- Feature flags and experiment assignments
- Authenticated user role and permission set
- Locale, language, and time zone
- Seeded test data version or dataset snapshot ID
If the failure involves a dynamic UI, a feature flag, or access control path, the environment fingerprint is often the difference between a useful triage and a blind rerun.
3. Full step timeline with timestamps
A replay that simply says “step 7 failed” is not enough. You need a per-step timeline.
Capture for each step:
- Step index and human-readable name
- Start and end timestamp
- Duration
- Step type, such as click, input, assertion, wait, navigation, extract, or recovery action
- Locator or selector used
- Target URL or route
- Outcome, such as success, failure, skipped, auto-retried, or recovered
- Error class and error message
The timeline should make it obvious whether the agent was slow, stuck, oscillating between locators, or failing consistently at the same checkpoint. This is also where replay logs become valuable, because they can show whether the agent chose the same step sequence on the rerun.
4. DOM, accessibility, and visual evidence at failure time
When the agent cannot explain the failure, it often means the state of the UI was not captured well enough.
Capture:
- HTML snapshot or relevant DOM fragment
- Accessibility tree or role map if available
- Screenshot at the moment of failure
- Optional short screen recording for complex or nondeterministic flows
- Viewport and scroll position
- Element bounding boxes for the intended target and nearby candidates
- Visible text around the failing element
This is especially important when the agent used fallback locators or a visual model to identify a control. A screenshot alone may show the issue, but pairing it with DOM and accessibility data tells you whether the element existed, was hidden, was overlapped, or was simply not the element the agent thought it was.
5. Locator decision trail
For AI-assisted or agentic tests, locator choice is part of the evidence. If the agent searched for a button, found several candidates, and selected one, that decision should be auditable.
Capture:
- Primary locator used
- Fallback locators attempted
- Confidence score, if your platform exposes one
- Candidate count and selection criteria
- Whether the locator was stable, dynamic, text-based, role-based, or heuristic-driven
- Any locator change between original run and replay
This is where a lot of “mysterious” failures become explainable. The agent may have selected the wrong element because a duplicate control appeared, or a locator previously anchored by text now matched a different locale string.
6. Assertion context, not just assertion text
Assertions fail for different reasons, and the surrounding values matter more than the failure message itself.
Capture:
- Assertion name or ID
- Expected value, rule, or threshold
- Actual value observed
- Tolerance window, if applicable
- Raw extracted data, before normalization
- Preprocessing steps, such as trimming, case folding, or date conversion
- Whether the assertion was soft, hard, or conditional
For example, if a test checks that order total equals a specific value, log the displayed value, the API value, the currency, the rounding rule, and any hidden tax or shipping components. A pure mismatch message rarely explains whether the problem is in the test, the UI, or the backend response.
7. Network and backend evidence
Many UI failures are symptoms of API or backend issues. If your replay does not include backend context, you may misclassify an application issue as a flaky test.
Capture:
- HTTP requests and responses relevant to the failure window
- Status codes, response times, and retries
- Correlation IDs or request IDs
- API payload excerpts, redacted as needed
- Server-side error IDs if the application exposes them
- Upstream dependency failures, such as 5xx responses or timeouts
If you can correlate frontend failure time with API errors, you often save hours of guessing.
8. Agent reasoning breadcrumbs
This should be concise and structured, not a verbose chain-of-thought dump. You want enough to understand why the agent made a choice, especially when replaying a failure.
Capture:
- Why the agent moved to the next step
- Why it retried or backtracked
- Whether it used a fallback strategy
- Whether it detected an ambiguous state
- Whether confidence was low or conflicting signals were present
A short structured note such as “primary locator not found, used role-based fallback, two matches detected, selected first visible match” is often more useful than a giant text log.
9. Input data and mutation history
If the test creates, edits, or deletes data, the state of that data is part of the failure.
Capture:
- Test data seed or fixture ID
- Unique identifiers used in the run, such as email addresses or order IDs
- Mutations made during the run
- Cleanup success or cleanup failure
- Pre-existing record collisions
This matters a lot when replaying a failure. If the original run created data that the replay could not recreate, the failure may be data-dependent rather than app-dependent.
10. Artifact retention and linkage
The final piece is not a log line, it is a linkage strategy. Every artifact should be attached to the run and cross-referenced.
Capture:
- Screenshot path
- Recording path
- HAR file or network archive path
- DOM snapshot path
- Console log path
- Agent trace path
- CI job link
- Issue tracker reference, if one exists
If artifacts are scattered across buckets and build jobs without a common run ID, triage slows down immediately.
What to log on the first failure, before replay starts
The first failed run is usually the most valuable signal. Replays can add context, but they can also introduce drift. Before triggering replay, store the following verbatim from the failed attempt:
- Exact error message
- Final page URL
- Final screenshot
- Page source or DOM snapshot
- Current browser context, tab count, and active frame
- Last successful step
- Last action taken by the agent
- Wait conditions currently in progress, if any
- Unhandled browser console errors
- Network failures around the failure timestamp
This first failure bundle is your baseline. When the replay behaves differently, you need a clean before-and-after comparison.
What to log during replay attempts
A replay should be treated as a separate experiment, not a simple rerun. Log whether the agent is reproducing the same path or taking an alternate one.
Replay-specific fields to capture
- Replay ID linked to original run ID
- Same test version or different test version
- Same environment or different environment
- Whether the replay used the same seed and data snapshot
- Divergence point from the original run
- Locator differences between original and replay
- Assertion differences between original and replay
- Whether the replay introduced extra waits, refreshes, or recovery steps
A replay that succeeds is not a contradiction, it is evidence that the test or environment has hidden nondeterminism.
If the replay succeeds but still cannot explain the original failure, log the divergence point. That is often the most useful clue, because it tells you where path sensitivity begins.
A practical log schema for agentic failure observability
You do not need to build a perfect schema on day one, but you do need a stable structure. A simple JSON envelope with nested evidence objects works well across CI, object storage, and observability tools.
{ “run_id”: “run_018f2”, “replay_id”: “replay_0042”, “test_name”: “checkout_flow_guest_to_paid”, “agent_version”: “3.4.1”, “environment”: { “browser”: “chromium-126”, “viewport”: “1440x900”, “locale”: “en-US”, “timezone”: “UTC” }, “failure”: { “step”: 7, “type”: “assertion_failed”, “message”: “Expected confirmation banner to be visible” }, “artifacts”: { “screenshot”: “s3://artifacts/run_018f2/fail.png”, “dom”: “s3://artifacts/run_018f2/dom.html”, “network”: “s3://artifacts/run_018f2/network.har”, “video”: “s3://artifacts/run_018f2/video.mp4” } }
The exact fields matter less than consistency. Once your team agrees on a schema, triage gets much faster because every failure can be searched, grouped, and compared.
How to decide whether to log more or log differently
Not every failure needs more data. Some need better structure, and some need different coverage.
Log more when:
- Failures are intermittent across runs or environments
- The agent uses fallback locators or recovery logic
- The app has dynamic content, personalization, or experiments
- Test data is created on the fly
- Replay behavior is inconsistent with the original run
Log differently when:
- You have screenshots but no DOM
- You have step logs but no timing
- You have error text but no environment fingerprint
- You have one run’s artifacts but cannot compare against the replay
- You can see the symptom but not the preceding state transition
The key is to avoid over-logging low-value noise. A hundred extra lines of generic trace output are less useful than one structured event that explains a locator change or a backend timeout.
Common failure patterns and the logs that expose them
Flaky timing
Symptoms: pass on replay, fail on original run, or fail only on slower machines.
Log focus:
- Step duration
- Network response time
- Explicit wait condition
- UI state at the time of failure
- CPU or container resource pressure, if available
Wrong element selected
Symptoms: click succeeds, but the wrong page opens or the wrong action is triggered.
Log focus:
- Candidate locators
- DOM snapshot
- Bounding boxes
- Accessibility roles and names
- Locator selection rationale
Hidden app error
Symptoms: UI element is missing because the app failed silently.
Log focus:
- API failures
- Console errors
- Correlation IDs
- Feature flag state
- Server response bodies
Data collision
Symptoms: replay fails because original data was already consumed or mutated.
Log focus:
- Fixture IDs
- Unique test data values
- Mutation history
- Cleanup logs
- Pre-run dataset snapshot
Agent uncertainty
Symptoms: the agent tries multiple paths, but cannot justify the selection.
Log focus:
- Confidence or ambiguity signals
- Search candidates
- Fallback sequence
- Divergence from original path
- Recovery decisions
How Endtest-style evidence capture fits into this model
Teams evaluating agentic QA workflows often want a platform that keeps evidence attached to the run and makes it easy to inspect without assembling ten tools together. A practical example is Endtest’s AI Test Creation Agent, which uses agentic AI to generate editable, platform-native test steps from plain-English scenarios. The important observability lesson is not the generation itself, it is that generated tests still need clear run evidence and triage-friendly artifacts when they fail.
A useful model is to preserve the full execution context in a form that testers and developers can inspect without translating between formats. That means the replay is not just a second run, it is a packaged evidence set: steps, assertions, locators, screenshots, and environment context, all tied to the same run ID. Endtest’s documentation also describes the agentic approach in the platform’s advanced AI Test Creation Agent docs, which makes it a relevant reference point for teams exploring agent-assisted test authoring and maintenance.
The broader takeaway is simple. Whether you use Endtest, Playwright, Cypress, Selenium, or a custom agent stack, the evidence model should remain the same: capture enough context to explain the failure, not just observe that it happened.
A failure triage workflow that uses the logs well
Good logging only helps if the team uses it consistently. A lightweight triage workflow can make the evidence actionable.
- Confirm whether the failure reproduced on replay.
- Compare environment fingerprints between original and replay.
- Diff the step timeline, especially the divergence point.
- Inspect the screenshot, DOM, and accessibility tree together.
- Correlate browser errors with API and backend logs.
- Check test data mutations and cleanup status.
- Classify the failure as product, test, data, environment, or agent behavior.
- Capture a follow-up action, such as locator repair, wait adjustment, data reset, or product bug escalation.
If your team already has a failure triage workflow guide, link the new observability fields to that process. Logging and triage are inseparable. One without the other produces artifact hoarding.
Implementation tips for CI and test infrastructure owners
Emit structured logs from the runner
Write logs in JSON or another parseable format. Free-form strings are useful for humans, but structured fields are what let you query failures by step, locator, browser, or replay divergence.
Store large artifacts outside the log stream
Screenshots, videos, and network archives should live in object storage or artifact storage, with URLs or IDs in the log record. Keep the log record small enough to index and query.
Redact sensitive values early
If your tests touch account data, payment flows, or private user records, redact tokens, emails, session cookies, and personal data before storage. Use stable hashes or surrogate IDs where needed.
Keep the agent trace bounded
Agent reasoning logs should be enough to explain action selection, but not so large that they drown out the actual evidence. Prefer short structured decisions over long prose.
Make replay deterministic when possible
Replay is much more useful if you can freeze data, feature flags, random seeds, and environment versions. Even partial determinism improves diagnosis significantly.
A concise checklist you can hand to the team
When an AI test agent fails and replay still cannot explain it, log:
- Run ID, replay ID, test name, and agent version
- CI job, commit SHA, build number, and trigger source
- Browser, OS, viewport, locale, timezone, and feature flags
- Exact step timeline with timestamps and durations
- Locator decisions, fallback attempts, and confidence signals
- Screenshots, DOM snapshots, accessibility tree, and recordings
- Assertion expected versus actual values, plus normalization steps
- Network requests, response codes, correlation IDs, and backend error markers
- Test data IDs, mutation history, and cleanup status
- Original failure bundle and replay divergence point
- Artifact links that tie everything together under one run record
If you have those fields, you can usually determine whether the issue is a flaky test, a product regression, a data dependency, or a weakness in the agent’s recovery logic.
Final thought
The hardest failures in agentic QA are not the ones that crash loudly. They are the ones that survive retries and still leave the team asking what actually happened. The answer is rarely to add more generic logs. It is to collect the right evidence, attach it to the run, and make replay comparisons obvious.
If your team is standardizing observability for AI testing, build around the question, what do we need in order to explain this failure later? That mindset turns replay from a hopeful rerun into a useful diagnostic tool.
For more practical implementation detail, you can also pair this article with your internal observability checklist and failure triage workflow.