agentleFS
qbs784qbs784/ledger/skills/diagnosing-flakes/SKILL.md

diagnosing-flakes

Skill0 starsChanged 3 months agoMITView on GitHub

Use when a test or CI job fails probabilistically — passes on rerun, fails on one platform only, fails under load, or fails in CI but not locally. Also use when asked to investigate a flaky test, a red run nobody can reproduce, or an intermittent timeout. DO NOT invoke to design a new test for isolation — route that to ledger:designing-concurrent-tests.

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 5 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this workflow when the task is to investigate an existing probabilistic test or CI failure.

    line 8
  2. Distinctive:

    Use the CI provider's logs and run metadata to establish whether failures overlap on one host or resource namespace.

    line 16
  3. Distinctive:

    If the evidence supports more than one independent fact, report each one.

    line 38
  4. Distinctive:

    When implementation is authorized, fix the component that allocates, publishes readiness, mutates global state, or owns teardown.

    line 60
  5. Distinctive:

    Keep stable fixture data separate from live resource allocation.

    line 62

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Diagnosing flakes

Use this workflow when the task is to investigate an existing probabilistic test or CI failure. Preserve the requested read/write scope: diagnosis does not authorize a fix, a workflow rerun, or a configuration change. Ask before crossing into any of those.

Freeze the evidence

Record the repository, workflow, job, commit SHA, runner labels, timestamps, the exact failing test or command, and the first stable failure signature. Keep infrastructure messages separate from test output.

Compare multiple failing and passing runs. Prefer runs of the same SHA; when that is impossible, verify that the relevant test and CI configuration are identical across the compared commits. One passing rerun does not prove an infrastructure fault, and one timeout does not prove a product race.

Use the CI provider's logs and run metadata to establish whether failures overlap on one host or resource namespace. Preserve links to the supporting runs rather than pasting large logs.

Classify the failure

Classify from recorded evidence, not from the eventual fix. The third column is what separates a class from its neighbours; a class assigned without that evidence is a guess.

ClassWhat it looks likeWhat discriminates it
Host-resource collisionthe failure needs something else running at the same timeindependent processes or jobs acquire the same port, socket, database, predictable path, cache, or external namespace
Incomplete lifecycleoutput or mutations from one test surface inside a later oneteardown returned before children, workers, streams, servers, or callbacks reached quiescence
Process-global contaminationthe outcome depends on test order, or on state the test never seta leaked environment variable, working directory, fake timer, global, mock, locale, or module-level state
Load-sensitive synchronizationthe failure follows load on the machine, not any change in inputa sleep, polling interval, or assumed event-loop turn substitutes for observable readiness or completion
Platform or entry-path mismatchthe failure consistently follows one operating system, shell, filesystem rule, source/build mode, or executable entrythat lane fails and the others pass, on the same commit and the same configuration
Product concurrency defectthe race is in shipped behavior, not in the testthe test controls its own resources and reproduces deterministically with explicit overlap
External-provider transiencea live API or network boundary owns the failurethe signature matches that provider's documented retry policy
Runner infrastructurecheckout, dependency download, disk, host process, or runner service fails independently of the test commanddirect runner evidence, which is required before assigning this class

Two rows carry a qualifier that does not fit beside them:

  • A platform result does not transfer. Timestamp precision, environment variable name case, handle-release timing, and permission semantics all differ between Windows and POSIX hosts, so a case passing on one platform says nothing about another lane.
  • A pool with no host metrics is still classifiable. Where a self-hosted pool exposes no host metrics, say so and classify from what the logs do carry: one signature repeating across unrelated branches on one pool is evidence of shared-host contention even when the host cannot be inspected.

If the evidence supports more than one independent fact, report each one. Do not collapse a timeout, a signal, an exit code, and an assertion into a single inferred outcome.

Reproduce the smallest relevant topology

Start with the owning test file or focused test name. Increase concurrency only to the first rung that reproduces the signature. A higher rung reproduces more readily and attributes less: once several components contend at once, the run no longer names which one owns the failure.

RungTopologyWhat reproducing here shows
1one test processthe signature needs no concurrency at all; the owner is the product, the platform, or a wait that never observes readiness
2concurrent tests or files under one runner invocationtests interfere when scheduled together: order dependence, leaked global state, or teardown that returned early
3multiple independent test-runner processesseparate processes do not contain it, so the contested thing is a host resource rather than module state
4the project's own check lane at its configured worker countthe lane CI actually runs produces the contention, not a topology assembled by hand
5separate jobs or runner processes sharing the implicated host resourcethe collision crosses job boundaries, so no fix confined to one test process reaches it

Match the active runner configuration, environment knobs, source/build mode, and platform. Do not lower a production timeout or add random load merely to manufacture a different failure.

Where the signature belongs to a platform the available host cannot run, the ladder stops at the last reachable rung. Record that limit rather than substituting a passing run on another platform, then use CI as the reproduction, changing one suspected owner per run so the result stays attributable.

For a suspected race, replace probabilistic timing with a barrier at the contested transition. For a suspected host collision, prove simultaneous acquisition of the same identifier, or prove that atomic unique allocation removes the conflict.

Fix at the owner

When implementation is authorized, fix the component that allocates, publishes readiness, mutates global state, or owns teardown. Do not hide the failure in a snapshot normalizer, a retry wrapper, a broader timeout, a global serialization setting, or a weaker assertion.

Keep stable fixture data separate from live resource allocation. A recorded URL can remain stable while the fixture maps its transport to an OS-assigned port; a stable expected path can remain an assertion without becoming a shared writable directory.

Close the investigation

The evidence is complete when:

  • the original signature has a supported classification;
  • the smallest relevant topology reproduces it, or the external evidence is sufficient and the reproduction limit is explicit;
  • an authorized fix fails under a negative control or pre-fix state, and passes under the same topology afterward;
  • any concurrent-process, restoration, or quiescent-teardown proof required by the resource owner passes;
  • remaining CI checks are reported as passing, pending, skipped, or failing from their observed state.

Do not run until a test happens to pass and call that result stable. Stop after the selected evidence establishes the conclusion, or report the missing fact that blocks classification.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.