diff --git a/packages/cursor/README.md b/packages/cursor/README.md index 122ef75..e30cd78 100644 --- a/packages/cursor/README.md +++ b/packages/cursor/README.md @@ -153,7 +153,10 @@ as prior usage. Stateless Runs otherwise keep the dashboard accounting above. `X-Magpie-Cursor-Continuity` identifies `same-run` or `stateless`, with the fallback reason where available. A missing native batch count can retry stateless once before any output is exposed or native result submitted; progressive output is -kept and its later errors are surfaced. +kept and its later errors are surfaced. A step's declared tool batch waits 30 +seconds from Cursor's latest call, count, text or heartbeat, so one long call +written under heartbeats is not cut off; the failure says how many of the +declared calls came. The existing request builder and model selection remain in use, including the legacy `thinking=false` mapping for explicit `none`/`off`. Retention adds no diff --git a/packages/cursor/native-session.mjs b/packages/cursor/native-session.mjs index 63d166c..beb9f20 100644 --- a/packages/cursor/native-session.mjs +++ b/packages/cursor/native-session.mjs @@ -768,14 +768,19 @@ class NativeSession { if (estimate != null) this.stepEstimate = estimate } // waitForBatch gives the step batchWait from its latest call, answered - // call or count, not from its first. Cursor sends each call once the model - // has written its arguments, so a step of many long calls arrives over - // longer than batchWait while never pausing that long (#155). + // call, count, text or heartbeat, not from its first. Cursor sends each + // call once the model has written its arguments, so a step of many long + // calls arrives over longer than batchWait while never pausing that long + // (#155), and one long call is written with only heartbeats meanwhile + // (#377); a heartbeat-only stretch is bounded by quiet. The failure says + // how much of the batch came, so a stall reads apart from a slow call. waitForBatch() { clearTimeout(this.batchTimer) + const since = Date.now() this.batchTimer = later(() => { - if (this.segment.expected == null && this.segment.calls.length && !this.resultSubmitted) this.missingCount() - else this.fail({ status: 502, message: "Cursor did not complete its declared native tool batch" }) + const s = this.segment + if (s.expected == null && s.calls.length && !this.resultSubmitted) this.missingCount() + else this.fail({ status: 502, message: `Cursor did not complete its declared native tool batch: ${s.calls.length} of ${s.expected ?? "?"} calls came, ${s.answered} answered here, none since ${Date.now() - since} ms` }) }, this.limits.batchWait) } missingCount() { @@ -1005,6 +1010,8 @@ class NativeSession { } else if (u.num === 27) { this.listed(num(uf, 1)) if (this.error) return + } else if (u.num === 13) { + if (this.batchTimer && !this.terminal && this.state !== "awaiting-results") this.waitForBatch() } } break diff --git a/packages/cursor/native-session.test.mjs b/packages/cursor/native-session.test.mjs index d7bd025..9dd2ee3 100644 --- a/packages/cursor/native-session.test.mjs +++ b/packages/cursor/native-session.test.mjs @@ -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 () => { diff --git a/packages/cursor/package.json b/packages/cursor/package.json index a0c2814..364c938 100644 --- a/packages/cursor/package.json +++ b/packages/cursor/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-cursor-auth", - "version": "0.2.21", + "version": "0.2.22", "description": "Cursor subscriptions (Pro, Pro+, Ultra, Teams) in OpenCode and magpie, through the API cursor-agent talks to", "type": "module", "main": "./index.mjs",