From a7614aa2ffa9c5671df267d30ec6515af16b6ab8 Mon Sep 17 00:00:00 2001 From: yetone Date: Fri, 16 Oct 2026 15:30:52 +0800 Subject: [PATCH] cursor: the lifetime-expiry test brings a Run's lifetime in after its first answer, not before it starts (#143) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- packages/cursor/native-e2e.test.mjs | 7 ++++++- packages/cursor/native-session.mjs | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/cursor/native-e2e.test.mjs b/packages/cursor/native-e2e.test.mjs index 010ac6a..38f6bb0 100644 --- a/packages/cursor/native-e2e.test.mjs +++ b/packages/cursor/native-e2e.test.mjs @@ -321,11 +321,16 @@ test("native retention: Task parent awaiting results permits a child sharing ses }) for (const limit of ["resultWait", "lifetime"]) test(`native retention: ${limit} expiry rebuilds supplied results on a fresh stateless Run`, async () => { - NATIVE_LIMITS[limit] = 65 + // #143: the lifetime counts from the Run's start, so a short one set before + // the first ask expired a first Run slower than it on a loaded machine. + // The result wait counts from the answer; the lifetime is brought in after + // it, the first Run having all of it. + if (limit === "resultWait") NATIVE_LIMITS[limit] = 65 const a = await agent(), account = auth(), chat = initial() const first = await a.ask(account, chat) expect(first.status).toBe(200) const owner = [...nativeSessions.entries][0] + if (limit === "lifetime") owner.expireIn(65) await until(() => owner.state === "expired") const marker = "late-result-" + limit rebuilt(await a.ask(account, continueWith(chat, first.body, [marker])), marker) diff --git a/packages/cursor/native-session.mjs b/packages/cursor/native-session.mjs index 18f5ead..16a6ef5 100644 --- a/packages/cursor/native-session.mjs +++ b/packages/cursor/native-session.mjs @@ -463,7 +463,13 @@ class NativeSession { this.terminal = false this.segment = new Segment(this, prepared.chat) this.retain(bytes(prepared.chat)) - this.lifetimeTimer = later(() => this.fail({ status: 410, message: "native Run lifetime expired" }, "expired"), this.limits.lifetime) + this.expireIn(this.limits.lifetime) + } + // expireIn sets the Run's absolute deadline ms from now: from its start, + // the whole lifetime; a test brings it in after the first answer + expireIn(ms) { + clearTimeout(this.lifetimeTimer) + this.lifetimeTimer = later(() => this.fail({ status: 410, message: "native Run lifetime expired" }, "expired"), ms) } retain(n) { if (this.retainedBytes + n > this.limits.outputBytes) invalid("native output/history retention limit reached", 503)