Documentation Index
Fetch the complete documentation index at: https://www.aidonow.com/llms.txt
Use this file to discover all available pages before exploring further.
Executive Summary
This analysis documents a critical failure mode in AI-assisted development: the fix-in-session anti-pattern, in which an AI agent responds to cascading compilation errors through sequential, locally-optimal corrections rather than through root cause analysis and systematic remediation. A single breaking macro change produced 30 fix commits across 24 hours, during which the codebase remained in an intermediate broken state and the AI agent began producing hallucinated fixes as context window saturation degraded its reasoning quality. Human intervention resolved the same problem in three commits and 90 minutes. The failure mode is predictable, detectable, and preventable — provided that engineers monitor error reduction rates, recognize batch-fixable patterns, and establish pre-change migration protocols for breaking changes.Key Findings
- The fix-in-session anti-pattern produces diminishing returns that are measurable in real time: error counts per commit declined from 12 in the first five commits to fewer than 2 in commits 16–30, with net error increases appearing in the final phase.
- AI agents performing reactive error correction lack a system-wide mental model, fixing each error in isolation without recognizing that multiple errors share a single upstream root cause requiring a single batch fix.
- Context window saturation in long error-fixing sessions degrades AI reasoning quality to the point of hallucination: the AI produced a structurally incorrect error type conversion after 24 commits, inventing a tuple variant that did not exist in the actual error enum.
- Human batch intervention using standard tooling (ripgrep, sed, cargo expand) resolved the same problem 16 times faster than AI sequential fixing, with zero errors introduced during the remediation.
- Breaking macro changes require pre-change migration plans: the cascade was preventable through a two-commit atomic strategy that would have taken two hours rather than 24.
1. Introduction
1.1 Background
A derive macro responsible for generating DynamoDB repository structs was extended to auto-generate CRUD methods. The change was expected to save approximately 200 lines of boilerplate per entity. The breaking change introduced four categories of downstream incompatibility across multiple crates:- Method name changes (
save→db_save,get→db_get) - Factory pattern change (field access
self.client→ method callself.client()) - Error type change (
RepositoryError→EventStoreError) - New dependency requirements (
aws-runtime,aws-sdk-dynamodb,serde_dynamo)
1.2 Expected vs. Actual Impact
Expected: manual updates to four affected crates, estimated at two hours of work. Actual: 30 fix commits, 24 hours of elapsed time, codebase remaining in a broken state throughout, and an unresolved error count of 14 at the point of human intervention.2. Cascade Progression Analysis
2.1 Phase 1: Initial Errors (Commits 1–5, Hour 1)
The first commits addressed straightforward symptoms: duplicate export conflicts introduced by newly generated code, and missing imports required by the generated methods. Error resolution rate during this phase was approximately 12 errors per commit. Commit cd7c3e1:2.2 Phase 2: Pattern Emergence (Commits 6–13, Hours 2–3)
The macro’s generated methods used a different factory pattern than the manually implemented methods they replaced: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
2.3 Phase 3: Type System Errors (Commits 14–24, Hours 4–6)
The macro changed the primary key method signature:- Previous:
pk_for_id(tenant_id, capsule_id, id) - Current:
pk_for_id(id)— tenant and capsule context inferred from entity type
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
3. The Hallucination Event
After 24 commits and approximately 24 hours, the AI produced the following fix for a type mismatch error: The error:CrmError::Repository variant is a struct variant, not a tuple variant:
4. Root Cause Analysis: The Fix-in-Session Anti-Pattern
4.1 Mechanism Description
The fix-in-session anti-pattern operates through the following cycle:- A breaking change is introduced
- Compilation errors appear across multiple files
- The AI is instructed to fix all compilation errors
- The AI reads the first error, identifies the immediate cause, and applies a local fix
- Compilation reveals new errors in adjacent files
- The AI repeats from step 4
4.2 Comparison with Effective Error Resolution
The error cascade that generated 30 commits was mechanically identical to the following pattern, repeated across each error category:- Recognize the pattern: all
save()calls require renaming todb_save() - Fix all instances in a single commit
- Recognize the pattern: all error type references require a unified conversion
- Add the conversion once
- Compile once to verify
4.3 Why AI Agents Do Not Self-Correct This Pattern
Three structural limitations prevent AI agents from escaping the fix-in-session pattern without human intervention: Absence of system-wide mental model: AI agents see errors as they appear in compiler output. They do not maintain a forward-looking model of which files will be affected by a given upstream change. Human developers with knowledge of the codebase can predict the full impact of a macro change before making it. Local optimization over global optimization: Each fix is evaluated against the criterion of resolving the current compiler error, not against the criterion of minimizing total work or preserving codebase coherence. A fix that adds a new method to seven structs instead of updating seven call sites is locally valid but globally wasteful. No self-assessment of diminishing returns: After 15 commits with declining error reduction rates, the AI does not re-evaluate its strategy. It continues applying the same approach until either the errors are resolved or context window saturation degrades output quality to the point of hallucination.5. Human Intervention and Recovery
5.1 Intervention Method
Upon recognizing the pattern — after examining commit messages and noting diminishing error reduction rates — the AI session was terminated. Recovery proceeded as follows: Step 1: Root cause analysis (30 minutes) The original macro change commit was read in full. All categories of breaking change were enumerated:save()→db_save()get()→db_get()clientfield →client()methodRepositoryError→EventStoreError- New dependency requirements
5.2 Comparative Metrics
| Approach | Commits | Elapsed Time | Final Error Count | Errors Introduced During Fix |
|---|---|---|---|---|
| AI fix-in-session | 31 | 24 hours | 14 remaining | ~40 new errors |
| Human batch intervention | 3 | 90 minutes | 0 | 0 |
6. Detection and Prevention
6.1 Early Warning Indicators
The following indicators signal that fix-in-session has become ineffective and manual intervention is required: Indicator 1: Declining error reduction rate. Track errors fixed per commit:| Commit Range | Error Reduction Rate | Action |
|---|---|---|
| Commits 1–5 | 10–15 errors per commit | Continue AI-assisted fixing |
| Commits 6–15 | 4–9 errors per commit | Monitor closely |
| Commits 16–30 | 0–3 errors per commit | Intervene manually |
| Any commit | Net error increase | Intervene immediately |
6.2 Pre-Change Protocol for Breaking Macro Changes
The cascade was preventable through the following pre-change discipline:Impact analysis
Run
cargo tree to identify all crates consuming the macro. Use cargo expand on one representative entity to inspect generated code before and after the change. Grep for all usage sites across the workspace.Breaking change enumeration
List all method signature changes, type changes, factory pattern changes, and new dependency requirements introduced by the macro modification.
Migration plan
Categorize required downstream changes by type. Prepare batch fix commands for each category. Document the workspace-wide verification command.
7. Post-Incident Analysis: AI as Prevention vs. Remediation
Following recovery from the cascade, a fresh AI session was used to analyze the incident. The result was instructive: the AI produced a comprehensive pre-change checklist for macro modifications that accurately described exactly the steps that would have prevented the cascade. This confirmed a structural observation about AI agent capability: AI agents are effective at planning ahead for known failure modes. They are poor at recognizing those same failure modes when experiencing them reactively. The distinction is between proactive pattern application (producing a checklist before a change) and reactive pattern recognition (recognizing mid-cascade that a batch fix is required). AI agents perform well on the former because it is a generation task applied to a well-defined input. They perform poorly on the latter because it requires a form of meta-cognition — recognizing that the current approach is failing and that a strategy change is required — that is not well-supported in current AI architectures.8. Recommendations
- Establish and enforce a pre-change protocol for all breaking changes to shared components. Macros, traits, and interfaces with multiple downstream consumers require impact analysis, breaking change enumeration, and atomic commit planning before the change is made.
- Monitor error reduction rate per commit during AI-assisted error fixing. When the rate falls below three errors per commit for three consecutive commits, halt the AI session and perform manual intervention.
- Constrain AI error-fixing sessions with explicit limits. A prompt structure such as “fix compilation errors, maximum five commits, group related fixes, do not add new methods or types, report and stop if stuck after three commits” produces better outcomes than an unconstrained “fix all errors” instruction.
- Use fresh AI sessions for post-incident analysis. Context window saturation during long error-fixing sessions degrades AI reasoning quality. Post-incident analysis benefits from a session that begins with the root cause clearly stated rather than one carrying accumulated error message context.
- Apply batch tools for systematic renames across a codebase. Ripgrep, sed, and similar utilities complete in seconds what AI agents address over dozens of commits. The tooling required to perform the human intervention in this analysis:
- Treat AI quality degradation in long sessions as a system property, not an anomaly. Context window saturation producing hallucinated fixes is a predictable outcome of extended error-fixing sessions, not an exceptional failure. Session management — recognizing when to start fresh — is a required operational skill.
9. Conclusion
The fix-in-session anti-pattern is a predictable failure mode in AI-assisted development, not an edge case. It emerges whenever a breaking change propagates errors across multiple files and an AI agent is instructed to resolve them without a structured migration plan. The pattern is detectable through real-time monitoring of error reduction rates and recognizable through characteristic commit message patterns. It is preventable through pre-change impact analysis and atomic commit strategies. As AI-assisted development tools become more prevalent in software engineering workflows, the distinction between tasks where AI generates value through autonomous execution and tasks where AI requires human-defined structure before execution will become increasingly important to document and transmit. Breaking change management belongs firmly in the latter category.All content represents personal learning from personal projects. Code examples are sanitized and generalized. No proprietary information is shared. Opinions are my own and do not reflect my employer’s views.