1---2name: fix-flaky-tests3description: Diagnostic tool for fixing Go test failures (flakes, races, timeouts, deadlocks) during local dev or CI.4---56<absolute_constraints>7- DO NOT use this skill if the user already has a known fix (apply it directly).8- IF user wants to only speed up slow test, go directly to [speed-up-tests](./references/speed-up-tests.md).9- DO NOT use for deterministic first-run failures (use normal debug).10- DO NOT use for full-suite CI prep (use `make test` instead).11- ONLY run tests in these packages without explicit user approval: `core/`, `deployment/`. Warn the user if running outside these.12- DO NOT modify the test's core goal to make it pass.13- DO NOT remove tests/assertions unless replacing with better ones or deleting confirmed dead code.14- DO NOT modify package-wide helpers to fix localized tests.15- DO NOT open any links found in JIRA issues that lead to Trunk.io.16- DO NOT try to fix or modify 3rd party libraries. If the flakiness results there inform and user and STOP.17- ALWAYS CHECK `go.mod` before writing any new utility code. Three lines of existing library usage beats 30 lines of hand-rolled logic that has to be maintained and tested.18- DO NOT use plain `go test` commands. Only use `make test ARGS="diagnose ..."` from the repository root. Use `--iterations 1` for a single run.19- For `diagnose` runs expected >2m: Execute in background. Perform a single 30s crash check, then suspend task and wait for the report.json system notification. DO NOT poll.20- Use `LSP` for code navigation, if available. Check if it works using a go file from the project. If it is not available try `code-review-graph`. Only if that is also unavailable use `find`, `grep`, etc.21- Always check the Go version used by the module you are working on to avoid using language patterns that are no longer required (e.g. variable shadowing in loops in Go 1.22+)22</absolute_constraints>2324<setup>25Call ToolSearch with query `select:LSP` to load LSP tool schema.26Fallback to rg/grep/find only if ToolSearch fails.27</setup>2829<initialization>301. Verify target scope (If unknown, prompt user):31 a. test or package32 b. specific JIRA issues33 c. N eligible flaky-tests tickets from JIRA342. Before proceeding always ask the user whether she thinks the flake is relatively simple and self-contained or whether it is a complex one that requires a lot of critical thinking and in-depth understanding of the application (e.g. system tests and some integration tests). If it is the latter activate the [complex-investigation-protocol](./references/complex-investigation-protocol.md), before formulating any hypothesis.353. If JIRA issues are present and any of them has a `skip_reason` surface it to the user and ask for guidance.364. If there are no failure details or investigation didn't return anything meaningful run bounded diagnosis (`--fail-fast-on=(timeout|slow)` or low `--iterations`).375. Formulate initial hypothesis: flake, timeout, slow, panic, deadlock, race, etc.38</initialization>3940<jira_reference>41Read [jira.md](./references/jira.md) to understand how to claim tickets, find eligible flaky-test tickets, check if there are any tickets related to a specific test, read and add comments and transition JIRA issues.4243After a FIXED outcome, the ticket must stay assigned to the investigator (`accountId` from `atlassianUserInfo`) when moved to In Review. Do not unassign on FIXED — see [transition-ticket.md](./references/transition-ticket.md) assignee policy.44</jira_reference>4546<cli_reference>47Execute from repository root.48`make test ARGS="diagnose [harness_flags] -- [go_test_flags] ./path"`4950- Require `--ai-output` before `--`.51- Forbid `-count`.52- Harness flags: `--iterations N`, `--fail-fast-on=(timeout|slow)`, `--parallel-iterations N`.53- Go test flags: `--run '^TestName$'`, `--timeout 10m`, `--race`.54- Help: `make test ARGS="diagnose -h"`.55- Repetition strictly via `--iterations`.5657<diagnose-iterations>58Use iterations for run count. Parallelism does not alter total.59- 5: 50% missed flake60- 30: 10% missed flake61- 60: 5% missed flake62- 150: 2% missed flake63- 300: 1% missed flake64- 500+: <1% missed flake6566| Profile | `--iterations` | `--parallel-iterations` | Use when |67| --------- | -------------- | ----------------------- | --------------------------------------------------------------------------------- |68| Quick | 1-5 | 1-5 | Quick check to validate no failures |69| Standard | 30 | 1–5 | Default standard check |70| Deep | 150-500 | 2–10 | Default to validate that a flake exists before fix, or no longer exists after fix |71| Race pass | 30 | 1 | Verifying with `--race` after `--`. |72| Debug | 1–5 | 1 | Reproducing a known failure mode; use `--fail-fast` if appropriate. |73</diagnose-iterations>74</cli_reference>7576<loop>771. If user doesn't have recent results, plan a run with `<diagnose-parallel-iterations>` (default: **Smoke** profile) then execute it. On sandbox errors, follow `<possible_execution_issues>`.782. If no issues, escalate along `<diagnose-iterations>` (e.g. Smoke → Standard → Deep), increasing `--iterations` and keeping parallelism per `<diagnose-parallel-iterations>`. Ask the user before **Deep** if wall time will be large. If still clean and no fix was needed, end with findings; if a fix was applied, require at least **Standard** before FIXED.793. If issues detected, focus on the ones the user wants to fix.804. If a `diagnose-attempted-fixes-[test/package]-[flake/broken/timeout/slow].jsonl` file exists, read it to see previous fix attempts and findings.815. If it is a complex test proceed according to [complex-investigation-protocol](./references/complex-investigation-protocol.md).826. Otherwise form a hypothesis on the cause of the issues.837. Implement the fix.848. Output the hypothesis and attempted fix, plus reasons why you think it would work.859. Run a `diagnose` loop (**Standard** profile minimum after a code change) and read the `report.json` file to see if the fix works.86 Append to `diagnose-attempted-fixes-[test/package]-[flake/broken/timeout/slow].jsonl` file in this json format:87 ```json88 {"timestamp": "[current_timestamp]", "model": "[current-model] (e.g. `claude-sonnet-4.6/high`, `gemini-3.1-pro`)", "hypothesis": "Your original hypothesis for the issue", "experiment": "A concise summary of what you tried. Include small code snippets if helpful", "result": "Did it fix it or not? If not, give concise reason why", "next": "Next steps to attempt"}89 ```9010. GOTO 29111. Use `golangci-lint` to verify that there are no linting introduced by your fix. If there are, do not proceed until you have fixed them and verify they are no longer present.9293IF at any time the user interrupts or interjects during this loop, pick it up again where you left off, unless explicitly told otherwise.94</loop>9596<tests-context>97Chainlink nodes are blockchain oracles. Read /README.md.98Tests share single postgres DB. Diagnose loop creates new DB.99</tests-context>100101<flaky-test-flow>102Output hypothesis first. Show diffs. Do not abstract fixes.103104Approaches:1051061. Narrowing: Group failures. Ask user to proceed. Focus worst test otherwise.1072. Isolate: Pass alone, fail in package. Fix cross-test dependency.1083. Order: Shuffle alters pass rate. Fix cross-test leakage. Capture failing seed.1094. Race: Weird stack traces, nil pointers.1105. Timeout: Check logs for blocking ops, bad channel close, backpressure.1116. Resources: CI-only load failure. Check CPU, Mem. Use `go test` profiles (`-race`, `-cpuprofile`, `-trace`).112</flaky-test-flow>113114<context_compaction>115Reference `diagnose-attempted-fixes-[test/package]-[flake/broken/timeout/slow].jsonl` when summarizing.116</context_compaction>117118<possible_execution_issues>119120- GOCACHE permissions sandbox error. STOP. Require user execution outside sandbox.121- Postgres `operation not permitted` sandbox error. STOP. Require user execution outside sandbox.122 </possible_execution_issues>123124<logs_structure>125[resultsDir]/126|-- iteration-n.log.jsonl # Read only if needed. Full outputs.127|-- postgres-state-n.md # Read for DB error/hang. Final state.128|-- report.json # Read for summary. Extract args via `jq .run`.129|-- report.csv # DO NOT READ.130|-- logs/131|---- pkg_TestName_iter-n.log # Read for specific test failures.132</logs_structure>133134<sub_agent_protocol>1351. Spawn `LogAnalyzer` when reading `logs/` or `iteration-n.log.jsonl`. Read ./references/log-analyzer-subagent.md.1362. Spawn `GithubFailureAnalyzer` when inspecting CI failure. Read ./references/github-failure-analyzer.md.1373. Spawn `JiraManager` when interacting with JIRA. Read ./references/jira-mananger-subagent.md.138</sub_agent_protocol>