A caller sets maxRetries: 0. After a network error, the client sends the request twice more. Give a coding agent the requirement “Zero disables retries. Callers that omit the limit still get up to two retries.” That establishes what a fix must demonstrate while leaving the agent to locate the implementation.

From the requirement to a file

The model receives the task and descriptions of the tools available to it. It might request a search for rg -n 'maxRetries'. The harness, the program running the agent session, executes the permitted command in the working directory and returns the matching lines. The model now has a reason to read a particular function. A failing test can change its next action in much the same way. How Claude Code works

Different harnesses give this loop different places to run. A developer can embed Pi through its SDK or delegate a task to a remote Codex environment. In either case, a reviewer needs to know which checkout the agent used and which checks actually ran there.

Reproducing the extra attempts

This is the complete delivery.mjs module for the example. A successful call returns immediately. After a failure, the function compares the retries already used with the configured limit.

export async function deliver(send, { maxRetries } = {}) {
  const limit = maxRetries || 2;
  for (let used = 0; ; used++) {
    try {
      return await send();
    } catch (error) {
      if (used >= limit) throw error;
    }
  }
}

In delivery.test.mjs, a stand-in for the network operation counts calls and always throws. Its call count makes the behavior observable. The test covers zero, an omitted limit, and one allowed retry.

import assert from 'node:assert/strict';
import test from 'node:test';
import { deliver } from './delivery.mjs';

for (const [options, expected] of [
  [{}, 3],
  [{ maxRetries: 0 }, 1],
  [{ maxRetries: 1 }, 2],
]) {
  test(JSON.stringify(options), async () => {
    let calls = 0;
    const send = async () => {
      calls++;
      throw new Error('offline');
    };
    await assert.rejects(deliver(send, options), /offline/);
    assert.equal(calls, expected);
  });
}

On the original implementation, node --test delivery.test.mjs finds one failure. With a limit of zero the counter reaches 3, where the contract calls for 1. The other two cases pass. They protect against a tempting fix that disables retries for every caller.

Why the patch fits on one line

Logical OR in maxRetries || 2 treats zero as falsy and selects two. Nullish coalescing selects the default only for undefined or null, so an explicit zero survives. ECMAScript specification

-  const limit = maxRetries || 2;
+  const limit = maxRetries ?? 2;

After that change, the same command passes all three cases. With a consistently failing operation, an omitted limit produces three calls, zero produces one, and one retry produces two. Both files above are sufficient to reproduce the result.

One question still belongs in code review. How does the public API handle an explicit null? If the contract requires the client to reject it, that behavior belongs in input validation. The three passing cases establish the retry counts for the configurations tested. A rule for null needs a test of its own.

Six coding agents and where each fits