AI-generated code technical debt accumulates because agentic coding ships the working 80% of a solution quickly and omits the production-grade remainder: error handling, security controls, and observability.
TL;DR
AI coding agents ship the visible 80% quickly: CRUD operations, standard patterns and passing tests. The invisible 20%, non-functional requirements, failure modes and architectural consistency, is systematically omitted because agents lack persistent context and verification. Retrofitting that 20% costs more than building it correctly because comprehension debt, duplication, and cross-cutting inconsistencies prevent single-point fixes.
The pattern repeats across teams adopting AI coding agents. The first PR looks miraculous: a complete feature, generated in minutes, tests passing. By the fifth, something breaks in production that no test caught. A missing retry, an unhandled null, an authentication check that exists on three endpoints but not the fourth. The agent wrote code that works. The agent did not write code that survives. This gap helps explain why teams shipping faster than ever can also accumulate technical debt faster than ever.
What Agentic Coding Is and Where AI-Generated Code Technical Debt Hides
Agentic coding is software development in which a human states an objective and an AI agent plans the work, edits files across a repository, runs commands, and iterates against test results until the objective is met. Scope of action separates it from autocomplete. An assistant such as GitHub Copilot proposes the next span of code inside a file a developer is already editing. An agent such as Claude Code, Cursor's agent mode, or Augment's Auggie CLI decides which files to open, changes several of them in one pass, and verifies its own work by executing it. Agentic engineering is the practice built around that shift: the review structures, specifications, and verification gates a team puts in place once agents write most of the diff.
Technical debt in agent-written code differs from hand-written debt in speed and in visibility. Hand-written debt is usually a known shortcut, taken deliberately under deadline by someone who can describe it. Agent-written debt arrives as an omission nobody chose, at the rate the agent generates code, in files no human has read closely. What is missing is consistent: the non-functional requirements, meaning the error handling, security controls, observability, and compliance behavior that decides whether code survives production.
That consistency is the reason the debt hides. A test suite exercises the behavior a developer specified, so code missing only the unspecified behavior passes every gate it meets.
What the 80% Problem Actually Is
Addy Osmani named the problem on January 28, 2026, in an analysis of agentic coding. It starts from Andrej Karpathy, whom Osmani quotes as having moved to "80% agent coding and 20% edits+touchups." The remaining 20% is not a minor cleanup task. Rate limiting, observability hooks, retry logic with backoff, circuit breakers, audit logging, PII handling, and input sanitization all live in it, and they determine whether code survives contact with production traffic, compliance audits, and real-world failure conditions.
Osmani names four failure modes that accumulate as prompting continues past a working prototype. Assumptions propagate from one generation into the next, abstractions bloat, dead code stays in place after an implementation is superseded, and agents agree with a developer who has stated a bad premise. All four add code, and none adds a test that would fail.
What agents reliably produce:
- CRUD operations, standard API patterns, and type definitions
- Basic validation and happy-path test coverage
- UI component rendering, state management, and database queries
What agents systematically omit:
- Error handling for failure modes beyond the happy path, and security controls applied at the architectural level instead of per endpoint
- Observability: structured logging, metrics, distributed tracing
- Edge cases, compliance requirements, and architectural consistency across files
A test suite checks the first list; a production incident checks the second.
Where the 80% Problem Hits Hardest
The gap between human-written and AI-generated code follows a consistent pattern across quality dimensions:
| Dimension | Human-Written Code | AI-Generated Code |
|---|---|---|
| Error handling | Shaped by production experience; handles known failure modes | Happy-path focused; omits retry logic, circuit breakers, graceful degradation |
| Security posture | Cross-cutting; applied at the architectural level | Per-endpoint; inconsistent across generated files |
| Observability | Structured logging, metrics and traces integrated during development | Minimal or absent; no correlation IDs, no alerting hooks |
| Code reuse | Abstractions consolidated over time | Duplicated patterns across files, with the markers of code reuse falling as AI authorship rises |
| Architectural coherence | Informed by ADRs, team conventions and system context | Context-window-limited; no awareness of decisions in other files |
Those gaps surface differently depending on what the agent is building.
| Scenario | What the Agent Ships | What Is Missing | Production Consequence |
|---|---|---|---|
| API endpoint generation | Working CRUD routes, request/response types, and basic validation | Rate limiting, auth middleware, input sanitization, audit logging | Endpoint passes tests but fails security review |
| Database migration | Schema changes, basic index creation, migration scripts | Rollback strategy, batched backfill, zero-downtime migration | Migration locks the production table; rollback requires manual intervention |
| Authentication flow | Login/logout, token generation, session management | Token refresh edge cases, brute-force protection, audit trail | Auth works in the happy path but fails the pen test |
| Frontend scaffolding | Component rendering, state management, API integration | Accessibility, error boundaries, loading/empty/error states, responsive edge cases | Passes visual QA but fails accessibility audit |
| Data pipeline orchestration | ETL job setup, basic scheduling, data transformation | Backpressure handling, dead letter queues, data validation gates, idempotent processing | Pipeline silently drops records under load |
What Agent-Generated Code Actually Looks Like
A typical agent-generated payment endpoint passes basic tests but omits everything that determines whether it survives production traffic:
On a well-formed request this returns a payment intent in requires_payment_method or requires_confirmation status and writes one row. It throws on a non-integer amount, because Stripe expects the smallest currency unit, and the handler has no catch, so a rejected card surfaces to the caller as an unhandled promise rejection, not a payment failure.
What's missing:
- An idempotency key on the request, without which a retried request creates a second payment
- Rate limiting per customer
- Input validation (negative amounts? unsupported currencies? missing fields?)
- Error handling, distinguishing retryable Stripe errors from permanent failures
- Audit logging, structured logging and authentication middleware
Debt cost: the endpoint passes its tests on the day it merges. The duplicate charge arrives with the first client retry after a network timeout. The missing rate limiting and audit trail surface at the next security review, by which point the same omissions sit in every payment endpoint the agent generated.
Agent-generated database migrations add columns, create indexes, and backfill data in a single script, functional but dangerous at scale:
What's missing:
- Rollback script to reverse the migration
- Batched UPDATE, because the single statement holds a row lock on every matched row for the length of the transaction
CREATE INDEX CONCURRENTLY, which builds the index without blocking writes and cannot run inside a transaction block, so the migration has to be split into separate statements- Data validation after backfill
- Monitoring for lock wait timeouts during migration
Debt cost: the migration completes instantly against a development database holding a few thousand rows. Against production it blocks writes for as long as the index build and the unbatched update take, and rollback requires manual intervention because no rollback script exists. The ALTER TABLE is safe here, because PostgreSQL adds a column with a constant default as a metadata-only change.
A typical agent-generated dashboard component fetches metrics on mount and renders a grid, functional but brittle. Missing: error state handling, loading skeleton, data refresh logic, accessibility attributes, ARIA labels, and authentication check before fetching sensitive metrics.
Environments Where the Gap Is Most Dangerous
The same omissions carry different costs depending on where the code runs.
| Situation | Why It's Worse | Example |
|---|---|---|
| Regulated industries | Missing compliance controls require architectural remediation, not patches | Healthcare app omits HIPAA audit logging |
| High-scale systems | Race conditions and missing backpressure are invisible until production load | Payment processor duplicates charges |
| Legacy system integration | Agents miss undocumented conventions and implicit contracts | Generated code breaks the unstated rate limit |
| Security-critical flows | Per-endpoint security gaps defeat defense-in-depth | Auth middleware on 3 of 4 endpoints |
| Multi-agent workflows | Every agent omits the same categories, and no agent owns the contract between them | Agents disagree on the API contract |
Why the Last 20% Is Worse Than Writing From Scratch
Retrofitting the missing 20% costs more than building it correctly from the start. Four structural reasons explain why the debt compounds instead of resolving.
- Comprehension debt precedes every fix. Before adding error handling, an engineer must reconstruct the intent of code generated without knowledge of the surrounding architecture. In Stack Overflow's 2025 developer survey, 45% of the 31,476 developers who answered that question listed more time-consuming debugging of AI-generated code among their frustrations with AI tools.
- Code duplication eliminates single-point remediation. GitClear, which sells the code-analytics product its own metrics come from, analyzed 211 million changed lines authored between January 2020 and December 2024. Copy/pasted code rose from 8.3% to 12.3%, and moved lines, the marker it treats as the signature of code reuse, fell from 24.1% to 9.5%. Every duplicated copy requires individual modification.
- Security gaps require architectural remediation. Accenture's State of Cybersecurity Resilience 2025 reports that 28% of organizations embed security into transformation initiatives from the outset. It puts spending on generative AI initiatives at 1.6 times security budgets from 2023 to 2024. Controls added afterward cut across every layer the implementation touched.
- Non-functional requirements are systematically deferred. AI agents optimize for functionality and test passage; verification of security, observability, and compliance requires explicit gates that agents do not impose on themselves.
Each of those failure modes carries a specific retrofitting cost:
| Debt Type | Why Retrofitting Costs More |
|---|---|
| Missing observability | Cannot trace production incidents to the commit that introduced them |
| Absent security controls | Cross-cutting across every layer, modification requires understanding all affected code paths |
| Inconsistent error handling | Subtle differences across duplicated implementations defeat automated refactoring |
| Deferred NFRs | Code requires reconstruction of the original intent before each fix |
How the 20% Gap Compounds Into Named Debt Patterns
The costs settle into five patterns, each with its own signature.
| Pattern | What Happens | Why It Is Hidden | When It Surfaces |
|---|---|---|---|
| Silent Schema Drift | Agent adds columns without a migration rollback strategy; the schema diverges from the ORM models | ORM models still compile; tests pass against dev data | On the first rollback attempt, when the schema and the models disagree |
| Missing Observability Hook | No structured logging, no correlation IDs, no metrics emission | No errors thrown; absence of data is invisible until an incident | First incident: diagnosis takes far longer than in a traced system |
| Compliance Gap | PII handling, audit logging and data retention were omitted from the generated code | Functional tests pass; compliance is not tested | Discovered during audit; requires architectural remediation across all affected services |
| Race Condition Time Bomb | No idempotency keys, no distributed locks, no optimistic concurrency | Single-threaded tests never trigger the race | Works in dev/staging; fails under production concurrency |
| Dependency Trap | Agent adds dependencies at unpinned or range-specified versions without compatibility verification | The install resolves cleanly on the day it is written | On the first transitive dependency release; resolution requires reading the whole dependency graph |
Root Cause 1: Missing Architectural Context
AI coding agents make framework, database, authentication, and deployment choices within a single interaction, at speeds outpacing any review process, with decisions buried in generated code rather than recorded in any architectural artifact.
An ICSE 2024 survey of 410 developers asked the ones who did not use an AI programming assistant at least monthly why not. Their most common answer, at 54%, was that the tools write code failing to meet functional or non-functional requirements. Context files, CLAUDE.md, .cursorrules and AGENTS.md, attempt to close that gap. A preprint from ETH Zurich and LogicStar.ai evaluated AGENTS.md across four coding agents, on SWE-bench and on CTXbench, a purpose-built set of 138 instances from 12 repositories carrying developer-committed context files. Version 2, published June 2026, reports no significant effect on task success in either direction: LLM-generated context files moved the average resolution rate by 0.5% and 2% on the two benchmarks and developer-written files by 2.4%, while inference cost rose by over 20% on average.
A retrieval layer addresses the same gap from the other side, deriving structure from the repository itself. In Cosmos, Augment Code's unified cloud agents platform available on all paid plans, that structure comes from the Context Engine. It indexes syntax trees and call graphs across hundreds of thousands of files, and tracks which third-party dependencies are deprecated. When using that index, an agent gets the callsites relevant to a change even where they are not textually similar to the code being edited, which is the case a static context file cannot cover because nobody wrote it down.
Root Cause 2: No Verification Loop (Ephemeral Plans)
AI agents generate implementation plans at the start of a session, use those plans to guide code generation, and then never persist or revalidate them as generation proceeds. The plan exists only in the context window. As the window fills and context rot in long agent sessions progresses, the plan degrades or disappears. At session boundaries, context is lost unless the state is explicitly externalized or persisted by the system.
Persistence therefore has to be an architectural property. A Cosmos Session holds the conversation and is saved indefinitely, so a session can be reopened and audited after the fact, and a triggered session is archived with its full conversation intact. The Cosmos Environment the session runs in is deliberately ephemeral. It pauses after inactivity, runs up to 24 hours at a time, and may restart from a clean state and lose uncommitted changes. Separating the two is what lets the record of a decision outlive the context window that produced it.
The test-automation vendor mabl, reporting on its own agent deployment across more than 75 repositories on April 8, 2026, put context drift at roughly 40% of its agent failures. That fell to under 5% once it layered a shared cross-repository rule base under a CLAUDE.md file in each repository. These are self-reported figures with no stated methodology behind them.
Root Cause 3: Agent Hallucinations Compound Across Files
Invented library names are the visible form of hallucination in generated code, and a build catches them immediately. A study accepted by IEEE Transactions on Software Engineering annotated 1,212 hallucinatory snippets drawn from 3,120 generated samples across five models on Python and Java benchmarks, and sorted them into three primary categories and twelve leaf categories. Incorrect functionality was the consequence in 95.30% of them. Code that compiles and behaves incorrectly is the normal case.
The category that matters most for cross-file work is API misuse. A study accepted at ISSTA 2025 classified LLM code hallucinations from six models on Python tasks. It found API knowledge conflicts, meaning parameter errors, improper guard conditions, deprecated API usage, and improper exception handling, at 20.41% of annotated hallucination instances. A further 11.26% relied on dependencies that were never defined or imported. None of that fails a syntax check, and an agent with no view of the caller has no way to notice.
Both figures describe single generations. The compounding is what a session boundary adds: a plan that was never persisted cannot be revalidated, so the next session reads the previous session's output as the design and builds on it. A review layer is where that gets caught, because the instruction not to hallucinate has already been given and did not work. A Cosmos Expert with Code Review Memory carries what earlier reviews established into the next one.
Catching the Invisible 20% Before Merge
Five techniques address the 20% gap at different points in the development workflow, from specification through CI.
1. The 20% Pre-Merge Checklist. Before merging any AI-generated PR, verify error handling for all failure modes, input validation beyond type checking, observability hooks, security controls, and edge cases. Augment Code's pre-merge verification gates belong in continuous integration, where they run on every pull request and not only when a reviewer remembers.
2. Spec-Driven Generation. Non-functional requirements belong in a written specification the agent reads before it generates, not in the prompt that starts the session. Automating spec-driven development breaks requirements into smaller pieces before generation, small enough that a reviewer can tell whether each one was satisfied.
3. Debt-Aware Prompting. Explicitly instruct agents to include error handling, logging, and security. Explicit prompting helps, but does not solve the problem. A study in the Journal of Systems and Software on the non-functional quality of LLM-generated code reports "the instability of optimizing NFQCs through prompts in practical software engineering settings," where an NFQC is a non-functional quality characteristic.
4. Automated Debt Detection. Run static analysis, security scanning, and complexity checks on every AI-generated pull request. These report what a single file gets wrong; none of them sees a contract break across a service boundary. Augment Code Review runs in the same pipeline, as an add-on across all plans. Cosmos ships review Experts built for the two checks a linter cannot make: Deep Reviewer reads a change against the surrounding codebase, and Risk Analyzer rates what the change endangers.
5. The 80/20 Review Ritual. For every AI-generated file, spend 20% of review time on functional code and 80% on what's missing. Weave automated tests into the process and run them after each task so that failures can inform the next prompt. Where the check needs a running system and not a diff, the Cosmos Verifier Expert exercises a change against a live environment, which is where a missing retry fails.
Core Tradeoffs When Mitigating the 80% Problem
Every one of the five costs something, and the cost decides which fits a team.
| Tradeoff | Tension | Practical Guidance |
|---|---|---|
| Speed vs. completeness | Comprehensive specs slow initial generation | Use spec-driven generation for production services; skip for throwaway prototypes |
| Explicit prompts vs. implicit assumptions | Listing every NFR in prompts hits context window limits | Encode NFRs in persistent specs, not per-prompt instructions |
| Human review depth vs. AI generation volume | Agents generate code faster than humans can review | Focus 80% of review time on the missing 20%, not functional code |
| Automation vs. architectural judgment | Static analysis catches syntax-level issues, not design flaws | Pair automated scanning with architectural review gates |
What Does NOT Work
Four common approaches fail for structural reasons.
| Approach | Why It Fails |
|---|---|
| "Just review more carefully." | Review fatigue scales with AI-generated volume |
| Longer prompts with all NFRs | Context window limits drop later requirements; research confirms instability |
| Post-hoc security scanning only | Finds symptoms, not root causes; cross-cutting concerns need architectural remediation |
| Trusting green tests | Agents optimize for test passage; tests may not cover the missing 20% |
Where Teams Start
Start from a failure that already happened. Audit one recent AI-generated pull request that caused a production incident and write down what the agent omitted, because that list is more specific to a codebase than any general checklist. Turn it into a pre-merge gate covering error handling, security, observability, and edge cases, then require a written specification carrying those non-functional requirements before an autonomous agent generates code for a production service. Run static analysis and security scanning on every agent-authored pull request in continuous integration, which a Cosmos Automation can wire to every pull-request event so it fires without anyone remembering. Then measure production incident rates against the period before the gate existed.
Distinguishing from the METR 19% Finding
METR's early-2025 study had 16 experienced open-source developers complete 246 tasks in repositories they maintained, and found they took 19% longer with AI tools than without, against their own pre-task forecast of a 24% speedup. METR has since revised that result. On February 24, 2026 it reported a confidence interval on the original figure of +2% to +39%. METR now believes developers are more sped up by AI tools in early 2026 than its early-2025 estimates suggest, and it calls its newer measurements unreliable because of selection effects. Separately, a METR analysis of 296 AI-generated pull requests across three repositories found that roughly half of test-passing pull requests would not be merged by the maintainers who reviewed them.
| Dimension | METR Study | Osmani's 80% Problem |
|---|---|---|
| Measures | Task completion time | Production-readiness of output |
| Methodology | Randomized controlled trial, 16 developers | Practitioner essay, no sample or protocol |
| Core finding | 19% slowdown on early-2025 tools, since revised by its authors | Last 20% requires human expertise |
| Does NOT measure | Code quality, technical debt, mergeability | Task completion speed |
A study presented at the 2026 Mining Software Repositories conference tracked 806 Cursor-adopting repositories against 1,380 matched controls. Lines added rose 3 to 5 times in the first month after adoption, the gain was gone after two months, and commit volume showed no significant effect overall. Static analysis warnings rose 30.3% and cognitive complexity 41.6%, and neither came back down. Speed and quality are not interchangeable metrics.
What to Do Next
The tradeoff is speed against comprehension. An agent can produce more code per hour than the people accountable for it can read, and every unread merge moves the constraint further downstream into review, incident response, and audit, where capacity did not change. Specifying the missing 20% up front costs generation speed. Leaving it unspecified costs the ability to fix anything at a single point later.
Before adding any gate, record what your agent-authored changes currently cost: how many production incidents traced back to them last quarter, and how long each took to diagnose. A gate with no baseline behind it cannot be shown to have worked, and those numbers are harder to reconstruct later than to capture now. Whether the gate then runs as a CI script or as a Cosmos Expert matters less than whether anything blocks a merge when the 20% is missing.
Frequently Asked Questions
Related Reading
Written by

Ani Galstian
Ani writes about enterprise-scale AI coding tool evaluation, agentic development security, and the operational patterns that make AI agents reliable in production. His guides cover topics like AGENTS.md context files, spec-as-source-of-truth workflows, and how engineering teams should assess AI coding tools across dimensions like auditability and security compliance
