Plugin eval report

brooks-lint v1.5.0

Plugin effect: ↓ -20.0 pts vs baseline — improved 0 · flat 0 · regressed 1 of 1 case.

. Claude Code v2.1.270 2026-09-14 13:02 UTC 3m 10s $0.53 2 runs 2 in flight judge opus threshold 100% filtered: --case 04-tradeoff-composition-root
Suite score · with plugin60%mean of per-case scores
Ablation Δ↓ -20.0score points vs baseline, 1 of 1 case
Baseline score80%without the plugin
Cases10 of 1 ≥ 100% threshold
Perfect runs0%runs where every grader passed
How to read this report

04-tradeoff-composition-root

evals/04-tradeoff-composition-root ↓ -20.0 pts with plugin 60%
Results
With plugin 60% 0% of runs perfect
Run 1 60% 10 turns · $0.38 · 13:02:24 UTC
✓ pass health-score-line ×0.5

matched Health Score\W*\d{1,3}\s*/\s*100

✓ pass no-composition-root-false-positive

judge votes: PASS PASS PASS

Judge votes✓ ✓ ✓
Evidence (what the judge was shown; for an image, a description of what was sent)
Reviewed the three files as the startup wiring + first use case for the orders service.

# Brooks-Lint Review

**Mode:** PR Review
**Scope:** `src/main.ts`, `src/orders/ports.ts`, `src/orders/placeOrder.ts` (pasted; `src/adapters/**` excluded per your note)
**Health Score:** 68/100

Solid hexagonal wiring with a genuinely well-thought-out idempotency story, but one gap turns a rare failure into a real money-without-a-record bug.

---

## Findings

### 🔴 Critical

**Domain Model Distortion — `"pending"` hides a charged-but-unrecorded state**
Symptom: In `PlaceOrder.execute`, `payments.charge(...)` runs, and only afterward is `orders.save(settled)` called. If the process crashes, throws, or the DB call fails between those two lines, Stripe has already moved money but the order row is left at `status: "pending"` with no record a charge was even attempted.
Source: Evans — Domain-Driven Design, Aggregate invariant ownership (the `Order.status` field is meant to be the single source of truth for "was this charged," but the Stripe charge and the DB write aren't updated atomically, so the model can silently disagree with reality).
Consequence: A customer can be charged with no matching "paid" order until (and unless) the exact same `(customerId, requestId)` request is retried by the client. If the client already surfaced an error and gives up, the money is gone and the order is invisible — recovering it requires a Stripe-to-DB reconciliation job, and none exists here.
Remedy: Persist an intermediate `"charging"` status before calling `payments.charge` so a stuck order is distinguishable from one never attempted, or move the charge+save into a retryable/outbox step so save failures self-heal instead of depending entirely on client-side retry.

### 🟡 Warning

**Cognitive Overload — shutdown doesn't wait for the server to actually close**
Symptom: In `main.ts`, `shutdown` calls `server.close()` with no callback or await, then immediately `await pool.end()`. `server.close()` only stops accepting *new* connections — it doesn't wait for in-flight requests to finish.
Source: McConnell — Code Complete, Ch. 8 (Defensive Programming / explicit completion paths).
Consequence: Every deploy or restart risks yanking the Postgres pool out from under requests mid-flight, turning routine rolling restarts into a source of `PlaceOrder` failures that look like payment problems but are actually infra.
Remedy: `await new Promise<void>((resolve) => server.close(() => resolve()))` before ending the pool.

**Primitive Obsession — payment failure reason is a raw string, and it's discarded**
Symptom: `PaymentGateway.charge` returns `{ ok: false; reason: string }`; in `placeOrder.ts` that `reason` is read only to compute `status: "failed"` — the string itself is never stored or logged.
Source: Fowler — Refactoring, Primitive Obsession.
Consequence: A transient failure (network blip, Stripe outage) and a hard decline (insufficient funds, fraud block) become identical `"failed"` orders. This blocks any future "auto-retry transient failures" logic and forces support to dig through the Stripe dashboard for every failed order.
Remedy: Model failures as a small discriminated union (e.g., `reason: "card_declined" | "processor_error" | ...`) and persist or log it instead of dropping it.

**Coverage Illusion — no tests included for the new use case**
Symptom: `PlaceOrder.execute` is new, non-trivial behavior (idempotent charge orchestration, three-way status transition) with no test file in the diff.
Source: Feathers — Working Effectively with Legacy Code, Ch. 1.
Consequence: The idempotency guarantee explained in the code comment — the most important property of this class — is untested and easy to silently break in a later edit.
Remedy: Add tests for: first-time success, first-time failure, retry of a still-pending order (charges again), retry of a settled order (returns as-is, `charge` not called again).

### 🟢 Suggestion

**Cognitive Overload — `currency` has no guard clause**
Symptom: `execute` validates `amountCents` but passes `cmd.currency` straight through unchecked.
Source: McConnell — Code Complete, Ch. 8 (Defensive Programming).
Consequence: A malformed/unsupported currency reaches Stripe as a generic API error, surfacing as an opaque `"failed"` order instead of a clear validation error.
Remedy: Validate `currency` against your supported set (or at least ISO-4217 shape) alongside the existing `amountCents` guard.

**Dependency Disorder — idempotency safety is an unenforced contract with the adapter**
Symptom: The comment asserts retries are safe because the order id is reused as "the idempotency key," but that only holds if `StripePaymentGateway` actually forwards `idempotencyKey` as Stripe's `Idempotency-Key` option — nothing here enforces or tests that.
Source: Ousterhout — A Philosophy of Software Design, Ch. 5 (Information Leakage: the "no double-charge" invariant is split between the use case and an adapter not visible here).
Consequence: If the adapter is ever refactored and drops the idempotency option, double-charge protection disappears silently with no compile- or test-time signal.
Remedy: Add a contract test against the real `StripePaymentGateway` asserting the idempotency key is forwarded, so this invariant is guarded somewhere.

**Recommended fix order:** 1 → 3 (paired findings) → 2 → 4 → 5 → 6.

---

## Summary

The idempotency design in `PlaceOrder` (`findOrCreate` + reusing the order id as the charge key) is genuinely well thought through, and the comment explaining it is a good sign. The one thing worth fixing before this touches real money is the charge/save atomicity gap (#1); tighten shutdown sequencing and add retry-path tests next. The rest is minor hardening.

Would you like to triage the Warning/Suggestion findings (accept/dismiss/defer/skip)?
✗ fail overall-healthy

judge votes: FAIL FAIL FAIL

Judge votes✗ ✗ ✗
Evidence (what the judge was shown; for an image, a description of what was sent)
Reviewed the three files as the startup wiring + first use case for the orders service.

# Brooks-Lint Review

**Mode:** PR Review
**Scope:** `src/main.ts`, `src/orders/ports.ts`, `src/orders/placeOrder.ts` (pasted; `src/adapters/**` excluded per your note)
**Health Score:** 68/100

Solid hexagonal wiring with a genuinely well-thought-out idempotency story, but one gap turns a rare failure into a real money-without-a-record bug.

---

## Findings

### 🔴 Critical

**Domain Model Distortion — `"pending"` hides a charged-but-unrecorded state**
Symptom: In `PlaceOrder.execute`, `payments.charge(...)` runs, and only afterward is `orders.save(settled)` called. If the process crashes, throws, or the DB call fails between those two lines, Stripe has already moved money but the order row is left at `status: "pending"` with no record a charge was even attempted.
Source: Evans — Domain-Driven Design, Aggregate invariant ownership (the `Order.status` field is meant to be the single source of truth for "was this charged," but the Stripe charge and the DB write aren't updated atomically, so the model can silently disagree with reality).
Consequence: A customer can be charged with no matching "paid" order until (and unless) the exact same `(customerId, requestId)` request is retried by the client. If the client already surfaced an error and gives up, the money is gone and the order is invisible — recovering it requires a Stripe-to-DB reconciliation job, and none exists here.
Remedy: Persist an intermediate `"charging"` status before calling `payments.charge` so a stuck order is distinguishable from one never attempted, or move the charge+save into a retryable/outbox step so save failures self-heal instead of depending entirely on client-side retry.

### 🟡 Warning

**Cognitive Overload — shutdown doesn't wait for the server to actually close**
Symptom: In `main.ts`, `shutdown` calls `server.close()` with no callback or await, then immediately `await pool.end()`. `server.close()` only stops accepting *new* connections — it doesn't wait for in-flight requests to finish.
Source: McConnell — Code Complete, Ch. 8 (Defensive Programming / explicit completion paths).
Consequence: Every deploy or restart risks yanking the Postgres pool out from under requests mid-flight, turning routine rolling restarts into a source of `PlaceOrder` failures that look like payment problems but are actually infra.
Remedy: `await new Promise<void>((resolve) => server.close(() => resolve()))` before ending the pool.

**Primitive Obsession — payment failure reason is a raw string, and it's discarded**
Symptom: `PaymentGateway.charge` returns `{ ok: false; reason: string }`; in `placeOrder.ts` that `reason` is read only to compute `status: "failed"` — the string itself is never stored or logged.
Source: Fowler — Refactoring, Primitive Obsession.
Consequence: A transient failure (network blip, Stripe outage) and a hard decline (insufficient funds, fraud block) become identical `"failed"` orders. This blocks any future "auto-retry transient failures" logic and forces support to dig through the Stripe dashboard for every failed order.
Remedy: Model failures as a small discriminated union (e.g., `reason: "card_declined" | "processor_error" | ...`) and persist or log it instead of dropping it.

**Coverage Illusion — no tests included for the new use case**
Symptom: `PlaceOrder.execute` is new, non-trivial behavior (idempotent charge orchestration, three-way status transition) with no test file in the diff.
Source: Feathers — Working Effectively with Legacy Code, Ch. 1.
Consequence: The idempotency guarantee explained in the code comment — the most important property of this class — is untested and easy to silently break in a later edit.
Remedy: Add tests for: first-time success, first-time failure, retry of a still-pending order (charges again), retry of a settled order (returns as-is, `charge` not called again).

### 🟢 Suggestion

**Cognitive Overload — `currency` has no guard clause**
Symptom: `execute` validates `amountCents` but passes `cmd.currency` straight through unchecked.
Source: McConnell — Code Complete, Ch. 8 (Defensive Programming).
Consequence: A malformed/unsupported currency reaches Stripe as a generic API error, surfacing as an opaque `"failed"` order instead of a clear validation error.
Remedy: Validate `currency` against your supported set (or at least ISO-4217 shape) alongside the existing `amountCents` guard.

**Dependency Disorder — idempotency safety is an unenforced contract with the adapter**
Symptom: The comment asserts retries are safe because the order id is reused as "the idempotency key," but that only holds if `StripePaymentGateway` actually forwards `idempotencyKey` as Stripe's `Idempotency-Key` option — nothing here enforces or tests that.
Source: Ousterhout — A Philosophy of Software Design, Ch. 5 (Information Leakage: the "no double-charge" invariant is split between the use case and an adapter not visible here).
Consequence: If the adapter is ever refactored and drops the idempotency option, double-charge protection disappears silently with no compile- or test-time signal.
Remedy: Add a contract test against the real `StripePaymentGateway` asserting the idempotency key is forwarded, so this invariant is guarded somewhere.

**Recommended fix order:** 1 → 3 (paired findings) → 2 → 4 → 5 → 6.

---

## Summary

The idempotency design in `PlaceOrder` (`findOrCreate` + reusing the order id as the charge key) is genuinely well thought through, and the comment explaining it is a good sign. The one thing worth fixing before this touches real money is the charge/save atomicity gap (#1); tighten shutdown sequencing and add retry-path tests next. The rest is minor hardening.

Would you like to triage the Warning/Suggestion findings (accept/dismiss/defer/skip)?
✓ pass skill-fired plugin-fired indicator

Skill called 1x (expected 1..∞)

Baseline (no plugin) 80% 0% of runs perfect
Run 1 80% 2 turns · $0.15 · 13:02:24 UTC
✗ fail health-score-line ×0.5

pattern not found in last_message

✓ pass no-composition-root-false-positive

judge votes: PASS PASS PASS

Judge votes✓ ✓ ✓
Evidence (what the judge was shown; for an image, a description of what was sent)
No files in the repo yet — this is pasted code, so I'll review it directly rather than diff-based.

Overall the idempotency design is solid: reusing the order id as the Stripe idempotency key on retries is the right call, and the atomic `findOrCreate` correctly handles concurrent duplicate requests. A few real issues though:

**`main.ts` — shutdown ordering bug**
```ts
const shutdown = async () => {
  server.close();
  await pool.end();
};
```
`server.close()` is not awaited — it's callback-based and only *starts* draining connections; it doesn't block until in-flight requests finish. As written, `pool.end()` runs essentially immediately, so requests still being handled when SIGTERM arrives can have their DB connections yanked mid-query. Wrap it in a promise:
```ts
const shutdown = async () => {
  await new Promise<void>((resolve, reject) =>
    server.close((err) => (err ? reject(err) : resolve()))
  );
  await pool.end();
};
```
Also worth a guard against the handler running twice (SIGTERM followed by SIGINT, or a double signal) — `pool.end()` on an already-ended pool will throw — and a forced-exit timeout in case a connection never drains.

**`placeOrder.ts` — retried request with different payload is silently ignored**
`findOrCreate` keys only on `(customerId, requestId)`. If a retry (or a colliding idempotency key from a client bug) arrives with a different `amountCents`/`currency`, the existing draft wins and the new values are dropped with no error — the caller has no way to know their request wasn't actually honored. Most idempotency-key implementations hash/compare the payload and return a conflict (409) on mismatch rather than silently reusing the old one. Worth confirming this is the intended semantic rather than an oversight.

**`placeOrder.ts` — failed orders are permanently terminal**
Once an order settles to `"failed"`, any retry with the same `requestId` just returns it as-is — there's no path to retry a payment after a transient failure (e.g., a card network blip) without the client minting a brand-new `requestId`. That may well be intentional (push retry semantics to the client), but it's a product decision worth confirming since it's easy to misread as a bug.

**`placeOrder.ts` — thin input validation**
Only `amountCents` is validated. Empty-string `currency`, `customerId`, or `requestId` will sail through to the repository/Stripe. If `requestId` can be empty, every request without an `Idempotency-Key` header collapses onto the same unique-index row for a given customer, which is probably not what you want.

Nothing else stood out — `ports.ts` is a clean, minimal set of interfaces, and the `PlaceOrder` control flow is easy to follow. The shutdown-ordering issue is the one I'd fix before shipping; the other three are worth a quick confirm-or-fix pass.
✓ pass overall-healthy

judge votes: PASS PASS PASS

Judge votes✓ ✓ ✓
Evidence (what the judge was shown; for an image, a description of what was sent)
No files in the repo yet — this is pasted code, so I'll review it directly rather than diff-based.

Overall the idempotency design is solid: reusing the order id as the Stripe idempotency key on retries is the right call, and the atomic `findOrCreate` correctly handles concurrent duplicate requests. A few real issues though:

**`main.ts` — shutdown ordering bug**
```ts
const shutdown = async () => {
  server.close();
  await pool.end();
};
```
`server.close()` is not awaited — it's callback-based and only *starts* draining connections; it doesn't block until in-flight requests finish. As written, `pool.end()` runs essentially immediately, so requests still being handled when SIGTERM arrives can have their DB connections yanked mid-query. Wrap it in a promise:
```ts
const shutdown = async () => {
  await new Promise<void>((resolve, reject) =>
    server.close((err) => (err ? reject(err) : resolve()))
  );
  await pool.end();
};
```
Also worth a guard against the handler running twice (SIGTERM followed by SIGINT, or a double signal) — `pool.end()` on an already-ended pool will throw — and a forced-exit timeout in case a connection never drains.

**`placeOrder.ts` — retried request with different payload is silently ignored**
`findOrCreate` keys only on `(customerId, requestId)`. If a retry (or a colliding idempotency key from a client bug) arrives with a different `amountCents`/`currency`, the existing draft wins and the new values are dropped with no error — the caller has no way to know their request wasn't actually honored. Most idempotency-key implementations hash/compare the payload and return a conflict (409) on mismatch rather than silently reusing the old one. Worth confirming this is the intended semantic rather than an oversight.

**`placeOrder.ts` — failed orders are permanently terminal**
Once an order settles to `"failed"`, any retry with the same `requestId` just returns it as-is — there's no path to retry a payment after a transient failure (e.g., a card network blip) without the client minting a brand-new `requestId`. That may well be intentional (push retry semantics to the client), but it's a product decision worth confirming since it's easy to misread as a bug.

**`placeOrder.ts` — thin input validation**
Only `amountCents` is validated. Empty-string `currency`, `customerId`, or `requestId` will sail through to the repository/Stripe. If `requestId` can be empty, every request without an `Idempotency-Key` header collapses onto the same unique-index row for a given customer, which is probably not what you want.

Nothing else stood out — `ports.ts` is a clean, minimal set of interfaces, and the `PlaceOrder` control flow is easy to follow. The shutdown-ordering issue is the one I'd fix before shipping; the other three are worth a quick confirm-or-fix pass.
Prompt

Can you review this? It's the startup wiring and the first use case for our new orders service. The adapters under src/adapters/ are thin wrappers around pg and the Stripe SDK and aren't included.

src/main.ts

import { Pool } from "pg";
import Stripe from "stripe";
import { loadConfig } from "./config";
import { createServer } from "./http/server";
import { PostgresOrderRepository } from "./adapters/postgresOrderRepository";
import { StripePaymentGateway } from "./adapters/stripePaymentGateway";
import { PlaceOrder } from "./orders/placeOrder";

async function main(): Promise<void> {
  const config = loadConfig(process.env);

  const pool = new Pool({ connectionString: config.databaseUrl, max: config.dbPoolSize });
  const stripe = new Stripe(config.stripeSecretKey);

  const orders = new PostgresOrderRepository(pool);
  const payments = new StripePaymentGateway(stripe);
  const clock = { now: () => new Date() };

  const placeOrder = new PlaceOrder(orders, payments, clock);

  const server = createServer({ placeOrder });
  server.listen(config.port, () => console.log(`listening on :${config.port}`));

  const shutdown = async () => {
    server.close();
    await pool.end();
  };
  process.on("SIGTERM", shutdown);
  process.on("SIGINT", shutdown);
}

main().catch((err) => {
  console.error(err);
  process.exit(1);
});

src/orders/ports.ts

export interface Order {
  id: string;
  customerId: string;
  amountCents: number;
  currency: string;
  status: "pending" | "paid" | "failed";
  createdAt: Date;
}

export interface OrderRepository {
  /**
   * Returns the order already recorded for (customerId, requestId), or stores and
   * returns `draft` if there is none. Atomic: backed by a unique index on both columns.
   */
  findOrCreate(customerId: string, requestId: string, draft: Order): Promise<Order>;
  save(order: Order): Promise<void>;
}

export interface PaymentGateway {
  charge(
    customerId: string,
    amountCents: number,
    currency: string,
    idempotencyKey: string,
  ): Promise<{ ok: true } | { ok: false; reason: string }>;
}

export interface Clock {
  now(): Date;
}

src/orders/placeOrder.ts

import { randomUUID } from "node:crypto";
import type { Clock, Order, OrderRepository, PaymentGateway } from "./ports";

export interface PlaceOrderCommand {
  /** The client's Idempotency-Key header; every retry of one request reuses it. */
  requestId: string;
  customerId: string;
  amountCents: number;
  currency: string;
}

export class PlaceOrder {
  constructor(
    private readonly orders: OrderRepository,
    private readonly payments: PaymentGateway,
    private readonly clock: Clock,
  ) {}

  async execute(cmd: PlaceOrderCommand): Promise<Order> {
    if (!Number.isInteger(cmd.amountCents) || cmd.amountCents <= 0) {
      throw new RangeError("amountCents must be a positive integer");
    }

    const order = await this.orders.findOrCreate(cmd.customerId, cmd.requestId, {
      id: randomUUID(),
      customerId: cmd.customerId,
      amountCents: cmd.amountCents,
      currency: cmd.currency,
      status: "pending",
      createdAt: this.clock.now(),
    });
    // A retried request gets its original order back: a settled one is returned
    // as-is, and a still-pending one is charged again under the same idempotency
    // key (the order id), so the customer is never charged twice.
    if (order.status !== "pending") {
      return order;
    }

    const result = await this.payments.charge(order.customerId, order.amountCents, order.currency, order.id);
    const settled: Order = { ...order, status: result.ok ? "paid" : "failed" };
    await this.orders.save(settled);
    return settled;
  }
}
Graders — what "good" means for this case
health-score-lineregexweight ×0.5
target"last_message"
pattern"Health Score\\W*\\d{1,3}\\s*/\\s*100"
flags"i"
match"contains"
no-composition-root-false-positivellm

Context: src/main.ts is the application's entry point. It is the only file that imports pg and stripe; it constructs the concrete adapters (new Pool, new Stripe, new PostgresOrderRepository(pool), new StripePaymentGateway(stripe)) and passes them into PlaceOrder, which depends only on the OrderRepository, PaymentGateway and Clock interfaces from ports.ts. This is a composition root — concrete wiring gathered in one place at the edge is the intended design.

FAIL if the answer does any of the following:

  1. Presents main.ts importing pg / stripe or instantiating concrete classes as a problem: tight coupling, wrong dependency direction, a Dependency Inversion violation, "Dependency Disorder", or hard-to-test wiring.
  2. Recommends introducing a DI / IoC container (e.g. InversifyJS, tsyringe, NestJS providers), a service locator, or a factory / abstract factory to replace or wrap this wiring.
  3. Suggests PlaceOrder or ports.ts should know about or depend on the concrete adapters.

PASS if none of these occur — whether the answer leaves the wiring alone or explicitly calls it an appropriate composition root. Findings about other aspects of main.ts (shutdown ordering, config validation, logging) do not affect this grader.

overall-healthyllm

PASS only if all of the following hold:

  1. No issue is labelled Critical, 🔴, High severity, Blocker, or "must fix before merge". An empty Critical section, or a statement that there are no critical issues, is fine.
  2. If the answer gives a numeric score out of 100 (e.g. a Health Score), it is 80 or higher.
  3. The overall verdict does not say the code needs significant rework or redesign before it can ship.

FAIL if any of 1–3 is violated.

skill-firedtool_used
tool"Skill"
input_match"brooks-review"