cursor 0.2.22: a heartbeat keeps a counted tool batch open, and its failure says how much came (#377)

Okxdd123's grok-4.7 step counted its batch, thought, then wrote one long
call for over 30 s with only heartbeats, and failed as "Cursor did not
complete its declared native tool batch". batchWait was reset by a
call, answered call, count or text, never a heartbeat, so a single long
call's arguments could not outlast it. A heartbeat (InteractionUpdate
13) now resets it while the batch is open; silence stays bounded by
idle (60 s) and a heartbeat-only stretch by quiet (240 s), as #2672 set.
The failure now reads "N of M calls came, K answered here, none since
X ms", the counts the report asked for.

Not changed: the issue's third ask, a stateless rebuild for this
failure. A streamed reply has already shown its reasoning by then, and
the rebuild only runs before output is exposed.

Run: the two new native-session tests and the updated #155 test are red
on the old code (3 fail) and green after; bun test packages/cursor 291
pass in a sandbox HOME; bun scripts/check.mjs ok. Not tried live: it
needs a real Cursor step writing one call for over 30 s.
This commit is contained in:
yetone
2026-10-25 14:44:44 +08:00
parent 2d59003f8e
commit f0bd94c4e2
4 changed files with 50 additions and 8 deletions
+33 -1
View File
@@ -322,10 +322,42 @@ test("native protocol: a step that stops sending fails batchWait after its lates
}
run.pump(stalled())
await until(() => run.error)
expect(run.error).toMatchObject({ status: 502, message: "Cursor did not complete its declared native tool batch" })
expect(run.error).toMatchObject({ status: 502, message: expect.stringMatching(/^Cursor did not complete its declared native tool batch: 2 of 3 calls came/) })
expect(Date.now() - started).toBeGreaterThanOrEqual(440)
})
// #377 (Okxdd123, grok-4.7): a step that counted its batch, then thought,
// then wrote one long call's arguments for over batchWait, sending only
// heartbeats while it wrote, failed as a batch never completed. A
// heartbeat is Cursor still on the step; silence and a heartbeat-only
// stretch are bounded by idle and quiet (#2672).
test("native protocol: heartbeats while a counted call's arguments are written keep the batch open (#377)", async () => {
const { run } = owner({}, { batchWait: 300 })
async function* slow() {
yield* frames([update(27, uint(1, 1)), update(4, text(1, "thinking"))])
for (let i = 0; i < 8; i++) {
await new Promise((r) => setTimeout(r, 100))
yield* frames([update(13, Buffer.alloc(0))])
}
yield* frames([tool(7, "call-7", "long arguments")])
await new Promise(() => {})
}
run.pump(slow())
await until(() => run.error || run.state === "awaiting-results")
expect(run.error).toBeUndefined()
expect(run.segment.events.filter((e) => e.tool)).toHaveLength(1)
})
test("native protocol: a batch that never completes says how much of it came (#377)", async () => {
const { run } = owner({}, { batchWait: 200 })
run.pump((async function* () {
yield* frames([tool(7, "call-7", "one"), update(27, uint(1, 3))])
await new Promise(() => {})
})())
await until(() => run.error)
expect(run.error.message).toMatch(/^Cursor did not complete its declared native tool batch: 1 of 3 calls came, 0 answered here, none since \d+ ms$/)
})
// #2672 bounds each wait on Cursor, not the step: calls that keep coming,
// each sooner than idle, seal however long the step takes in all.
test("native protocol: a step whose calls each come within idle outlasts idle in all (#2672)", async () => {