mir-backend-rustlisted
Install: claude install-skill anantbhandarkar/make-it-right
# /mir-backend-rust · Make It Right (Rust runtime)
The middle tier. `mir-backend` decides **what is correct** (any language). The framework module (e.g. `mir-backend-rust-axum`) knows the **library's mechanics**. This tier owns what is true for **all Rust async backends because they run on Tokio** — the concurrency model and ownership rules that Axum, Actix-web, Warp, and Poem all inherit.
**Runtime assumed:** async Rust on Tokio (current-thread or multi-thread scheduler). The notes hold for any Tokio-based framework. Load order: `mir-backend` → `mir-backend-rust` → `<framework module>`.
## The Tokio async Rust footguns AI walks into (framework-agnostic)
### 1. DON'T BLOCK THE ASYNC RUNTIME
Tokio runs async tasks on a fixed pool of worker threads (by default, one per CPU core). A blocking call on any of those threads **stalls every task scheduled to that thread** — the async "event loop" analog.
Blocking operations that must never appear inside an `async fn` on a Tokio thread:
- `std::thread::sleep` → use `tokio::time::sleep`
- Synchronous file I/O (`std::fs::read`, `std::fs::write`) → use `tokio::fs` or `spawn_blocking`
- Blocking DB or socket calls (any sync driver, e.g. `postgres` crate's sync API) → use async driver (`sqlx`, `tokio-postgres`) or `spawn_blocking`
- Heavy CPU computation (hashing, encoding, ML inference, large sort) — blocks a Tokio thread even though it's "not I/O" → use `tokio::task::spawn_blocking` (runs on a separate blocking thread pool) or a de