
triage-flaky-test
โ 139by datadog-labs ยท part of datadog-labs/agent-skills
Load when investigating a specific flaky test. Gets history, failure pattern, and category, then recommends fix, quarantine, or escalate.
This is the playbook your agent receives when the skill activates โ you don't need to read it to use the skill, but it's here to audit before installing.
Triage Flaky Test
One-line summary: Investigate a specific flaky test โ get history, failure pattern, and category, then recommend fix, quarantine, or escalate.
Requires: dd-pup skill (pup CLI installed and authenticated).
Backend
Detection โ At the start of every invocation, before taking any action, determine which backend to use:
- If the user passed
--backend pupanywhere โ use pup mode immediately. Skip steps 2โ4. - Check whether
get_datadog_flaky_testsappears in your available tools. - If present โ use MCP mode throughout. Call tools exactly as named in this skill's workflow sections.
- If absent โ check whether
pupis executable: runpup --versionvia Bash. If the command exits successfully (exit code 0), pup is available. - If pup responds โ use pup mode throughout. Translate every tool call using the Tool Reference appendix at the bottom of this file.
- If neither is available โ stop and tell the user:
"Neither the Datadog MCP server nor the pup CLI is available. Connect the MCP server or install pup (
brew install datadog-labs/pack/pup)."
pup invocation rules:
- Invoke via Bash. pup always outputs JSON โ parse directly.
- Repository IDs passed to pup must be fully lowercase (the API rejects mixed-case).
- Sort values starting with
-require=syntax:--sort="-last_flaked"(not--sort "-last_flaked"). - If pup returns a 401/403, tell the user to run
pup auth refreshorpup auth login.
Input
| Parameter | Description |
|---|---|
| Test name | Fully qualified test name (e.g. TestMyFunc or com.example.MyTest) |
| Repository | Lowercase, no-schema URL (e.g. github.com/org/repo). Derive from git remote get-url origin if not provided. |
Workflow
STEP 0 โ Parse Input
Derive repository ID from git if not provided:
git remote get-url origin
# Strip protocol and trailing .git, then lowercase the result
# e.g. https://github.com/DataDog/my-repo.git โ github.com/datadog/my-repoValidation fallback: If STEP 1 returns no results, confirm the correct repository by searching without a repo filter:
Tool: search_datadog_test_events
query: @test.name:"<test-name>"
from: now-30d
test_level: testExtract @git.repository.id_v2 from results and retry STEP 1 with the confirmed value.
STEP 1 โ Get Flaky Test Details
Preferred โ use fingerprint_fqn if known (fingerprint_fqn is a valid CI Visibility search facet):
Tool: get_datadog_flaky_tests
query: fingerprint_fqn:<fqn>
sort_field: last_flaked
sort_order: descFallback โ use name + suite + repo:
Tool: get_datadog_flaky_tests
query: @test.name:"<test-name>" @test.suite:"<suite>" @git.repository.id_v2:"<repo>"
sort_field: last_flaked
sort_order: descOmit @test.suite if unknown. Do not filter by flaky_test_state โ return the test regardless of state.
Note: the query filter facet is flaky_test_state; the returned response attribute is flaky_state โ do not use flaky_state:active as a query filter.
Extract from results:
fingerprint_fqnโ unique test identifier; used as theidin STEP 5 write call. If absent, do not proceed to quarantine โ see STEP 5.flaky_stateโ current state (active / quarantined / disabled / fixed)test_stats.failure_rate_pctโ percentage of runs that failflaky_categoryโ root cause categorycodeownersโ owning teampipeline_stats.total_lost_time_msโ total CI time lost
STEP 2 โ Get Recent Failure History
Tool: search_datadog_test_events
query: @test.name:"<test-name>" @test.suite:"<suite>" @test.status:fail @git.repository.id_v2:"<repo>"
from: now-7d
test_level: testExtract:
- Error messages and stack traces (
@error.message,@error.stack) - Failing branches (
@git.branch) โ branch-specific vs. widespread - Frequency pattern โ random timing or specific conditions
- Unique
@ci.pipeline.idvalues for blast radius (STEP 3)
STEP 3 โ Check Blast Radius
Count distinct pipelines impacted using pipeline IDs from STEP 2:
Tool: aggregate_datadog_ci_pipeline_events
query: @ci.status:error @ci.pipeline.id:(<id1> OR <id2> OR ...) @git.repository.id_v2:"<repo>"
ci_level: pipeline
aggregation: count
group_by: ["@ci.pipeline.name"]
from: now-7dUse the first 10 pipeline IDs from STEP 2 (cap at 10; if more are available, run a second batch and merge results by summing counts per @ci.pipeline.name across batches). Report blast radius as: total number of unique pipelines impacted and whether failures are branch-specific or widespread.
Note: a pipeline failure is not necessarily caused solely by this flaky test โ treat blast radius as a signal, not a definitive count.
STEP 4 โ Recommend Fix or Quarantine
Use flaky_category from STEP 1 and error messages from STEP 2.
Root cause first:
- Read the full error trace from bottom to top โ chained errors hide the real cause; the innermost error is the root cause, not the first line.
- Identify the exact source of nondeterminism (race, ordering, stale state, timing).
- If the root cause is a CI infrastructure problem (runner unavailable, Docker daemon failure, network outage) โ do NOT propose a code fix; classify as
infraand recommend retry instead. - If root cause is uncertain and cannot be confirmed from the stack trace โ skip fix, go to quarantine.
Fix at the correct layer:
- Test issue โ fix in test or test helper only.
- Production bug exposed by the test โ fix in production code.
- Shared helper used by multiple tests โ fix the helper AND update all call sites.
Forbidden โ do not propose these:
- Timing hacks: increasing timeouts, adding sleeps, widening time windows, adding retries.
- Masking: relaxing assertions (e.g., exact match โ at least 1), dropping validations.
- Partial fixes: touching one call site when multiple share the root cause.
Fix patterns by category:
| Category | Approach |
|---|---|
timeout | Identify the slow operation and make it synchronous or deterministic โ do NOT simply raise the timeout constant |
concurrency | Add deterministic synchronization (barriers, channels, locks); remove shared mutable state between tests |
network | Mock or stub network calls at the boundary; if the test requires a real connection, isolate it with a test server |
time | Inject a controllable clock; replace wall-clock assertions with relative or event-driven checks |
order_dependency | Isolate test state with setup/teardown; eliminate dependencies on execution order or global state |
environment_dependency | Mock env variables and external config; use test-local fixtures, not shared directories or singletons |
resource_leak | Ensure every resource opened in a test is closed in teardown; use cleanup hooks that run even on failure |
randomness | Fix the random seed for the test run; use deterministic inputs instead of random generation |
asynchronous_wait | Replace fixed sleeps with condition polling or event/signal-driven waits with a hard timeout |
io | Use temp files/dirs cleaned up in teardown; mock or stub filesystem interactions |
unknown | Skip fix attempt โ go to quarantine |
Before proposing code changes, verify all of the following โ if any fails, skip fix and recommend quarantine:
- The root cause is the innermost error in the trace, not a surface-level symptom.
- The failure is a code problem, not a CI infrastructure problem.
- The fix eliminates the root cause (not just reduces flake probability).
- The fix is at the correct layer (test vs. production vs. shared helper).
- All call sites of any shared code are updated.
- No timing hacks or relaxed assertions introduced.
Decision:
- If category is
unknownOR verification above fails โ skip fix, recommend quarantine - If category is known AND root cause is confirmed AND fix is valid โ propose specific code change
STEP 5 โ Produce Triage Brief and Act
Flaky Test Triage Brief
=======================
Test: <fully qualified test name>
Service: <@test.service>
Category: <flaky_category>
Failure Rate: <test_stats.failure_rate_pct>%
Duration Lost: <pipeline_stats.total_lost_time_ms>ms
Codeowners: <codeowners>
Blast Radius: <N> pipelines (<branch-specific | widespread>) [approximate โ other failures in the same pipeline runs may not be related]
Evidence:
<1-2 key error message lines from STEP 2>
Recommendation: <fix | quarantine | escalate>
Confidence: <high | medium | low>
Action: <specific next step>Decision thresholds:
failure_rate_pct > 10OR blast radius > 5 pipelines โ quarantinefailure_rate_pct โค 10AND known category AND clear fix โ fixfailure_rate_pct โค 10AND categoryunknownโ escalate to codeowners with triage brief
If recommending quarantine, present and require explicit user approval before writing:
Proposed action: quarantine "<test-name>"
id (fingerprint_fqn): <fingerprint_fqn from STEP 1>
Effect: test still runs but failures are suppressed (CI will not be blocked)
Reversible: yes โ set new_state: active to restore
Approve? (yes/no)If fingerprint_fqn was not returned in STEP 1 (test not yet in FTM or query returned no results): do not attempt the write. Surface an error and ask the user to open the Flaky Test Management UI directly to quarantine manually.
Only after explicit approval and a confirmed fingerprint_fqn:
MCP mode:
Tool: update_datadog_flaky_test_states
test_ids: ["<fingerprint_fqn>"]
new_state: quarantinedpup mode:
cat > /tmp/flaky-update.json <<'EOF'
{
"data": {
"type": "UpdateFlakyTestsRequest",
"attributes": {
"tests": [{"id": "<fingerprint_fqn>", "new_state": "quarantined"}]
}
}
}
EOF
pup test-optimization flaky-tests update --file /tmp/flaky-update.jsonTo undo: repeat with new_state: active / "new_state": "active".
Tool Reference
This appendix applies only in pup mode. In MCP mode, use the tool names in the workflow sections directly.
| MCP Tool | pup Command |
|---|---|
get_datadog_flaky_tests (by fingerprint_fqn) | pup cicd flaky-tests search --query "fingerprint_fqn:<fqn>" --sort="-last_flaked" --limit 5 |
get_datadog_flaky_tests (by name + suite + repo) | pup cicd flaky-tests search --query "@test.name:\"...\" @test.suite:\"...\" @git.repository.id_v2:\"...\"" --sort="-last_flaked" --limit 10 |
search_datadog_test_events (validation fallback) | pup cicd tests search --query "@test.name:\"<test-name>\"" --from 30d --limit 5 |
search_datadog_test_events (failure history) | pup cicd tests search --query "@test.name:\"...\" @test.suite:\"...\" @test.status:fail @git.repository.id_v2:\"...\"" --from 7d --limit 20 |
aggregate_datadog_ci_pipeline_events (blast radius) | pup cicd events aggregate --query "@ci.status:error @ci.pipeline.id:(...) @git.repository.id_v2:\"...\"" --compute count --group-by "@ci.pipeline.name" --from 7d |
update_datadog_flaky_test_states | Write body to /tmp/flaky-update.json, then pup test-optimization flaky-tests update --file /tmp/flaky-update.json |
npx skills add https://github.com/datadog-labs/agent-skills --skill triage-flaky-testRun this in your project โ your agent picks the skill up automatically.
No common issues documented yet. If you hit a problem, the repository's GitHub Issues page is the best place to look.
Licensed under MITโ you can use, modify, and redistribute it under that license's terms.
View the full license file on GitHub โ