A one-line request, a surprising result
You typed: *Add pagination to GET /orders.* A few minutes later the agent reported done, tests green. After deploy, the mobile app shows an empty list, because it expected a JSON array and now gets an object. Support also finds some orders appearing twice across pages. Nothing in the diff is obviously broken code. Many of the choices in it just were not yours.
Every open decision becomes a guess
Your request left many decisions open: page numbers or cursor, default size, maximum, sort order, response shape, what existing clients rely on. The agent did not stop to ask. It filled each gap with the most common choice from public code. You also could not judge whether it was 'done', because 'does what was asked' had no fixed meaning.
**Later cost:** the guesses surface after merge, as broken clients and rework.
Five parts of a finishable task
- **Goal**: what must be true afterwards.
- **Reason**: why it matters, so the agent chooses sensibly where you said nothing.
- **Constraints**: what must hold, such as compatibility and the helpers and conventions to use.
- **Non-goals**: what to leave alone.
- **Acceptance criteria**: checks with a yes/no answer, such as a command, a test or an observable behaviour.
Then scan for gaps. Wherever two good developers would choose differently, decide it yourself or tell the agent to ask.
The diff: four guesses in seven lines
Each `+` line settles something you never decided. It uses page numbers with offsets, the most common pattern. The default is 20 with no upper bound, so `?size=1000000` loads everything again. No sort order is given, and offsets shift when new orders arrive, so rows can move between pages. That explains the duplicates. `res.json({ items: rows, page, size })` replaced a bare array and broke every existing client. From the agent's view none of this was wrong, because your request never ruled it out.
// TypeScript
--- a/src/routes/orders.ts
+++ b/src/routes/orders.ts
router.get("/orders", async (req, res) => {
- const rows = await db.orders.all();
- res.json(rows);
+ const page = Number(req.query.page) || 1;
+ const size = Number(req.query.size) || 20;
+ const rows = await db.orders.list({
+ offset: (page - 1) * size,
+ limit: size,
+ });
+ res.json({ items: rows, page, size });
});
The same request, written to be finished
**Goal:** GET /orders returns one page of orders, **because** the mobile app times out on large accounts.
**Constraints:** the body stays a JSON array. The next cursor goes in an `X-Next-Cursor` header. Newest first. Default 50, max 200. Use `paginate()` from `src/db/paging.ts`.
**Non-goals:** other endpoints, total counts, client code.
**Acceptance:** `npm test` is green. New tests: 120 orders read in pages of 50 come back in 3 pages, newest first, each order exactly once. With 250 orders, `size=1000` returns 200.
Remember
The agent settles every decision your task leaves open with the most typical guess. State the goal and its reason, the constraints, the non-goals and yes/no acceptance checks. Then both the agent and you know what 'done' means.
On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.