GuidesZero flaky tests

Triage failed tests on demand

Replace blind CI retries with a quick "why did this fail?" check that shows whether a Playwright failure is new, with replays and optional quarantine.

When an end-to-end test turns a pull request red, the fastest reflex is clicking "Re-run failed jobs". Every blind retry trains the team to treat red checks as noise, hides whether the failure came from this branch or from main, and wastes another CI cycle when a real regression is sitting right in front of you.

Instead of re-running first and asking questions later, add a "why did this fail?" triage step whenever a pull request fails. Using Endform's run history and attempt diffs, you or a coding agent can answer two questions in seconds:

  1. Is this already failing for everyone else on main or other pull requests? If yes, notify an owner, feed it into your weekly flake loop, and move on. (If it is blocking merges right now, you can also add a short-lived quarantine rule.)
  2. Is it isolated to this pull request? If yes, do not mute it. Pull the diverging step, error details, and replay link so the next human or coding agent gets an actionable diagnosis instead of a raw timeout.
Pull request triage flowchart: when a test fails on a PR, check Endform history on main and other PRs. If it is failing for everyone else too, notify an owner and feed the weekly flake loop (with optional quarantine with an expiry to unblock the PR). If it is only failing on this PR, inspect the failure with Endform's automatic diff and post a diagnosis for the next human or agent.

Run the triage check (MCP or CLI)

Whether you ask your coding agent in your editor or run the Endform CLI directly, on-demand triage pulls the same context. Switch between MCP and CLI below to inspect how this works on BikeBook's PR #4 (demo/checkout-regression):

Triage a red pull request
You
Checkout failed on PR #4 (branch demo/checkout-regression). Why did it fail, and is anyone else hitting this?

I'll pull the failing test runs on this branch, check the same test's 7-day history on main, inspect the failing attempt, and grab a replay link.

MCP toolsamples_query
{
  "dataset": "test-runs",
  "where": "branch = demo/checkout-regression, testRun.outcome = fail",
  "period": "24H",
  "limit": 10
}
MCP toolanalytics_query
{
  "dataset": "test-runs",
  "metric": "pass-rate",
  "groupBy": "test",
  "where": "branch = main, test.id = <testId>",
  "period": "7D"
}
MCP tooltest_attempt_inspect
{
  "testAttemptId": "<testAttemptId>"
}
MCP tooltest_attempt_replay
{
  "testAttemptId": "<testAttemptId>"
}

Isolated to PR #4 (100% pass rate on main over the last 7 days, so do not quarantine). In "upgrading to Plus records exactly one payment", clicking Complete Purchase fails because processPayment looks up lowercase "plus" while the pricing form submits "Plus". Ready for a fix with the replay linked.

Three habits make triage fast and accurate:

  • Group related failures first: If five or more tests failed together with the same upstream 503 or preview deployment error, treat them as one environment incident instead of triaging each test separately.
  • Check main before touching code: Comparing the failing test.id against a 7-day pass-rate query on branch = main immediately separates a brand-new regression on this PR from a known recurring flake.
  • Share the replay link: test_attempt_replay (or npx endform@latest test-attempt replay <testAttemptId>) returns a shareable replay link for the failing attempt. Whenever a matching passing run is available, Endform pairs the two runs side by side automatically.

Here is a live replay from that BikeBook checkout regression, where Endform automatically paired the failure beside a passing main run. Scrub the frames to see checkout fail as soon as the user clicks Complete Purchase:

Failed on PR #4

Choose the right next step

Once you have the main history and failure details, every red pull request falls into one of three buckets:

Signal from Endform historyWhat happenedWhat to do
Green on main, broken only on this PRReal regression introduced by this branchPost the diverging step, error, and replay link on the PR so the author or a coding agent fixes the app. Do not quarantine.
Green on main, selector or copy mismatch on this PRIntentional UI or product change broke an older testUpdate the test on this branch (or delegate volatile steps with natural-language steps).
Already failing on main or across other PRsShared recurring flake or broken upstream dependencyNotify the owning team and let the weekly flake loop fix the root cause. Optionally add a time-boxed quarantine rule if it is blocking merges.

Automate triage as a pull request feedback step

Passing pull requests should pay zero extra cost. Wire triage in as a failure-only CI step right after npx endform@latest test so every red run posts a structured diagnosis and replay link automatically.

Here is a GitHub Actions example that gives the coding agent access to the Endform MCP server and runs only when the Endform step fails:

.github/workflows/e2e.yml (excerpt)
permissions:
  contents: read
  id-token: write
  pull-requests: write

steps:
  - name: Run Playwright suite on Endform
    id: e2e
    run: npx endform@latest test

  - name: Triage failed tests
    if: ${{ failure() && steps.e2e.outcome == 'failure' }}
    uses: anthropics/claude-code-action@v1
    env:
      ENDFORM_API_KEY: ${{ secrets.ENDFORM_API_KEY }}
    with:
      anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
      claude_args: >-
        --mcp-config '{"mcpServers":{"endform":{"command":"npx","args":["-y","endform@latest","mcp"]}}}'
        --allowedTools "mcp__endform__*"
      prompt: |
        Endform E2E tests failed on branch "${{ github.head_ref }}"
        (PR #${{ github.event.pull_request.number }}).

        Use the Endform MCP server to investigate the failures and post
        one concise triage comment on this pull request with:
        - Whether each failure is isolated to this PR, caused by an
          intentional UI change, or already failing on main (include
          recent pass rates on main). If 5+ tests failed with the same
          upstream error, group them as one environment incident.
        - The root cause, diverging step, and error summary for each
          distinct failure.
        - A replay link for the failing attempt when available.
        - A clear recommended next step for the engineer or follow-up
          coding agent.

        Do not modify code or create quarantine rules automatically.

npx endform@latest test authenticates via GitHub OIDC (id-token: write) when the Endform GitHub App is installed, while the Endform MCP server in CI needs an ENDFORM_API_KEY secret (create one with npx endform@latest api-key create --name "GitHub Actions"). Notice that the prompt describes the outcomes you want and lets the agent choose which Endform MCP tools to call.

That gives every reviewer and follow-up coding agent a high-signal comment on the pull request before anyone thinks about hitting re-run:

Example automated triage comment on PR #4
### Endform E2E Triage: 1 failure (isolated to this PR)

**Test:** `tests/signed-in/checkout.spec.ts`
(*upgrading to Plus records exactly one payment*)
**Main branch (7D):** 100% pass rate (28/28 runs)
**Classification:** PR-only regression (do not quarantine)

**What diverged:**
- Clicking `Complete Purchase` stays on `/pricing/checkout` with an
  inline checkout error instead of redirecting to
  `/dashboard/team?payment=success`.
- In `lib/payments/actions.ts`, `processPayment` looks up plans with
  lowercase `"plus"`, while the pricing form submits `"Plus"`.

**Replay:** [Open the full replay](https://endform.dev/app/demo/failing-checkout-replay?view=full)
**Next step:** Fix the plan-name lookup mismatch on this branch and
re-run `tests/signed-in/checkout.spec.ts`.

Quarantine

Quarantine is an optional add-on when a known shared failure is actively blocking unrelated pull requests while someone investigates the root cause.

Quarantine keeps selected tests running while you investigate. When a quarantined test fails, the suite does not fail. Endform still records its results and traces, so you keep collecting evidence and can see when the fix lands.

You need a suite that has run on Endform at least once, so you can pick it.

Create a rule

Create a time-boxed quarantine rule
You
Quarantine the flaky checkout timeout test in our web suite until Friday while we investigate #412.

I'll look up the suite and test IDs from recent runs, then create a scoped quarantine rule with an expiry.

MCP toolsamples_query
{
  "dataset": "test-runs",
  "where": "branch = main, testRun.outcome = fail",
  "period": "7D",
  "limit": 5
}
MCP toolquarantine_create
{
  "suiteId": "suite_123",
  "testId": "test_456",
  "reason": "Tracking flaky checkout test in #412",
  "endsAt": "2026-12-01T12:00:00Z"
}

Quarantined "checkout times out on retry" in the web suite until 2026-12-01T12:00:00Z. The test will keep running and collecting traces, but its failures will not block merges.

All filled-in fields must match exactly. Empty fields match any value within the suite, so a rule with only a branch quarantines every test on that branch. Prefer scoping rules to a specific suiteId and testId, writing a clear reason, and setting an endsAt expiry so the rule never outlives the investigation.

Check which tests are quarantined

Check active quarantine rules
You
Which tests are quarantined in our suites right now?

Let me list the active quarantine rules across your suites.

MCP toolquarantine_list
{
  "includeInactive": false
}

One active rule: "checkout times out on retry" in the web suite (expires 2026-12-01T12:00:00Z, reason: "Tracking flaky checkout test in #412").

Remove quarantine once the fix lands

After the owner or your weekly flake loop fixes the test, verify that recent runs pass cleanly and deactivate the rule so the test returns to blocking CI:

npx endform@latest quarantine deactivate <ruleId>

For every argument the rules take, see the quarantine reference.

Next steps

Last updated