Back to cookbook

AI Prompt to Triage Flaky CI Test Failures Using GitHub's MCP Server

0 views Published

Make this prompt yours

Share

This AI prompt helps engineers and tech leads figure out which failing CI tests are genuine bugs and which are flaky tests that fail intermittently for unrelated reasons, using GitHub's MCP Server to pull the actual workflow run history, logs, and commit diffs for a repository instead of relying on a single failed run. A model connected through MCP can query recent runs of the same test across different commits and spot whether a failure correlates with a specific code change or shows up randomly regardless of what changed.

The prompt asks the model to compare the failing test's recent run history, check whether the failure message is identical across runs or varies (a sign of a race condition or timing issue), and cross-reference the commits that landed around the first failure. This saves engineers from re-running a flaky suite repeatedly by hand or quarantining a genuinely broken test as 'just flaky' and shipping a real regression.

Because CI logs and run histories can run long and get expensive to pass through a model repeatedly during an active incident, teams pulling large volumes of log output alongside this prompt can use Token Optimizer to trim verbose logs down before each triage pass.

Prompt template

Make this prompt yours

prompt-template
345 tokens
Role: You are a CI reliability engineer helping triage test failures. Context: - Repository: [REPO_NAME] - Failing test(s): [TEST_NAME_OR_FILE] - Workflow or CI pipeline: [WORKFLOW_NAME] - Number of recent runs to review: [NUMBER_OF_RUNS, e.g. 15] - Approximate time the failures started: [DATE_OR_COMMIT_RANGE] Task: 1. Retrieve the run history for the specified test across the last [NUMBER_OF_RUNS] workflow runs. 2. For each run, note whether the test passed or failed, and if it failed, record the exact failure message and stack trace line. 3. Determine whether the failure message and location are consistent across failing runs or vary from run to run. 4. Identify the commits merged in the window right before the failures began and flag any that touch the same files, dependencies, or test fixtures as the failing test. 5. Classify the failure as either "Likely flaky" (intermittent, inconsistent messages, no related code change) or "Likely real regression" (consistent failure tied to a specific commit). Constraints: - Do not classify a test as flaky without at least 3 failed runs to support it. - Always name the specific commit(s) you suspect if classifying as a real regression. - State your confidence level (high, medium, low) for the classification. Output format: Test: [name] Classification: [Likely flaky / Likely real regression] Confidence: [high/medium/low] Evidence: [run-by-run summary] Suspect commit(s), if any: [commit hash and message] Recommended next step: [one sentence]

Want it sharper? Optimize this prompt with Prompt Optimizer, check it with the Prompt Debugger or shorten it with the Token Optimizer.

Example input

example-input
74 tokens
Repository: acme-corp/checkout-service Failing test: tests/payments/test_retry_logic.py::test_retry_on_timeout Workflow: ci.yml (test suite) Number of recent runs to review: 15 Approximate time failures started: last 4 days, around commit range a1b2c3d..f9e8d7c

When to use it

  • A CI pipeline has intermittent test failures and the team needs to know which ones are flaky versus real regressions before merging.
  • You're deciding whether to quarantine a test or investigate it, and want evidence from run history instead of a gut call.
  • A release is blocked by failing tests and you need a fast triage of which failures are safe to re-run and which need a fix first.
  • You want a repeatable process for distinguishing timing-related test flakiness from genuine logic bugs introduced by a recent commit.

Best practices

  • Pull the test's run history across at least the last 10-15 runs through MCP rather than judging from one failed run, so you can see whether the failure is consistent or intermittent.
  • Ask the model to check whether the failure message, stack trace, or line number changes between runs, since identical failures point to a real bug and varying ones point to flakiness.
  • Have it cross-reference the commits merged around the first failure, not just the most recent one, since flaky tests sometimes start failing a few commits after the actual cause landed.
  • When log output from multiple runs is too long to review efficiently, trim it with Token Optimizer before feeding it into the triage prompt.

Common mistakes

  • Labeling a test as flaky after only one or two failures instead of checking its run history for a real pattern.
  • Quarantining a test without checking whether a genuine regression landed around the same time the failures started.
  • Ignoring differences in failure messages between runs, which is often the clearest signal separating a timing issue from a logic bug.
  • Triaging the symptom (the failing test) without looking at what changed in the surrounding code or infrastructure right before failures began.

FAQs

How do I tell if a failing CI test is flaky or a real bug?

Check the test's run history instead of a single failure: if the failure message and stack trace are identical across multiple runs and line up with a specific commit, it's likely a real regression; if the failures are inconsistent and uncorrelated with any code change, it's more likely flaky.

How many failed runs should I look at before calling a test flaky?

At least 3 to 5 failed runs is a reasonable minimum before quarantining a test as flaky, since one or two failures can easily be a real but intermittent bug rather than true flakiness.

Can an AI model actually pull my GitHub Actions run history automatically?

Yes, if it's connected through GitHub's MCP server it can query workflow run history, logs, and the commits associated with each run directly, rather than you needing to copy and paste logs manually.

What should I do with a test I've confirmed is genuinely flaky?

Quarantine it so it doesn't block merges, but track it separately and revisit it, since a test that's flaky due to a real race condition can mask a production bug if ignored indefinitely.

What tool can help me check this prompt's quality before using it on a live incident?

Prompt Debugger — scans the prompt for vague constraints or missed edge cases, which matters here since a weak classification rule could mislabel a real regression as flaky.

Found this prompt useful? Share it.

Share

More in Engineering

Engineering

AI Prompt to Triage Production Incidents Using Datadog's MCP Server

This AI prompt is built for on call engineers who need to triage a production incident fast, using Datadog's MCP server to pull live metrics…

ROLE: You are an on-call engineering assistant helping triage a live production incident.

CONTEXT:
- Service(s) affected: [SERVICE NAMES]
- Triggered monitor(s): [MONITOR NAME(S) AND ALERT MESSAGE(S)]
- Time incident started: [TIMESTAMP]
- Relevant metrics/logs: [PASTE RECENT ERROR RATES, LATENCY, OR LOG EXCERPTS FROM DATADOG]
- Recent changes: [LIST DEPLOYS, CONFIG CHANGES, OR INFRA CHANGES IN THE LAST 24 HOURS WITH TIMESTAMPS]

TASK:
1. Identify the pattern connecting the triggered alert(s) to the symptoms in the metrics/logs.
2. List the top 3 most likely root causes, ranked by how well each fits the timing and symptoms.
3. For each hypothesis, state what additional data would confirm or rule it out.
4. Recommend the single next diagnostic step to run first.

CONSTRAINTS:
- Do not recommend a rollback or fix until at least one hypothesis has supporting evidence beyond timing correlation.
- Flag explicitly if the available data is insufficient to form a confident hypothesis.

OUTPUT FORMAT:
- One-line incident summary
- Ranked list of root-cause hypotheses with supporting/against evidence for each
- Single recommended next diagnostic step
- Open questions still unresolved

Make this prompt yours

Engineering

AI Prompt to Write a Load Testing Plan for a REST API Endpoint

This prompt has ChatGPT, Claude, or Gemini draft a concrete load testing plan for a REST API endpoint before you run a single test. It's for…

You are a performance engineer designing a load test for a production API endpoint.

Context:
- Endpoint: [METHOD AND PATH, e.g. POST /api/v1/orders]
- Expected traffic: [REQUESTS PER SECOND AT PEAK, e.g. 150 rps average, 600 rps peak]
- Downstream dependencies: [LIST, e.g. PostgreSQL, Redis cache, payment gateway API]
- Load testing tool in use: [TOOL NAME, e.g. k6, Locust, JMeter]
- Current known constraints: [e.g. database connection pool size, rate limiter config]

Write a load testing plan with the following requirements:
1. Define a steady-state ramp test (target rps, ramp-up duration, hold duration) sized to the expected traffic above
2. Define a separate spike test that exceeds the expected peak by a specified margin
3. List the metrics to capture during both tests, prioritizing p95/p99 latency and error rate over averages
4. Identify which downstream dependency from the list above is most likely to be the first bottleneck, and why
5. Propose specific pass/fail thresholds for latency and error rate, agreed before the test runs
6. Note any test environment differences from production that could invalidate the results

Output format:
- A short test plan summary (one paragraph)
- The steady-state and spike test parameters as a table
- The metrics and thresholds as a table
- A short risk note on the likely first bottleneck and the environment caveat

Make this prompt yours

Engineering

AI Prompt to Write a Feature Flag Rollout and Cleanup Plan

A feature flag rollout plan lays out how a new capability ships behind a flag, moves through stages of exposure, and eventually gets removed…

You are a senior platform engineer helping plan a feature flag rollout.

Context:
- Feature/change controlled by the flag: [FEATURE DESCRIPTION]
- Flag name: [FLAG NAME]
- Systems or services affected: [AFFECTED SYSTEMS]
- Traffic segments available (e.g. internal, beta list, percentage buckets): [TRAFFIC SEGMENTS]
- Key risk if this goes wrong: [PRIMARY RISK]
- Current monitoring/metrics available: [AVAILABLE METRICS]

Task:
1. Propose a staged rollout sequence (minimum 3 stages) from lowest to highest exposure, with a suggested duration for each stage.
2. For each stage, list the specific metrics to watch and the exact threshold that should trigger a pause or rollback.
3. Define who should approve advancing to the next stage.
4. Write a rollback procedure: the steps to disable the flag and the maximum acceptable time to recovery.
5. Write a cleanup plan: the condition that signals the feature is stable enough to remove the flag, the code paths to delete, and a target removal date relative to full rollout.

Constraints:
- Do not recommend going straight to 100% rollout for any change affecting [AFFECTED SYSTEMS].
- Keep each stage's exit criteria measurable, not subjective.
- Flag any step that depends on information not provided above.

Output format:
- A numbered rollout table (Stage | Exposure % | Duration | Watch Metrics | Rollback Trigger)
- A short rollback procedure
- A short cleanup plan with a target date

Make this prompt yours