Beagle review-verification-protocol
Mandatory verification steps for all code reviews to reduce false positives. Load this skill before reporting ANY code review findings.
git clone https://github.com/existential-birds/beagle
T=$(mktemp -d) && git clone --depth=1 https://github.com/existential-birds/beagle "$T" && mkdir -p ~/.claude/skills && cp -r "$T/plugins/beagle-rust/skills/review-verification-protocol" ~/.claude/skills/existential-birds-beagle-review-verification-protocol-0d2215 && rm -rf "$T"
plugins/beagle-rust/skills/review-verification-protocol/SKILL.mdReview Verification Protocol
This protocol MUST be followed before reporting any code review finding. Skipping these steps leads to false positives that waste developer time and erode trust in reviews.
Pre-Report Verification Checklist
Before flagging ANY issue, verify:
- I read the actual code - Not just the diff context, but the full function/impl block
- I searched for usages - Before claiming "unused", searched all references
- I checked surrounding code - The issue may be handled elsewhere (trait impls, error propagation)
- I verified syntax against current docs - Rust edition, crate versions, and API changes
- I checked the project's Rust edition - Edition 2021 vs 2024 changes what is required vs optional (see Edition-Aware Review)
- I distinguished "wrong" from "different style" - Both approaches may be valid
- I considered intentional design - Checked comments, CLAUDE.md, architectural context
Verification by Issue Type
"Unused Variable/Function"
Before flagging, you MUST:
- Search for ALL references in the codebase (grep/find)
- Check if it's
and used by other crates in the workspacepub - Check if it's used via derive macros, trait implementations, or conditional compilation (
)#[cfg] - Verify it's not a trait method required by the trait definition
Common false positives:
- Trait implementations where the method is defined by the trait
items only used in test builds#[cfg(test)]- Derive-generated code that uses struct fields
- Types used via
/From
conversionsInto
"Missing Error Handling"
Before flagging, you MUST:
- Check if the error is handled at a higher level (caller propagates with
)? - Check if the crate has a top-level error type that wraps this error
- Verify the
isn't in test code or after a safety-ensuring checkunwrap()
Common false positives:
in tests and examples (expected pattern)unwrap()
after validation (e.g.,expect("reason")
on a literal)regex::Regex::new- Error propagation via
(the caller handles it)?
— intentional when receiver may have droppedlet _ = tx.send(...)
"Unnecessary Lifetime" / RPIT Capture (Edition 2024)
Before flagging, you MUST:
- Check the project's Rust edition in
Cargo.toml - In edition 2024,
captures ALL in-scope lifetimes by default-> impl Trait - A lifetime that appears "unnecessary" may be implicitly captured — the code is correct
- If the author uses
syntax, this is precise capture control, not a mistake+ use<'a>
Common false positives:
- Lifetime parameters on functions returning
— edition 2024 captures them implicitlyimpl Trait
syntax — this is the new precise capturing syntax, not an error+ use<'a, T>- Removing an explicit lifetime bound that edition 2024 now provides automatically
"Missing Unsafe Block" (Edition 2024)
Before flagging, you MUST:
- Check if the code is inside an
unsafe fn - In edition 2024,
is deny-by-default — unsafe operations insideunsafe_op_in_unsafe_fn
REQUIRE explicitunsafe fn
blocksunsafe {} - This is edition-required behavior, not unnecessary verbosity
Common false positives:
blocks insideunsafe {}
— REQUIRED in edition 2024, not redundantunsafe fn
— REQUIRED in edition 2024, not optionalunsafe extern "C" {}
/#[unsafe(no_mangle)]
— REQUIRED in edition 2024#[unsafe(export_name)]
"Unnecessary Clone"
Before flagging, you MUST:
- Confirm the clone is actually avoidable (borrow checker may require it)
- Check if the value needs to be moved into a closure/thread/task
- Verify the type isn't
(clone on Copy types is a no-op)Copy - Check if the clone is in a hot path (test/setup code cloning is fine)
Common false positives:
— this is the recommended explicit clone for ArcArc::clone(&arc)- Clone before
— required fortokio::spawn
bound'static - Clone in test setup — clarity over performance
"Potential Race Condition"
Before flagging, you MUST:
- Verify the data is actually shared across threads/tasks
- Check if
,Mutex
, or atomic operations protect the accessRwLock - Confirm the type doesn't already guarantee thread safety (e.g.,
)Arc<Mutex<T>> - Check if the "race" is actually benign (e.g., logging, metrics)
Common false positives:
— already thread-safeArc<Mutex<T>>- Tokio channel operations — inherently synchronized
operations — designed for concurrent accessstd::sync::atomic
"Performance Issue"
Before flagging, you MUST:
- Confirm the code runs frequently enough to matter
- Verify the optimization would have measurable impact
- Check if the compiler already optimizes this (iterator fusion, inlining)
Do NOT flag:
- Allocations in startup/initialization code
- String formatting in error paths
- Clone in test code
on small iterators.collect()
Severity Calibration
Critical (Block Merge)
ONLY use for:
code with unsound invariantsunsafe- SQL injection via string interpolation
- Use-after-free or memory safety violations
- Data races (concurrent mutation without synchronization)
- Panics in production code paths on user input
Major (Should Fix)
Use for:
- Missing error context across module boundaries
- Blocking operations in async runtime
- Mutex guards held across await points
- Missing transaction for multi-statement database writes
Minor (Consider Fixing)
Use for:
- Missing doc comments on public items
parameters whereString
would work&str- Suboptimal iterator patterns
- Missing
on functions with important return values#[must_use]
Informational (No Action Required)
Use for:
- Suggestions for newtypes, builder patterns, or type state
- Performance optimizations without measured impact
- Suggestions to add
#[non_exhaustive] - Refactoring ideas for trait design
These are NOT review blockers.
Do NOT Flag At All
- Style preferences where both approaches are valid (e.g.,
vsif let
for single variant)match - Optimizations with no measurable benefit
- Test code not meeting production standards
- Generated code or macro output
- Clippy lints that the project has intentionally suppressed
Valid Patterns (Do NOT Flag)
Rust
| Pattern | Why It's Valid |
|---|---|
in tests | Standard test behavior — panics on unexpected errors |
in test setup | Clarity over performance |
in test modules | Standard pattern for accessing parent items |
in binaries | Not every app needs custom error types |
fields in structs | Owned data is correct for struct fields |
| Explicit Arc cloning is idiomatic and recommended |
with reason | Intentional suppression is valid |
instead of | Self-cleaning suppression (stable since 1.81) — warns when lint no longer triggers |
inside | Required in edition 2024 ( = deny) |
| Required in edition 2024 for extern blocks |
| Required in edition 2024 for safety-relevant attributes |
| Required in edition 2024 for safety-relevant attributes |
on returns | Precise capture syntax for edition 2024 RPIT |
as identifier | is reserved in edition 2024 |
/ | Standard library replacements for / (stable since 1.80) |
in trait definitions | No longer needs crate (stable since 1.75) |
| Custom trait error messages (stable since 1.78) |
Async/Tokio
| Pattern | Why It's Valid |
|---|---|
for short critical sections | Tokio docs recommend this for non-async locks |
without join | Valid for background tasks with shutdown signaling |
with branch | Non-blocking check, intentional pattern |
without multi_thread | Default single-thread is fine for most tests |
Testing
| Pattern | Why It's Valid |
|---|---|
in tests | Acceptable for test setup/assertions |
with | Valid for testing panic behavior |
| Large test functions | Integration tests can be long |
in test cleanup | Cleanup errors are often unactionable |
General
| Pattern | Why It's Valid |
|---|---|
in new code | Valid placeholder during development |
during development | Common during iteration |
Multiple blocks for one type | Organized by trait or concern |
| Type aliases for complex types | Reduces boilerplate, improves readability |
Context-Sensitive Rules
Ownership
Flag unnecessary
.clone() ONLY IF:
- In a hot path (not test/setup code)
- A borrow or reference would work
- The clone is not required for
/Send
bounds'static - The type is not
Copy
Error Handling
Flag missing error context ONLY IF:
- Error crosses a module boundary
- The error type doesn't already carry context (thiserror messages)
- Not in test code
- The bare
loses meaningful information about what operation failed?
Unsafe Code
Flag unsafe ONLY IF:
- Safety comment is missing or doesn't explain the invariant
- The unsafe block is broader than necessary
- The invariant is not actually upheld by surrounding code
- A safe alternative exists with equivalent performance
Edition 2024 unsafe changes — check
Cargo.toml edition before flagging:
insideunsafe {}
is required (not style) in edition 2024unsafe fn
is required in edition 2024 — bareunsafe extern "C" {}
is a compile errorextern "C" {}
and#[unsafe(no_mangle)]
are required in edition 2024#[unsafe(export_name)]- In edition 2021, these patterns are optional style choices — do not require them
Edition-Aware Review
BEFORE flagging any edition-specific pattern, check
Cargo.toml for the project's edition:
[package] edition = "2024" # or "2021", "2018"
Edition 2024 changes that affect review findings:
| Change | Edition 2021 | Edition 2024 |
|---|---|---|
inside | Optional style | Required ( = deny) |
| Valid | Must be |
| Valid | Must be |
| Valid | Must be |
lifetime capture | Explicit only | Captures all in-scope lifetimes |
as identifier | Valid | Reserved keyword (use ) |
type fallback | Falls back to | Falls back to |
temporaries | Dropped at end of block | Dropped earlier (end of ) |
| Tail expression temporaries | Dropped after locals | Dropped before local variables |
iteration | Needs explicit | Has impl |
If edition is not specified, Rust defaults to edition 2015. Most modern projects use 2021 or later.
Cross-reference: The
beagle-rust:rust-code-review and beagle-rust:rust-best-practices skills provide edition-specific code review guidance and idiomatic patterns.
Macro-Specific Verification
"Macro Hygiene Issue"
Before flagging, you MUST:
- Verify the identifier actually leaks — types, modules, and functions are NOT hygienic in
macro_rules! - Check if
is used correctly for exported macros (not$crate
orcrate
)self - Confirm
/::core::
paths are needed (only for macros used in no_std contexts)::alloc:: - Check whether the macro is internal-only or
#[macro_export]
Common false positives:
- Non-hygienic type names in internal macros — only matters for exported macros
not used in macros that are only$crate
—pub(crate)
is for cross-crate usage$crate- Using
in macros for std-only crates — only flag if crate supports no_std::std::
"Procedural Macro Performance"
Before flagging, you MUST:
- Verify the macro is actually in a proc-macro crate (check
forCargo.toml
)proc-macro = true - Check if
features are minimized (fullsyn
withsyn
feature vs selective features)"full" - Confirm compile-time impact is meaningful (proc macros used across many files vs one-off)
"Wrong Fragment Type"
Before flagging, you MUST:
- Verify the suggested fragment type actually works in that position
- Check if
is intentionally used for flexibility (common in TT munching patterns):tt - Confirm
greediness issues actually manifest (test with the macro's actual call sites):expr
FFI-Specific Verification
"Missing repr(C)"
Before flagging, you MUST:
- Confirm the type actually crosses the FFI boundary (passed to/from C code)
- Check if the type is only used on the Rust side of the FFI wrapper
- Verify there isn't a
wrapper instead#[repr(transparent)]
Common false positives:
- Internal Rust types that are converted before FFI call — only the FFI-facing type needs
repr(C) - Types used with
newtype wrappers — the wrapper handles layoutrepr(transparent) - Opaque pointer types (
) — no layout guarantee needed*mut c_void
"FFI Safety"
Before flagging, you MUST:
- Check if the unsafe FFI call has a SAFETY comment documenting invariants
- Verify ownership transfer is actually ambiguous (check for
/Box::into_raw
pairs)Box::from_raw - Confirm CString lifetime issues are real (the CString must outlive the pointer passed to C)
- Check if callback unwinding is actually possible (pure data functions can't panic across FFI)
Common false positives:
callbacks that never panic —extern "C" fn
not neededcatch_unwind
from CStr::as_ptr() held within the same scope — lifetime is fine*const c_char- Bindgen-generated code with
— bindgen output is inherently unsafe-heavy by designunsafe
Concurrency-Specific Verification
"Memory Ordering Too Weak"
Before flagging, you MUST:
- Verify the atomic is actually shared between threads that need synchronization
- Check if
is sufficient (counters, flags with no dependent data)Relaxed - Confirm
vsAcquire/Release
choice matters (most code doesn't need SeqCst)SeqCst
Common false positives:
on simple counters/metrics — no ordering needed for independent valuesRelaxed
on boolean flags polled in a loop — the loop provides eventual visibilityRelaxed
used "for safety" — not wrong, just potentially over-synchronizedSeqCst
Before Submitting Review
Final verification:
- Re-read each finding and ask: "Did I verify this is actually an issue?"
- For each finding, can you point to the specific line that proves the issue exists?
- Would a Rust domain expert agree this is a problem, or is it a style preference?
- Does fixing this provide real value, or is it busywork?
- Format every finding as:
[FILE:LINE] ISSUE_TITLE - For each finding, ask: "Does this fix existing code, or does it request entirely new code that didn't exist before?" If the latter, downgrade to Informational.
- If this is a re-review: ONLY verify previous fixes. Do not introduce new findings.
If uncertain about any finding, either:
- Remove it from the review
- Mark it as a question rather than an issue
- Verify by reading more code context