---
name: flake-vs-bug-triage
description: >
  Decide if a failing test is flaky or a real regression. Use on intermittent CI
  failures, or Chinese "flaky", "偶发失败", "是不是不稳定测试". Practical triage workflow.
---

# Flake vs Bug Triage

## Overview

Don’t “re-run until green” forever. Classify failure, quarantine or fix with evidence.

## Signals

| Prefer **flake** | Prefer **real bug** |
|------------------|---------------------|
| Passes on re-run same commit | Fails consistently same commit |
| Timing/order/network race | Deterministic assertion on logic |
| Shared mutable global state | Clear code path regression |
| Only one shard/environment | Multiple envs same fail |

## Steps

1. Capture: test name, log excerpt, commit SHA, first fail time.  
2. Reproduce locally (N runs). Record pass/fail count.  
3. Classify: flake | bug | infra | unknown.  
4. Actions:  
   - flake → quarantine ticket + stabilize plan (not delete assert silently)  
   - bug → root cause + fix + test  
   - infra → env/owners  
5. Stop endless re-run loops; set max re-run policy.  

## Exit criteria

- [ ] Evidence of consistency (or lack)  
- [ ] Classification  
- [ ] Next action owner-ready  
- [ ] No silent deletion of coverage  

## Anti-patterns

- Merge with failing test “it’s flaky” without ticket  
- Deleting the test to green CI  

## Output template

```markdown
## Triage
- Test: ...
- Runs: pass=… fail=…
- Class: flake | bug | infra | unknown
- Action: ...
```
