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.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import "./nonet.mjs"
|
||||
import { afterEach, beforeEach, expect, test } from "bun:test"
|
||||
import { afterEach, beforeEach, expect, spyOn, test } from "bun:test"
|
||||
import http2 from "node:http2"
|
||||
import { randomUUID } from "node:crypto"
|
||||
import { getEventListeners } from "node:events"
|
||||
@@ -320,6 +320,24 @@ test("native retention: Task parent awaiting results permits a child sharing ses
|
||||
expect(a.runs).toHaveLength(2)
|
||||
})
|
||||
|
||||
test("native retention: a near-expiry Run rebuilds before submitting results or exposing output", async () => {
|
||||
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]
|
||||
const now = Date.now.bind(Date)
|
||||
const clock = spyOn(Date, "now").mockImplementation(() => now() + NATIVE_LIMITS.lifetime - 1000)
|
||||
try {
|
||||
const marker = "result-before-lifetime-boundary"
|
||||
rebuilt(await a.ask(account, continueWith(chat, first.body, [marker])), marker)
|
||||
expect(a.runs).toHaveLength(2)
|
||||
expect(a.results).toEqual([])
|
||||
expect(owner.state).toBe("expired")
|
||||
expect(nativeSessions.entries.has(owner)).toBe(false)
|
||||
expect(a.errors).toEqual([])
|
||||
} finally { clock.mockRestore() }
|
||||
})
|
||||
|
||||
for (const limit of ["resultWait", "lifetime"]) test(`native retention: ${limit} expiry rebuilds supplied results on a fresh stateless Run`, async () => {
|
||||
// #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.
|
||||
|
||||
Reference in New Issue
Block a user