Keeping the last word: working with AI in the IDE without losing control
TL;DR
Difficulty: Intermediate
AI can write most of the code, but a person has to understand it, decide about it and answer for it. Research finds AI help can weaken debugging skill and raise false confidence, so protect understanding on purpose:
- Work in small steps, one test and one commit each.
- Read every diff with a checklist: scope, dependencies, secrets, errors, data access, personal data, names, tests.
- Write payments, sign in, the data model and the critical path yourself. The AI advises.
- When a test fails, read the trace from your own code, reproduce, isolate, blame or bisect, then ask the AI one narrow question.
- Log why in commits and releases.
AI types faster than you think, and the tests stay green until the evening they do not. This chapter is about the person: how to keep understanding what you ship, how to read an AI change before you accept it, and how to debug a red test yourself, shown on one evening at an invented Bristol tea shop.
The question this article answers
The two chapters before this one set the rules. In test driven development with AI the assistant works test first because a rules file, a hook and a CI check make it. In when AI changes the test instead of the code the tests are protected from the assistant quietly bending them. Both chapters are about machinery. This one is about the person.
The question is simple to ask and hard to live by: how do I stay the one who understands and decides, when AI writes much of my code? Not in theory, but on an ordinary working day, with a deadline, a tool that types faster than you think, and a test that goes red at the worst possible moment.
The answer in this article has six parts. Understand the construct you ship. Work in small steps. Read every diff before you accept it. Write the high risk code yourself. Keep the critical path in view. And when something breaks, debug it yourself first, then ask the AI with evidence in hand. A short section on keeping a decision log, and on why all of this keeps the work insurable, closes it.
The example business is the same as in the rest of the series. Fernhill Tea is an invented online tea shop in Bristol at fernhilltea.example. It sells loose tea and monthly subscriptions, takes card payments through a payment provider, and has discount codes, stock and order emails. Its developer is Priya, also invented, who works with an AI coding assistant every day.
Why understanding the construct still matters
When code was expensive to write, everyone who shipped it had at least typed it. That is no longer true. An assistant can produce a working feature in a minute, and the person who accepts it may never have looked at how it works. For as long as the tests stay green, that seems fine. The trouble starts when a test goes red at 11pm and you have to know where to dig.
The research on this is young, but it points one way. In a randomised study published in January 2026, 52 mostly junior developers learned a Python library they had not used before, some with an AI assistant and some without. Afterwards the AI group scored 50% on a quiz about the library, the group that coded by hand 67%, and the largest gap was on debugging questions1. The skill you need most when something breaks is the one that grew least.
A second study found something more uncomfortable. Participants with an AI assistant wrote significantly less secure code than those without one, and were more likely to believe their code was secure2. Less safe, and more confident. A Microsoft Research survey of 319 knowledge workers found the same pattern in general terms: higher confidence in generative AI went with less critical thinking3.
Developers sense this themselves. In the 2025 Stack Overflow Developer Survey, 46% of respondents said they distrust the accuracy of AI tools and 33% said they trust it. The most common frustration, named by 66%, was "AI solutions that are almost right, but not quite", and 45% said debugging AI generated code takes more time4. Almost right is the dangerous kind of wrong, because it passes a glance.
None of this says "do not use AI". I use AI every working day, sorted by risk tier, and I come back to the tiers below. It says that understanding does not arrive as a side effect. You have to protect it on purpose.
Example: two versions of the same late evening
It is 10.50pm and the renewal job for Fernhill Tea's subscriptions has failed in the test run before a release. Imagine two versions of Priya.
The first version accepted the last month of changes as the assistant wrote them. She knows the shop has subscriptions and that they renew, but not where the renewal date is calculated, which object charges the card, or what calls what. She pastes the error into the assistant, gets a confident fix, applies it, sees green and goes to bed. Whether the fix is right, she cannot say.
The second version read every change before she accepted it. She knows that renewals run through a service object, that the date comes from a method on the subscription model, and that the payment call sits behind its own class. She looks at the error, opens the right file within a minute, and asks the assistant one narrow question about a method she does not recognise.
Both versions used AI all month. Only the second one can answer the question the shop's owner will ask in the morning: what broke, why, and is it fixed properly? The rest of this article is how to be the second Priya.
Small steps and small diffs
A diff is the list of lines a change adds and removes. Assistants are happy to produce large ones: ask for a feature and you may get twelve files, a new library and a refactor you did not ask for. A large diff is hard to read, so it gets skimmed, and a skimmed diff is barely reviewed at all.
Google's public engineering guidelines put it plainly. Small changes are reviewed more quickly and more thoroughly, are less likely to introduce bugs, waste less work when rejected, and are easier to roll back. As a rule of thumb the guide calls 100 lines usually a reasonable size and 1,000 lines usually too large5.
The 2024 DORA report, Google Cloud's annual study of software delivery, adds a warning that fits AI work exactly. As AI adoption rose, the report estimated a 1.5% fall in delivery throughput and a 7.2% fall in delivery stability, and concluded that a better development process does not automatically improve delivery "without proper adherence to the basics of successful software delivery, like small batch sizes and robust testing mechanisms"6.
So the habit is: ask for one small, named step at a time, each tied to one test, and commit it before you ask for the next.
Example: one feature, three diffs
Fernhill Tea wants customers to see the date of their next delivery on the account page, and to pause a subscription for a month. Asked in one prompt, the assistant would touch the model, the controller, the view, the mailer and the tests all at once.
Priya splits it into three requests instead.
- "Change
Subscription#next_renewal_onso that the next renewal date takes a pause into account. Start with a failing unit test." About 30 lines, one model and one test file. - "Show the next delivery date on the account page, using
next_renewal_on. Start with a failing system test." About 40 lines, one view and one test. - "Add the pause button, as described in the Gherkin scenario in
features/pause_subscription.feature." About 80 lines across a controller, a view and step definitions.
Each step is small enough to read line by line in a few minutes, each has its own test, and each is its own commit. If step two turns out wrong, it can be thrown away without losing steps one and three. As you will see later in this article, step one is also where a bug slipped in, and the small commit is what made it quick to find.
Read every diff before you accept it
Every serious assistant shows you its changes before they become yours. Claude Code, Anthropic's command line assistant, has permission modes: in its manual mode it asks before every file edit and shell command, and before it edits a file it takes a snapshot you can rewind to7. In Visual Studio Code, edits made by the Copilot agent stay highlighted in the editor until you choose Keep or Undo, change by change or file by file8. Other tools work in similar ways. The tool gives you the moment. Whether you use it is up to you.
Reading a diff is proofreading, and proofreading works best with a short list. This is the one I would hand any developer working with an assistant:
- Does it do what the test says, and nothing more? Lines that have nothing to do with the test are the first thing to question.
- New dependencies. Every new library is code you now trust. One study of 576,000 generated code samples found that models suggested packages that do not exist, at least 5.2% of the time for commercial models and 21.7% for open source ones9. Check that a new name is the real package, maintained by the people you think.
- Secrets. No keys, passwords or tokens in the code. GitHub's push protection can block known secret formats before they reach a repository10, but it is a net, not a habit.
- Error handling. What happens when the network call fails, the record is missing or the value is empty? See error handling done right.
- Data access. Whose data does this query read or change, and is that checked on the server? Broken access control sits first in the OWASP Top 10, the standard list of web application risks, and 94% of applications tested showed some form of it11.
- Personal data. Is anything personal written to a log, an email or a third party that does not need it?
- Names. Do the new names say what the code does? A name you would not have chosen is a hint that you do not yet understand the change.
- Tests untouched. If a test changed in the same diff as the code, read that first. The previous chapter is about exactly this.
The decision at the end is one of three: accept it, change it yourself, or reject it and write it yourself. The flow below adds the critical path question, which the next sections explain.
Example: proofreading a customer export
A Fernhill Tea customer asked to download their order history. Priya asks the assistant for a CSV export, test first. The test it writes passes, and this is the code it proposes:
# Gemfile
gem "csv"
# app/controllers/order_exports_controller.rb
class OrderExportsController < ApplicationController
def show
orders = Order.where(customer_id: params[:customer_id])
Rails.logger.info("CSV export for #{current_customer.email}")
send_data OrdersCsv.new(orders).to_s, filename: "orders.csv"
end
end
Priya goes down her list.
- Does it do what the test says and nothing more? Yes. The test signs a customer in, requests the export and checks that the file contains their orders.
- New dependencies. A new line,
gem "csv". Is that a made up package? No. Since Ruby 3.4 the csv library is a bundled gem rather than a default one, so a Rails app on Ruby 3.4 has to list it12. She checks that the name is the official gem and keeps the line. - Secrets. None.
- Error handling. Nothing here can fail in an unusual way. Fine.
- Data access. This is the problem. The orders are looked up by
params[:customer_id], a number from the web address. Any signed in customer could change that number and download someone else's order history, with names and addresses. The test did not catch it, because it only ever asked for the customer's own export. - Personal data. The log line writes the customer's email address into the server log. Nobody needs it there.
- Names. Fine.
- Tests untouched. No existing test changed.
This is customer data, so it sits in the high risk tier. Priya does not ask for a second attempt. She writes the missing test herself, the one that tries to read another customer's orders and must get nothing, watches it fail, and fixes the controller herself:
def show
orders = current_customer.orders.order(:placed_at)
Rails.logger.info("CSV export for customer #{current_customer.id}")
send_data OrdersCsv.new(orders).to_s, filename: "orders.csv", type: "text/csv"
end
current_customer.orders only ever reaches the orders of the person who is signed in, so there is no number in the address to change. The log line now records an internal identifier instead of an email address. Two lines changed, and both came out of the checklist, not out of luck.
Write the high risk code yourself
Not every line deserves the same care, and pretending otherwise wears you out until you review nothing properly. I sort every piece of work by risk tier before AI touches it. Low risk: the AI builds it and I review it. Medium risk: the AI drafts it and I edit it. High risk: I decide, and the AI only advises.
High risk is anything where a mistake costs money, breaks the law or locks you in: payments and refunds, sign in and permissions, the data model (the tables and how they relate), personal data, and every step of the critical path. The reason is not that AI writes worse code there. It is that this is where you most need to understand every line when it breaks, and writing it yourself is the most reliable way to understand it. The AI responsibility article explains the tiers in more depth.
Example: sorting a week of Fernhill Tea work
Priya has five tasks this week. Before she opens the assistant, she gives each one a tier.
| Task | Tier | Who writes it |
|---|---|---|
| New layout for the "About our teas" page | Low | The AI builds it, Priya reviews the diff |
| Admin report of best selling teas per month | Low | The AI builds it, Priya reviews the diff |
| Order confirmation email with the next delivery date | Medium | The AI drafts it, Priya edits the wording and the logic |
| A discount code that only works on subscriptions | High | Priya writes it, the AI explains Rails methods when asked |
| Subscription renewal and the card charge | High | Priya writes it, the AI only advises |
The admin report reads data but never changes it, and only staff see it, so a mistake is visible and harmless. The discount code changes what customers pay, so it is money. The renewal charges a card every month without anyone watching, which makes it the most expensive place in the shop to be wrong. Ten minutes of sorting decides where the hours of careful reading will go.
Keep the critical path in view while you work
The critical path of a piece of software is the chain of steps that must work for the business to earn money or meet its legal duties. For a shop: browse, basket, checkout, payment, order confirmation, and for Fernhill Tea also the monthly renewal. The critical path in software explains how to find it and guard it. It is a different idea from the critical path in project planning.
While you work, three small habits keep it in view. A critical path file in the repository lists every step, with the code that implements it and the tests that guard it. The tests on the critical path carry a tag or live in their own folder, so they can be run on their own. And you run those tests first, locally, before you push, because they are the ones that must never be red.
In my own work every product has a defined critical path, and once a critical path is verified it is frozen behind an approval step: a change to it needs an explicit sign off. Every release then passes a test gate.
Example: Priya's critical path file and her routine
Priya keeps a short file in the Fernhill Tea repository:
# docs/critical_path.md
## 6. Monthly renewal
Code: app/services/subscriptions/renewal.rb, Subscription#next_renewal_on,
app/jobs/renew_subscriptions_job.rb
Tests: test/critical/subscription_renewal_test.rb,
features/renewal.feature (@critical)
Change rule: approval by Priya before merge
Her critical tests live in test/critical, and her Cucumber scenarios on the path carry the @critical tag. Cucumber can run only the scenarios with a given tag13. Before every push she runs two commands:
bin/rails test test/critical
bundle exec cucumber --tags @critical
The first runs every Minitest test in the critical folder, the second every scenario tagged @critical. Together they take under a minute. Only when both are green does she run the full suite and push. When she reviews a diff from the assistant, she checks it against the "Code" lines in the file. That is the critical path decision in the review flow above.
Debug it yourself first, then ask with evidence
When a test fails, the quickest move is to paste the error into the assistant. Sometimes that works. But it skips the part where you learn how your own system behaves, and it hands the diagnosis to a tool that is, by the survey numbers above, "almost right, but not quite" a good deal of the time.
The order that keeps you in charge has five steps.
- Read the message. The first line of the error says what went wrong in plain terms, more often than people expect.
- Read the stack trace from the top of your own code. A stack trace is the list of method calls that were running when the error happened, newest first. Skip the lines from Ruby and from gems, and find the first line that points into your own files. Rails filters the trace to your application's lines by default, and
bin/rails test -bshows the full one14. - Reproduce it. Make the error happen again on purpose, in the console or in a smaller test. If you cannot reproduce it, you cannot know you fixed it.
- Isolate it. Cut the failing case down until only the cause is left: one object, one method, one input.
- Find the change. If the trace points at a line,
git blameshows which commit last changed it15. If it does not,git bisectfinds the first bad commit by halving the range of commits again and again, testing each midpoint as good or bad16.
Only then ask the AI, and ask a narrow question with the evidence in hand: the message, the trace, the line and what you already know.
git bisect is worth a moment of maths, because it shows why it is so fast. Each test halves the commits still in doubt, so the number of tests grows with the logarithm of the number of commits (Foundations: logarithms):
is the number of commits you have to test, is the number of commits between the last known good one and the first known bad one, asks how many times you must halve to get down to one, and rounds the result up to a whole number.
For nine commits that gives:
So with , about test runs find the culprit, and even commits need only . With git bisect run and a test command, git does the runs for you: exit code 0 means good, most other codes mean bad, and 125 means "cannot test this one, skip it"16.
Example: an evening at Fernhill Tea
This is the worked example for the whole method, step by step.
The change. That afternoon Priya built the "next delivery date" feature in the three small steps from earlier. In step one the assistant changed an existing method on the subscription model. Before, it was:
def next_renewal_on
renewed_on.next_month
end
After the assistant's change, so that a pause would push the date back, it read:
def next_renewal_on
[paused_until, renewed_on >> 1].max
end
The idea is reasonable: take whichever is later, the end of a pause or one month after the last renewal. Priya read the diff, ran the account page tests, saw green and committed. What she missed: the renewal service also calls this method, and she did not check the diff against her critical path file. That is the lesson, and it comes back at the end.
The red test. At 7.40pm, before pushing, she runs her critical tests as always. One fails:
Error:
SubscriptionRenewalTest#test_renews_a_monthly_subscription_and_schedules_the_next_renewal:
ArgumentError: comparison of Date with nil failed
app/models/subscription.rb:42:in 'Array#max'
app/models/subscription.rb:42:in 'Subscription#next_renewal_on'
app/services/subscriptions/renewal.rb:23:in 'Subscriptions::Renewal#call'
test/critical/subscription_renewal_test.rb:8:in 'block in <class:SubscriptionRenewalTest>'
bin/rails test test/critical/subscription_renewal_test.rb:5
Nothing was pushed, so no customer is affected. The gate did its job. Now the job is hers.
Read the message. "comparison of Date with nil failed". Something tried to compare a date with nil, which is Ruby's word for "no value".
Read the trace from the top of her own code. The first line, Array#max, is Ruby's own method, but it was called from her file: app/models/subscription.rb, line 42, inside next_renewal_on. The line below shows who called that: the renewal service, line 23. The last line is the test itself. So the renewal broke because next_renewal_on raised an error, and the error happened inside max.
Reproduce it. She opens the Rails console with bin/rails console and builds a subscription that has never been paused:
subscription = Subscription.new(renewed_on: Date.new(2027, 1, 31))
subscription.next_renewal_on
# => ArgumentError: comparison of Date with nil failed
Same error, on purpose, in two lines. A subscription that was never paused has paused_until set to nil. The array becomes [nil, a date], and max cannot compare the two. The account page tests passed because their fixture subscription happened to have a pause.
Isolate it. She writes the smallest test that shows the bug, in the model test file, and runs it with bin/rails test test/models/subscription_test.rb to see it fail for exactly this reason:
test "next renewal is one month on when the subscription was never paused" do
subscription = Subscription.new(renewed_on: Date.new(2027, 1, 31))
assert_equal Date.new(2027, 2, 28), subscription.next_renewal_on
end
Find the change. The trace points at line 42, so blame is enough:
git blame -L 40,44 app/models/subscription.rb
The -L 40,44 limits the output to lines 40 to 44. It shows that line 42 came from the commit "Take pauses into account in next_renewal_on", made at 3.12pm. Had the trace not pointed at a changed line, she would have run git bisect start HEAD v58 (the bad commit first, then the last release, which was good) and git bisect run bin/rails test test/critical/subscription_renewal_test.rb, and with nine commits since that release, about four test runs would have named the culprit.
Ask the AI the narrow question. One thing still puzzles her: the >> on a date. She has never used it. So she asks, with the evidence:
In Ruby, what does `Date#>>` do? In app/models/subscription.rb:42 I have
`renewed_on >> 1`. With renewed_on = 31 January 2027 my test expects
28 February 2027. Is that what >> returns, and what happens on the next renewal?
Explain only, do not change any files.
The assistant explains that >> moves a date forward by a number of months, and that when the target month has no such day, it uses the last day of that month. Priya checks this against the Ruby documentation, which says exactly that and gives the 31 January example17. The documentation also shows the catch: from 31 January, one month on is 28 February, and one month after that is 28 March, not 31 March. So a customer who started on the 31st slowly drifts to the 28th. That is not a bug in the code, it is a business decision, so Priya writes it down as a question for Fernhill Tea's owner instead of guessing.
The fix, written by her. Renewal is high risk, so she writes the fix herself. First a second test for the paused case, then the method:
test "next renewal waits until the day after a pause ends" do
subscription = Subscription.new(renewed_on: Date.new(2027, 1, 31),
paused_until: Date.new(2027, 3, 14))
assert_equal Date.new(2027, 3, 15), subscription.next_renewal_on
end
def next_renewal_on
regular = renewed_on >> 1
return regular if paused_until.nil?
[paused_until.next_day, regular].max
end
Line by line: regular is the date one month after the last renewal. If there is no pause, that is the answer, and the method returns it straight away without comparing anything to nil. If there is a pause, the next renewal is whichever comes later, the day after the pause ends or the regular date. The new tests pass, the critical tests pass, then the full suite. She also adds Subscription#next_renewal_on to the "Code" line of her critical path file. It was already there in spirit, now it is there in writing, so the next diff that touches it will raise the critical path question.
The AI helped twice that day: it wrote the feature, and it explained an unfamiliar method. Every decision that mattered was Priya's.
Keep a decision log
Understanding fades. Six months from now neither Priya nor anyone else will remember why next_renewal_on returns early on a missing pause. The decision log is what remembers: commit messages that explain the why, release notes that say what changed for customers, and a register of what went live when.
Git's own documentation recommends starting a commit message with a short summary line of no more than 50 characters, then a blank line, then a fuller description18. That body is where the reasoning goes. A commit message like "fix" tells no one anything. In my own work every production release also gets a version in a release register, and after every deploy a smoke test requests every page of the site. The article on evidencing compliance explains how such a register works.
Example: Priya's commit message and release note
Fix renewal for subscriptions that were never paused
next_renewal_on compared paused_until with a date using Array#max.
For a subscription without a pause, paused_until is nil and the
comparison raised ArgumentError, so the renewal job would have
failed for every unpaused subscriber.
The method now returns the regular date when there is no pause.
Added two model tests (never paused, paused) and listed the method
in docs/critical_path.md under step 6.
Open question for the owner: renewals from the 31st drift to the
28th after February (Date#>> clamps to the end of the month).
The release note for the shop's owner is shorter: "The next delivery date now shows on the account page. A fault in the renewal date, found by the tests before release, was fixed. One question for you about subscribers who started on the 31st." The release register gets a new version with the commit, the test run and the date. Anyone who asks later can follow the trail from the question to the line of code.
Why the last word keeps the work insurable and accountable
Everything above serves one idea. For every change there is a named person who understood it and approved it. That is what accountability means in software, and AI does not change it. The assistant cannot be asked in a meeting why a renewal failed, cannot sign a release, and cannot carry liability.
This also matters for insurance and contracts. In the United States, a standard generative AI exclusion for general liability policies has been available to insurers since January 2026, and by mid 2026 more than 2,000 such exclusion records were in force across 49 states19. Policies in the UK work differently and change on their own timetable, so read your own, but the direction is clear: insurers are starting to ask how AI written code is controlled. A trail of reviewed diffs, tests, approvals and releases is the answer they can work with. The AI responsibility article goes into insurance exclusions and liability in more detail.
Example: the question from Fernhill Tea's owner
The next morning the shop's owner reads the release note and asks: "Who approved the change that broke renewals, and how do I know it won't happen again?"
Priya can answer every part of that with evidence. The change was hers, made with the assistant's draft, in commit "Take pauses into account in next_renewal_on" at 3.12pm. The critical tests caught it at 7.40pm, before release, so no customer was charged wrongly or missed a delivery. The fix is in a separate commit with its reason and two new tests. The method now sits on the critical path list, so any future change to it needs her approval and runs the critical tests first. And the drift question is waiting for the owner's decision. That answer takes two minutes, because she stayed the one who understood.
Conclusion
AI can write most of the code. It cannot be the one who understands it, decides about it and answers for it. That role stays with a person, and it has to be protected on purpose, because the research shows that understanding and critical thinking shrink when they are not used.
The habits are not complicated. Work in small steps. Read every diff with a checklist before you accept it. Write the high risk code yourself and let the AI advise. Keep the critical path in a file and its tests at the front of every run. When a test fails, read the trace from the top of your own code, reproduce, isolate, find the change, and only then ask the AI a narrow question with the evidence. And write down why, in commits and releases, so the next person can follow.
That is how you keep the last word. The tests from the first chapter of this series tell you when something is wrong. Understanding tells you why.