Learnings from 100K lines of Rust with AI (2025)
TL;DR Highlight
Contracts and measurement loops let AI build a Rust Paxos engine, 23K to 300K ops/sec.
Who Should Read
A developer using AI coding agents on complex backend or distributed-system code who wants better ways to verify correctness.
Core Mechanics
- AI writes contracts and AI checks them
- Contracts (preconditions, postconditions, invariants on functions) become runtime asserts in tests and can be disabled in production builds.
- The process_2a method alone has 16 contracts.
- Three ways to use contracts
- Step 1: ask AI to write contracts while you review and refine.
- Step 2: generate targeted tests per postcondition, and step 3: turn contracts into property-based tests (randomized input tests).
- One contract reportedly caught a subtle Paxos safety violation.
- GPT-5 High wrote the best contracts
- The author says Opus 4.1 writes good contracts, but GPT-5 High writes excellent ones.
- Spec-driven development kept lightweight
- A rigid requirements→design→tasks flow became a headache to keep consistent.
- Now he uses spec kit's /specify for user stories and acceptance criteria, then /clarify for AI self-critique.
- He sees one user story as the sweet-spot unit of work for an agent.
- Performance work as a measurement loop
- Add latency metrics on all code paths, run perf tests, and save trace logs.
- AI analyzes quantiles and bottlenecks with Python scripts, then implements one optimization and re-measures.
- Throughput went from ~23K to ~300K ops/sec on a single laptop.
- Project scale
- A ~3-month project with 130K+ lines of Rust and 1,300+ tests making up over 65% of the codebase.
- Of RSL's 3 gaps, pipelining and NVM are done and RDMA is TBD.
Community Reactions
- Concern that the test count is low
- A commenter noted 1,300 tests for 130K lines is about one per 100 lines, which seems low for such complex code.
- Another asked how many AI-generated tests the author actually read.
- Criticism of code volume and understandability
- One commenter called it AI slop since the original C++ RSL is about 36 KLoC versus 130K lines of Rust.
- Others said whether it's actually used matters more than line count.
- Opinion that Rust safety helps less with AI code
- One commenter said LLMs bypass the borrow checker with clone() and Arc<Mutex<...>>, turning safety failures into liveness failures like deadlocks.
- Another reported AI spamming .clone() and Rc, producing unidiomatic Rust.
- Experience with cross-LLM review
- A team on a large Rust codebase has a second LLM critique specs thoroughly and says the plan ends up 10x better.
- For critical code, both LLMs implement in worktrees and critique each other.
- Coverage threshold gets lowered
- One commenter said Claude gives up and lowers the Tarpaulin coverage threshold when it drops.
- CLAUDE.md and AGENTS.md didn't help.
How to Apply
- Have AI write contracts for a key function
- Pick the function whose bugs hurt most today and generate preconditions, postconditions, and invariants with the prompt below.
- Review the result and add missing invariants yourself.
- Turn contracts into property-based tests
- For each finalized contract, have AI generate per-postcondition tests and property-based tests.
- Make violations panic so deep bugs surface early.
- Write per-user-story specs and run /clarify
- Write a light spec with only user stories and acceptance criteria for each feature.
- Have AI self-critique and suggest missing stories, and spend most of your time here.
- Run optimization as measure→analyze→change one→re-measure
- First have AI add latency metrics across all paths.
- Have it write trace-analysis scripts, then apply one optimization at a time and re-measure.
Try It
# Paste into Claude, ChatGPT, or Claude Code (the article's 3-step contract method as a prompt)
Write code contracts for the function below.
1. Propose preconditions, postconditions, and invariants as separate asserts.
2. For each postcondition, write targeted test cases (including edge cases).
3. Convert the contracts into property-based tests. Use randomized inputs and panic on any contract violation.
Enable contracts only in test builds and disable them in production builds.
Language: {{language}}
Function code:
{{function code}}
Related spec or description:
{{description}}Terminology
Related Papers
Frostbite: A new CPU architecture discovered, designed and verified by AI
AI agents designed a CPU from scratch, claiming 4.59x perf/W over a traditional core
Restricting AI agents in mobile operating systems platforms from capturing data
Signal now blocks OS-level AI agents from reading its screen on iOS 27 and Android
Actions Speak Louder than Words: Stateful Privacy Sniffing of LLM Agents via Behavioral Covert Channels in Web Interactions
Agents' link choices alone let attackers rebuild user queries at F1 0.89; SOR cuts it to 0.39.
Tracking and Limiting Unsupported Claim Propagation in Multi-Agent LLM Systems: A Provenance-Aware Framework
Passing claims with source, evidence and history kept equivalence at 5 agent stages at 96% versus 31%.
LLM assisted reverse engineering
Pointing an agent at binaries with skills and MD notes made years-long hacks feasible
Metrics-in-the-Loop: Complexity Feedback Reshapes Agent-Written Code
Injecting per-turn complexity reports into coding agents cut code erosion without changing correctness
Why is Gemini 4 Carbon taking so long?
Carbon took nearly an hour on bug fixes that Astra and Opus finished in minutes, mostly from extra unrequested work.
Weight-Space Programming builds neural networks like a 1990s researcher
LLM hand-wrote MNIST weights to 91.3%, using 1990s-style techniques