AI Wrote Your Code. Now Who Fixes It at 2 AM?
Why AI-assisted development quietly breaks at 2 AM when the thinking behind your code lives in heads, chats and stale wikis — and how turning the repo into your team's first brain restores ownership, lowers MTTR, and makes answers reproducible.
AI Wrote Your Code. Now Who Fixes It at 2 AM?
When AI ships the code and humans inherit the archaeology.

TL;DR: AI has made throughput cheap and outcomes scarce. The bug in AI-assisted development isn’t the AI — it’s that the thinking behind your code still lives in heads, Teams/Slack, and stale wikis, where no AI agent (and no on-caller at 2 AM) can reach it. Move that thinking into the repo as requirements, architecture, decisions, and an engineering changelog, all enforced by guardrails as code, and measure yourself on the outcomes that actually move — MTTR, change-failure rate, on-call confidence — not on the PRs you ship. The repo stops being just a codebase. It becomes your team’s first brain — the one the humans carry in their heads is the second, and it keeps forgetting.
A story you’ve already lived
Monday, 10 AM. A ticket lands: “Add a new discount type to the renewal pipeline.” An engineer hands it to an AI agent with a short prompt with task details copied from AzureDevops and a couple of attached files. The agent returns a clean PR — tests green, logic reasonable, review thorough. Ships by 4 PM.
Two weeks later. Saturday, 2:00 AM. An alert fires. Annual-contract customers are being charged the wrong amount.
The on-caller has never touched this code. The original author rotated teams last month. The ticket is closed and has no useful detail. The commit message says "implement discount per ABC-1234". There’s a Teams/Slack thread from the design meeting. The meeting was not recorded.
The on-caller spends the first 40 minutes not fixing the bug, but reverse-engineering the intent of the original change. What was it supposed to do? What was it supposed to not do? By the time a fix ships, the real damage is done — not to the customer, but to the engineer’s confidence in ever touching AI-generated code again.
The post-mortem will politely conclude that the code was “technically correct.” It was. The AI produced the only answer consistent with the context it was given. The context just happened to be missing the one rule that mattered — annual customers bypass the renewal pipeline entirely — a rule that lived in someone’s head, not in any file the AI or the reviewer could see.
So whose fault is it? The AI’s, for not knowing a rule nobody wrote down? The engineer who prompted it, for not pasting in context they didn’t know existed? The reviewer who approved a change that looked reasonable? The on-caller now trying to fix code no human fully designed?
None of them. The fault is that the rule was never in a place any of them — human or AI — could see. This is the signature failure mode of AI-assisted development. And it is not a prompting problem.
The AI didn’t get it wrong. Your knowledge base did.
When AI-generated code ships with a subtle violation of an unwritten rule, the root cause isn’t the model. It’s that every engineer on your team is prompting the AI from a different knowledge base.
Engineer A pastes three files and a ticket. Engineer B pastes five files and a design doc from 2023. Engineer C uses an agent that crawls the repo — but only reaches what’s in the repo. Engineer D gives no context at all because “the AI is smart, it’ll figure it out.”
Same question. Different knowledge bases. Different answers. None of them reproducible next week, next sprint, or by anyone else on the team.
Per GitClear’s 2025 analysis of ~211M lines of changed code, the share of new lines revised within a month rose 20–25% over the pre-AI baseline. Per METR’s 2025 controlled study, AI tools made experienced developers ~19% slower on familiar codebases — while they felt 20% faster.
Adoption is universal. Output volume is up. Rework is up. Actual throughput on non-trivial work is down.
AI has made throughput cheap and outcomes scarce. Lines shipped, PRs merged, tickets closed — the metrics that worked when typing was the bottleneck — are now the least meaningful signals a team can track. A team can double its PR volume and ship a worse product, with higher change-failure rate, longer MTTR, and engineers who no longer understand their own system.
The gap between apparent productivity and actual value is explained by one variable: the thinking behind the code — its intent, constraints, decisions, and quirks — isn’t in the repo. It’s in heads, Teams/Slack, and stale wikis, where the AI cannot reach it and the on-caller cannot find it.
Five problems you’re probably already living with
Read these fast. If any of them feel like your team, keep reading — the rest of this piece is the fix.
- “Who has to fix this?” The AI wrote some code. Months later it breaks. The person who asked the AI didn’t really write it. The person fixing it at 2 AM never saw it. Nobody wants to own it.
- Rules nobody wrote down. A rule lives in one person’s head. The AI can’t see it, so the AI breaks it. The reviewer didn’t know the rule either. Production finds out.
- Knowledge that hides even when the team talks every day. Standups, retros, demos — they move tickets, not the real thinking. The real thinking stays in chats, slides, and one teammate’s head. They move teams, the knowledge moves with them and fade slowly.
- Doing the same homework every Monday. Every new ticket starts with half an hour of re-reading old code and re-asking the AI what things mean. You learned this last sprint. You’re paying for the same lesson again.
- “My AI changed and now my answers are weird.” The AI tool gets a small update. Friday it worked. Monday it doesn’t. You can’t tell if the AI changed or your setup changed, because nothing was locked down.
The repo is the only place this thinking can actually live
So where should the thinking behind your code live? Not in heads — people rotate, leave, forget. Not in Teams/Slack — it’s unsearchable the moment the thread scrolls off. Not in AzureDevops/Jira — tickets close and sink. Not in a Confluence page last edited in 2023 that nobody including its author trusts anymore.
You’ve probably heard of a “second brain” — Tiago Forte’s term for an external system that holds the thinking you can’t trust yourself to remember. For an individual knowledge worker the hierarchy is obvious: the brain in your head is first, the external one is second.
For an engineering team, that hierarchy is backwards. The “brain” that lives in your engineers’ heads and Teams/Slack threads is lossy, biased, and walks out the door with every rotation. Memories drift. Meetings aren’t recorded. Context dies with the sprint. The repo — if you use it right — is versioned, reviewable, queryable, patient, and reachable by every human and every AI agent that opens it.
Call it what it actually is: the repo is your team’s first brain. The one in heads is the second — helpful, but not the source of truth. And an AI grounded only in the second one is operating on the wrong brain.
The repo earns that title by being the only artifact in your stack that is simultaneously:
- Versioned — every state is addressable by commit.
- Access-controlled — the same policy that protects the code protects the knowledge.
- Reviewed — changes to knowledge go through PR review, like code.
- Reachable by every AI agent — the agent is already cloning the repo.
- Co-located with the thing it describes — the intent sits next to the code it produced.
No other tool has all five. Wikis lose review. Ticket trackers lose versioning. Teams/Slack loses everything. Design tools aren’t accessible to AI agents.
So the task is concrete: move the thinking into the repo. Not as prose nobody reads, but as structured artifacts the build knows how to check.
Four paradigms for the first brain
Requirements as code. Specs, invariants, acceptance criteria, and a domain glossary — in /.context/, not in Azure DevOps/Jira. A Jira ticket closes and sinks out of view. A spec in the repo is queryable forever, diffable against the code, and visible to every AI agent that opens the file tree.
A single line in invariants.md — “annual-contract customers bypass the monthly renewal pipeline entirely; they are reconciled via the annual true-up job” — is often the difference between a safe PR and a production incident.
Architecture as code. Diagrams in Mermaid or Structurizr, service contracts in OpenAPI or Protobuf, a dependencies.md listing upstream failure modes — all text, all PR-reviewable, all next to the code.
The Confluence diagram someone drew in 2023 and is wrong today is worse than no diagram. It teaches humans and AI agents a false mental model. Text-based, PR-reviewed architecture is the only form that doesn’t rot.
Decisions as code. Architecture Decision Records. Fifteen minutes to write. Immutable once accepted. Each one ends with a revisit trigger — “revisit if monthly order volume exceeds 10M, or if we onboard a second payment processor.”
AI is excellent at pattern-matching to code. It’s structurally incapable of inferring why a decision was made when the reason lived in a meeting room two years ago. ADRs are the only artifact that reliably captures the “why.”
Engineering changelog as code — and this one matters to name carefully.
This is not your product changelog, release notes, or content/marketing changelog. Those belong in your CMS and answer “what should the customer know?”
The engineering changelog belongs in the repo — one per subsystem — and answers a completely different question: “what changed here, and why, that the next maintainer or AI agent needs to know to avoid breaking it?”
A single entry is three lines:
2026-02: annual-contract bypass added to renewal pipeline.
Intent: exclude annual customers from monthly dunning.
See ADR-0043. Invariants touched: #14.
Do not try to generate one from the other. They serve different audiences and different questions. Conflating them is how teams end up with a public changelog that’s useless for engineering and an engineering history that’s invisible to maintainers.
The thread that runs through all four: guardrails
Here’s where most teams stop. They write the files, the files drift, and the whole thing decays back into documentation nobody trusts.
The fix is guardrails — not a fifth paradigm, but the enforcement layer that runs through every other one. They turn a requirement into a test, an ADR into a fitness function, a changelog entry into a contract check. Without them, requirements become a wish list, decisions become a museum, operational context becomes folklore, and prompts become suggestions.
If a claim in your first brain cannot fail a build, it cannot protect the code. Every claim needs a check. Every check is a guardrail.
A practical heuristic — every time you add a claim to any layer, ask “what executable check fails when this claim stops being true?” If you can’t name one, the claim isn’t a rule. It’s a preference, and it will drift.
📎 Guardrail design is its own deep topic — the Guardrail Stack (task / feature / team / org levels), pre-flight, in-flight, and post-flight patterns, common failure modes, and the metrics that show whether they’re working — covered in the companion piece: Guardrails: The One Thing Missing in Most AI-Assisted Development.
The 2 AM test
What’s the real benchmark of AI-assisted development? Not how fast you ship. Not how many PRs you merge. Not how much of the codebase is AI-authored.
It’s this: couple of months after the AI wrote the code, when a production incident fires on a Saturday night — can the engineer on-call fix it with confidence? Or does the team need to wake up whoever originally prompted it?
If it’s the second, you don’t have AI-assisted development. You have AI-assisted construction and human-assisted archaeology — and the archaeology is where your team is actually spending its time.
Without a first brain, 2 AM looks like this: the on-caller opens the service and starts reading code that is dense, branch-heavy, and recognizably AI-shaped — plausible but un-obvious. They drop the alert payload and the traces into an AI session too, because that’s the habit now. But the AI has nothing to correlate against except the code it can see. It confirms the symptom, generates three plausible hypotheses, and cannot tell them apart. There is no first brain to ground the analysis in just the code, and the lossy memory in whoever’s head.
So the archaeology begins. They git blame the suspect lines — the commit says “implement X per ABC-1234,” the ticket says “add support for X,” and neither explains why the branch exists or what it was explicitly trying to avoid. They search Teams/Slack, find a thread, find a reference to a meeting, find that the meeting was not recorded.
They page the original author. The author says “I don’t remember, the AI wrote most of it, let me look.” Two engineers are now debugging at 2 AM instead of one. A fix eventually ships — the smallest change that stops the alert, a symptomatic fix. The underlying intent is still undocumented, so the next incident in the same area will repeat the whole dance.
With a first brain, 2 AM looks like this: the on-caller opens an AI session and drops in the raw material of the incident — the alert payload, the error traces, the affected customer IDs, the last hour of logs, the recent deploys to this subsystem. The agent auto-loads /.context/, the service’s context file, and the relevant ADRs before it answers.
It correlates the symptoms against what the first brain already knows. The traces show annual-contract customers reaching a code path that invariant #14 says they must never reach. ADR-0043 explains why the bypass exists and points to the true-up job that should have handled them. The recent deploy changed a routing predicate in exactly that path.
The AI doesn’t guess. It returns a grounded root-cause hypothesis: “Symptom: annual customers charged on the monthly dunning path. Invariant violated: #14. Likely cause: the predicate change in commit a1b2c3d removed the contract-type filter. ADR-0043 requires this filter. Proposed fix: restore the filter; regression test on invariant #14.” The on-caller verifies the hypothesis against one more trace, ships the fix, and writes the regression test. Thirty minutes later, the alert clears.
The post-incident action item isn’t “document this retroactively.” It’s “add a regression test for the invariant we almost missed.” The knowledge base was already current.
Ownership is no longer a function of authorship. The on-caller isn’t recovering knowledge. They’re reading it.
That is the whole argument. Everything else is implementation.
Measure the outcomes, not the throughput
Your PR count is up. Your AI adoption sits at ~100%. Your engineers say they feel 20% faster. So why is change-failure rate climbing? Why is MTTR getting worse? Why does every incident in AI-authored code start by paging the person who wrote the prompt six months ago?
Because you’re measuring the wrong things.
There’s one habit that matters more than any other, and it’s the one most teams skip: change what you measure.
The throughput metrics go up the moment you hand engineers an AI tool — PRs merged, lines generated, tickets closed, “AI adoption %.” None of them mean anything anymore. In a world where generating code is near-free, they are signals of activity, not value.
The outcomes only move when the first brain is in place:
- Change-failure rate on AI-authored PRs — should trend toward parity with human-authored PRs.
- MTTR on incidents in AI-authored code — should trend toward parity with human-authored code.
- On-call author-escalation rate — % of incidents where the on-caller had to page the original author. Should trend toward zero.
- New-hire time to first independent incident resolution — not first PR. Fixing is the honest signal; writing is cheap.
- Rediscovery time per ticket — the 15–45 minutes every engineer currently spends re-establishing context. Should trend down.
If the throughput column goes up and the outcomes column doesn’t, you have adopted AI. You have not adopted AI-assisted development.
A fair warning on the time horizon: these are slow-moving metrics. Expect the first measurable improvement in ~6–8 weeks on the subsystems you start with, and parity in one to two quarters. A team looking for a two-week win will walk away before the curve turns.
What to do on Monday
You don’t need to build all of this at once. Pick one:
- Confidently wrong AI output passing review? Start with
invariants.mdandnon-goals.md. - “Why is this like this?” on every ticket? Start writing 15-minute ADRs going forward — no retroactive backfill.
- Silent regressions, refactored-away workarounds? Start
/docs/context/<service>.mdper subsystem. - Incidents where the on-caller has to page the author? Start requiring a three-line intent block on every non-trivial PR.
Then make it sustainable with four habits:
- One ADR per significant decision — 15 minutes, ending with a revisit trigger.
- One intent block per non-trivial PR — three to five lines stating goal, non-goals, and invariants touched. This is the note the on-caller will read at 2 AM two months from now.
- One invariant check per PR — tick the box or link the ADR. Thirty seconds.
- One knowledge-base gap review per incident post-mortem. The post-mortem is the single highest-yield moment to extend the first brain, because the cost of the gap is fresh and quantified.
The shift
In the code era, your most valuable asset was the code. The bottleneck was typing, and throughput — lines shipped, PRs merged — was a reasonable proxy for value.
In the AI era, typing is free. Throughput is no longer scarce. Outcomes are.
Your most valuable asset now is the thinking that produces the code — the requirements, architecture, decisions, and intent that let any engineer, or any agent, generate the right output for the right reason and fix it when it breaks.
If that thinking lives in heads, Teams/Slack threads, AzureDevOps/Jira tickets, and a marketing changelog, your knowledge base works by coincidence. Every AI output is a lottery ticket. Every incident is a reconstruction project. Your throughput numbers will look great. Your outcome numbers will quietly get worse.
If that thinking lives in your repo — structured, reviewed, testable, enforced by guardrails running through every layer — then your repo has stopped being just a codebase and become your team’s first brain.
The teams that win the AI era won’t be the ones with the best prompts, the best models, or the highest PR counts. They’ll be the ones whose repo has become the first brain of the team — and who measure themselves on the outcomes a first brain produces: lower MTTR, flatter author-escalation, durable ownership, reproducible answers.
Your codebase is already in Git. The only question left is whether the thinking that produced it is too.
Start moving it in today. One artifact per PR. The repo is patient. It will hold everything you put into it, and give it back to whoever asks — at any hour, in any timezone, whether they’re human or not.
Related Posts
Guardrails: The One Thing Missing in Most AI Assisted Development
Why guardrails — not better AI models — separate teams that ship fast from teams that ship fast into a wall, and the four-layer Guardrail Stack that makes engineering speed sustainable in the AI era.
I Shipped a Black Box, Not a Feature
I merged a 400-line AI-assisted PR I understood for about 48 hours, then couldn't explain my own code when a bug came in. That gap between 'I shipped it' and 'I understand it' is comprehension debt, the third of seven AI debts.
I Shipped a Feature That Didn't Match Our Codebase
AI assistants write code that looks like it belongs, but they work from context we never gave them. That invisible gap between what the model assumed and what our codebase does is context debt, the second of seven AI debts.