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.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user