Aakash Howlader
All writing

Gauntlet: how to review AI-generated code before you merge it

Review AI-generated code with Gauntlet: reproduce a missed failure, repair the cause, and test the fix. Includes a runnable Node.js example.

A steel gauntlet pulls a chain anchored in a bench vise; a split link carries a yellow inspection tag.

TL;DR: Give the agent a clear contract, ask it to challenge the implementation, and make it prove any suspected bug. Keep the original code long enough to watch the new test fail. Then fix the cause and review the changed code again. Below is a small example you can run yourself, including the passing tests that missed the problem.

You ask your coding agent to implement something. It writes the code, adds tests, runs them and tells you everything works. Tests pass, awesome! Now comes the boring part - reading what it actually did before you merge it. 😄

I wrote about why I started using Gauntlet for adversarial review in the previous post. But explaining what I want from a review only gets us so far. What does the workflow look like when there is actual code to run, a test that passes and a behavior it never checked?

So, let’s do that. This is a deliberately flawed teaching example, prepared for this walkthrough. The tests and review steps below were actually run; the example is small enough that you can check the reasoning yourself too.

Get the example and install Gauntlet

Download the complete example. Extract it, then open a terminal in the gauntlet-review directory. It contains the original implementation, the repair, all three test files and a review record with the source hashes.

The example uses Node’s built-in test runner and has no npm dependencies. I ran it with Node.js 24.18.0. For the skill installer, use Node.js 22.20 or newer and npm, as required by the maintained Skills CLI.

From that directory, install Gauntlet for your coding agent:

npx skills add aakashH242/gauntlet --skill gauntlet --agent codex

For Claude Code, replace --agent codex with --agent claude-code. This installs into the current project; add --global if you prefer a user-wide installation. Choose one scope. I checked the Codex project install in a disposable directory while preparing this post.

Gauntlet is an agent skill. You run it through your coding agent; there is no separate gauntlet review command to start. In Codex, select it with $gauntlet; in Claude Code, use /gauntlet. The project README covers installation and invocation for both.

You can run every test below without installing the skill. The skill is what directs the review work; the test runner gives us something we can verify outside the agent’s answer.

First, decide what the code should do

Imagine two parts of an application asking for the same post at almost the same time. We don’t need two identical requests to the backend. If one is already running, the second caller can share it.

That’s all this helper should do:

  • Concurrent calls for the same key share one running load and receive its value or error.
  • Different keys run independently.
  • After a load finishes, successfully or otherwise, a later call starts a new load.

The loader takes a string key and returns a native Promise. We aren’t building a result cache, an automatic retry loop or a request cancellation system. Those would need their own requirements. Here, a retry means the caller asks again after a failure.

Writing this down matters. Otherwise, an agent could keep a completed result forever, call it caching and argue that the implementation works as intended. Well, whose intention? I want the contract clear before the review starts.

The implementation and its green tests

Here is initial.mjs:

export function createSingleFlight(load) {
  const inFlight = new Map();

  return function get(key) {
    if (!inFlight.has(key)) {
      const pending = load(key).then((value) => {
        inFlight.delete(key);
        return value;
      });
      inFlight.set(key, pending);
    }
    return inFlight.get(key);
  };
}

The map stores the Promise while the request is running. Another call with the same key gets that Promise. Once the request succeeds, the entry is removed.

The original tests check that the helper returns the loader’s value and that two concurrent callers cause only one load. Run them:

node --test --test-reporter=spec baseline.test.mjs

Result, with timings omitted:

✔ returns the loader result
✔ shares an in-flight request for the same key
ℹ tests 2
ℹ pass 2
ℹ fail 0

Both tests are useful. They check real requirements. But they only send the implementation down the successful path. The behavior after a rejection hasn’t been exercised at all.

This is where I want the agent to slow down. It has demonstrated two behaviors; there are more in the contract.

Ask it to challenge the code

For the first review, I kept the implementation unchanged and gave a separate reviewer the contract, original code and original tests. The reviewer did not get the author’s explanation of the bug.

You can ask your agent to do the same. In Codex, for example:

Use $gauntlet to review initial.mjs against the Contract section
of README.md. Read baseline.test.mjs too.

Focus on shared requests, failure recovery and independent keys.
Do not modify the implementation. You may write a reproduction
in a temporary directory. For each suspected defect, show the
requirement it violates and a runnable counterexample.

Use a focused review budget: at most two rounds and one fresh
re-attack after any repair. Do not install anything or deploy.
Separate confirmed findings from unresolved concerns.

The review found that a failed request leaves its rejected Promise in the map. Cleanup only happens inside .then’s success handler. A later call sees the entry and gets the old rejection, even if the backend would now succeed.

The sequence is straightforward: the first call fails, its error is observed, and a later call asks for the same key. The loader runs once when it should run twice.

So a temporary failure can make that key fail for the remaining lifetime of this helper instance. In an application, fixing the backend wouldn’t be enough to unblock those callers. The helper is still holding on to the earlier error.

That gives us a finding we can check, rather than just an opinion about the code.

Make the missed behavior fail in a test

Before changing the implementation, I added regression.test.mjs. It imports the original by default:

import { test } from 'node:test';
import assert from 'node:assert/strict';
const { createSingleFlight } = await import(
  process.env.TARGET ?? './initial.mjs'
);

test('a later call can recover after a rejected load', async () => {
  let calls = 0;
  const get = createSingleFlight(async () => {
    calls += 1;
    if (calls === 1) throw new Error('temporary failure');
    return 'recovered';
  });

  await assert.rejects(get('post-42'), { message: 'temporary failure' });
  assert.equal(await get('post-42'), 'recovered');
  assert.equal(calls, 2);
});

There is no live API, timeout or sleep involved. The loader deliberately fails once and would succeed on its next invocation. The expected behavior comes from the contract: after the first request settles, a later call must start a new one.

node --test --test-reporter=spec regression.test.mjs

Against the original, this exits with status 1. The shortened output is:

✖ a later call can recover after a rejected load
ℹ tests 1
ℹ pass 0
ℹ fail 1
Error: temporary failure

The first rejection is expected and checked by assert.rejects. It’s the second call that breaks the test: it receives the original error instead of recovered.

I want to see this failure before accepting the fix. Otherwise, we might add a test that passes on both versions and congratulate ourselves without checking whether it distinguishes the broken behavior.

Fix the lifetime of the entry

The map entry should exist only while the load is in flight. Fulfillment and rejection both end that lifetime, so cleanup belongs on both paths.

If you want the agent to make the repair, authorize that explicitly after checking the reproduction:

Fix the confirmed settlement-cleanup defect. Preserve initial.mjs
and put the repair in repaired.mjs. Keep the original tests and
the failing regression. Preserve the contract, including errors
reaching callers. Then use $gauntlet to review the repair again.

The repair in repaired.mjs changes the Promise chain to:

const pending = load(key).finally(() => inFlight.delete(key));
inFlight.set(key, pending);

The surrounding function stays the same. We return the Promise produced by finally, which lets callers receive the original value or rejection after cleanup. That is the behavior of Promise.prototype.finally when the cleanup callback completes normally.

An easy mistake here would be to catch the error and return null. The test might stop throwing, but the request still failed and callers need to know that. We also don’t need a retry loop inside this helper. We need the next caller to be able to make a new request.

Run the original tests and the regression against the repair:

TARGET=./repaired.mjs node --test --test-reporter=spec baseline.test.mjs regression.test.mjs

This passes 3 tests. TARGET only selects which file the tests import; it doesn’t overwrite either implementation. These commands use a POSIX shell, such as Bash or Zsh.

Review what changed, again

At this point, the agent has fixed the defect we already know about. I still want it to look for a different way the implementation could fail.

For this run, a second reviewer received the contract and repaired implementation before seeing the earlier finding or tests. It checked the behavior from those requirements, using controlled Promise settlement instead of timing guesses. These were separate reviewer contexts using the same model, so they can still share blind spots.

A useful follow-up request is:

Use $gauntlet to re-attack repaired.mjs against the Contract
section of README.md. Keep the implementation unchanged.

Derive checks from the contract before reading the previous
review. Challenge shared failures, different-key isolation,
and calls made after success or rejection. Check that errors
still reach callers. Report exactly what ran, any confirmed
defects, and what remains unverified.

Use a fresh reviewer when available. Otherwise, label this
as a separate solo review pass.

The reviewer added five checks: sharing successful values, sharing failures without swallowing their reasons, different keys settling out of order, fresh loads from success and failure handlers, and already-settled loader Promises. No further confirmed defect was found within that scope. I retained those assertions in reattack.test.mjs, making its import portable so you can run it with the other tests:

TARGET=./repaired.mjs node --test --test-reporter=spec baseline.test.mjs regression.test.mjs reattack.test.mjs

The combined run passes 8 tests. The sequence we actually ran looks like this:

Run Implementation Result
Original two tests Original 2 pass
New recovery regression Original 1 fails with the earlier error
Original tests and regression Repaired 3 pass
Those tests plus the fresh re-attack Repaired 8 pass

You can inspect the full tests and review.md in the download. The recorded source hashes identify which implementation was checked.

This is also why I keep a small record of the review. It tells me what was checked, what failed and which code the evidence applies to. Gauntlet can use a Markdown ledger for this; its optional Python tracker isn’t required to follow this exercise.

What I want before merging

For a change like this, I want to read the contract, inspect the diff, run the tests and understand why the repair closes the failure path. If the agent reports another suspected issue, I want to see the evidence or have it left clearly unresolved.

On a real pull request, I’d also follow the callers. Does the application create one helper per request or keep it for the process lifetime? Can keys cross user boundaries? Who owns timeouts? Those answers change the impact and the review scope. Our small fixture doesn’t establish any of them for your application.

The result here is bounded to the helper and the cases exercised. We didn’t test a live HTTP integration, cancellation, synchronous or reentrant loaders, or every possible schedule. A clean review within that scope still leaves me responsible for what I merge.

If you try Gauntlet on your own changes, keep the failing reproduction when it finds something useful. And if it misses a bug, that example is useful too. I’d much rather have a small case someone else can run than a confident answer with nothing behind it. 😄

Keep reading

All writing

Software. Football. Heavy metal.

Aakash HowladerSame person. Different playgrounds.