← Blog

Separation of Duties When the Same Agent Writes and Tests the Code

Marco Masut

Separation of duties (also called segregation of duties) is an internal control principle: no single person or system should be able to carry out and approve the same critical action, so that an error or an abuse has to get past a second, independent party. It is a core idea in the COSO internal control framework, behind the financial controls auditors test under Sarbanes-Oxley, and it appears as a named control in ISO/IEC 27001:2022, Annex A, control 5.3. A coding agent that writes the change, writes the tests for it and reports that they pass holds three roles at once: author, tester and approver. Unless something outside the agent runs the verification and a person gives the final approval, those three roles collapse into one, and the evidence that "the tests pass" is the author's own statement about its own work. The fix is not to distrust agents. It is to place each duty somewhere the agent cannot reach.

What does separation of duties actually require?

The principle is older than software. A person who raises a purchase order does not approve the payment. The person who writes a change does not release it alone. What matters is not the job titles but three properties:

  • Independence: the party that checks cannot be controlled or edited by the party being checked.
  • Distinct roles: the ability to do and the ability to approve are held by different parties.
  • A record: both actions leave something a third person can inspect later.

An auditor does not ask whether you trust your team. They ask whether the control makes the bad outcome require two failures instead of one. That is the standard to apply to agents too. Control 5.3 of ISO/IEC 27001:2022 states the same expectation in plain terms: conflicting duties and areas of responsibility should be segregated.

How do agents collapse the author, tester and approver roles?

In a classic pipeline, three different parties touch a change: a developer writes it, a test suite or a QA person checks it, a reviewer or release owner approves it. An agent session can do all three in one loop, usually in minutes.

| Role | In a classic pipeline | In an unconstrained agent session | | --- | --- | --- | | Author | Developer | The agent | | Tester | Separate suite, or QA | The agent writes the tests and chooses what they cover | | Verifier | CI run by the pipeline | The agent runs the tests and reports the result | | Approver | Reviewer or release owner | The agent's own summary, "done, all green" |

Two failure modes follow. The first is circular verification: tests written by the same model that wrote the code tend to encode the same assumptions, so they pass for the same wrong reason. The second is self-reported evidence: a result that the model states in prose is a claim, not a measurement. Neither needs bad intent. A model under pressure to finish can weaken a test, skip a failing case or edit a config, and the summary will still say green. This is why what an agent leaves behind as proof matters more than how much code it produced.

Which controls restore the separation?

The goal is to put each duty on a party that the agent cannot overwrite. Four controls do most of the work:

  1. The runner executes the verification, not the agent. The command that decides pass or fail is run by the pipeline, outside the agent session, and its output is stored. The agent never states the result.
  2. The scope is declared before the work starts. A written contract lists the paths the change may touch and the paths it may not. A check against the actual diff, run after the fact, catches an agent that edited the test or the pipeline to get a pass.
  3. Tests are protected from their author. Forbidden paths cover the verification itself, so the agent that writes the feature cannot rewrite the check that judges it.
  4. A person signs. The final approval is a named human decision tied to the exact change, not an automatic merge. Auto mode and the human signature covers why a classifier blocking dangerous commands is a different thing from a person accepting responsibility for a release.

None of these controls limit what the agent can write. They limit what the agent can certify.

What can an auditor verify afterwards?

The test of a control is whether a stranger can reconstruct it later. For separation of duties, an auditor should be able to answer five questions from stored records alone, without asking anyone:

  • Who or what authored the change, and under which written scope?
  • Which command verified it, and who executed that command?
  • Did the diff stay inside the allowed paths?
  • Who approved the release, when, and against which version of the change?
  • Was the approver a different party from the author, and a person?

If any answer depends on someone's memory or on the agent's own account, the duty was not separated, it was assumed. The record described in software audit trail when an agent made the change is the artifact that turns those answers into something checkable.

What does a minimal pipeline that keeps the duties apart look like?

You do not need a new platform to start. A minimal version has five steps, and the useful thing is that each one hands the next a stored artifact:

| Step | Who acts | Artifact left behind | | --- | --- | --- | | 1. Request and scope | A person writes it | The request and the allowed and forbidden paths | | 2. Implementation | The agent | The diff | | 3. Verification | The runner, outside the agent | The command and its output | | 4. Scope check | The runner | A pass or fail against the declared paths | | 5. Approval | A named person | A signature tied to the plan and the product version |

Detent, the end-to-end delivery system, is organised around this shape: the system prepares the change and its evidence, a person signs, and nothing is released without that signature. It is one way of implementing the table, not the only one. To see how coding tools compare on what they leave behind once a session ends, look at the benchmark.

A practical first step: take your last agent-assisted change and fill in the table with what actually happened. Wherever the "who acts" column says the agent for both step 3 and step 5, you have found the duty to separate first.