Skip to main content

Root Cause Analysis (RCA)

Root Cause Analysis explains why a test failed and suggests a fix. Open a failed run, go to the AI Analysis tab of the Investigation Hub, and click Ask AI on a failed test.

Requires: the rootCauseAnalysis feature flag in Settings → Features, and your organization's own AI provider key (BYOK).


How a Diagnosis Is Built​

  1. Evidence. Agnox collects the test's error, its logs, and the runtime context captured at the moment of failure: page URL, console errors, failed network requests, page errors and a page snapshot. An Adapter gives the richest context.
  2. Analyzer. The model produces a structured root cause and a suggested fix.
  3. Critic. A second pass checks every claim against the raw logs and removes anything they don't support.

The result is developer-facing Markdown. Agnox records the AI model that produced each diagnosis alongside the run.

Diagnoses are cached by failure fingerprint. When the same failure happens again, Ask AI answers from the cache without a new AI call.


GitHub Code Context​

When your organization has connected a GitHub token, RCA also reads the failing test's code and what changed since it last passed. That lets it tell a product bug from an outdated locator from a flaky test.

Requirements​

  • A GitHub token under Settings → Connectors → CI Providers → GitHub, with Contents: read access to the test repository. It's the same token Agnox uses for pull request integration.
  • A run that came from GitHub, with its repository and commit or branch:
    • External CI runs reported by @agnox/playwright-reporter on GitHub Actions.
    • Agnox Hosted runs triggered by the GitHub Smart PR Routing webhook, or by POST /api/ci/trigger with ciContext.source: "github".

Runs from GitLab, Azure DevOps or Bitbucket, and hosted runs started manually or by a schedule, are analyzed without GitHub context.

What Agnox reads​

PartDetail
Test snippetAbout 70 lines around the failing line, read at the run's commit (falling back to its branch, then the default branch). The failing line is marked. It comes from the reporter's error location (2.6.1+), else from file:line in the error text, else from the line that declares the test.
Diff summaryWhat changed between the last passing run on the same project and branch and the failing commit. The failing test's file comes first, then related files, then source files by size of change. Lockfiles, assets and build output come last.

Limits and safety​

  • Strict budget. The diff is capped at 3,000 characters and the snippet at 4,500, and together they never exceed 7,500 characters (about 1,900 tokens). Over budget, the diff is trimmed first.
  • Org-scoped cache. GitHub responses are cached in Redis under keys that include your organization: 24 hours for commit SHAs, 10 minutes for branch references and for "not found" results. Another organization can never read your cached code.
  • Never blocks RCA. If GitHub is slow (each request has a 4-second limit, 6 seconds overall), returns an error, hits its rate limit, or doesn't have the commit yet (for example, a local commit you haven't pushed), RCA still runs, just without code context.
  • Data, not instructions. The code is passed to the model as clearly marked data, with secrets redacted.
  • No tokens exposed. Your GitHub token is never logged, cached, sent to the model or returned by the API.

The GitHub context badge​

When code context was used, the diagnosis shows a GitHub context badge with the file, the commit it was read at, and the commit the diff starts from, for example tests/checkout.spec.ts @ 3f2a9c1 · diff since 8b41d07. It shows only file paths and commit SHAs. The badge also appears on saved diagnoses.


Re-analyze​

Once a diagnosis exists, the button changes to Re-analyze. Re-analyze skips the cached diagnosis (forceRefresh: true), reads GitHub context again, runs the model again, and replaces the cached and saved diagnosis.

Use it after connecting GitHub, after pushing a fix, or whenever a diagnosis seems out of date. The first Ask AI on a failure still uses the cache.

API: POST /api/executions/:executionId/tests/:testName/analyze with { "forceRefresh": true }. The older refresh: true still works as an alias.