Skills tokio-async-code-review
Reviews tokio async runtime usage for task management, sync primitives, channel patterns, and runtime configuration. Covers Rust 2024 edition changes including async fn in traits, RPIT lifetime capture, LazyLock, and if-let temporary scoping. Use when reviewing Rust code that uses tokio, async/await patterns, spawn, channels, or async synchronization. Also covers tokio-util, tower, and hyper integration patterns.
install
source · Clone the upstream repo
git clone https://github.com/openclaw/skills
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/openclaw/skills "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/anderskev/tokio-async-code-review" ~/.claude/skills/clawdbot-skills-tokio-async-code-review && rm -rf "$T"
manifest:
skills/anderskev/tokio-async-code-review/SKILL.mdsource content
Tokio Async Code Review
Review Workflow
- Check Cargo.toml — Note tokio feature flags (
,full
,rt-multi-thread
,macros
, etc.). Missing features cause confusing compile errors.sync - Check runtime setup — Is
or manual runtime construction used? Multi-thread vs current-thread?#[tokio::main] - Scan for blocking — Search for
,std::fs
,std::net
, CPU-heavy loops in async functions.std::thread::sleep - Check channel usage — Match channel type to communication pattern (mpsc, broadcast, oneshot, watch).
- Check sync primitives — Verify correct mutex type, proper guard lifetimes, no deadlock potential.
Output Format
Report findings as:
[FILE:LINE] ISSUE_TITLE Severity: Critical | Major | Minor | Informational Description of the issue and why it matters.
Quick Reference
| Issue Type | Reference |
|---|---|
| Task spawning, JoinHandle, structured concurrency | references/task-management.md |
| Mutex, RwLock, Semaphore, Notify, Barrier | references/sync-primitives.md |
| mpsc, broadcast, oneshot, watch channel patterns | references/channels.md |
| Pin, cancellation, Future internals, select!, blocking bridge | references/pinning-cancellation.md |
Review Checklist
Runtime Configuration
- Tokio features in Cargo.toml match actual usage
- Runtime flavor matches workload (
for I/O-bound,multi_thread
for simpler cases)current_thread -
used for async tests (not manual runtime construction)#[tokio::test] - Worker thread count configured appropriately for production
Task Management
-
return values (spawn
) are tracked, not silently droppedJoinHandle -
used for CPU-heavy or synchronous I/O operationsspawn_blocking - Tasks respect cancellation (via
,CancellationToken
, or shutdown channels)select! -
(task panic or cancellation) is handled, not just unwrappedJoinError -
branches are cancellation-safetokio::select! - Native
in traits used instead ofasync fn
crate where possible (stable since Rust 1.75)async-trait - RPIT lifetime capture reviewed in async contexts —
now captures all in-scope lifetimes in edition 2024-> impl Future
Sync Primitives
-
used when lock is held acrosstokio::sync::Mutex
;.await
for short non-async sectionsstd::sync::Mutex - No mutex guard held across await points (deadlock risk)
-
used for limiting concurrent operations (not ad-hoc counters)Semaphore -
used when read-heavy workload (many readers, infrequent writes)RwLock -
used for simple signaling (not channel overhead)Notify -
used instead ofstd::sync::LazyLock
oronce_cell::sync::Lazy
for runtime-initialized singletons (stable since Rust 1.80)lazy_static! -
lock guard patterns reviewed for edition 2024 temporary scoping — temporaries drop earlier, may change borrow validityif let
Channels
- Channel type matches pattern: mpsc for back-pressure, broadcast for fan-out, oneshot for request-response, watch for latest-value
- Bounded channels have appropriate capacity (not too small = deadlock, not too large = memory)
-
/SendError
handled (indicates other side dropped)RecvError - Broadcast
errors handled (receiver fell behind)Lagged - Channel senders dropped when done to signal completion to receivers
Timer and Sleep
-
used instead oftokio::time::sleepstd::thread::sleep -
wraps operations that could hangtokio::time::timeout -
used correctly (tokio::time::interval
for periodic work).tick().await
Severity Calibration
Critical
- Blocking I/O (
,std::fs::read
) in async context withoutstd::net::TcpStreamspawn_blocking - Mutex guard held across
point (deadlock potential).await
in async function (blocks runtime thread)std::thread::sleep- Unbounded channel where back-pressure is needed (OOM risk)
Major
silently dropped (lost errors, zombie tasks)JoinHandle- Missing
cancellation safety considerationselect! - Wrong mutex type (std vs tokio) for the use case
- Missing timeout on network/external operations
Minor
for trivially small async blocks (overhead > benefit)tokio::spawn- Overly large channel buffer without justification
- Manual runtime construction where
suffices#[tokio::main]
where contention is high enough to benefit from tokio's async mutexstd::sync::Mutex
Informational
- Suggestions to use
utilities (e.g.,tokio-util
)CancellationToken - Tower middleware patterns for service composition
- Structured concurrency with
JoinSet - Migration from
crate to nativeasync-trait
in traitsasync fn - Migration from
/once_cell
tolazy_staticstd::sync::LazyLock - Using
instead of#[expect(lint)]
for self-cleaning suppression#[allow(lint)]
Valid Patterns (Do NOT Flag)
for short critical sections — tokio docs recommend this when nostd::sync::Mutex
is inside the lock.await
without explicit join — Valid for background tasks with proper shutdown signalingtokio::spawn- Unbuffered channel capacity of 1 — Valid for synchronization barriers
in simple binaries — Not every app needs multi-thread runtime#[tokio::main(flavor = "current_thread")]
onclone()
beforeArc<T>
— Required for moving into tasks, not unnecessary cloningspawn- Large broadcast channel capacity — Valid when lagged errors are expensive (event sourcing)
- Native
in traits withoutasync fn
— Stable since 1.75; the crate is still valid forasync-trait
dispatch casesdyn
on+ use<'a>
returns — Correct edition 2024 precise capture syntax to limit lifetime capture-> impl Future
on complex async types — Self-cleaning alternative to#[expect(clippy::type_complexity)]
, warns when suppression is no longer needed#[allow]
Before Submitting Findings
Load and follow
beagle-rust:review-verification-protocol before reporting any issue.