| name | audit-safety |
| description | Audit Rust codebase for production safety issues. Checks unsafe blocks, panic surfaces, resource leaks, concurrency footguns, lint suppression, error swallowing, and dependency risks. Use when reviewing code for production readiness, auditing unsafe usage, or evaluating a crate's safety posture. |
| allowed-tools | Read, Glob, Grep, Bash, LSP |
| model | claude-sonnet-4-6 |
Rust Production Audit Checklist
A comprehensive checklist for auditing Rust codebases, focused on patterns that compile cleanly but cause real production issues. Organized by severity and likelihood of occurrence.
1. Memory Safety Escape Hatches
unsafe blocks
std::mem::transmute
unsafe impl Send / unsafe impl Sync
String::from_utf8_unchecked and similar _unchecked functions
2. Panics and Unwinding
.unwrap() and .expect()
panic!(), todo!(), unimplemented!()
Array/slice indexing
Integer overflow
3. Resource Leaks
Box::leak()
std::mem::forget()
Rc / Arc reference cycles
Unbounded collections
File descriptors and handles
4. Concurrency
Deadlocks
Async pitfalls
Atomics
5. Error Handling
Silent error swallowing
Error type design
6. Lint Suppression and Compiler Bypasses
#[allow(...)] audit
CI enforcement
7. Process and System
std::process::abort() and std::process::exit()
Signal handling
8. Serialization and Data Integrity
serde pitfalls
Type confusion
9. Performance Footguns
Cloning
Allocation
Regex
Quick Grep Commands
rg 'unsafe' --type rust
cargo geiger
rg '\.unwrap\(\)|\.expect\(|panic!\(|todo!\(|unimplemented!\(' --type rust
rg 'Box::leak|mem::forget|ManuallyDrop' --type rust
rg '#\[allow' --type rust
rg 'let _ =|\.ok\(\);' --type rust
rg 'mpsc::channel\(\)' --type rust
rg 'process::abort|process::exit' --type rust
rg '_unchecked\(' --type rust
Output Format
## Testing Audit: {target directory}
**Persona**: {persona}
**Scope**: {what was examined}
---
## Overall: {X}/10
{2-3 sentence summary. "Has solid unit tests but integration tests are thin and idempotency is untested."}
## Ratings
Use the merit sections above eg "Performance Footguns" and apply an individual rating to each with any notes.
Skip categories that don't apply.
---
## What I Like
{Specific things the tests do well. File references. Not generic — cite the exact test pattern, helper, or coverage choice.}
- **{Merit}** — `{file:line}`. {Why this is good.}
- ...
---
## What Concerns Me
{Missing tests and test quality issues. Compact ICE. Only suggest what to write for clear gaps.}
### {Missing test or quality issue}
`{file or area}` · {type} · ICE {I}/{C}/{E} → {score} · {trivial | moderate | significant}
{What's missing and what production failure it would catch. 2-4 sentences.}
**Sketch** (only for high-ICE items):
```{language}
// Brief test skeleton — 5-10 lines max
Concerns Summary
| # | Gap | Type | Effort | ICE |
|---|
| 1 | {description} | {performance} | {effort} | {n.n} |
Quick Wins
{Top 3 tests that add the most confidence with least effort.}
## Calibration Rules
- **Stack rank honestly.** The #1 missing test should catch the most dangerous bug.
- **Do not list more than 15 gaps.** Keep the top 15 by ICE score.
- **Every gap must be specific.** Not "add more error tests" but "test that `CreateVM` returns `AlreadyExists` when called twice with the same ID."
- **Sketches only for high-ICE items.** Don't pad the output with boilerplate test skeletons for every gap.
- **Wire compat tests are non-negotiable.** If a Go consumer lacks `wire_compat_test.go`, that is always high-ICE.