100K Lines of Rust with AI: Contracts, Spec-Driven Dev, and Performance

Cheng Huang spent ~6 weeks building a Rust-based multi-Paxos consensus engine designed to modernize Azure's Replicated State Library (RSL). The project involved over 130K lines of Rust code (~100K written in 4 weeks by AI agents, plus 3 weeks of optimization) and achieved a throughput jump from 23K to 300K operations per second.
Huang used multiple AI coding agents: GitHub Copilot, Claude Code, Codex CLI, Augment Code, Kiro, and Trae. His primary setup now is Claude Code + Codex CLI from the terminal, with VS Code only for diffs and minor edits. He maintains two ChatGPT subscriptions to handle rate limits (one Mon-Wed, one Thu-Sun).
Code Contracts — Written by AI
The core correctness strategy: AI-generated code contracts that specify preconditions, postconditions, and invariants for critical functions, converted into runtime asserts during testing. Huang found GPT-5 High writes excellent contracts; Opus 4.1 is good but requires more review. For example, the process_2a method (handling Paxos phase 2a messages) has 16 contracts. Contracts are then used to generate targeted test cases and property-based tests that explore randomized inputs — one contract caught a subtle Paxos safety violation that could have caused replication consistency issues.
Lightweight Spec-Driven Development
Huang initially tried a rigid spec-driven approach: requirement markdown → design markdown → task list markdown. He found it too inflexible for iterative changes. He now uses a lighter-touch SDD: start with a concise spec, let AI generate code, then refine contracts and tests iteratively. The full system includes 1,300+ tests spanning unit, integration, and multi-replica failure injection tests.
Performance Optimization
The optimization phase (3 weeks) boosted throughput from 23K to 300K ops/sec. Key architectural changes: added pipelining (requests no longer wait for in-flight votes), support for non-volatile memory (NVM) to reduce commit time, and RDMA awareness for modern Azure datacenter hardware.
What's Next
Huang wishes for better AI support for property-based test generation from contracts and more seamless handling of breaking changes in codebases above 100K lines.
📖 Read the full source: HN AI Agents
👀 See Also

Firefox Workaround for Claude.ai Freeze Issue Using Tampermonkey Script
A Reddit user shares a Tampermonkey script workaround for Firefox users experiencing freezes on Claude.ai. The script modifies Date.now() behavior to prevent timing conflicts that cause the interface to hang.

Wtf.md and Dreaming: Two Claude Workflow Concepts Worth Exploring
A developer shares two Claude concepts: Wtf.md for storing errors Claude makes, and Dreaming, Karpathy's idea for nightly session consolidation.

Cost-Effective OpenClaw Automation: Using LLMs Only When Needed
A developer shares a practical approach to using OpenClaw for deterministic tasks without constant LLM calls, creating Python scripts for cron jobs and only invoking the LLM when errors require analysis and fixes.

Practical Habits for Critical LLM Interaction
A Reddit post outlines specific techniques for avoiding confirmation bias when working with LLMs, including custom prompt modes like 'strawberry' for neutral explanation and 'socrates' for adversarial scrutiny, plus evaluating training data composition.