Reviewing Agent Work

Pull requests, diffs, and code review

Brendan Chapuis

April 7, 2027

Draws on talks by Scott Cunningham
Course Home Page

Lecture Goals

  • Why work an agent produced has to be reviewed
  • One pull request per stage of a project
  • How to read a diff of research code, and what to look for
  • A review checklist, and GitHub’s review tools
  • Having an agent review first, then sending its comments back
  • The AI replication assignment

The last 25 minutes are for midterm questions.

Why Review

Where We Are

Date Topic
3/24 From chatbots to agents
4/5 Directing agents: AGENTS.md, skills, hooks
4/7 Reviewing agent work (today)
4/12 Midterm
4/14 Quarto: every number comes from code
4/19 Checking results

On 4/5 you told the agent what to do. Today: how to check what it did.

You Did Not Write It

Recall the three legs: production, checking, understanding.

  • When you wrote the code, writing it was also checking it.
  • When an agent writes it, you have only the result.
  • Code that runs is not code that is right.
  • A table that looks plausible is not a table that is right.

You did not write it, so you cannot assume it is right.

Hidden Actions

Working with an agent is a principal–agent problem. Things it can do without telling you:

  • Cherry-picking: reports the results that look best and leaves out the rest
  • Cue-driven analysis: runs analyses because of stray hints in your files or prompt
  • Specification searching: tries outcomes and controls until something “works”
  • Rule-breaking: ignores the rules you wrote in AGENTS.md

None of these shows up in the table the agent hands you.

After Scott Cunningham’s list of hidden actions (Baylor talk, October 2026).

The Diff Shows What Happened

The table hides what the agent did. The diff shows it.

  • Every line added, removed, or changed
  • In every file, including the ones you did not ask about

“The diff is the unit of observation.” — Paul Goldsmith-Pinkham, as quoted by Scott Cunningham

If you cannot read every line of every diff, follow one thread hard. Scott’s is always: did the treatment actually do anything?

One Pull Request per Stage

Recall: Branches and Pull Requests

From the 2/03 lecture:

  • A branch is a separate line of commits.
  • A pull request (PR) asks to merge a branch into main.
  • GitHub shows the PR’s diff, and collaborators can comment before merging.

Today the collaborator who opens the pull request is an agent, and the reviewer is you.

Every Stage Ships as a Pull Request

Break the project into stages. Each stage is one pull request.

  • The unit is one exhibit: the cleaned data, a figure, the balance table, the main regression.
  • The PR is the review: read the script diff and look at the output it produced.
  • The merge is the gate: the next stage does not start until this one is approved.

Figures are where errors hide in plain sight. A figure can render cleanly and still be wrong.

Adapted from Scott Cunningham’s workflow (Baylor talk, October 2026).

Stages in Your Final Project

A possible sequence of pull requests:

  1. Clean the raw data (you did a version of this by hand for the checkpoint)
  2. One descriptive figure
  3. The main specification
  4. Robustness checks
  5. The Quarto write-up

Each one is small enough to read in one sitting. A PR that touches 30 files cannot be reviewed; it can only be trusted.

Asking the Agent to Open the PR

A prompt for one stage:

Create a branch called main-regression. Write code/03-regressions.R to
estimate the main specification described in AGENTS.md. Run it, save the
table to output/tables/, and commit. Do not edit any other files.
Then open a pull request with `gh pr create`, and in the description list
every file you changed and the number of observations in the regression.
  • gh is GitHub’s command-line tool. The agent uses it to open the PR for you.
  • Asking for the file list and the N in the description gives you two things to check right away.

Small Pull Requests

A good PR

  • One stage, one exhibit
  • A few files
  • A description that says what changed and why
  • Output you can open and look at

A bad PR

  • “Did the analysis”
  • Dozens of files
  • Data, code, and outputs changed together
  • No description

If a PR is too big to review, ask the agent to split it.

Reading a Diff

Anatomy of a Diff

--- a/code/02-clean.R
+++ b/code/02-clean.R
@@ -12,3 +12,3 @@ cps <- read_csv("data/raw/cps.csv")

 cps <- cps |>
-  filter(year >= 2010)
+  filter(year >= 2012)
  • --- and +++: the file before and after
  • @@ -12,3 +12,3 @@: where the change is (starting at line 12, three lines shown)
  • - lines were removed, + lines were added, other lines are context

Where to See Diffs

  • GitHub: the pull request’s Files changed tab
  • VS Code: the Source Control panel; click a file to see it side by side
  • Terminal:
    • git diff for changes not yet committed
    • git diff main...my-branch for a whole branch
    • gh pr diff 12 for pull request 12

Read the list of changed files first. Then read each file.

What to Look for in Research Code (1)

  • Hard-coded numbers. A coefficient, a mean, or an N typed into the code or text instead of computed.
  • Dropped observations. drop_na(), na.omit(), inner joins, and filters all remove rows. How many?
  • Changed sample filters. Years, ages, or regions that quietly differ from the ones you chose.

What to Look for in Research Code (2)

  • Silent defaults. An argument that was removed or never set: standard errors, na.rm, join type, the reference category.
  • Files touched outside the task. You asked for a regression; why did the cleaning script change?
  • Outputs edited by hand. A table, a figure, or a .csv in output/ changed without the code that makes it changing.

Silent Defaults You Have Seen

Code The default you get
feols(y ~ x \| fe, data) iid standard errors (since fixest 0.13)
mean(x) NA if any value is missing
merge(a, b) an inner join: unmatched rows disappear
factor(x) the first level, alphabetically, is the reference
read_csv() column types guessed from the data

None of these is wrong. Each is a choice, and in a diff the choice is the line that is not there.

A Small Example: drop_na()

library(tidyverse)
df <- tibble(
  wage = c(15, 22, 18, 30),
  educ = c(12, NA, 16, NA),
  union = c(0, 1, NA, 0)
)
nrow(drop_na(df))           # drops rows missing anything
[1] 1
nrow(drop_na(df, wage))     # drops rows missing wage only
[1] 4

drop_na() with no columns drops a row if any column is missing, including columns your regression never uses.

Exercise: Spot the Problems

The Task

You gave the agent this task on your project:

Add a second specification to code/03-regressions.R that also controls
for years of education. Keep everything else the same.

It ran without errors, opened a pull request, and the description says “Added the education control.”

On the next slide is the diff. Find the problems. Take three minutes with your neighbor.

The Diff

--- a/code/03-regressions.R
+++ b/code/03-regressions.R
@@ -8,9 +8,11 @@ library(fixest)
 cps <- read_csv("data/clean/cps.csv")

 sample <- cps |>
-  filter(age >= 25, age <= 64, !is.na(wage))
+  filter(age >= 25, age <= 54) |>
+  drop_na()

-m1 <- feols(log(wage) ~ min_wage | state + year,
-            cluster = ~state, data = sample)
+m1 <- feols(log(wage) ~ min_wage | state + year, data = sample)
+m2 <- feols(log(wage) ~ min_wage + educ | state + year, data = sample)

-etable(m1, file = "output/tables/main.tex")
+etable(m1, m2, file = "output/tables/main.tex")
+writeLines("Effect of a $1 increase: 0.083", "output/effect.txt")

What Was Wrong

The task was one line: add m2. Everything else is outside it.

  1. Changed sample filter. The upper age limit moved from 64 to 54. The sample is now different for both models.
  1. Dropped observations. drop_na() with no columns drops anyone missing any variable in the file, not just wage.
  1. Silent default. cluster = ~state was removed, so both models now use iid standard errors, which are usually too small here.
  1. Hard-coded number. 0.083 is typed in, not computed. Change the data and it will still say 0.083.

Why Tests Would Not Catch Any of This

  • The code runs.
  • Both models estimate.
  • The table renders.
  • The coefficient has a plausible sign and size.

Each change also alters m1, the result you had already checked. The description said “Added the education control.” It did not mention the other four changes.

Only reading the diff finds this.

What to Write Back

A review comment should say what is wrong and what to do:

Lines 11-12: keep the original filter (age 25-64, wage not missing).
If educ is missing for some people, drop them only in m2, and report
how many observations each model uses.

Line 14: restore cluster = ~state for both models.

Line 18: remove effect.txt. Numbers in the paper come from the
table, which Quarto will read (4/14).

A Review Checklist

Checklist: Scope

  • Does the PR do what the task asked, and only that?
  • Which files changed? Is each one expected?
  • Did anything in data/raw/ change? (It never should.)
  • Did any output change without the code that produces it changing?
  • Does the PR description match the diff?

Checklist: Data

  • How many observations go in, and how many come out of each step?
  • Were rows dropped? By which filter, join, or drop_na()?
  • Did the sample definition change (years, ages, units)?
  • Are merges one-to-one where they should be? Did the row count jump?
  • Are variables in the units you expect (dollars or thousands; shares or percent)?

Checklist: Estimates and Outputs

  • Is the specification the one you asked for? Same controls, fixed effects, clustering?
  • Are any numbers typed in rather than computed?
  • Open the figure or table. Does it look right? Axis labels, units, N?
  • Does a previously checked result still match what it was before?
  • Can you rerun it from scratch and get the same output?

Rerun It Yourself

Check out the PR’s branch and run the code:

gh pr checkout 12
Rscript code/03-regressions.R
  • Compare the N and the coefficients to the PR description.
  • Compare the old results to main: did anything you did not ask about move?

The agent says it ran the code. Run it anyway.

Write the Checklist Down

The 4/5 lesson: what is obvious to you is not obvious to the agent.

  • Put the checklist in a pull request template: .github/pull_request_template.md. GitHub fills it into every new PR description.
  • Ask the agent to fill it in when it opens a PR: files changed, N at each step, anything it dropped.
  • Add the rules that matter to AGENTS.md: “never edit data/raw/,” “always cluster by state.”

The agent’s answers are a claim. The diff is the evidence.

GitHub’s Review Tools

Comments on Lines

In the Files changed tab:

  • Hover over a line and click the blue comment button next to its line number.
  • Click and drag over line numbers (or Shift-click) to comment on a range.
  • Each comment is attached to the exact lines it is about.

Click Start a review instead of posting comments one by one. The comments stay pending until you submit them together.

Source: GitHub Docs, “Reviewing proposed changes in a pull request.”

Suggested Changes

In a comment, click the suggestion button and edit the code yourself:

```suggestion
m1 <- feols(log(wage) ~ min_wage | state + year,
            cluster = ~state, data = sample)
```
  • The author sees your exact replacement and clicks Commit suggestion.
  • Several suggestions can be added to a batch and committed together.

Use suggestions for small, exact fixes. Use plain comments when the agent has to figure out the fix.

Submitting the Review

Click Review changes and choose one:

  • Comment: feedback without a decision
  • Approve: ready to merge
  • Request changes: must be addressed before merging

Two details:

  • “Request changes” only blocks merging if branch protection requires reviews.
  • You cannot approve your own pull request. If the agent opened the PR with your GitHub account, you are the author: leave a Comment review and merge when it is right.

Keeping Track

  • Tick Viewed on each file as you finish it. The file collapses, and it un-ticks itself if the file changes again.
  • After the agent pushes fixes, check the new commits, not just the conversation.
  • Resolve each comment thread once it is fixed.

Merge only when every comment is resolved and you have looked at the outputs.

Agents Reviewing Agents

Let an Agent Review First

Every major tool can review a pull request:

Tool How
Claude Code /code-review 12 in a session; --comment posts the findings on the PR
Codex comment @codex review on the PR, or /review in the CLI
GitHub Copilot add Copilot as a reviewer in the PR sidebar

The easy catches are flagged before you start. You still read the diff.

Use a Fresh Reviewer

  • The agent that wrote the code has already convinced itself it is right.
  • A new session, with no memory of writing it, reads the diff cold.
  • Better still: a different tool or model, whose mistakes are less likely to match the first one’s.
  • Point it at your checklist: “Review PR 12 against the checklist in .github/pull_request_template.md.”

We return to independent checks on 4/19.

Sending the Comments Back

The round trip:

  1. The agent opens a pull request.
  2. You (and a reviewing agent) comment on the lines in the browser.
  3. You hand the comments back to the agent.
  4. It fixes, commits, and pushes to the same branch.
  5. You refresh the PR and review the new commits.

You review in the browser. The agent works in the terminal. Same pull request, both sides.

Adapted from Scott Cunningham’s code review demo (Texas A&M talk, October 2026).

Handing Comments Back

On your machine: tell the agent to read the thread.

Read the review comments on PR 12 with `gh pr view 12 --comments`.
Address each one, commit, and push. Reply to each comment with what you did.

On GitHub: some tools answer a mention in a PR comment.

  • Claude Code: @claude after installing its GitHub app (/install-github-app)
  • Codex: @codex after connecting it to GitHub

The Agent on a Timer

Claude Code’s /loop runs a prompt on a schedule:

/loop 10m pull the branch, read new review comments on PR 12,
address them, and push
  • It runs only while the session stays open. Close the terminal and it stops.
  • For work around the clock, you would use a scheduled GitHub Action instead.

You do not need this. It shows what the round trip looks like when nobody has to type “go.”

What Agent Reviewers Miss

  • They are good at bugs that look like bugs: typos, wrong variables, code that will crash.
  • They are worse at choices that look reasonable: an age cap of 54, a missing cluster.
  • Only you know which sample you meant and why.
  • An agent reviewer can also be wrong, or flag things that are fine.

The reviewer’s comments are input. The merge is your decision.

In-Class Exercise

Exercise: An Agent Opens a PR

On your final project repo, with the AGENTS.md you wrote on 4/5:

  1. Pick one small stage: a figure, a summary table, or one regression.
  2. Ask the agent to do it on a new branch and open a pull request, listing the files it changed and the N.
  3. Do not look at its work in the terminal. Wait for the PR.

About 15 minutes.

Exercise: Review It

  1. Open the PR’s Files changed tab. Read the file list first.
  2. Go through the checklist: scope, data, estimates and outputs.
  3. Leave at least two line comments, one of them a suggestion.
  4. Optional: have a fresh agent session review it too. Compare its comments with yours.
  5. Hand the comments back, review the fix, and merge.

If the PR is clean, say why you believe it is. That is a review too.

Exercise: Debrief

  • Did the agent change anything you did not ask for?
  • Did the N match what you expected from your checkpoint data?
  • What did the reviewing agent catch that you missed, or the other way around?
  • What would you add to your AGENTS.md or PR template after this?

AI Replication

The AI Replication

Assigned today. Due Friday 4/16.

  • Pick one replication package from the list on the assignment page.
  • Use an agent to reproduce one table or figure from the paper.
  • Your job is to check its work, not to do the work for it.

The packages are small, public, and in R or Python. One table, not the whole paper.

What to Submit

  1. The result: the reproduced table or figure, with the code that made it.
  2. The transcript: the full agent session (or sessions).
  3. A log, 1–2 pages:
    • What matched the paper, and how closely
    • What you checked, and how
    • What the agent got wrong, or did without saying

We discuss what you found on 4/19.

Tips for the Replication

  • Work in a repo, and have the agent make one pull request per step. Review each one.
  • Before you look at the agent’s numbers, write down the paper’s.
  • Check the N first. Most replication gaps start with a different sample.
  • When it does not match, ask why before asking the agent to “fix” it. An agent told to match a number may tune things until it does.
  • It overlaps the midterm week. Start early, and keep the scope to one table.

Summary

  • You did not write it, so you cannot assume it is right.
  • One pull request per stage; the merge is the gate.
  • Read the file list, then every diff. Look for hard-coded numbers, dropped rows, changed filters, silent defaults, files outside the task, and outputs edited by hand.
  • Use a checklist, and write it down for the agent.
  • Let a fresh agent review first; you still decide.

References

Midterm Q&A

Midterm Q&A

Midterm: Monday 4/12, in class, no AI and no internet.

  • Covers the first half: R, Python, Git, and project organization. Mostly R.
  • The practice exam and its solutions are on the course site. [TBD: link to practice exam]

Questions?