Build & fix · Recorded September 28, 2026

One bug.
A patch you can inspect.

We gave Grok Build a broken order-total function and explicit acceptance criteria. It returned a JavaScript module, which we checked independently.

Actual run · Isolated sample code

The starting point

The function below adds values without checking payment status or converting strings. It can concatenate text and count refunded orders.

// Bug: adding strings concatenates, refunded orders are counted,
// and rounding uses binary floating point without a currency boundary.
export function paidTotal(orders) {
  return orders.reduce((sum, order) => sum + order.amount, 0);
}

Download the input · Read the exact prompt

What we asked for

Count only paid rows. Accept non-negative numbers or decimal strings with at most two decimals. Sum in integer cents. Reject malformed values and unsafe totals. Return zero for an empty list.

The actual output

Grok returned a parser and a replacement function. The original output is preserved below; we did not rewrite it to make the test pass.

Inspect the full generated patch
// Parse one money amount into integer cents, or throw.
function amountToCents(amount) {
  let text;

  if (typeof amount === "number") {
    // NaN, Infinity, and negatives are invalid amounts.
    if (!Number.isFinite(amount) || amount < 0) {
      throw new TypeError("invalid amount");
    }
    // The amount itself must stay inside the safe integer range.
    if (amount > Number.MAX_SAFE_INTEGER) {
      throw new RangeError("amount overflow");
    }
    text = amount.toString();
    // Exponent form means more than two decimal places.
    if (/[eE]/.test(text)) {
      throw new TypeError("invalid amount");
    }
  } else if (typeof amount === "string") {
    // Plain non-negative decimals only; blank and other text are rejected.
    if (!/^\d+(?:\.\d+)?$/.test(amount)) {
      throw new TypeError("invalid amount");
    }
    text = amount;
  } else {
    throw new TypeError("invalid amount");
  }

  const dot = text.indexOf(".");
  const whole = dot === -1 ? text : text.slice(0, dot);
  const frac = dot === -1 ? "" : text.slice(dot + 1);
  if (frac.length > 2) {
    throw new TypeError("invalid amount");
  }

  const digits = whole.replace(/^0+/, "") || "0";
  if (digits.length > 16) {
    throw new RangeError("amount overflow");
  }
  const dollars = Number(digits);
  if (!Number.isSafeInteger(dollars)) {
    throw new RangeError("amount overflow");
  }

  const centsPart = Number(frac.padEnd(2, "0"));
  // This row's cent value must also be a safe integer.
  if (dollars > Math.floor((Number.MAX_SAFE_INTEGER - centsPart) / 100)) {
    throw new RangeError("amount overflow");
  }
  return dollars * 100 + centsPart;
}

// Sum paid orders in cents and return a currency number.
export function paidTotal(orders) {
  if (!Array.isArray(orders)) {
    throw new TypeError("orders must be an array");
  }

  let totalCents = 0;
  for (const order of orders) {
    // Skip non-paid rows and do not validate their amounts.
    if (!order || order.status !== "paid") {
      continue;
    }

    const cents = amountToCents(order.amount);
    if (totalCents > Number.MAX_SAFE_INTEGER - cents) {
      throw new RangeError("sum overflow");
    }
    totalCents += cents;
  }

  return totalCents / 100;
}

Download the generated JavaScript

What passed

24 independently written checks passed. They cover decimal-string conversion, refunded rows, 0.1 + 0.2, empty input, invalid paid amounts, non-array inputs and individual or aggregate safe-integer overflow.

node verify.mjs
24 checks passed. Original model output unchanged.

Download the verification script · Read the captured results

What this does not prove

This is a small, self-contained coding task, not a production financial implementation or an evaluation of Grok across repositories. The criteria use plain decimal strings, not localized money formats. The returned numeric total still has JavaScript number representation limits; payment systems should preserve an exact monetary representation throughout.

The Grok CLI used its configured grok-4.7 model. Its run metadata reported an estimated model cost of $0.0726; this is not a confirmed billing charge and does not include the surrounding development work.

Human work and setup

We prepared the bug, specified the acceptance criteria and wrote the independent checks. The site-building assistant ran the checks and reviewed the patch; a separate human reviewer did not certify it. The model did not deploy code or access a production system. To repeat the workflow, install the Grok CLI, authenticate, provide an isolated problem and review the resulting diff and tests.

Grok official website ↗ · Compare coding agents →