2026-05-09 · benchmark
Fix off-by-one in cursor pagination — agentic code edit head-to-head
Show 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. | Model | Latency | Cost | Verdict |
|---|---|---|---|
| claude-opus-4-7 | 2240ms | $0.011 | Win |
| gpt-5 | 1890ms | $0.009 | Win |
| gemini-3-pro | 2050ms | $0.007 | Tie |
| qwen3.6-35b-a3b-nvfp4 | 920ms | $0.001 | Win |
Show responses
claude-opus-4-7
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
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
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
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,
};
} 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.