agentleFS
jscott3201jscott3201/yet-more-skills/skills/rust-async-concurrency/SKILL.md

rust-async-concurrency

Skill4 starsChanged 2 months agoApache-2.0View on GitHub

Design or debug Rust async lifecycles, cancellation, deadlines, locks, channels, and backpressure. Use for concurrent behavior; not a blanket conversion to async.

The file

We split this skill into the rules it gives an agent

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

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    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:

    Do not automatically retry non-idempotent writes or reinterpret ambiguous completion as no effect.

    line 21
  2. Distinctive:

    Test cancellation before/after admission, mid-I/O, completion racing expiry, shutdown under load, task panic, stale replies, and resource …

    line 39
  3. Distinctive:

    Read concurrency cases when selecting tests.

    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 Async and Concurrency

Map the operation's lifecycle before changing synchronization. Follow the repository runtime and ownership model; this skill does not authorize more writers, runtime replacement, or automatic retries.

Identify ownership and state transitions

Find the admission authority, logical-operation lifetime, per-attempt lifetime, in-flight resources, completion authority, shutdown owner, and task handles. Explain what happens if the caller disappears at each await. Distinguish a timeout from rollback: a request may already have reached the peer or mutated state.

Keep permits, registrations, timers, buffers, and cleanup attached to the lifetime they actually govern. Use RAII or an equally explicit cleanup owner so early returns and cancellation cannot strand resources. Check exact request identity before completing or freeing a reused slot. A modular slot number alone is not identity.

Bound work and waiting

Bound both queued and active work where the product needs bounded resources. A semaphore on active operations does not bound an unbounded input queue or tasks waiting to acquire it. Define overload behavior and whether deadlines include queueing. Preserve one absolute deadline when a total operation budget is intended, rather than resetting a timeout at every stage or retry.

Do not automatically retry non-idempotent writes or reinterpret ambiguous completion as no effect. Distinguish logical requests from attempts for permits, telemetry, and shutdown accounting. Use the protocol's retry/error classification and caller policy.

Choose synchronization from ownership and contention. Short, low-contention synchronous critical sections can be appropriate in async code; do not replace every mutex with an async mutex. Keep blocking guards and large CPU work out of await paths. Async mutexes can still create deadlocks or long serialized queues. Preserve lock order and avoid callbacks while holding locks when they can re-enter.

Review cancellation and scheduling

Inspect each select! branch for cancellation safety and lost partial progress. A dropped future does not undo bytes written or state already changed. Retain framing/progress state across cancellation where required. Check fairness and shutdown responsiveness rather than assuming a busy ready branch will yield appropriately.

Move blocking work only when needed. A started spawn_blocking task cannot simply be aborted; use bounded concurrency and cooperative stop design for long-running work. Do not offload every tiny function or create a new runtime per request. Keep background tasks owned and their failures observable.

For custom atomics, write down what data an atomic publishes and which synchronization establishes visibility. An atomic counter used only for identity allocation is different from publishing initialized state. Prefer a simple lock until a measured reason and a sound ordering argument justify complexity.

Distinguish cancelling a future from dropping a spawned task's handle. Dropping a Tokio JoinHandle detaches its task; timing out an owned handle can therefore leave work running. Keep an explicit owner, use cooperative cancellation or abort where appropriate, and observe termination rather than treating an abort request as completed cleanup. See spawned-task lifetime cases.

Shutdown and verification

Seal admission, let admitted work drain according to policy, signal cancellation when appropriate, and join owned tasks within the intended deadline. Preserve response/deadline processing during drain if admitted requests still depend on it. Drop is not an async graceful-shutdown mechanism.

Test cancellation before/after admission, mid-I/O, completion racing expiry, shutdown under load, task panic, stale replies, and resource recovery. Use deterministic clocks and a focused concurrency model where practical, plus real runtime integration. Return lifecycle invariants, tests, resource bounds, and unresolved interleavings.

Read concurrency cases when selecting tests.

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.