Learning center

How to fix a code review finding with a coding agent

A GitHub CLI maintainer asked Copilot to fix a diagnostic that disappeared when someone redirected command output. Follow the review from that request to the approved commit, then use the same handoff on your own pull request.

Start with the behavior the reviewer can see#

When gh auth status failed to reach GitHub, its output could send someone looking for a bad token even though the underlying error was a rate limit or network failure. Copilot's first patch printed the recorded error when standard error was attached to a terminal. Someone running the command interactively would see the reason. Someone saving the same output to a log would lose it. Original GitHub CLI patch

The tests on that patch already exercised redirected output. Their expected output omitted the diagnostic in that case. Asking an agent to make the tests pass would have given it no reason to change a line.

Give the agent an observable requirement#

The maintainer addressed Copilot in the review thread. They asked the agent to put the diagnostic in the method that formats an account entry and give it the same treatment whether the output goes to a terminal or a pipe. The comment sat on the code that made the decision, so the agent had the exact revision and location. Maintainer's handoff to Copilot

A handoff for the same bug could read like this.

Run the error path for gh auth status with standard error redirected. Compare the diagnostic with the terminal output. Put the underlying error in the shared account-entry formatter. Show the test that requires both destinations to receive the reason for the failure.

For a different finding, replace the command, the triggering condition, and the two results to compare. An agent can choose its edit once it knows what an observer has to see. If the finding describes behavior in production, include the evidence for that condition as well.

Read the change between the two reviews#

Copilot moved the formatting into authEntry.String and removed the terminal check from its caller. The test now expects the diagnostic on standard error for all four combinations of terminal and redirected standard output and standard error. It also checks that standard output stays empty on those failures. The cases include a rate limit, a server error and a network error. Fix and test changes

The agent replied with the commit it had changed. The maintainer who requested changes then approved that same commit. Agent's reply ยท Maintainer's second review

When an agent returns a fix to you, read the changed assertion first. Here, a regression that restored the terminal check would lose the diagnostic in a pipe and fail the assertion. If someone puts the original bug back tomorrow, which assertion in your patch will catch it?

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading