Your AI Agent Says “Done!” When It Isn’t: A Deterministic Check for Every Turn

November 27, 2026 · Devansh Ranjan

TL;DR

When a coding agent like Claude Code, Codex or Cursor ends a turn, Contral compares what actually changed on disk with what you asked for. It parses the request for names, files and scope, then flags a turn where nothing changed, a file rewritten unchanged, an asked-for name that is missing, broken syntax, placeholder code, and claims the code doesn't back up. Edits outside an 'only edit X' scope are shown as a note. The check is plain code: no extra LLM call and no commands run. Clear failures get one specific correction (two for smaller and free models); Claude Code gets an 'Ask Claude Code to fix it' button instead. It doesn't run your tests, and a whole turn can be undone in one click.

If you use a coding agent every day, you know this turn. You ask for a function. The agent reads a few files, writes something, and replies "Done! I added uptimeSeconds() to health.js." You open the file and the function isn't there. Or it's there with a // TODO: implement body. Or the agent rewrote the whole file with identical content and called it a day.

Any agent can end a turn like this, and smaller and free models do it most. A comment in our source puts it plainly: weak models "skip steps, rewrite whole files, stop early and claim success."

In Contral 1.1, every turn in Agent mode goes through a check before it's presented as finished. This post explains how that check works, what it catches, what it deliberately doesn't, and why it is plain code rather than a second model grading the first.

The idea: compare the request with the diff, not with the reply

The agent's final message is the least reliable part of a turn. What you can trust is the file system: what each file looked like before the turn and what it looks like after. So the check has three inputs:

  • The request you sent.
  • The files involved, each with its content before and after the turn, and whether the agent reported changing it.
  • The agent's final reply, which is only used to look for claims.

A file counts as changed when its content before and after differs. Only when the content isn't known does Contral fall back to what the agent reported. That one rule already removes a whole class of false "Done!"s.

Step 1: work out what the request actually asks for

A function called taskExpectations turns your prompt into a small, structured list of things that must be true when the agent is done:

interface TaskExpectations {
    wantsChange: boolean;   // a code change, as opposed to a question
    files: string[];        // files the request names: "health.js", "src/app.ts"
    onlyFiles: string[];    // "only edit health.js"
    names: ExpectedName[];  // names that must exist afterwards
    noCommands: boolean;    // "don't run commands / don't install"
}

It's regular expressions and a few rules, tuned to be conservative:

  • Change or question. Verbs like add, fix, refactor or rename mean a change. A request that starts with "why", "explain" or "what" is a question, unless it goes on to say "and then add…". "Don't change anything", "just answer" and "read-only" turn the change expectation off.
  • Files. Anything that looks like a source file path with a known extension (.ts, .py, .go, .rs, .java and so on).
  • Scope. "Only edit X" (or only change, modify, touch, update), with one or more files.
  • Names. "Add a function uptimeSeconds()", "create class Cart", "export a helper `slugify`", "add a /health route", and "rename foo to bar" (then bar must exist).
  • No commands. "Don't run any commands", "don't run the tests", "no commands".

The interesting part is what it refuses to extract. A name only counts if it looks like code: it's in backticks or quotes, has call parentheses, follows "called" or "named", or is camelCase, snake_case or contains a digit. Capitalised words count for classes and types. So "add a type annotation" expects nothing, while "add a type UserId" expects UserId. A list of common words (error, handling, logging, tests, validation…) is never treated as a name, so "add error handling to app.py" expects a change to happen but no specific identifier.

Illustrative examples (not user data), with what taskExpectations returns:

RequestWhat Contral expects
Add a function uptimeSeconds() to health.js. Only edit health.js. Don't run any commands.A change; uptimeSeconds must exist; only health.js in scope; no commands
Add a /health route to server.jsA change; the text /health must appear
Rename getUser to fetchUser in users.tsA change; fetchUser must exist
Add a type annotation to the handler in api.tsA change; no specific name
Why does health.js return ok: true when the database is down?A question: no change expected, so nothing to fail

Step 2: check the turn

checkAgentWork takes the expectations and the before/after files and returns a list of findings. Each finding has a severity (fail or warn), a message for you and a fix written for the agent. The turn passes when there are no fail findings.

FindingWhenSeverity
nothing-changedThe request asks for a change and no file changedfail
unchanged-rewriteThe agent reported writing a file but its content is byte-for-byte the samefail if it was the only "change", warn otherwise
missing-nameA name the request asked for isn't in the changed or named filesfail
claimed-not-doneThe reply says it added a name that isn't in any file Contral can seefail
broken-fileA changed file no longer parsesfail
placeholderNew lines contain placeholder code instead of an implementationfail
out-of-scopeA file outside "only edit X" changedwarn (shown as a note)

Nothing changed, or a rewrite with no change

The most common false "Done!". If the request asks for a change and nothing on disk differs, that's nothing-changed. If the agent did "write" a file but the bytes are identical, Contral says so specifically, because the fix is different: the agent believes it edited the file.

An asked-for name is missing

Contral searches the changed files and the files the request named. Identifiers are matched as whole words, so uptime doesn't satisfy a request for uptimeSeconds. Routes are matched as text.

Claimed but not done

The reply is scanned for phrases like "added", "created", "implemented" or "exported" followed closely by a name in backticks or with call parentheses. If that name exists in none of the files Contral can see, the reply is making a claim the code doesn't back up.

Broken syntax

Changed files go through Contral's multi-language deterministic verifier, and only its critical and major "does this run" signals become findings (at most three). JavaScript files also get a real parse: ES module syntax is neutralised, then the body is compiled with new Function, which parses the code without running it. That catches things bracket counting can't, like the same const declared twice. For that parse, a file is only blamed if it parsed before the turn: if your file was already broken, that's not the agent's fault.

Placeholder code

Only lines the agent added are checked, so your own existing TODOs never trigger it. The patterns are the familiar ones: // ... rest of the code, // existing code, // implementation goes here, // TODO: implement, a line that is just ..., throw new Error("not implemented"), raise NotImplementedError.

Out-of-scope edits

If you said "only edit health.js" and server.js changed too, you see a note. It's a warning, not a failure, and it never triggers a correction: sometimes touching another file is the right call, and you're better placed to judge that than a regex.

An illustrative turn (not user data). The request is the first row of the table above. The agent changes two files and replies:

Done! Added `uptimeSeconds()` to health.js and created the `formatUptime` helper.

It actually added a function called uptime to src/health.js and touched src/server.js. Contral reports:

fail  `uptimeSeconds` isn't in health.js.
fail  The reply says `formatUptime` was added, but it isn't in the changed files.
warn  src/server.js was changed, but the request said to only edit health.js.

Precision over recall

The design rule is written at the top of the file: a finding must be something the user would agree is wrong. Anything unsure is a warning (shown, never auto-corrected).

A checker that cries wolf is worse than no checker. If it sends the agent back to "fix" something that was fine, you pay for an extra turn and the agent may break working code to satisfy it. So every rule above leans towards staying quiet: names must look like code, questions expect nothing, pre-existing JavaScript parse errors and TODOs are ignored, a claim that was already reported as a missing name isn't reported twice, and scope is a note rather than a failure. The check will miss things. When it fails a turn, it should be right.

Step 3: one specific correction

When a turn has fail findings, Contral sends the agent a short follow-up built from the findings' fixes. For a turn where only uptimeSeconds is missing, it looks like this:

Contral checked your work and the request is not done yet (check 1 of 2):
- The request asks for `uptimeSeconds`, but it does not exist in health.js. Add it.

The request was: "Add a function uptimeSeconds() to health.js. Only edit health.js. Don't run any commands."

Fix exactly these points now by editing the files. Keep what is already correct. Do not rewrite files you do not need to change.
When you are done, reply with one line per change: the file and what you changed in it.
Do not run any commands.

It restates the original request, says exactly what's missing, tells the agent not to rewrite files it doesn't need to touch, and repeats "Do not run any commands" if you said so. The turn is then checked again.

Smaller and free models get up to 2 corrections; others get 1. "Smaller" is decided by the model name: free tiers, names containing flash, mini, nano, small, lite or tiny, small parameter counts, and OpenCode's default free model. Unknown models are treated as capable. That's a hard cap, so a stubborn agent can't loop. Corrections Contral sends don't count against your Agent mode messages, and you can turn the whole check off with contral.agentMode.checkWork.

Claude Code gets a button, not a message

With Claude Code, Contral never sends a message you didn't start. Instead, the findings come with an Ask Claude Code to fix it button, with the correction ready to send. It's your Claude plan and your session, so you decide whether the agent gets another turn.

Before the turn: a checklist for weak models

The cheapest correction is the one you never need. For smaller and free models, Contral also sends your request restated as a short checklist, built from the same expectations. For the example request:

How to do it (from Contral):
1. Read health.js first, so you know what is already there.
2. Make the change by editing the files. Change only what the request needs; keep all
   other code exactly as it is. Do not rewrite a file just to restate it.
3. When you finish, these must exist: `uptimeSeconds`.
4. Only edit health.js.
5. Do not run any commands.
6. Write complete code: no placeholders, no "rest of code here", no TODOs instead of the implementation.
7. Before you finish, re-read the changed files and check every point of the request is done.
8. End with one line per change: the file and what you changed in it.

Each step maps to a failure the check looks for afterwards. You still see your own words in the conversation; the checklist goes to the agent.

Why deterministic, and not another model

The obvious alternative is to ask a second LLM "did the agent do what was asked?". We chose not to, for four reasons:

  • No extra LLM call. The check adds no tokens, no API cost and no network round-trip to a turn.
  • Same input, same answer. You can reason about why a turn failed, and the rules don't drift when a model is updated.
  • It can't be talked round. A model grading a confident "Done!" can be persuaded by it. A regex over the file contents can't; the reply is only ever used to find claims to verify.
  • No commands. It reads file contents and parses them; it runs nothing in your workspace. That keeps it side-effect free and consistent with "don't run commands" requests.

The trade-off is real: a deterministic check only sees structure. It knows uptimeSeconds exists and parses; it doesn't know whether it returns the right number.

What it doesn't do (yet)

It doesn't run your tests. Running tests means running commands in your project, with your dependencies and your environment, and that conflicts with both the "no side effects" property above and requests that say "don't run commands". So today the check stops at "the asked-for thing exists, is real code and parses". Logic bugs, wrong return values and failing tests are still yours to catch, with the help of the teaching card on every change and Defense mode.

An opt-in test run, where you choose to let Contral run your test command after a turn, is the natural next step for this design. It isn't in 1.1, and we'd rather get it right than ship it fast.

When the check isn't enough: undo the whole turn

Sometimes the agent did what you asked and you still don't want it. After every turn, the changed-files row has Undo, which puts back every file the agent created, changed or deleted in that turn, including files it didn't report, and removes empty folders it created. Contral tells the agent about the undo the next time you write to it, so it doesn't assume its changes are still there.

Undo skips dependency, build and version-control folders such as node_modules, dist and .git, and files larger than 512 KB. Files it can't restore are listed instead of being touched.

Where it runs

The check runs on every turn in Agent mode, whichever agent you use there: Claude Code, OpenAI Codex, Cursor, OpenCode, Gemini CLI or GitHub Copilot CLI. Contral's own Build agent goes through the same check before it may claim it's done. Agent mode is in Contral IDE 1.1 and the Contral extension 1.0; the release post covers the rest of what shipped, and the Agent mode docs have the setup steps for each agent.

Frequently Asked Questions

How does Contral know whether an AI agent actually finished a task?

When a turn ends, Contral compares each file's content before and after the turn with what the request asked for. It parses the request for names, files and scope, then flags a turn where nothing changed, a file rewritten with identical content, a requested name that is missing, a file that no longer parses, placeholder code, and names the agent's reply claims to have added but that aren't in the code.

Does the check use another LLM or run my code?

No. It is deterministic code: regular expressions over the request and the reply, content comparison, and syntax parsing of changed files. There is no extra LLM call and it runs no commands in your workspace.

What happens when the check finds a problem?

Clear failures get one short, specific correction sent to the agent automatically: up to 2 tries for smaller and free models, 1 for others. Uncertain findings, such as edits outside an 'only edit X' scope, are shown as a note and never auto-corrected. Corrections don't count against your Agent mode messages.

Does Contral send messages to Claude Code on its own?

No. With Claude Code, Contral never sends a message you didn't start. You get an 'Ask Claude Code to fix it' button with the correction ready to send.

Does Contral run my tests after an agent's turn?

Not today. The check confirms the requested code exists, is real code and parses, but it doesn't run tests or verify logic. Opt-in test runs are a natural next step for the design but aren't part of Contral 1.1.

Can I turn the work check off?

Yes. Set contral.agentMode.checkWork to false.

Put your agent's "Done!" to the test

Use Claude Code, Codex or Cursor inside Contral. Free to start.