A Fail-Closed Gate for Rust AI Assistants
Source: Dev.to
Stop AI from suggesting workarounds before it proves the rejection
Most AI coding assistants follow the same workflow:
- Read the compiler error
- Explain it
- Suggest a fix
This works well in many languages, but in Rust it often breaks the language’s guarantees.
The problem
Rust compiler errors—especially borrow‑checker rejections—are formal rejections:
- the requested state cannot be proven safe, or
- it cannot exist under Rust’s invariants
AI assistants usually treat them as “something the user probably wants to work around,” leading to a predictable pattern:
clone()appears too earlyArcbecomes the default escape hatchRefCellandunsafeshow up without an explicit trade‑off
The AI does not decide which invariant is being sacrificed—it just sacrifices one.
Core idea: suggestion must be earned
Instead of making AI “better at explaining Rust,” this project enforces one rule:
An AI assistant must not suggest anything until it proves it is allowed to.
This is implemented as a fail‑closed adjudication gate.
Two roles, one hard boundary
Adjudicator (LLM)
Allowed to:
- classify the rejection (A / B / C / D)
- describe conflicts or proof gaps
- state which Rust invariant is preserved
Not allowed to:
- suggest code
- propose workarounds
- hint at escape mechanisms
Auditor (Gate)
-
Does not interpret meaning or understand Rust semantics.
-
Performs only structural validation:
- required fields exist
- enums match
- scopes are consistent
- forbidden suggestion behavior is absent
If validation fails → fail‑close.
Fail‑close is the key design choice
Most AI systems fail open (“If unsure, still help.”).
Compilers fail closed (“If unproven, stop.”).
This gate copies the compiler’s philosophy, not the assistant’s instinct. When adjudication is incomplete, the system returns only a structured rejection—no suggestions, no workaround hints, no “you could try…”.
Minimal flow
Input (code + intent)
↓
Adjudicator (LLM)
- classify rejection
- describe conflict
↓
Auditor (Gate)
- schema validation
- enum checks
↓
PASS → suggestions allowed
FAIL → suggestions blocked
The gate decides, not the model.
What this demo intentionally does not do
- Map
rustcerror codes - Judge explanation quality
- Optimize prompts
- Teach Rust
It proves only one thing: suggestion control can be enforced as a product behavior, not a prompt convention.
Why Rust makes this visible
Rust exposes invariant violations explicitly, but the same failure mode exists in:
- security tooling
- financial systems
- safety‑critical code
- policy‑driven systems
Any domain where “helpfulness” can override authority needs a gate like this.
Takeaway
AI assistants should not compete with compilers; they should respect them. Sometimes the correct output is not a workaround—but silence enforced by rules.