Design a feature Exercise 6 of 9

Review and implement

Use your saved design to hand off work to a reviewer and then to an implementer. The linked source and tests give reviewers a shared baseline for checking feasibility.

  1. Select egm-review and send the prompt below. Keep the Elephant chat available for decisions and document edits.

    Review docs/designs/retry-delivery.md with the interactive preset and fresh Goldfish subagents. GoldfishContext has no additional files. Use the design's local source links where the stage permits them.

  2. At the comprehension checkpoint, compare the reviewer's account to your intended contract. If the reviewer needed a decision that lived only in chat, write it into the design. Resolve any blocking findings and use reviewer evidence to decide whether to approve the design.

  3. After approval, open a fresh implementation chat in the lab. Ask the coding agent to implement the approved design and update the tests. Give it the design path and ask it to surface any decision it cannot derive from that file and its references.

  4. Run node --test test/deliver-batch.test.mjs. Inspect the source diff and tests for both the retry budget and the behavior after a failed event. Trace at least one test assertion to a sentence in the approved design.

You're done when you can show the approved design, the implementation, and a passing test for a case the review helped clarify. If the review found no gaps, trace one test to a rule it confirmed was clear.

Reference answer

The full review proceeds through zoom out, comprehension, critique, a second zoom out, and implementation readiness. Use comprehension to see whether a reader can reconstruct the policy from the document. Use implementation readiness to check that the plan translates the policy into code changes and tests. Review skill

For the two-attempt policy, each event can be retried locally inside the existing serial loop:

export async function deliverBatch(events, send) {
  const results = [];

  for (const event of events) {
    let status = "failed";
    for (let attempt = 1; attempt <= 2; attempt += 1) {
      try {
        await send(event);
        status = "delivered";
        break;
      } catch (error) {
        if (error?.replaySafe !== true) break;
      }
    }
    results.push({ id: event.id, status });
  }

  return results;
}

Keep the original tests passing. This runnable check covers the three new behaviors together. Run it from the lab directory after implementing the reference policy.

node --input-type=module <<'JS'
import assert from "node:assert/strict";
import { deliverBatch } from "./src/delivery/deliver-batch.mjs";

const events = [
  { id: "recovers" },
  { id: "exhausts" },
  { id: "ambiguous" },
  { id: "after" },
];
const calls = [];
const results = await deliverBatch(events, async ({ id }) => {
  calls.push(id);
  if (id === "ambiguous") throw new Error("acknowledgement lost");
  if (id === "exhausts" || (id === "recovers" && calls.length === 1)) {
    throw Object.assign(new Error("request was never sent"), { replaySafe: true });
  }
});

assert.deepEqual(calls, [
  "recovers", "recovers", "exhausts", "exhausts", "ambiguous", "after",
]);
assert.deepEqual(results, [
  { id: "recovers", status: "delivered" },
  { id: "exhausts", status: "failed" },
  { id: "ambiguous", status: "failed" },
  { id: "after", status: "delivered" },
]);
JS