Commit Graph
10 Commits
Author SHA1 Message Date
yetone 3f615ea9ef cursor 0.2.37: a step with under 10 minutes of a retained Run's lifetime left starts fresh, and a deadline cut says to retry (#616)
yetone/magpie#4419 (Okxdd123; ggbdpq traced the cause and wrote the
repro): a Pi turn on cursor/grok-4.7@500k kept one native Run across 12
tool steps. The 13th went on in that Run with 494 s of its 15-minute
lifetime left, the answer was still streaming at the deadline, and the
Run failed mid-answer with "native Run lifetime expired". The 200 was
long sent, so the agent read only those words, and Pi doesn't retry on
any of them, so the turn ended although asking again goes on.

- native-session.mjs: a retained Run takes a tool batch's results only
  with more than continueReserve (10 minutes, new in NATIVE_LIMITS; at
  most two thirds of the lifetime) left. With less, the owner is retired
  and the step goes on a fresh Run from the supplied history, as #157
  did for the last minute. 60 s didn't cover a long answer.
- The deadline's error now says "native Run lifetime expired: the Run
  timed out; retry your request" (LIFETIME_EXPIRED). "timed out" is in
  Pi's _isRetryableError list and in magpie's passingSaid; "retry your
  request" is in passingSaid, so magpie's gateway adds nothing more. For
  Claude Code and Codex, magpie translates the error as api_error /
  server_error, as before.
- README: the 10-minute reserve and the wording.

Tests (native-e2e.test.mjs), no network and no real waiting: Date.now
moved so a continuation has 494 s (the reporter's case) or 599 s left ->
rebuilt on a fresh Run, no result written to the old one; 660 s left ->
same Run. A retained continuation streams half an answer, the deadline
is brought in with expireIn(0), and the SSE's one error starts "native
Run lifetime expired" and matches Pi's retry regex and magpie's
passingSaid (both copied into the test).

Broken by hand: the old reserve (min(60 s, lifetime/10)) turns the 494 s
and 599 s cases red; the old wording turns the mid-answer case red
(3 fail, 135 pass in native-e2e).

Run (mote, HOME=$(mktemp -d), as CI): bun test at the repo root, 4716
pass, 0 fail; bun scripts/check.mjs, exit 0. packages/cursor alone: 384
pass, 0 fail.

Not tried: a real Cursor account reaching the 15-minute deadline; a real
Pi, Claude Code or Codex reading the new wording (Pi's regex is the one
in pi-coding-agent's agent-session.js as installed locally, not
necessarily Pi 1.4.0's).
2026-11-02 08:00:09 +08:00
yetone 1a5b184991 cursor 0.2.34: the quiet error names its checkpoint; an opt-in Wire trace saves a failed Run's frames (#550)
Windsland52 (#550, 0.2.33, cursor/grok-4.6 at xhigh): four Runs ended
"Cursor went quiet: 24 heartbeats and nothing else for 240 s, its last
message checkpoint". They asked for the checkpoint to be named, and for a
way to see what Cursor sends after it. No change to quiet's budget or to
retry, as asked.

The quiet error now says, for a checkpoint: its number in the Run, which
of its step's checkpoints it was (native path; the stateless path doesn't
count steps), how many came in a row, and the kinds before it, e.g.
"its last message checkpoint #1 of the Run, the first of step 1, after
blob request x2, thinking". Other kinds read as before.

Wire trace is a new plugin option (wire_trace), off by default. With it
on, a Run that fails (not one the caller cancels), native or stateless,
writes <magpie's folder>/cursor-traces/<start>-<rand>.json (temp and
rename, mode 600, newest 20 kept). It holds both directions' frames as
time, size, kind, top-level field numbers with wire type and size, and
the field numbers and sizes one level inside: the shape, never the bytes.
No text, thinking, tool name or argument, blob or blob id, checkpoint
content, token, header, account or conversation id is read into it. The
error message is scrubbed of email-, uuid-, auth-id- and token-shaped
strings. It also has quiet's counters, the model id and plugin version.
The first 2000 and last 3000 frames are kept, the rest counted. The
folder comes from input.directory, which magpie sets to its config
folder. The option exists only in magpie, so OpenCode's project folder is
never written to.

Run on mote at this tree (33027a8 + this change):
- HOME=$(mktemp -d) bun test at the root: 4186 pass, 9 skip, 0 fail.
- bun scripts/check.mjs cursor ok.
- native-session + native-e2e on xiaomi-gpu (Windows, win-run): 165
  pass, 0 fail.
Broken by hand, on mote:
- The new tests against origin/main's code: 5 fail.
- Raw frame bytes added to each entry: both e2e trace tests red (secret,
  token found).
- Tracing cancelled Runs too: the cancelled test red.
- Ignoring the option: "off unless the option is on" red.
Not tried: a real Cursor account. The stall hasn't been reproduced here,
so the fixtures follow what #550 reports (heartbeats after a checkpoint),
not a captured Run. Not tried in the magpie GUI either: that the option
shows as a toggle under Plugin options is from how Included usage only
shows, not looked at.
2026-10-31 15:10:54 +08:00
yetone c9a0215f31 cursor: a continued Run that goes quiet after the caller's results ends (#364)
Test only. #364's tests covered the pause at a sealed batch but not the
resume after the submit: with resume() leaving the Run paused, every
test passed and a retained Run that went quiet on its second model call
would wait for lifetime again. This one is red with that break (times
out at 5 s) and green at cf1873e.

Run: packages/cursor native-e2e.test.mjs, Bun 1.4.2, sandbox HOME:
131 pass, 0 fail.
2026-10-24 20:35:20 +08:00
LooSheng cf1873e292 cursor 0.2.21: a Run Cursor stops answering ends, retained or stateless (yetone/magpie#2672) (#364)
A Run Cursor stops answering mid-turn now ends with a 502 that says so,
on both the stateless path (runOnce/decode) and the retained path
(NativeSession.pump), instead of holding the reply open until the agent
gives up (yetone/magpie#2672: two composer-2.5 turns waited 305 s).

Quiet wraps a Run's frames: 60 s with no message at all, or 240 s with
only Cursor's heartbeats (InteractionUpdate.heartbeat), ends it. Only
time spent waiting on Cursor's next frame counts; a retained Run parked
for the caller's tool results is paused (resultWait bounds it) and
resumes from nothing after the submit. Each frame gets a fresh wake
promise, so frames already passed on are not held for the stream's life
(review of cbd5d3b). cursor 0.2.20 -> 0.2.21.

Run at the reviewed head 6a17d61 (base 79e383c; main 8d687ad since
touched only kimi-work), Bun 1.4.2, sandbox HOME:
- packages/cursor `bun test`: 288 pass, 0 fail (17 files).
- `bun scripts/check.mjs`: every package ok.
- 20,000 frames of 50 KB through Quiet.frames with the stream left
  open: 95 MB RSS (1376 MB at cbd5d3b).

Broken by hand, each red:
- the long-lived `gone` promise put back: the WeakRef frames test fails;
- heartbeats counted as frames: both heartbeats-only tests fail;
- stateless path unwrapped: 3 stateless tests fail;
- resume() leaving the Run paused: no test went red. A test for it
  (a continued Run going quiet after the caller's results) follows in
  its own commit; red with that break, green at this head.
- decode's `e.quiet` branch removed: no test red (the message then
  reads "the reply broke off: Cursor went quiet: ..."; tests use
  toContain). Cosmetic, left as is.

Not tried by the reviewer: a real Cursor account, Windows, Cursor
actually going quiet (the author's live runs are on the PR).
2026-10-24 20:34:47 +08:00
nicegui 0a2496bb3a cursor 0.2.19: conflicting native batch counts rebuild once from history before any output (#207, nicegui)
A Cursor native Run whose step lists two different tool counts (a Codex-to-Cursor failover hit "inconsistent native tool count") now retires the owner instead of throwing. When no native result was submitted to that Run and no Chat output was exposed, the request is rebuilt once from Chat history (the same stateless rebuild the missing-count case uses), with reason=inconsistent-batch-count in X-Magpie-Cursor-Continuity. A Run that had a result submitted, or a stream that already sent output, still returns the error. The decoder stops reading the failed Run at once. Cursor 0.2.19.

Reviewed at c43b93c (on main 0b58032, clean). Run there, HOME and XDG in a sandbox dir:
- packages/cursor `bun test`: 275 pass, 1 fail. The fail is latency.test "events never show in time", red 6 of 6 on untouched main 0b58032 under load average ~270; filed as #210.
- `bun scripts/check.mjs cursor`: ok.
- native-e2e -t "conflicting count": 4 pass. With index.mjs and native-session.mjs from main: 3 of 4 red (JSON and stream rebuild, submitted-result guard). With retentionIneligible forced true: the submitted-result test goes red.
- The fake Cursor is the test's HTTP/2 server on 127.0.0.1; no real account used. The conflict is injected; why Cursor sent two counts is still unknown.
2026-10-17 21:17:45 +08:00
nicegui 0b821908bc cursor: a tool-result continuation in a Run's last minute rebuilds before writing results, not 502 at the lifetime (#157, nicegui)
The 15-minute absolute lifetime spans all of a retained Run's tool
roundtrips. A tool-result continuation that arrives with no more than
min(60s, lifetime/10) left now retires the owner (410 "retired before
lifetime deadline") and rebuilds from the supplied history before writing
any result, instead of resuming and failing mid-segment with "native Run
lifetime expired". Replays of an already submitted batch keep their path.
Merging main resolved a conflict with a7614aa (#143): expireIn sets
expiresAt as well as the timer.

Reviewed at 75e481a (nicegui's 6f03753 plus the merge of main):
- packages/cursor `bun test` (isolated HOME) 267 pass, 0 fail, three
  times; `bun scripts/check.mjs` ok; PR CI run 38868447170 green, attempt 1.
- The near-expiry test fails on the source without the reserve check.
- Near-deadline injected by shifting Date.now() from the owner's
  expiresAt, not by waiting: 62s left resumes on the same Run (1 Run, 1
  result written); 59s and 0.5s left rebuild (2 Runs, no result written).
  With the check removed by hand, 59s and 0.5s go red.
2026-10-16 15:39:10 +08:00
yetone a7614aa2ff cursor: the lifetime-expiry test brings a Run's lifetime in after its first answer, not before it starts (#143)
The native retention test set NATIVE_LIMITS.lifetime = 65 before the
first ask. The lifetime counts from the Run's start, so on a loaded
machine the first Run expired before it answered: 410 where the test
wants 200. NativeSession now sets its deadline through expireIn(ms), the
constructor giving it the whole lifetime as before, and the lifetime case
calls owner.expireIn(65) after the first answer. The resultWait case
still sets its limit up front, since that wait counts from the answer.
The plugin's behaviour is unchanged, so there is no version bump.

Run:
- Injected: on the old test, a lifetime of 0–10 ms is red ("Expected: 200
  Received: 410"); 15 ms and up is green. The new test is green.
- HOME=$(mktemp -d) bun test, whole repo: 10 runs in a row, 0 fail
  each. On current main 2dd4328 plus this change: 1609 pass, 0 fail.
- bun test packages/cursor/latency.test.mjs 8 runs: green with this
  change. On main without it, 1 red in 8 runs. That red is
  "events never show in time" at load ~120, filed as #159. It is not
  this test. grok's login flake from an earlier run is #160.
2026-10-16 15:30:52 +08:00
yetone c7c6498d85 cursor: a multi-step turn's last step reports its own share of usage, and a step's calls get batchWait from the latest one (#156 erzay, #155 midmirror)
#156: a native Run of N tool steps ended with TurnEndedUpdate's totals as
the final step's prompt_tokens (1,105,934 on erzay's ~21-step turn, where
the real context was ~61K), and Codex compacted at once. The final step
now keeps its last model call's share, max(that call's chars/4 prompt
estimate, turn total / model calls), split proportionally across input,
cache read and cache write; the rest goes into usage.magpie_deferred
(merged with any settled stateless debt), so magpie still bills the whole
turn. On erzay's numbers that is ~52.7K reported, ~1.05M deferred.

#155: waitForBatch armed once, at a step's first call, so a step whose
calls arrive one by one as the model writes them (13 calls, 9 long-arg)
failed 502 "did not complete its declared native tool batch" ~30s after
the first call even though it never paused that long. The deadline now
restarts on every call, answered call, count and text/reasoning frame.

Run at this commit: packages/cursor `bun test` (isolated HOME) 266 pass,
0 fail, three times; `bun scripts/check.mjs` ok. The three new tests fail
on 4e64f26's source (prompt 1105934; sealed step failed at 300ms; stall
failed 303ms after the first call instead of after the latest).
2026-10-16 15:09:25 +08:00
yetone 1bf9113390 cursor: calls the bridge answers itself count toward Cursor's tool count, and KV replies wait for a slow link instead of failing the Run (#142, Evopower)
Cursor's tool_requests_listed (InteractionUpdate 27) counts every call of
the model's step, and is sent after them. That count includes calls the
plugin answers itself: a tool the request doesn't have (0.2.14's native
path refuses those) and Cursor's get_mcp_tools (exec 36). 0.2.14 counted
only the calls it accepted. A step with a refused call then either waited
30s for a call that never came (502 "did not complete its declared native
tool batch") or met the next step's count with the stale one (502
"inconsistent native tool count", the reporter's error). The stateless
decoder had the same miscount and hung. Both paths now count answered
calls toward the step and end a step whose calls were all answered without
one.

503 "native outbound messages limit reached": a long history goes out as
one blob per message, and Cursor asks for every blob at once. The native
transport caps its pending writes at 256 messages / 16 MiB and failed the
Run when a slow link backed them up past that. KV replies now wait for
room (NATIVE_LIMITS.writeWait, 30s) and fail only if the link doesn't
drain for that long. The stateless path writes directly and has no cap.

The fixtures are real Cursor frames captured on 2026-10-15 (model auto,
cursor-agent's agent.v1): get_mcp_tools plus a refused WebSearch in one
step followed by read_file, which gave 0.2.14 the reporter's exact
"inconsistent native tool count"; and read_file, refused WebSearch,
read_file under a count of 3, which gave 0.2.14 the batch timeout.

Run at this commit (on origin/main 43d93b0):
- packages/cursor `bun test` (isolated HOME): 263 pass, 0 fail.
- `bun scripts/check.mjs`: every package ok.
- Broken by hand: with native-session.mjs and index.mjs reverted to
  0.2.14, the new tests fail with "inconsistent native tool count",
  "native outbound messages limit reached", the batch wait, and the
  stateless decoder's hang; 4 of 5 red (the stateless mixed case passes
  on 0.2.14, which hands WebSearch to the caller there).
- Real Cursor, before the fix: the captures above reproduced both 502s
  through the plugin's native path. The 503 was not reproduced on a real
  link (my queue peaked at 160 of 256); it is reproduced in the test with
  a 16-message bound and a slow fake write.
- Real Cursor, after the fix (owner's account, model auto, the mixed
  prompt): native path 3 of 3 runs 200 with read_file a.txt and b.txt
  (WebSearch refused to the model), stateless 3 of 3 runs 200; a native
  Run with 1200 history messages 200.
- Not proven: the reporter's empty replies. They are likely the turns
  after these failures and are not addressed separately.
2026-10-15 17:51:41 +08:00
nicegui 33cdf7c1a8 cursor: Run tool calls stay on one native Cursor session and resume stateless after a long tool, not a failed turn (#135, nicegui)
Cursor's Run (native) calls stay on one Cursor session across a tool result. With them, a tool that runs longer than Cursor's limit resumes stateless, not as a failed turn. The session pool lives in native-session.mjs. It applies to a conversation's first user turn, and a new user turn goes stateless (see the README). X-Magpie-Cursor-Continuity says which path a request took.

The dashboard-usage ledger counts two distinct events in one response that share a millisecond, as main did. Only timestamps claimed by earlier fetches are left out. A new deferred-usage test covers it.

Run at the reviewed head 398aeddc0186cfc38189b1f05577b181aa2d587d (merge base 5d5d86e; main has no packages/cursor change since):
- packages/cursor `bun test` 3 times: 258 pass, 0 fail each time.
- `bun test latency` 12 times with fresh HOMEs: 12/12 pass.
- Broken by hand: putting back `if (claimed.has(key + "\0" + ev.timestamp) || at >= before()) continue` makes the new test "distinct same-millisecond events in one response are billed together, not again on later fetches" fail (2 pass, 1 fail). The head's line passes.
- `bun scripts/check.mjs`: all packages pass.
- `npm pack`, extracted into a fresh dir: index.mjs, native-session.mjs, package.json, README.md. `import("./index.mjs")` exports CursorAuthPlugin and _internal, and native-session.mjs imports.
- CI: test and on-npm green.

Not tried: a real Cursor account. The owner's stored plugin sign-in has no access token. The author reports a real Claude Code run through an isolated gateway: a child resumed stateless after a 125s tool, and all 6 requests returned 200.
2026-10-15 13:39:14 +08:00