What they’re really asking
If you only remember one thing, say this in the first minute: “A nightly job picks modules with low coverage, and a coding agent writes tests for each one in a sandbox where it can only touch test files. Checks in code then throw away tests that don’t build, are flaky, don’t raise coverage or don’t catch a deliberately broken version of the code. A person reviews only what survives, in small pull requests. Every run ends with a recorded reason, and I page only on stuck runs or a blown budget.”
The rest of this page explains each part of that answer.
The interviewer wants to know whether you can put an AI agent into an engineering process and still be accountable for what it produces. The candidate who reported this felt the interviewer was “mainly checking whether I understood AI agents end to end” (Aced (formerly Exponent)). The three follow-ups were hallucination, minimizing human oversight and alerting. Those follow-ups are the round: a strong answer says what the agent may do alone, what catches a bad agent-written test, and who finds out when the system fails.
What makes this different from a normal CI job
A normal CI job runs code you wrote. It does the same thing every time, and when it is wrong, it is wrong the same way.
A test-writing agent is different. An agent is a loop in which a large language model (LLM) decides its own next action each turn: read a file, write a test, run the tests, read the failure, try again. It stops when it says it is done or a limit stops it. That loop is useful here, because the test runner gives honest feedback.
But the model can also be confidently wrong. It can call a function that doesn’t exist, or write a test that passes for the wrong reason. This is called hallucination. And every loop step costs money. So the design is about two things: limits on what the agent can do, and checks in code on what it produces.
Clarify first
- Which service, which language, what coverage tool? Assume a backend service with a unit-test suite and line coverage in CI.
- Coverage of what? New code in each pull request, or the existing backlog? Assume a nightly job over low-coverage modules.
- Is reliability also about flaky tests and production incidents? Assume the flake rate counts.
- May the agent change production code? Assume no: tests only.
- Who reviews, and how much time do they have? Assume one team, a few minutes per pull request.
Say it like this: “I’ll assume the agent may only add tests. If it can change production code, I’d need much stronger review.”
Answer
Words you need first
- Sandbox: an isolated environment, such as a container, where the agent can touch only what you allow.
- Mutation check: deliberately break the code under test (flip a condition, change a constant) and confirm the new test fails. If it still passes, the test checks nothing.
- Flaky test: a test that sometimes passes and sometimes fails with no code change. A flaky test is worse than none.
- Stop reason: a recorded reason every run ends with (finished, step cap, budget, error).
The shape
Nightly cron ── read the coverage report, pick target modules (plain code)
│
▼
Coding agent in a sandbox (one per module)
can: read the repo, write under test/ only, run the test command
cannot: use the network, see production credentials
limits: step cap, dollar cap
│
▼
Filters in code, cheapest first:
builds? → passes several runs in a row? → raises coverage on target lines?
→ fails on a mutated version of the code? → leaves existing tests untouched?
│ (most attempts are dropped here)
▼
Small pull request with the coverage diff and the mutant it caught
│
▼
Person reviews and merges
The nightly job is plain code. It picks target modules from the coverage report.
The agent works on one module at a time in a sandbox. It can read the repository, write only under test directories, and run the test command. It has no network, no production credentials, a step cap and a dollar cap.
The filters run in code, cheapest first. The test builds. It passes several runs in a row. It raises coverage on the target lines. It fails when the code under test is deliberately broken (the mutation check). It doesn’t edit, skip or weaken existing tests. Only survivors become a small pull request, with the coverage diff and the caught mutant attached.
There is published evidence for this shape. Meta’s TestGen-LLM paper reports that 75% of its generated test cases built, 57% passed reliably and 25% increased coverage, and that engineers accepted 73% of its recommendations (arXiv 2402.09171, 2024-02-14). The filters, not the model, made the output worth reviewing.
Follow one module
Say the target is billing/proration.py at 41% line coverage (an illustrative example).
| Step | What happens | What to say in the interview |
|---|---|---|
| Pick | The nightly job picks the module from the coverage report. | ”Plain code decides what to work on.” |
| Agent | In about 20 steps it reads the module, writes 6 tests, runs them, fixes two import errors. | ”It iterates because the test runner tells it the truth.” |
| Build | All 6 build. | ”Invented APIs die here, cheaply.” |
| Repeat runs | One test fails on the third run: it depends on today’s date. Dropped. | ”A flaky test is worse than none.” |
| Coverage | 4 of the remaining 5 raise coverage on target lines. | ”No coverage gain, no pull request.” |
| Mutation | 3 of the 4 fail when a boundary check is flipped. Kept. | ”This proves the test checks something.” |
| Review | One pull request with 3 tests, the coverage diff and the mutants they catch. | ”Small and with evidence, so review takes minutes.” |
The follow-ups
“What if the AI hallucinates?” There are two kinds. Invented APIs fail the build, which is cheap. The dangerous case is a test that passes because it asserts the current behavior, bug included. No filter catches that. The reviewer reads the assertions, and tests asserting surprising values (empty, negative, zero) get flagged for a closer look.
“How would you minimize human oversight?” Lower the cost of each review instead of removing the reviewer. The agent may open pull requests that pass every filter. It may never touch production code or CI configuration. A person merges. Check a weekly sample of merged agent tests against later reverts.
“How do you get notified about failures?” Every run ends with a stop reason. Page on stuck runs or an exhausted budget. Post quality signals (pull-request acceptance falling, flake or revert rate rising) to the team channel. Never page on one failed run.
Say it like this: “I don’t remove the reviewer. I make each review cheaper and send fewer items to them.”
What it costs: the review is the expensive part
One agent attempt costs about $1.18 in tokens. If an assumed 25% of attempts survive the filters, that is $4.72 in tokens per useful test. Five minutes of an engineer’s review time costs about $7.80. So a useful test costs about $12.50 in all, and the review costs more than the tokens. The filters are what keep review time down.
The arithmetic behind the numbers (for a Staff-level follow-up)
- Cost per useful test = attempt cost ÷ yield + review minutes × engineer cost per minute.
- Attempt cost: assumed 540,000 input and 10,000 output tokens per attempt (an agent re-sends its whole history at every step, so input grows quickly over 20 steps). At Claude Sonnet 5 list price ($2 / $10 per 1M, fetched 2026-10-11): $1.08 + $0.10 = $1.18.
- Per useful test: $1.18 ÷ 0.25 (assumed yield) = $4.72.
- Review: 5 minutes of a $93/hour loaded engineer ≈ $7.80. The $93 is the US Bureau of Labor Statistics median software-developer wage ($135,980, May 2025, BLS, fetched 2026-10-12) divided by an assumed 0.70 for benefits and overhead, over 2,080 hours.
- Total: $4.72 + $7.80 ≈ $12.50.
Senior vs Staff
AI-written tests
Senior
- Sandboxes the agent, filters its tests in code and alerts on stuck runs and budgets.
Staff
- Prices the review time, designs filters to cut it, and names the metric (revert or flake rate of agent tests) that would switch the automation off.
In plain words: a Senior answer makes the agent safe and its output checked. A Staff answer also puts a price on the people, and says which number would make them turn the system off.
Small-team version
Build this as a nightly CI job plus a small orchestrator in plain code. The coding agent can be a hosted command-line tool or an API you call in a container. Buy the model; keep the filters, because nobody sells yours.
Skip auto-merge until a month of human-reviewed pull requests shows reviewers rarely reject filtered tests. Give the job its own workspace with a lower spend limit than the company’s, so a runaway night can’t use up the monthly cap that customer features share.
At an assumed 40 attempts a night, the tokens cost 40 × $1.18 × 30 ≈ $1,400 a month uncached. With prompt caching (the provider charges much less to re-read the start of a prompt it has seen recently, which suits an agent that re-sends its history) it is about $360 ($0.30 per attempt). The reviewer’s time is still the larger cost.
Revisit when reviewers become the bottleneck. Then improve the filters, not the agent’s freedom.
Pitfalls
- Treating green tests as proof of correct tests. A test can pass because it asserts the bug.
- Letting the agent edit or delete existing tests to make the suite pass. The suite then goes green by checking less, which is the opposite of the goal.
- Removing the human instead of shrinking each review. Wrong assertions then reach the main branch with no one reading them.
- Paging on every failed run. Agents fail individual runs routinely, so the pager stops meaning anything.
Go deeper
- Family walkthrough: Agent or workflow?, especially “Checking what the agent produces” and the review-load estimate.
- Build the loop’s limits: Build Your Own Agent FrameworkPartial. Compare prompt versions with a paired test: Build Your Own LLM Evaluation Harness.
- Trace each run: Build Your Own Observability StackPartial.