This is Week 5 of “Building with AI” - a 10-week journey documenting how I use multi-agent AI
workflows to build a production-grade SaaS platform.This week: The flip side of Week 4’s success story. When AI gets stuck in cascading errors,
watching error counts increase while the fix-in-session approach spirals out of control.
31 commits, 24 hours, and the hard lesson that AI excels at preventing problems but struggles
to fix complex cascading failures.Previous: Week 4: When AI Excels
Watch the 60-Second Summary
Week 5: Architecture mistakes and cascading errors
The Ironic Timing
Coming off Week 4’s spectacular success (107 commits, everything working beautifully), I was confident. AI had proven itself with:- End-to-end test coverage (21 scenarios)
- Organization modeling
- API architecture
- Usage metering pipelines
The Setup: A “Simple” Macro Enhancement
After successfully building 5 derive macros that eliminated 4,700 lines of boilerplate, I wanted to add one more feature: auto-generated CRUD methods. The change seemed straightforward:What We Built (or Tried To)
The CRUD Macro Enhancement
Goal: ExtendDynamoDbEntity macro to generate repository methods automatically
Breaking changes introduced:
- Method renames:
save()→db_save(),get()→db_get() - Factory pattern change:
self.clientfield →self.client()method - Error type change:
RepositoryError→EventStoreError - New dependencies:
aws-runtime,serde_dynamo
The Cascade: Hour by Hour
Hour 1: “This is fine”
Commit 508f43e:cd7c3e1: fix(crm): remove duplicate DynamoDbLegalEntityRepository export1ef9150: fix(crm): fix syntax errors and add missing imports
Hour 2-3: The Pattern Emerges
Commit 23d0baf:9e0815f: replace self.client with client11fe195: add client creation to save_calendar methodb1a1ff0: batch fix organization_dynamodb.rs methodseb5e215: fix pipeline_dynamodb client callsa7fbb9b: fix remaining client() method calls
Hour 4-6: Type System Whack-a-Mole
Each fix revealed new errors. Commit 8d6c763:- Old:
pk_for_id(tenant_id, capsule_id, id) - New:
pk_for_id(id)(macro infers tenant/capsule from entity)
9249626: fix pk_for_id and gsi method signatures7503f9f: add GSI methods and fix syntax errors47fd4ae: fix CrmError variants, field access errors3afc5a0: move contact methods to ContactRepository impl block3862c3e: fix E0425 errors (missing values) and self.client() calls
The Breaking Point: When I Stopped Trusting AI
Hour 7 (next morning): I found the AI session had made 6 more commits overnight (I left it running). Latest commit (f1ed1e7):The Fix: Human Intervention
What I did:- Stopped the AI session
- Read the original macro change (commit 508f43e)
-
Made a list of ALL changes the macro introduced:
- New method names (save → db_save)
- New factory pattern (client field → client() method)
- New error types (EventStoreError instead of RepositoryError)
- New dependency requirements (serde_dynamo)
- Fixed them systematically in 3 commits instead of 30:
- AI: 30 commits, 24 hours, 63 errors remaining
- Human: 3 commits, 90 minutes, 0 errors
What Went Wrong: AI’s Fix-in-Session Anti-Pattern
The Problem
When AI encounters a compilation error, it follows this pattern:- Read the error message
- Understand the immediate cause
- Fix that specific error
- Compile
- If more errors, repeat from step 1
- Each fix addresses symptoms, not root cause
- No holistic understanding of “what changed upstream”
- No batching of related fixes
- Creates more errors by partial fixes
The Example
Error cascade from macro change:- Recognize pattern: “All save() calls need to be db_save()”
- Fix ALL save() calls in one commit
- Recognize pattern: “All error types changed”
- Add unified error conversion
- Compile once → done
What I Learned: When to Stop Using AI
Red Flags That AI Is Stuck
Red Flag #1: Diminishing Returns Track errors fixed per commit:- Commits 1-5: Average 12 errors fixed each
- Commits 6-15: Average 4 errors fixed each
- Commits 16-30: Average 1 error fixed each (sometimes net increase!)
Red Flag #2: Repeated Fix Patterns If you see the same type of fix across multiple commits:
- “fix client() calls” (7 commits)
- “fix pk_for_id signature” (5 commits)
- “fix error variants” (6 commits)
Red Flag #3: Partial Fixes in Commit Messages Commit messages with “partial fix” or “fix remaining” indicate AI doesn’t have a complete solution. Examples from the cascade:
- “partial fix for organization_dynamodb.rs factory pattern”
- “fix remaining client() method calls”
- “batch fix organization_dynamodb.rs methods”
Principles Established This Week
Principle 1: Breaking Changes Need Migration Plans
Principle 1: Breaking Changes Need Migration Plans
What we learned: Macro changes are breaking changes that affect multiple crates simultaneously.New rule: Before making breaking macro changes:
- List all affected crates
- Identify all breaking changes (method renames, type changes, etc.)
- Create migration checklist
- Fix all affected crates in a single atomic commit
- Never commit broken intermediate states
Principle 2: Monitor AI's Error-Fixing Progress
Principle 2: Monitor AI's Error-Fixing Progress
What we learned: If error count isn’t decreasing steadily, AI is stuck.Tracking metric: Errors fixed per commit
- Healthy: 5-10 errors fixed per commit
- Warning: 2-4 errors fixed per commit
- Critical: Less than 2 errors per commit
Principle 3: Batch Fixes Beat Incremental Fixes
Principle 3: Batch Fixes Beat Incremental Fixes
What we learned: 30 small commits are worse than 1 comprehensive commit for systematic changes.When to batch:AI limitation: AI doesn’t use these batch tools effectively. Prefers file-by-file fixes.
- Method rename across many files
- Type signature changes
- Dependency updates
- Error handling pattern changes
Principle 4: AI Needs Constraints for Error Fixing
Principle 4: AI Needs Constraints for Error Fixing
What we learned: Unconstrained “fix all errors” leads to hallucination and inefficiency.Better prompt:This forces AI to: Think strategically about batching fixes instead of fixing one at a time.
The Surprising Discovery: AI Can Prevent This
After recovering from the cascade, I asked a fresh Evaluator session:-
Impact Analysis:
- Run
cargo treeto find all crates using the macro - Grep for all usage sites across workspace
- Estimate affected lines of code
- Run
-
Breaking Change Detection:
- Compare old vs new generated code (cargo expand)
- List method signature changes
- List type changes
- List new dependencies
-
Migration Plan:
- Create checklist of required updates per crate
- Batch fixes by category (method renames, type updates, etc.)
- Prepare workspace-wide test command
-
Atomic Commit Strategy:
- Update macro
- Update ALL downstream crates
- Verify workspace compilation
- Commit atomically
Week 5 By The Numbers
- The Failure
- The Recovery
- The Lesson
Commits: 31 (1 feature + 30 fixes)Time invested: 24 hoursFinal state: 63 errors remainingToken usage: 850k tokens ($13)Errors fixed per commit (average): 5.1Lowest errors fixed in single commit: -2 (net increase!)Developer frustration: Maximum
The Contrast: Week 4 vs Week 5
Week 4 (AI Excels):- AI built features from scratch
- Clear requirements, no existing code to conflict with
- 107 commits, all green
- Productivity: 6-8 weeks of work in 5.5 days
- AI fixed breaking changes it created
- Complex interdependencies, cascading effects
- 31 commits, increasing errors
- Productivity: 2 hours of work took 24 hours
Takeaways from Week 5
For breaking changes:- Always create migration plan first (Week 2 principle applies)
- Fix all affected sites atomically (never commit broken states)
- Use batch tools (rg, sd) for systematic renames
- Verify with
cargo check --workspacebefore committing
- Monitor error-fixing progress (errors per commit metric)
- Intervene when progress stalls (< 3 errors per commit)
- Use AI for planning/prevention, human for reactive fixes
- Fresh AI sessions for post-mortem analysis (worked brilliantly)
What’s Next
Week 6 Preview: Taking the lessons from Weeks 4 and 5, we’ll establish a hybrid workflow:- AI for feature planning and implementation
- Human for migration plans and systematic refactoring
- Clear decision trees for when to use which approach
Discuss This Week
Week 5 was humbling. Share your own “AI got stuck” stories or ask questions about the error-fixing
decision tree we established.
Disclaimer: All examples are from personal projects. No proprietary code or employer-specific
patterns included.