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)