2026-05-09 — views · 4 models
Fix off-by-one in cursor pagination — agentic code edit head-to-head
Prompt
Here is a Node.js handler for cursor pagination:
```js
function paginate(items, cursor, limit = 20) {
const start = cursor ? items.findIndex(i => i.id === cursor) : 0;
return {
data: items.slice(start, start + limit),
next: items[start + limit]?.id ?? null,
};
}
```
It has a subtle off-by-one bug: when called with a cursor, the first item returned is the cursor itself (it should be the item *after* the cursor). Fix the function. Preserve the same signature and return shape. Add a single inline comment only where the bug was. Return only the corrected function, no preamble. Notes
Tests whether the model spots the off-by-one (start should be findIndex(...) + 1) without breaking the cursor=null branch. Latency client-side. Cost from public May 2026 pricing. All models given the same exact prompt.
Results — 4 models
claude-opus-4-7 WIN · 2240ms · in 312 · out 142 · $0.011
function paginate(items, cursor, limit = 20) {
const start = cursor ? items.findIndex(i => i.id === cursor) + 1 : 0; // bug fix: skip cursor itself
return {
data: items.slice(start, start + limit),
next: items[start + limit]?.id ?? null,
};
} gpt-5 WIN · 1890ms · in 312 · out 168 · $0.009
function paginate(items, cursor, limit = 20) {
// bug fix: cursor item itself was being returned; advance past it
const start = cursor ? items.findIndex(i => i.id === cursor) + 1 : 0;
return {
data: items.slice(start, start + limit),
next: items[start + limit]?.id ?? null,
};
} gemini-3-pro TIE · 2050ms · in 312 · out 220 · $0.007
function paginate(items, cursor, limit = 20) {
let start = 0;
if (cursor) {
const idx = items.findIndex(i => i.id === cursor);
if (idx >= 0) start = idx + 1; // bug fix: cursor was inclusive
}
return {
data: items.slice(start, start + limit),
next: items[start + limit]?.id ?? null,
};
} qwen3.6-35b-a3b-nvfp4 WIN · 920ms · in 312 · out 156 · $0.001
function paginate(items, cursor, limit = 20) {
const start = cursor ? items.findIndex(i => i.id === cursor) + 1 : 0; // off-by-one fix
return {
data: items.slice(start, start + limit),
next: items[start + limit]?.id ?? null,
};
}