ankit.pandey
Back to SDET Engineering Journal
AGENT-05EXPERIMENTAL•14 min read•Staff / Architecture

AI Playwright Failure Investigation Agent: From Red Build to Root-Cause Diagnosis

Automating root-cause analysis by correlating Playwright traces, NestJS terminal logs, and PostgreSQL query state.

#Root Cause Analysis#Observability#Trace Correlation#Defect Triage

01. The Problem

When a complex end-to-end test fails in CI, developers spend hours digging through disparate log streams (browser console, server stdout, Docker Redis logs, Postgres query logs) trying to understand what went wrong.

02. The Concrete Engineering Scenario

A nightly Playwright transfer test fails intermittently on CI with 'Error: Timed out waiting for transfer status COMPLETED'. Is it a frontend polling bug, a BullMQ queue stall, or a database dead-lock?

Agent Role Definition:

Acts as a Forensic Debugging agent that correlates timestamped Playwright network traces, backend application logs, and database transaction queries to pinpoint the exact failure mechanism.

03. Context & Inputs Provided to Agent

  • •Playwright Trace archive (network requests, console errors, DOM snapshots).
  • •NestJS application container logs during the test window.
  • •PostgreSQL query log showing transaction locks and status updates.
  • •Redis BullMQ job event stream.

04. Agent Reasoning & Planning Steps

Step 1: Timestamp Correlation — Synchronizes client browser click timestamp with server API request log.
Step 2: Distributed Trace Inspection — Follows the transfer request: NestJS controller (201 Created) -> Redis queue.add() -> Worker job pickup.
Step 3: Root-Cause Detection — Discovers that the BullMQ worker crashed on simulated partner bank timeout and caught the exception without updating the DB status.
Step 4: Report Synthesis — Compiles an authoritative Defect Dossier with exact line numbers.

Playwright Interaction

Extracts action metadata from Playwright's trace.playwright.dev artifact format, identifying the exact assertion that timed out.

Evidence Collection

Generates an aggregated timeline showing: T+0ms UI Click -> T+120ms API 201 -> T+150ms BullMQ Enqueue -> T+2100ms Worker Error -> T+5000ms UI Timeout.

05. Concrete Code Excerpt

Correlated Timeline Report Output
=== AUTOMATED FORENSIC TIMELINE ===
[12:04:12.102] [BROWSER]   User clicks "Confirm Transfer" (btn_transfer_submit)
[12:04:12.215] [BACKEND]   POST /api/v1/transfers returned HTTP 201 (TxID: 88f2a)
[12:04:12.228] [DATABASE]  INSERT INTO transactions status='PENDING' (Commit OK)
[12:04:12.240] [BULLMQ]    Job 'transfer-88f2a' enqueued to transfersQueue
[12:04:14.350] [WORKER]    FATAL: Partner banking simulation timed out
[12:04:14.355] [DEFECT]    TransfersProcessor caught error but omitted wallet refund (WP-QA-001)
[12:04:22.215] [BROWSER]   Assertion timeout: expected status 'COMPLETED', received 'FAILED'

Failure & Edge Case Handling

Differentiates between test infrastructure issues (e.g., container ran out of memory) and genuine product defects (e.g., WP-QA-001 refund gap).

Measurable Result

Pinpoints the root cause in 8 seconds, identifying that TransfersProcessor failed silently on simulated network dropouts, drafting a complete bug report for Jira.

Human Review & Approval Gate

Staff SDET validates the finding, confirms the reproduction steps, and links it directly to the known-defect regression suite.

Key Engineering Lessons Learned

Lesson 01

Correlating browser traces with server-side logs is the only way to debug asynchronous distributed workflows.

Lesson 02

Attaching transaction IDs and correlation IDs to Playwright test metadata makes automated forensic analysis possible.

Lesson 03

Clear defect classifications (Bug vs Flake vs Infrastructure) save hundreds of hours of developer friction.