Review a change an agent made for a usage-summary endpoint against the request it was given, prove each defect, fix what is wrong and leave what is right.
Outcome: Decide from evidence what to accept and what to reject in a change you did not write.
Note
Reading as a visitor
Everything in this lesson is free to read. Sign in and enrol to answer the questions and record your progress.
Review a diff against the request it was written for, not against its author's description.
Trace every change in a diff to a sentence of the request, and question the ones with none.
Recognise values from a request concatenated into SQL, and replace them with validation and parameters.
Reproduce each suspected defect with a request or a test before reporting or fixing it.
Write review findings that say what is wrong, where, how you know, and what you checked and found right.
Prerequisites
Comfortable reading TypeScript and SQL, including WHERE clauses and aggregates.
Can read a unified diff.
Can send HTTP requests with curl, including a query string and an Authorization header.
Concepts
What a review of an agent's change is for
When an agent opens a pull request you get three things: a diff, a set of tests and a description. Only the diff is a fact. The tests were written by the same author as the code, usually after it, and the description is the author's account of its own work. An agent's description is fluent and confident whether or not the work is right, and it can state things that never happened: tests that were not run, behaviour that was not preserved.
So the review does not ask "does the description sound right?" It asks "does this diff do what the request says, and nothing else?", and it answers with evidence you produced yourself.
Review against the request
Read the request before the diff and before the description. Write down each condition it states, as a list you can tick off:
who may call it and what happens when they may not;
which inputs are allowed, and the answer to each kind that is not;
exactly which data counts: whose, in which state, between which bounds;
the response, field by field, including the empty case;
what must not change.
Then read the code against that list. Most logic defects in a generated change are a condition the request states and the code leaves out. They are invisible if you read the code first, because code that omits a condition reads as naturally as code that includes it. A query with no status filter looks complete until you hold it against the sentence "confirmed bookings only".
Boundaries deserve a separate pass. "From A up to but not including B" becomes >= and <. Any other pair of operators is a defect that only shows for data exactly on a boundary, which is exactly the data hand-written test fixtures avoid.
Every hunk needs a reason
Go through the diff one hunk at a time and name the sentence of the request that needs it. Three outcomes are possible:
Worked example
This walk-through reviews a different, smaller change with the method you will use in the exercise. It is an illustration only: the change is not in your workspace, and it is not assessed.
The request
GET /bookings should accept an optional limit query parameter, an integer from 1 to 100, and return at most that many bookings. Without it, the endpoint behaves as today. The order, soonest first, does not change. Any other value is a 400 VALIDATION_FAILED.
The agent's description
Adds limit to GET /bookings with schema validation. Also made the ordering deterministic. Added a test. All tests pass.
1. List what must be true
From the request, before reading any code:
limit is optional; without it, the response is as today.
limit is an integer from 1 to 100; 0, 101, abc and 1.5 are .
Concept questions
Sign in and enrol to answer and save your progress.
Exercise
Your task
An agent was given the request in docs/usage-summary-request.md and opened a pull request for it. Its change is already applied to your workspace. You are the reviewer.
File
What it is
docs/usage-summary-request.md
The request the agent was given. Treat it as the specification.
docs/pull-request.md
The agent's own description of its change.
docs/pull-request.diff
The complete change, as a diff against the service before it.
The agent says the change is ready to merge. Some of it is right and some of it is not. Find out which, prove each defect, fix it, leave the correct parts alone, and write up your review in REVIEW.md.
Steps
Read the request first. List each condition it states: who may call the endpoint, which values are allowed, exactly which bookings are counted, the response, and what must not change.
Reflection
Recorded for you to look back on. It is not graded and does not by itself show understanding.
Prompt: Which finding did you reach by reading, and which only by running something? Describe one thing in the change that looked wrong and turned out to be right, how you checked it, and what in the agent's description of its own change you would no longer take on trust.
Needed by the implementation, such as registering a new route. Fine, if it does only that.
Needed by neither. This is the hunk to study.
Agents make out-of-scope changes for local reasons: a test would not pass, a type did not match, a limit was in the way. The change is small, it makes the run green, and it does not appear in the description because from the agent's point of view it was a detail. From yours it is a change to behaviour nobody asked for. Ask what the change needed it for. Often the honest fix is on the other side: change the test fixture, not the rule.
Check deletions and edits in existing tests the same way. A weakened assertion or a removed test is a behaviour change that hides its own evidence.
Values from the caller
Everything in a request is chosen by the caller: path parameters, query strings, headers, bodies. Follow each value from where it enters the handler to where it is used. Two questions cover most of the risk:
Is it validated before use? In this service a route schema refuses anything of the wrong type or format with 400 VALIDATION_FAILED before the handler runs. A handler that reads request.query with no schema accepts any string.
How does it reach the database? Every existing query passes values as parameters ($1, $2). A value placed into the SQL text with a template string becomes part of the statement. resource_id=3 OR 1=1 then changes which rows match, and because a query sent without parameters may contain several statements, a value can end the query and start another.
An inconsistency with the surrounding code is the tell. When every other query in src/ uses parameters and the new one builds a string, the reason given ("easier to add an optional filter") is not a reason to accept it.
Prove it before you report it
A suspicion is not a finding. For each one, build the smallest input that would show the defect and run it: a curl command, or better, a test, because a test stays. This does two things. It removes false alarms, which are common when you review unfamiliar code. And it turns "I think the boundary is off" into "a booking starting exactly at to is counted: here is the request and the response".
Apply the same standard to things that look wrong but may be right. An unusual cast, a route that seems to collide with another, a query that looks too clever: check before changing. Rewriting correct code because it is unfamiliar adds risk and teaches the next reviewer nothing.
Using an agent as a second reviewer helps if you direct it. Ask narrow questions, such as "which values from the request reach SQL without being parameters?" or "which hunks change files the description does not mention?", and require a reproduction for every answer. An agent asked to "review this" tends to return style remarks and plausible findings in equal measure.
Write findings someone can act on
A finding says what is wrong, where, how you know and how much it matters:
Where: the file, and the line or function.
What and evidence: the behaviour you observed and the sentence of the request it breaks.
Severity: blocking (must be fixed before merging) or non-blocking (worth fixing, does not stop the merge).
End with a verdict, and with a list of what you checked and found correct. That list is not politeness. It tells the author and the next reviewer which parts have been examined, and it is the difference between "I found four problems" and "I found four problems and looked for more".
400 VALIDATION_FAILED
With limit=n, at most n bookings come back, and they are the n soonest.
The order does not change.
2. Read the diff hunk by hunk
- app.get("/bookings", async (request) => {
+ app.get<{ Querystring: { limit?: number } }>(
+ "/bookings",
+ { schema: { querystring: { type: "object", properties: { limit: { type: "integer", minimum: 1 } } } } },
+ async (request) => {
const user = await requireUser(db, request);
const { rows } = await db.query<BookingRow & { resource_name: string }>(
`SELECT b.*, r.name AS resource_name
FROM bookings b
JOIN resources r ON r.id = b.resource_id
WHERE b.user_id = $1
- ORDER BY b.starts_at, b.id`,
- [user.id],
+ ORDER BY b.id
+ LIMIT $2`,
+ [user.id, request.query.limit ?? null],
);
Hunk
Needed by
Verdict
Route schema with limit as an integer, minimum: 1
Condition 2
Incomplete: there is no maximum: 100
LIMIT $2 with limit ?? null
Conditions 1 and 3
Looks odd, check it
ORDER BY b.id replacing ORDER BY b.starts_at, b.id
Nothing
Out of scope, and contradicts condition 4
The description's "made the ordering deterministic" is the third hunk. The old ordering was already deterministic, because b.id breaks ties. The new one sorts by creation order, which is a different order.
It asserts how many bookings come back, not which. The fixtures are created in time order, so sorting by id and sorting by start time give the same result, and the ordering change cannot fail this test.
It fails: the response holds the booking that was created first, not the one that starts first. Confirmed, and it affects the unlimited list too.
LIMIT $2 with null. This is the part that looked wrong. In PostgreSQL, LIMIT NULL means no limit, so GET /bookings without the parameter returns everything, as condition 1 requires. A request without limit against a user with three bookings returns three. It is correct, and the value is passed as a parameter, as every other query in the service does. Leave it alone.
4. Write the review
## Verdict
Request changes.
## Findings
- F1 (blocking) `src/routes/bookings.ts`: the list is now ordered by id instead of by start time. The request
says the order does not change. A booking created first but starting later is returned first; the new test in
`test/bookings.test.ts` shows it. This also changes `GET /bookings` without a limit.
- F2 (blocking) `src/routes/bookings.ts`: the schema has no `maximum`, so `limit=101` returns 200. The request
says 1 to 100.
- F3 (non-blocking) `test/bookings.test.ts`: the added test checks only the number of results, with fixtures
created in time order, so it passes with either ordering.
## Checked and correct
- `LIMIT $2` with `null` when no limit is given: PostgreSQL treats it as no limit, and the full list is returned.
- `limit=0`, `limit=abc` and `limit=1.5` are refused with 400 VALIDATION_FAILED.
- The value reaches the query as a parameter.
5. Fix, and prove the fixes
Restore ORDER BY b.starts_at, b.id, add maximum: 100, keep the new ordering test and add one for limit=101. Run npm run verify, then repeat the curl request and see 400.
Every finding came from holding the diff against the request. None came from the description.
Read the diff, one hunk at a time. For each hunk, name the sentence of the request that needs it. Note every hunk where you cannot, and every place where the code leaves out a condition from your list.
Only then read the description, and mark each claim in it as shown, not shown or contradicted by what you found.
dev-token-ada, dev-token-grace and dev-token-edsger are seeded. Try the endpoint as different users and with values the request does not allow. For cases the seed data lacks, such as a cancelled booking or a booking exactly on a boundary, write a test: useTestApp() in test/helpers.ts also returns the database, so a test can set a booking's status directly. Run npm run db:reset again after any experiment that may have changed the data.
Check what looks wrong but may be right. Verify it with a request before you change it.
Fix what you proved, in the smallest way that makes the code match the request. Keep the tests that reproduce each defect, and fix any existing fixture that only worked because of a defect.
Write REVIEW.md at the root of the repository, in the format below.
Verify. Run npm run verify, then repeat your requests from step 4.
The format of REVIEW.md
# Review: usage summary endpoint
## Verdict
Request changes.
## Findings
- F1 (blocking) `src/routes/summary.ts`: what is wrong, the request or test that shows it, and the sentence
of the request it breaks.
- F2 (non-blocking) `test/summary.test.ts`: …
## Checked and correct
- What you verified and found right, and how.
Three level-2 headings: ## Verdict, ## Findings, ## Checked and correct.
The verdict says either "Approve" or "Request changes".
Each finding is a list item that starts with F1, F2, …, then (blocking) or (non-blocking), then a file of this repository in backticks. Write at least three.
"Checked and correct" lists at least one thing.
No placeholders such as TODO.
Constraints
Do not change package.json or package-lock.json, and do not add dependencies. A submission whose lockfile differs is not assessed.
Do not edit db/migrations/001_init.sql. No schema change is needed.
Keep the endpoint's path, parameters, response shape and error codes as the request describes them.
Leave docs/ as it is: it is the record of what you reviewed.
How Check work assesses this
Check work takes a snapshot of your workspace's source files and assesses it outside the lab. Your service is started with node src/server.ts against a fresh database with its own users and bookings, some of them inserted directly in states and at times the API alone would not produce. The checks call the endpoint as several users, with allowed values and with values the request does not allow, and afterwards look at the database to see that nothing else happened. They also check that behaviour outside the feature is as README.md documents it, and that the parts of the change that were right still work.
REVIEW.md is checked for its shape only: the headings, a verdict, at least three numbered findings that each name a file, and something under "Checked and correct". Whether your findings are right is not judged, and the result page says so.
Not assessed: how your code refuses bad values, the tests you write, code style. Your reflection is recorded but not graded.
Tools
You can do this exercise with Claude Code, OpenCode, Codex CLI or OpenHands in the lab. If you use an agent as a second reviewer, give it the request and the diff, ask narrow questions, such as which values from the request reach SQL and which hunks the description does not mention, and ask for a request or test that proves each answer before you accept it.
Acceptance criteria
AC1The summary counts exactly the bookings the request says it should.Verified behaviour
AC2The summary's period is applied as the request defines it.Verified behaviour
AC3Query values the request does not allow are refused with 400 VALIDATION_FAILED and have no other effect.Verified behaviour
AC4Behaviour outside the requested feature is as it was before the change.Verified behaviour
AC5The parts of the change that were right still work as the request describes.Verified behaviour
AC6REVIEW.md gives a verdict, numbered findings with their files, and what was checked and found correct.Structure check
Verified behaviour is checked by running your submitted work from outside the lab. A structure check confirms that something is present and in the expected format; it does not prove it is correct.
Not assessed
Whether your findings in REVIEW.md are correct or complete: the check sees its shape only.
How the code refuses bad values. The checks send such values and observe the outcome; they do not read your SQL.
The tests you add or change.
Code structure and readability.
Your reflection: it is recorded, not graded.
Hints
Try the exercise first. Each hint gives away a little more than the one before.
Check your work
Submit your work from the lab's Check work panel. Hidden checks run your submitted code from outside the lab; your own test output is never taken as a result. You can revise and resubmit.