agentleFS
narenaryannarenaryan/agent-skills/skills/rust/rust-deterministic-concurrency-tests/SKILL.md

rust-deterministic-concurrency-tests

Skill0 starsChanged 39 days agoMITView on GitHub

Use when Rust concurrent data structures pass stress tests intermittently, lose updates despite atomics, or need reproducible interleaving tests; applies to Loom or Shuttle instrumentation, sequential-model oracles, replay, and bounded schedule exploration.

The file

We split this skill into the rules it gives an agent

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

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Treat the schedule as test input.

    line 8
  2. Distinctive:

    Use maintained tooling rather than copying an educational scheduler.

    line 17
  3. Distinctive:

    Start with two actors and few operations.

    line 22
  4. Very specific:

    Run the ordinary build separately to catch conditional-import drift.

    line 32
  5. Distinctive:

    Do not replace the implementation with a simplified test-only algorithm.

    line 41

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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

Rust Deterministic Concurrency Tests

Treat the schedule as test input. Even sequentially consistent loads and stores do not make a compound read-modify-write atomic. More threads and sleeps increase opportunities for failure without making the failing execution reproducible.

Choose a scheduler

ToolGood fitBoundary
Loom 0.7Small synchronization algorithms; explore interleavings and modeled memory behaviorsState-space growth and configured bounds limit coverage
Shuttle 0.9Larger scenarios with randomized/PCT exploration and deterministic replayPassing sampled schedules does not establish correctness

Use maintained tooling rather than copying an educational scheduler. Keep production logic shared with the instrumented build.

Build a meaningful model

  1. Route synchronization and thread creation through a small conditional-import module. Replace the primitives used by the implementation itself, not only the test. Reset state inside every scheduler invocation.
  2. Start with two actors and few operations. For a counter, compare completed increments with the final value. For queues/maps, specify permitted histories and ordering; final-state equality alone does not prove linearizability.
  3. Control other nondeterminism. Mock I/O, clocks, and system calls; use scheduler-supported randomness or fixed inputs. Uncontrolled randomness prevents reliable replay.
  4. Capture the failing input and schedule before shrinking. Reduce actors/operations while retaining the same invariant violation, then keep the small regression case.

For a project wired with Loom's documented cfg(loom) dependency/import scheme and an integration test named loom_counter:

RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg loom" cargo test --release --test loom_counter

Run the ordinary build separately to catch conditional-import drift. For Shuttle failures, preserve the emitted schedule string and replay it with shuttle::replay; record the tool version alongside it.

Sources: matklad, 2024-07-05, Loom 0.7.2, Shuttle 0.9.5.

Pitfalls

  • Any uninstrumented synchronization can hide behaviors from the scheduler.
  • A bounded or randomized pass covers the explored model, not every production execution or memory-model behavior.
  • Spin loops can exhaust exploration without progress; use the tool's modeled yield where its documented fairness requirements apply.
  • Do not replace the implementation with a simplified test-only algorithm; that proves the substitute, not the shipped code.

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.