cursor 0.2.47: wait for announced MCP execs before sealing a batch (#1133)

A Cursor step can send its tool count, then a checkpoint naming only the
first MCP call, then the second call's exec. The count made the #550
fallback seal the batch at that checkpoint, so the second tool was lost
(native: "native call arrived after its batch was sealed"; stateless: one
tool). StepCalls now tracks MCP calls announced by a partial or started
update until their exec or Cursor's own completion arrives, and neither
path seals on a checkpoint while one is pending. Cleared at nextStep.

Reviewed at d3a50d48. Run (macOS, mica): bun test packages/cursor 425
pass 0 fail; bun scripts/check.mjs cursor ok. Broken by hand: without
both pendingMcp checks the four new tests fail; with them they pass.
PR checks bumped, test, on-npm green. Not tried: a real Cursor account
(the author ran a live Pi -> magpie -> Cursor probe, 6 tool calls ok).

Co-authored-by: wuuli <wuuli@users.noreply.github.com>
This commit is contained in:
wuuli
2026-11-14 16:04:32 +08:00
committed by GitHub
co-authored by wuuli
parent 2e4403d1fb
commit 62c3241954
5 changed files with 54 additions and 7 deletions
+5 -2
View File
@@ -153,8 +153,11 @@ Cursor completes by itself, which it writes and completes in the step but never
starts on the client or sends to it; those count toward it too. When the count
comes after the step's calls, a checkpoint whose state waits on exactly the
calls the caller was given also ends the step (#550); a checkpoint between
calls after a count sent ahead of them does not seal the batch early. The
step's calls are the rest.
calls after a count sent ahead of them does not seal the batch early. A
partial or started MCP call can also precede the count while its exec follows
the checkpoint. Until that call arrives as an exec or is completed by Cursor,
the checkpoint cannot end the step merely because it lists only calls already
sent. The step's calls are the rest.
These are retention limits. A missing, expired, restarted, busy, incompatible,
or full owner uses the original history reconstruction and stateless decoder
+4 -2
View File
@@ -3374,8 +3374,10 @@ async function* decode(stream, { send, blobs, tools, estimate, close, stepUsage,
// conversation_checkpoint_update: Cursor's state. Once the step
// has its count after the calls, a state waiting on just the
// calls handed to the caller is a step Cursor has finished: what
// more the count says will not come (plugins#550)
if (listed && step.listedAfter && calls > 0 && pendingCalls(m.data, fields) === calls) {
// more the count says will not come (plugins#550). An announced
// MCP call without an exec or completion must still be awaited,
// even if this checkpoint omits it.
if (listed && step.listedAfter && !step.pendingMcp && calls > 0 && pendingCalls(m.data, fields) === calls) {
note?.("waited on")
yield await settled()
return
+14 -2
View File
@@ -566,6 +566,7 @@ export class StepCalls {
this.started = new Set()
this.execs = new Set() // the short strings of each exec's args: its tool_call_id among them
this.partial = new Set() // calls the model is writing in this step
this.mcp = new Set() // MCP calls announced by a partial or started update
this.byCursor = new Set()
this.listedAfter = false // whether tool_requests_listed came after the latest call/update
}
@@ -578,6 +579,8 @@ export class StepCalls {
this.listedAfter = false
const id = str(uf, 1)
if (!id) return false
const call = field(uf, 2)
if (n !== 3 && call && this.parse(call.data).some((f) => f.num === 15)) this.mcp.add(id)
if (n === 2) this.started.add(id)
if (n === 7) this.partial.add(id)
if (n !== 3) return false
@@ -607,6 +610,13 @@ export class StepCalls {
get completed() {
return this.byCursor.size
}
// Announced MCP calls still awaiting an exec or a Cursor-side completion.
// A checkpoint can omit them while their execs are still on the way.
get pendingMcp() {
let n = 0
for (const id of this.mcp) if (!this.execs.has(id) && !this.byCursor.has(id)) n++
return n
}
// writing is how many calls the step wrote (7) that are neither started
// on the client, sent as an exec, nor completed by Cursor: a call of
// Cursor's own still running, or one still to be sent
@@ -618,6 +628,7 @@ export class StepCalls {
// nextStep starts the next step's count
nextStep() {
this.partial.clear()
this.mcp.clear()
this.byCursor.clear()
this.listedAfter = false
}
@@ -1233,10 +1244,11 @@ class NativeSession {
// When the count was sent before or between the step's calls, a mid-batch
// checkpoint after an early call has only the calls sent so far in
// pending_tool_calls and must not seal the batch early before the
// remaining calls arrive.
// remaining calls arrive. Even a count after a partial/started MCP update
// can precede its exec: a checkpoint omitting that call must wait for it.
waitedOn(data) {
const s = this.segment
if (this.terminal || this.state === "awaiting-results" || s.closed || s.expected == null || !s.calls.length || !this.stepCalls.listedAfter) return
if (this.terminal || this.state === "awaiting-results" || s.closed || s.expected == null || !s.calls.length || !this.stepCalls.listedAfter || this.stepCalls.pendingMcp) return
if (pendingCalls(data) !== s.calls.length) return
s.waitedOn = true
this.sealBatch()
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-cursor-auth",
"version": "0.2.46",
"version": "0.2.47",
"description": "Cursor subscriptions (Pro, Pro+, Ultra, Teams) in OpenCode and magpie, through the API cursor-agent talks to",
"type": "module",
"main": "./opencode.mjs",
+30
View File
@@ -193,6 +193,36 @@ const until = async (predicate) => {
}
const nativeFrames = (opts) => wire(opts).map((b) => ({ data: envelope(b).subarray(5) }))
// Two real Hydrogen failures: the count follows a partial second call,
// but its exec arrives after a checkpoint waiting on only the first.
const partialBatch = (started) => [
callUpdate(7, "c3", MCP),
callUpdate(2, "c3", MCP),
bin(2, execMessage("c3")),
callUpdate(7, "c4", MCP),
...(started ? [callUpdate(2, "c4", MCP)] : []),
bin(1, bin(27, uint(1, 2))),
bin(3, state(['{"call":"c3"}'])),
...(!started ? [callUpdate(2, "c4", MCP)] : []),
bin(2, message(uint(1, 8), text(15, "exec-c4"), bin(11, mcpArgs("c4")))),
]
for (const started of [false, true]) test(`native: a checkpoint after the count waits for a ${started ? "started" : "partial"} call's exec`, async () => {
const run = owner()
run.pump(open(partialBatch(started).map((data) => ({ data }))))
await until(() => run.error || run.state === "awaiting-results")
expect(run.error).toBeUndefined()
expect(run.segment.events.filter((e) => e.tool).map((e) => e.tool.name)).toEqual(["read_file", "read_file"])
expect(run.segment.events.at(-1).stop).toBe("tool_calls")
})
for (const started of [false, true]) test(`stateless: a checkpoint after the count waits for a ${started ? "started" : "partial"} call's exec`, async () => {
const { how, events } = await stateless(partialBatch(started))
expect(how).toBe("ended")
expect(events.filter((e) => e.tool).map((e) => e.tool.name)).toEqual(["read_file", "read_file"])
expect(events.at(-1).stop).toBe("tool_calls")
})
// pending: a checkpoint that waits on more than came, so only the calls
// Cursor completed can seal it
for (const [name, opts] of [["call updates", { pending: ["c3", "c9"] }], ["the checkpoint alone", { updates: false }]]) test(`native: the reporter's step seals on its one call, by ${name} (#550)`, async () => {