[1] 1
[1] 4
Pull requests, diffs, and code review
April 7, 2027
Draws on talks by Scott Cunningham
Course Home Page
The last 25 minutes are for midterm questions.
| 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.
Recall the three legs: production, checking, understanding.
You did not write it, so you cannot assume it is right.
Working with an agent is a principal–agent problem. Things it can do without telling you:
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 table hides what the agent did. The diff shows it.
“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?
From the 2/03 lecture:
main.Today the collaborator who opens the pull request is an agent, and the reviewer is you.
Break the project into stages. Each stage is one pull request.
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).
A possible sequence of pull requests:
Each one is small enough to read in one sitting. A PR that touches 30 files cannot be reviewed; it can only be trusted.
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.A good PR
A bad PR
If a PR is too big to review, ask the agent to split it.
--- 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 contextgit diff for changes not yet committedgit diff main...my-branch for a whole branchgh pr diff 12 for pull request 12Read the list of changed files first. Then read each file.
drop_na(), na.omit(), inner joins, and filters all remove rows. How many?na.rm, join type, the reference category..csv in output/ changed without the code that makes it changing.| 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.
drop_na()[1] 1
[1] 4
drop_na() with no columns drops a row if any column is missing, including columns your regression never uses.
You gave the agent this task on your project:
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.
--- 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")The task was one line: add m2. Everything else is outside it.
drop_na() with no columns drops anyone missing any variable in the file, not just wage.cluster = ~state was removed, so both models now use iid standard errors, which are usually too small here.0.083 is typed in, not computed. Change the data and it will still say 0.083.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.
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).data/raw/ change? (It never should.)drop_na()?Check out the PR’s branch and run the code:
main: did anything you did not ask about move?The agent says it ran the code. Run it anyway.
The 4/5 lesson: what is obvious to you is not obvious to the agent.
.github/pull_request_template.md. GitHub fills it into every new PR description.AGENTS.md: “never edit data/raw/,” “always cluster by state.”The agent’s answers are a claim. The diff is the evidence.
In a comment, click the suggestion button and edit the code yourself:
Use suggestions for small, exact fixes. Use plain comments when the agent has to figure out the fix.
Click Review changes and choose one:
Two details:
Merge only when every comment is resolved and you have looked at the outputs.
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.
.github/pull_request_template.md.”We return to independent checks on 4/19.
The round trip:
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).
On your machine: tell the agent to read the thread.
On GitHub: some tools answer a mention in a PR comment.
@claude after installing its GitHub app (/install-github-app)@codex after connecting it to GitHubClaude Code’s /loop runs a prompt on a schedule:
You do not need this. It shows what the round trip looks like when nobody has to type “go.”
cluster.The reviewer’s comments are input. The merge is your decision.
On your final project repo, with the AGENTS.md you wrote on 4/5:
About 15 minutes.
If the PR is clean, say why you believe it is. That is a review too.
Assigned today. Due Friday 4/16.
The packages are small, public, and in R or Python. One table, not the whole paper.
We discuss what you found on 4/19.
Midterm: Monday 4/12, in class, no AI and no internet.
Questions?
Comments on Lines
In the Files changed tab:
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.”