To review an agent-written UI failure, preserve the first failing attempt, collect a Playwright trace on the first retry, and classify the result before asking the agent to change code. Open the saved trace with the Playwright CLI, compare the action timeline and rendered state with the test contract, and attach only bounded review metadata. The trace tells you where the observed browser state diverged from the expectation; it does not, by itself, prove that the patch is safe.

A retry that passes is still a changed outcome. Keep the original failure visible, distinguish a flaky test from a product defect and from a broken test environment, and make the next action follow that classification. Playwright documents first-retry tracing for CI and provides a trace viewer for inspecting the saved evidence. This workflow turns those features into a review boundary for coding-agent UI changes.

Last reviewed: December 3, 2026 (Asia/Shanghai; official references re-fetched December 2, 2026 UTC).

Record the failure contract before rerunning

Start with a short contract for the changed browser behavior. Record the test title, patch revision, browser project, route, initial state, action under test, expected result, and the evidence that will decide whether the patch is acceptable. Also record whether the failure is expected to block the merge or whether it belongs to a known, separately owned quarantine.

Do not begin by rerunning the whole workflow. A browser failure can represent an incorrect UI state, a locator that no longer describes the intended control, a timing race, a failed dependency, or a runner problem. A full rerun can erase the narrow evidence needed to tell those cases apart. The site’s flaky-test classification guide provides a related rule: preserve each attempt before deriving an aggregate result.

For UI changes, write the state explicitly. For example, a task may require a generated error panel to be visible after a failed save, the toggle to expose its details, and the focus indicator to remain usable. That is more useful than a generic instruction such as make the page pass. If the patch changes accessibility behavior, pair the trace with the site’s accessibility review guide ; a trace can show what the browser rendered, but it cannot replace a human accessibility check.

Configure traces where the failure can teach you

Use a bounded retry policy in CI and enable tracing on the first retry. A minimal Playwright Test configuration is:

import { defineConfig } from '@playwright/test';

export default defineConfig({
  retries: process.env.CI ? 1 : 0,
  use: {
    trace: 'on-first-retry',
  },
});

With one CI retry, the initial attempt preserves the original failure while the retry records a trace for the same test. That gives the reviewer a diagnostic artifact without recording a trace for every successful test. Playwright also documents retain-on-failure for suites that do not use retries: it records traces and removes them from successful runs. Use on-all-retries only when the extra attempt history answers a specific question, because more artifacts increase storage and review cost. Recording every test with trace: 'on' is generally too expensive for a normal merge gate.

Keep the trace setting in the repository’s reviewed test configuration rather than hiding it in an ad hoc CI command. Record the selected browser project and retry count with the review. If the agent changes the configuration while repairing the test, review that change as part of the patch: disabling traces, increasing retries, or narrowing the project can make a failure disappear without fixing the UI.

Make the browser state reproducible

A trace is most useful when the test reaches a deliberate state before the assertion. Use locators and readiness assertions rather than an arbitrary sleep. Attach a small context record before the failure-prone assertion so the report explains what the test intended to prove without copying the page or user data.

import { test, expect } from '@playwright/test';

test('opens the generated error details', async ({ page }, testInfo) => {
  await page.goto('/settings');
  await testInfo.attach('review-context', {
    body: JSON.stringify({
      route: '/settings',
      state: 'error-details-open',
      expected: 'error details visible and toggle expanded',
    }),
    contentType: 'application/json',
  });

  await page.getByRole('button', { name: 'Show details' }).click();
  await expect(page.getByRole('region', { name: 'Error details' })).toBeVisible();
  await expect(page.getByRole('button', { name: 'Show details' }))
    .toHaveAttribute('aria-expanded', 'true');
});

The expected result is not merely a passing exit code. The test should reach the named route and state, then establish the visible region and expanded control. If the click itself times out, the trace should help determine whether the control was absent, hidden, disabled, covered, or never reached because navigation failed. If the control is visibly correct but the locator is wrong, the test contract needs repair rather than a production change.

Keep state setup deterministic. Use stable fixture data, explicit network or service readiness, and the same browser project for the base and candidate revisions. Do not put credentials, cookies, full HTML, typed user input, or raw response payloads in the attachment. The context record should be enough to identify the intended state, not a second copy of the application.

Replay the trace and classify the divergence

After CI produces the artifact, replay it locally with the saved path:

npx playwright show-trace path/to/trace.zip

Playwright’s Trace Viewer presents the test actions alongside a filmstrip and captured browser state. Start at the first action that differs from the contract, not at the final assertion. Check the navigation result, the locator target, the actionability state, the rendered DOM snapshot, and the point at which the expected state stopped being true. Then compare the trace with the first attempt’s error and the retry’s outcome.

Use a classification such as the following:

Evidence in the traceClassificationNext action
The expected control never renders or renders the wrong stateProduct or integration defectKeep the merge blocked and give the agent the route, state, expected result, and first divergent action.
The control is present, but the locator describes the wrong elementTest contract defectRepair the locator only if it matches the intended user-facing control; rerun the original failure fixture.
The state changes after an unbounded wait or guessed delaySynchronization defectReplace the delay with a state-specific readiness assertion and verify the failure path again.
Navigation, service, console, or browser setup fails before the UI assertionInfrastructure or dependency failureClassify the run as inconclusive, preserve the artifact, and compare a matched base run before changing product code.
The first attempt fails and the retry passesFlaky observationKeep both attempts, run the same test on the base revision, and require an explicit merge decision.
The trace or report is missing, unreadable, or attached to the wrong attemptEvidence failureDo not call the test green; repair artifact collection before relying on the result.

A trace can narrow the cause, but it does not establish causality by itself. A retry may pass because the service recovered, the timing changed, or the browser began with different state. If the candidate fails while the base passes under matched inputs, the patch is a stronger suspect. If both revisions show the same flip, investigate the test or environment before assigning the defect to the agent’s code.

Attach bounded evidence to the review

Keep the report small enough for a reviewer to inspect. An allowlisted record can contain the test title, patch and base revisions, browser project, attempt number, retry count, route name, state name, expected outcome, observed classification, trace artifact path, and the command used to open it. Add the runner version and service fixture identifier when they are needed to reproduce the result.

Use testInfo.attach for a compact JSON record or a deliberately selected text file. Playwright documents attachments as part of the test result, and its reporter documentation says every attempt of an included test is retained, including successful retries. That means a fail-then-pass result can remain visibly flaky instead of being flattened into a green summary.

Do not attach a complete DOM dump by default. It may include account names, tokens rendered into a page, private identifiers, or large unrelated payloads. Prefer the state label, selector or role under review, expected and observed values, and a pointer to the trace. If deeper inspection needs a screenshot or network artifact, add only the narrow file needed for the decision and apply the repository’s redaction policy first.

The artifact itself must be part of the merge contract. A missing trace is not proof that the test did not fail. A report that contains only the final retry is incomplete. A reporter that cannot preserve the attempt relationship should be treated as an infrastructure limitation, not as evidence that the patch passed.

Decide whether the agent patch is safe

Use the classification to choose the repair boundary:

  • First attempt passes: retain the normal result and run the required suite. For a high-risk UI change, still inspect the changed state rather than assuming an untouched path proves the interaction.
  • First attempt fails and the retry fails: keep the merge blocked. Give the agent the smallest reproducible state and require a repair that preserves the original assertion.
  • First attempt fails and the retry passes: label the test flaky, retain both traces or attempt records, and compare the base revision under the same browser and fixture settings. Do not silently promote the retry to passed.
  • The trace shows the expected UI but the assertion is obsolete: update the test only when the requested behavior and the user-facing contract changed. Record why the assertion changed and show that the old failure was understood.
  • The trace shows an environment failure: stop product diagnosis until the browser, service, fixture, or artifact pipeline is healthy. A green rerun after an infrastructure repair does not validate the agent patch retroactively.

When the agent proposes a fix, rerun the original failure case before accepting a broader suite result. Then run the changed-state matrix and review the new trace policy. A patch that fixes the page by removing the assertion, broadening a locator, adding a long timeout, or disabling retries has changed the evidence contract and needs separate review.

Failure modes that should block approval

Recording every test forever. Full tracing can increase runtime, storage, and report noise. Start with first-retry traces or retain-on-failure and expand only for a documented investigation.

Treating a retry pass as a clean pass. The changed outcome is itself evidence. Keep the failed attempt, classify the test as flaky until the cause is understood, and preserve the merge decision.

Using sleeps as state proof. A delay may hide a race on one runner and fail on another. Wait for the specific route, role, attribute, or response condition that defines readiness.

Dumping sensitive browser state. Full pages, headers, local storage, and screenshots can expose data unrelated to the defect. Attach the smallest sanitized artifact that answers the review question.

Letting the agent optimize for the test. A removed assertion, disabled trace, altered retry count, or broad locator can make the report look healthier while weakening the contract. Review test and configuration changes with the same care as UI code.

Comparing unlike runs. Changing browser version, fixture data, concurrency, dependencies, or service readiness between base and candidate makes attribution weak. Record those inputs before deciding that the agent caused the failure.

Sources checked

Reader next step

Choose one recent coding-agent UI failure and write its state contract before rerunning it. Enable one CI retry with trace: 'on-first-retry', attach a redacted context record, and replay the first divergent action in Trace Viewer. Classify the result as product defect, test-contract defect, flaky observation, infrastructure failure, or missing evidence. Then require the agent’s repair to rerun the original failure fixture and the changed-state matrix without weakening the assertion or hiding the artifact.