GB-Power-Market-JJ tokio-async-code-review
Reviews tokio async runtime usage for task management, sync primitives, channel patterns, and runtime configuration. 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/GeorgeDoors888/GB-Power-Market-JJ
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/GeorgeDoors888/GB-Power-Market-JJ "$T" && mkdir -p ~/.claude/skills && cp -r "$T/openclaw-skills/skills/anderskev/tokio-async-code-review" ~/.claude/skills/georgedoors888-gb-power-market-jj-tokio-async-code-review && rm -rf "$T"
OpenClaw · Install into ~/.openclaw/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/GeorgeDoors888/GB-Power-Market-JJ "$T" && mkdir -p ~/.openclaw/skills && cp -r "$T/openclaw-skills/skills/anderskev/tokio-async-code-review" ~/.openclaw/skills/georgedoors888-gb-power-market-jj-tokio-async-code-review && rm -rf "$T"
manifest:
openclaw-skills/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 |
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!
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
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
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)
Before Submitting Findings
Load and follow
beagle-rust:review-verification-protocol before reporting any issue.