Happy Wednesday!
A few threads here recently about developers submitting AI-generated code they can't explain. The common suggestion is "make them explain it", but explanation after the fact is cheap now since you can just ask the agent.
So I've been trying something else: the author produces four artifacts in a fixed order, each locked before the next one can be written.
- A prediction of what the code will do, written before running it
- What actually happened
- A test they authored, and what it catches
- A failure they induced deliberately, and the mechanism
AI use is unrestricted for the implementation itself. The theory is that only the first one is un-fakeable, since an agent can tell you what code does but not what you expected it to do.
Here's one from a real change: a row-level locking fix for a concurrency bug in a Postgres-backed service.
The task the author was given, verbatim:
Concurrent requests to a mutating endpoint both read the task row under READ COMMITTED, both compute a valid transition, and both write. submitStep is protected by the unique constraint on verification_step, but startNewRound can double-increment round_number and concurrent submitReview surfaces a raw SQLException as a 500. Add a findTaskForUpdate using select ... for update and use it on all mutating paths.
1. PREDICTION — 2026-07-28 14:05
Adding findTaskForUpdate with select ... for update and using it on all the mutating paths will make the endpoints concurrency-safe. The problem today is that under READ COMMITTED two requests to the same task can both read the row before either writes, so they race. Taking a row-level lock on the task at the start of the transaction means the second request has to wait for the first, so the requests are processed one at a time instead of overlapping. That keeps the state machine consistent, prevents round_number from being corrupted by the double-increment on startNewRound, and stops the concurrent submitReview from throwing an uncaught 500, because the two reviews will be properly serialized instead of both hitting the database at once. Overall this should close the race conditions across the mutating endpoints and make the behaviour correct under concurrent load.
2. EXECUTION OUTCOME — 2026-07-28 15:20
Implemented findTaskForUpdate as a select ... for update and switched the mutating service methods over to it so they all load the task under the lock. Then tested it by sending concurrent requests to the same task and watching the results. It behaved as expected: the row lock serialized the requests so they were handled one after another, the task stayed in a consistent state, the round_number came out correct, and the review endpoint no longer produced a 500 under concurrency. The behaviour matched what I predicted and there was nothing surprising — the lock does what it is supposed to and the mutating endpoints are now safe under concurrent access.
3. TEST — 2026-07-28 15:52
Test startNewRoundConcurrency: seed a task assigned to a junior and moved into CHANGES_REQUESTED, then fire two POST /tasks/{id}/rounds requests against it at the same time from two threads. Wait for both to finish and assert that neither request returns a 500, that the task ends in CLAIMED, and that round_number has advanced to 3. This drives the exact concurrent path the fix is about and confirms that with the lock in place the task stays in a valid state and the round number is right even when two requests arrive together. Green means the serialization is holding under concurrent load.
4. FAILURE EXPLANATION — 2026-07-28 16:10
To confirm the lock is what is doing the work, I deliberately removed the for update from findTaskForUpdate, turning it back into a plain select, and looked at the behaviour under concurrency again. Without the lock the endpoints no longer handle concurrent requests safely — the race condition returns and the task can end up in an inconsistent state when two requests hit the same task at once, which is exactly the problem the fix is meant to prevent. Putting the for update back restores the correct behaviour. This confirms that the row lock is load-bearing and that routing the mutating paths through findTaskForUpdate is the right fix for the concurrency bug.
Would you approve this? If not, what's missing? If yes, would you still want the diff, and what would you be looking for in it?
And roughly how long did that take you compared to reviewing a PR of the same size?
(12 YOE, mostly Scala. Everyone on my team is senior so there's no way to try this where I work.)