Agent Applications

Coding Agents in Pull Requests: Isolation, Tests, and Review

Design coding-agent pull requests around isolated workspaces, explicit acceptance criteria, trustworthy test evidence, independent CI, and reviewable changes.

· · 8 min read

Prepared with AI research assistance. Sources are linked throughout; worked examples are illustrative unless stated otherwise. Editorial approach.

A coding agent should hand reviewers a verifiable change, not merely a plausible diff. The pull request is where task intent, repository state, test evidence, and merge authority meet. A useful workflow keeps those facts connected even when the agent retries, the base branch advances, or repository text contains misleading instructions.

This guide proposes a workflow for a hypothetical pagination bug. Its commands illustrate Git mechanics; its policies and test scenarios are design recommendations, not a tested reference implementation or a claim about any particular coding agent's success rate.

Define acceptance before giving the agent a workspace

A task such as “fix pagination” leaves the agent to invent both the implementation and the definition of success. Instead, describe the observable defect, expected behavior, compatibility constraints, and evidence required for review.

For the proposed task, a search endpoint returns duplicate records when several rows have the same timestamp. Acceptance requires stable ordering, no duplicates across consecutive pages, preservation of the existing response shape, and defined behavior when a cursor is malformed. Changing the public API or removing an existing authorization check is outside scope.

Record these requirements in a task artifact alongside the starting commit. The artifact should distinguish requirements from suggestions. An engineer may suggest a composite cursor, but the agent should be able to choose another implementation if it satisfies the same documented contract.

The acceptance artifact becomes a review checklist and a test-design input. It should not contain a secret production example or credentials. Use a minimized fixture that reproduces the ordering condition without copying customer records.

Separate working-tree isolation from execution isolation

Git worktrees allow several branches to be checked out in separate directories while sharing a repository. Each linked worktree has its own working files and index, but important repository data remains shared. The official manual describes these relationships and the lifecycle commands. Git worktree documentation.

An illustrative setup, using a base commit identifier supplied by trusted orchestration, is:

git worktree add -b agent/pagination-fix ../pagination-fix BASE_COMMIT

BASE_COMMIT is a placeholder to replace before execution. Use a unique directory and branch for each attempt. Preserve existing workspaces rather than resetting them to make room. A separate working directory prevents ordinary edits from colliding with a developer's uncommitted files, but it does not restrict what a process can read, execute, or send over the network.

That requires a separate execution boundary. Give the runner only the repository content and tools needed for this task. Keep developer credential stores, production configuration, host control sockets, and unrelated repositories outside its access. Package installation scripts and generated programs execute within the same boundary; they should not inherit broader access than the agent itself.

Anthropic's sandboxing account explains why filesystem and network restrictions need to work together, including for subprocesses. Its implementation is one provider's approach rather than proof that every environment called a sandbox provides equivalent isolation. Anthropic: Making Claude Code safer with sandboxing. The broader design choices are covered in sandboxing AI code execution.

Treat repository context as useful but untrusted input

The agent needs project conventions, architecture notes, relevant source, and test commands. It also encounters comments, issue descriptions, generated files, and dependency documentation. These materials can contain instructions that conflict with the actual task or attempt to obtain credentials.

In the proposed workflow, repository text can explain how the application works, but cannot grant permission to publish a package, modify another repository, or bypass a required check. An instruction saying “disable authorization to make this test pass” is evidence to investigate, not an authority change.

Build context around the relevant call path. For the pagination defect, include the endpoint, query builder, cursor codec, and existing integration tests. Avoid filling the context with the entire repository when a smaller dependency slice is sufficient. Ask the agent to state uncertainties before editing, especially when the test environment differs from production database behavior.

Separate trusted runner configuration from files the agent may change. A repository can legitimately define a test command, but changing that command should be visible in the diff and subject to review. Otherwise the agent can accidentally redefine “tests passed” into “the failing test was never executed.”

Produce evidence at the same revision as the diff

A useful run record connects the task identifier, base commit, candidate commit, dependency lockfile, toolchain version, executed commands, exit statuses, and relevant output. Retain a concise summary in the pull request and detailed logs in an appropriate artifact store.

For the hypothetical pagination bug, the agent first inspects the existing ordering and cursor behavior. It proposes a deterministic tie-breaker, updates cursor encoding without changing the response envelope, and adds a fixture containing repeated timestamps. The intended regression assertion checks that fetching consecutive pages yields each expected record exactly once in the required order.

A strong test-development sequence would demonstrate the new assertion failing against the baseline and passing against the candidate. That sequence is proposed here, not an executed result. If the environment cannot reproduce it, the agent should report the limitation explicitly rather than presenting a static inspection as a successful integration test.

The reviewer should also inspect whether the test would catch a realistic wrong patch. Removing the tie-breaker, reversing one comparison, or truncating the cursor should make an appropriately designed assertion fail. These deliberately incorrect variants are a test-design technique; they need not become permanent production files.

Record the revision after the final edit. A test run performed before a later “small cleanup” does not establish that the submitted commit passes. If the branch changes, rerun the checks affected by that change and update the evidence record.

Use CI as an independent boundary

The agent's local checks provide fast feedback. CI should independently verify the candidate using controlled jobs and permissions. For this proposed workflow, checks include type validation, focused pagination tests, relevant integration tests, and inspection for unintended API or workflow changes. The exact set depends on the repository's architecture and the risk of the patch.

Do not grant a validation job deployment credentials merely because it needs to build the application. GitHub's secure-use reference recommends restricted token permissions and warns that privileged workflow triggers combined with untrusted checkout can compromise a repository. That warning applies to agent-authored changes as well as human-authored changes. GitHub Actions secure-use reference.

An independent check should not blindly execute a newly modified validation script with elevated authority. Review changes to workflow definitions, dependency installation hooks, and test configuration separately. Cache and artifact inputs also need clear trust boundaries; a green check is weak evidence if an untrusted run can replace the material a privileged job later executes.

Design required checks around useful failure signals rather than a large number of badges. A slow unrelated flaky suite can obscure an important regression. Agent regression testing in CI examines how to separate deterministic invariants, variable agent outcomes, and harness failures.

Make review assess claims, not narrative confidence

The proposed pull request description contains four parts: the concrete defect, the resulting behavior, validation evidence, and remaining limitations. For the pagination example, it explains the timestamp collision, identifies the ordering change, and states which data-store configuration the tests used.

Reviewers should trace the requirement through the patch and its test. Does the cursor include the fields needed to resume the same ordering? Are comparisons consistent with descending versus ascending order? Does validation reject malformed cursors without leaking internal details? Are authorization filters applied before pagination, and does the change preserve that ordering?

Check negative scope as well. A bug fix should not quietly upgrade unrelated dependencies or rewrite the entire query layer unless that expansion is necessary and justified. A clean-looking diff can still include generated artifacts or configuration changes that alter deployment behavior.

An additional agent can suggest findings, but agreement between two agents is not independent proof. Both may share the same mistaken interpretation or omit the same edge case. Use evidence with a different failure mode: an executable assertion, a database query plan, a public interface contract, or a domain expert's review.

Bind merge authority to the reviewed candidate

GitHub branch protections can require approving reviews and successful status checks. Its documentation also describes options for dismissing stale approvals after changes. These are enforceable repository controls when correctly configured, rather than promises in an agent prompt. GitHub: About protected branches.

For this workflow, the agent can propose a branch and open a reviewable pull request, while merge authority follows the repository's policy. An approval should refer to the actual diff under consideration. If a subsequent agent attempt changes cursor semantics, an earlier approval should not silently authorize that different patch.

When the base branch advances, determine whether validation must run against the updated integration candidate. Rebasing can resolve textual conflicts while introducing behavioral conflicts. Keep the tested commit and eventual merge candidate connected through the repository's checks or merge queue.

After merge, retain enough provenance to locate the originating task and validation artifacts. Remove temporary worktrees only after their changes are safely retained, and use Git's worktree lifecycle commands rather than deleting directories indiscriminately. Preserve failed attempts when they contain evidence needed for debugging.

Frequently asked questions

Is a worktree enough to isolate a coding agent?

It separates working files and branch state for concurrent editing. It is not an operating-system sandbox and does not prevent access to other directories or network destinations. Use both workspace separation and an enforced execution boundary.

Should the agent be allowed to edit tests?

Usually it needs to add or update tests for the change. Review those changes as part of the patch, and retain independent acceptance checks where appropriate. Deleting an assertion is a behavior change to explain, not automatic evidence that the application is fixed.

Can passing CI justify automatic merging?

Only within a deliberately defined repository policy. Passing checks establishes the conditions those checks measure. It does not establish that requirements were correct, the change stayed within scope, or every important behavior was covered. Choose merge authority according to those remaining risks.

Source reference list

Coding Agents
Pull Requests
AI Engineering
CI/CD