Harness Engineering for Codex: A First Pull Request Checklist

Updated
8 min read
Codex harness cover with a branch, test checklist and final approval mark.
TL;DR

Give Codex one small fix, a workspace with clear limits, and a test that proves the bug existed. This checklist takes an existing repository from setup to a reviewable pull request.

Harness engineering for Codex starts with a small pull request and a reviewer who can tell exactly what changed. Give the agent one reproducible bug, a restricted workspace, and a test that fails before the fix. The PR should show all three pieces of evidence. A green check on the final commit tells only part of the story.

Take a familiar example. A CSV import accepts rows with a missing required column and silently produces incomplete records. Ask Codex to make that input return the existing validation error. Leave the import schema, dependencies, and CI configuration alone. The result is a small enough change that another engineer can reproduce it in a few minutes.

Give the agent a map of the repository

Start by opening the project’s main instructions file. List where the importer lives, how to run its tests from a clean checkout, and which directories require approval. Use commands a new contributor could run. If the command depends on your shell history or a password in your local environment, fix that dependency before handing the task to an agent.

OpenAI’s harness engineering write-up describes keeping engineering knowledge in the repository where Codex can find it. In an existing project, that can be as simple as pointing from the root instructions to the importer’s README and the test command. Our AGENTS.md templates for Codex and Cursor show how to give those instructions a home.

For the import ticket, the handoff could read:

Reproduce the missing-column bug with a fixture that is valid apart from the missing field. Use the existing validation error. Edit the importer and its tests. Keep schema, dependency, and CI changes out of this PR. Report the focused test that failed before the fix and the checks that passed afterward. Stop and ask if the fix requires edits outside that scope.

That last line matters. Sometimes a small ticket turns out to require a decision about compatibility. The agent should surface it while the diff is still easy to review.

Set permissions before opening the task

Use a separate branch or Git worktree so the agent’s edits are easy to inspect. Set filesystem and network permissions independently. A worktree is a second checkout, and processes launched from it still need real permission boundaries. Keep production credentials and private data out of that environment. Use a small synthetic fixture for the import task.

Start with the access needed to read the repository, edit the task workspace, and run the local tests. If dependency setup needs the network, prepare the environment separately or approve the specific setup step. Keep deployment and merge permissions with the people who own them. Check the Codex security documentation for the settings available in your environment.

Keep the test that proves the bug existed

Add the missing-column case and run it against the old code. Read the failure. It should show that the importer accepted the bad row. A parsing crash at this stage usually means the fixture needs a closer look. Then make the smallest fix and run the same assertion again.

Run the nearby import tests too. In this example, a valid CSV should still work, an empty value should follow the existing validation rules, and the new error should use the project’s existing format. Choose these checks before looking at the finished diff. Our Vitest testing guide covers how to keep the failure local and readable.

Make CI repeat the check from a clean checkout. If the agent touched an existing test, inspect that hunk before trusting the green build. A reviewer should be able to tell whether the implementation improved or the assertion became weaker.

Put the evidence in the pull request

Click any column to sort
4 rows
What was broken?The input that triggered the bug and the behavior it produced.
What changed?The files edited and the intended behavior, stated in one sentence.
Can I reproduce it?The focused test command, its failure before the fix, and the passing result afterward.
What still needs a person?Any change to a schema, protected file, or release behavior that requires its owner.

On the first few PRs, pay attention to places where the review gets stuck. If two tickets wander into unrelated modules, narrow the allowed scope. If CI catches the same regression twice, improve the local test command and document it. Birgitta Böckeler’s guide for coding agent users distinguishes the guidance an agent receives ahead of a change from the feedback it gets after acting. The CSV ticket needs both.

For longer work, leave a short handoff with the last verified command, the remaining task, and the branch state. Anthropic describes the same problem in its research on long-running agents. The next session should start by checking that state and running the relevant test. If you also run agents as part of a service, the production AI agent guide covers the separate problem of monitoring runtime behavior.

Prepare a baseline you can hand to another engineer

Begin outside the agent session. Pick a commit, make sure the nearby tests pass, and note how the test data is created. In the CSV example, give the baseline one known-good file and one file with the required column missing. Keep the files small enough that a reviewer can read their entire contents. If the output includes timestamps, random identifiers or locale-dependent text, write the assertion around the behavior you actually need to protect.

Record the original failure before editing the importer. If the baseline test suite is already red for an unrelated reason, write down the failing check and decide whether a focused run is enough for this ticket. This matters because a reviewer needs to distinguish an inherited failure from something new. A large build log with one unexplained red line makes that decision harder.

A good handoff contains four short fields:

  • Starting commit and runtime. Include the command version when it changes the result.
  • Fixture and expected behavior. A missing required column should produce the named validation error.
  • Change boundary. List the production directory and test directory the agent is allowed to edit.
  • Verification. Give the focused test command and the ordinary package-level checks.

Keep the handoff with the issue or the review. A teammate can then repeat the task even if they cannot access the original agent session.

Decide what happens when a check fails

A harness earns its keep on a bad run. Before you start, decide what the agent may try again and what it should hand back to a person. A typo in a test command is usually easy to correct inside the workspace. A missing dependency may require a separate setup step. A test that exposes a disagreement about the intended importer behavior needs the owner to make a decision.

Here is how that looks in the example. The new test reads a blank value as a missing column. The old code distinguishes those cases. Instead of making both paths return the same error, ask the agent to show the two fixtures and identify which requirement applies. If the ticket only covers the missing column, keep the blank-value behavior and report the distinction. That small pause prevents a harmless-looking patch from changing how historical uploads are handled.

Do the same with approval requests. If a command reaches for a path or an external service the task did not mention, look at the exact operation and decide whether it belongs in the workflow. The developer who owns the environment should be able to say what they approved and why. See our Codex sandbox permissions guide for a way to diagnose which boundary stopped an operation.

Give the reviewer a short, repeatable route through the diff

Review the regression test first. Read the test name, the input and the failed assertion from the baseline. Then open the implementation hunk that changed the behavior. Finally, check the broader tests and any touched configuration. This order lets the reviewer decide early whether the task itself is represented correctly.

Watch for generated artifacts that look like a side effect of the build. A regenerated lockfile, a snapshot representing a different input, or a reformatted module can make a two-line fix hard to understand. Ask the author to explain why any such change is in scope. If it is needed, keep the reason close to the hunk or give it its own follow-up.

One useful exercise is to ask another engineer to take the pull request description and reproduce the focused test without opening the agent log. If they need to ask which directory to run it from, record that detail in the repository instructions. If they cannot reproduce the assertion on the baseline, fix the test setup before using the PR as an example for the rest of the team.

What to change after the first few tickets

Read the reviews before adding a new rule. If every reviewer asks for the same fixture, add a fixture pattern to the importer tests. If agents keep editing a generated file, make the source file and generation command obvious in the project notes. If the same class of patch passes tests and then breaks in review, add a check that catches the behavior the reviewers are seeing.

Keep a list of the few changes that would have prevented actual rework. Give each change an owner and a way to tell whether it helped. A new lint rule should have a small failing example. A new instruction should point to the file or command it talks about. A change in permissions should be explainable to the developer who uses the project on the next ticket. That is enough to turn one good pull request into a method the rest of the team can try.

A first Codex PR has done its job when another engineer can reproduce the old failure, explain the new behavior, and approve the change from the diff and CI logs. Start with one ticket that gets you there.

Frequently Asked Questions

What is harness engineering for Codex?

It is the work of preparing the repository, permissions, task instructions, and verification process around Codex so a reviewer can decide whether a change is safe to merge.

Does a Git worktree sandbox Codex?

A worktree gives the task a separate checkout. Use the runtime sandbox and permission settings to control filesystem and network access, and keep credentials out of the environment.

Which check should I automate first?

Start with a regression test that fails on the original code and passes with the fix. Run it in normal CI alongside the repository’s existing checks.

When should Codex be allowed to merge its own changes?

Keep human review for the initial rollout. Revisit merge permissions after you have reviewed enough comparable tasks to understand what the tests miss and which parts of the code still need an owner.

#harness-engineering#codex#ai-agents#sandboxing#regression-testing#code-review

One AI engineering post, weekly

LLM benchmarks, prompt techniques, and token-cost breakdowns, delivered to your inbox.

What should we test or explain next?

Comments

Have a question or something to add? Sign in to join the discussion.

Mahmudul Haque Qudrati — CEO & ML Engineer at Pristren

Mahmudul Haque Qudrati

CEO & ML Engineer

Software architect, full-stack engineer, and machine learning practitioner. Founder & CEO of Pristren, CTO at Venture Kick-backed PIN Sport Application GmbH (Basel, Switzerland), Software Development Lead at DailyFrame GmbH (building Dimetra patient transport software), and creator of Zlyqor. Focused on custom workflow automation, scalable web and mobile applications, and production AI/ML systems.