DEV Community

Start
Start

Posted on Edited on AI-assisted

Your AI Assistant Cannot Be Trusted With Your Build. Here Is What Can.

Your AI Assistant Cannot Be Trusted With Your Build. Here Is What Can.

A review checklist is a suggestion. A build gate is a decision.

That distinction used to matter mostly to teams with junior engineers. Now it matters to everyone, because the diff in front of you may have been written by a model that is very good at producing plausible code and very bad at knowing when it is wrong.

I maintain three Rust crates — rust-dix (DI), rust-ef (ORM), rust-webx (Web API). Over the past months I have watched what happens when these crates sit underneath AI-assisted work. The useful part was never that they generate better code. It is that a whole class of generated mistakes cannot pass the build.

Here is the machinery, and what it actually rejects.

A half-wired endpoint does not boot

An assistant will generate a handler, a request type, and a route — usually in that order, usually forgetting that the framework needs all three to agree.

In rust-webx, route metadata and handler registrations are collected at compile time through inventory, then joined by TypeId inside Host::build(). If a request has no handler, the host refuses to start. Duplicate (method, path) pairs and handlers with no dispatch bridge are assembly errors too.

try_build() returns the whole report at once, sorted, with a Fix: line per group. --doctor prints what is registered and what is orphaned.

This changes the review question. You no longer ask "did the assistant wire the whole endpoint?" You run the binary. If it boots, the endpoint is wired.

The same request type carries validation and OpenAPI metadata, so the route string, the DTO, the validation rules and the documented schema cannot drift apart. There is one description instead of four.

Ownership errors become typed errors

The most expensive generated bug I see is not an algorithm mistake. It is a lifetime decision nobody made: a request-scoped context registered as a singleton, or wrapped in Arc<Mutex<_>> to make it shareable.

rust-dix rejects it during build():

let provider = ServiceCollection::new()
    .scoped(|_| Arc::new(Session))
    .build()?;

let err = provider.get::<Session>();
// Err(ScopedFromRootProvider { service: "…Session" })
Enter fullscreen mode Exit fullscreen mode

A singleton capturing a scoped dependency reports SingletonDependsOnScoped. Resolving services from inside a constructor — which makes the dependency graph unknowable at validation time — is rejected as well.

These are deterministic failures with a named service in the error. They do not depend on a reviewer noticing a registration line in a 600-line diff at the end of a long day.

The escape hatch is called ServiceProviderOptions::lenient(). That name is deliberate.

The performance budget is a number, not an opinion

"Fast enough" is not a gate. Allocation count is.

On the Windows reference /hello benchmark, the bare-hyper floor is 6.00 allocations per request. rust-webx measures 10.42 — a framework tax of 10.42 above the floor in this configuration, gated in CI at ≤12 on the Windows reference and ≤13 on Linux CI, where the allocator adds roughly two allocations per request.

Those numbers come from the repo's allocation budget documentation. They are regression signals, not a capacity guarantee, and they are checked on every pull request. If a generated change adds an allocation on the hot path, the build says so.

The same repository runs property tests and a wire-level fuzz-lite pass in PR CI — 128 cases per property, 240 malformed requests for the fuzz pass. Nightly adds soak, five chaos scenarios, a p99 wire test, and a separate cargo-fuzz workspace covering cursor decode, config binding, client-IP resolution, problem-details round-trips, file-name sanitization and event wire frames.

None of this makes the framework "correct." It makes specific classes of regression visible without a human forming an opinion.

Ports fail closed

Generated code is remarkably good at silently doing nothing when a dependency is missing. It falls back to an in-memory stub, or a no-op, and the test suite stays green.

rust-webx turns most infrastructure dependencies into ports: IIdempotencyStore, IOutbox, ISessionStore, IMeter, IAdvisoryLock, IEmailSender. A missing adapter fails at startup as a DI error. There is no quiet default that lets a feature appear to work.

#[authorize(dynamic)] follows the same rule. Use it without registering an IDynamicAuthorizer and Host::build() fails — it does not downgrade to "authenticated is good enough."

This is the design decision I would defend most strongly in an AI-assisted workflow. Fail-open code is exactly what a model produces when it is trying to make a test pass.

What the gate does not cover

Be precise about the boundary, or you will trust it too much.

  • It does not verify business logic. A handler can pass every gate and still compute the wrong price.
  • It does not replace tests. The framework gates cover assembly, lifetimes, wire shape and allocation regressions — not your domain rules.
  • It is opinionated. One operation = one request + one handler + one file. A one-line webhook feels heavy.
  • It costs MSRV 1.95 and slower incremental builds from proc macros and link-time registration.
  • v2.9.x is young. Few production users. APIs can still move.

Also worth stating: the widely cited METR study found experienced developers were 19% slower with AI tools while believing they were 20% faster. That result is about developer perception, not about these crates, and it is the reason to prefer mechanical gates over confidence.

The practical move

Take the CI you already have and add one step: boot the host in a test with try_build(), assert the report is empty, and assert the transaction-scope error you expect. Then add the allocation check from the repo's budget doc as a threshold, not a log line.

That is an afternoon of work. After it, "the AI wrote it" stops being a special case in review. It is just code that has to pass the same gate as everything else.

Repositories:
rust-webx · rust-ef · rust-dix

Which check in your CI is currently a document rather than a command? That is the one I would convert first.

Top comments (0)