From f40c410edd649aa4c5f4f8c0a79f642d1f8d3610 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Wed, 29 Jul 2026 18:37:34 -0700 Subject: [PATCH] fix(tests): stop pi-lifetime asserting the ceiling on a racing boundary MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `keeps the ceiling when the run outlives it` passed a deadline of exactly `PI_SANDBOX_MAX_LIFETIME_MS`, then asserted the resolved lifetime equalled that ceiling. But the lifetime is `Math.min(ceiling, deadline - Date.now())`, so the remaining budget decays below the ceiling as soon as one millisecond of test time elapses and `Math.min` returns the budget instead. It passed only when zero milliseconds happened to pass, which is why it failed CI as `expected 5399999 to be 5400000` — 1 failure in 16,047. Demonstrated: with the old input, a 5ms delay before the assertion yields 5399994 (off by 6ms); with a deadline 60s past the ceiling it yields 5400000 exactly, regardless of elapsed time. An equal deadline was also not the case the test name describes — the run has to *outlive* the ceiling, not match it — so raising it past the ceiling fixes the assertion and the intent together. Derives the input from `PI_SANDBOX_MAX_LIFETIME_MS` rather than restating 90 minutes, so the test cannot drift if the async execution ceiling moves. Also drops the old comment's claim that "the provider cap still wins": the provider cap is 24h, far above the 90m async ceiling, so the ceiling is what wins here. --- .../lib/execution/remote-sandbox/pi-lifetime.test.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/sim/lib/execution/remote-sandbox/pi-lifetime.test.ts b/apps/sim/lib/execution/remote-sandbox/pi-lifetime.test.ts index da2cdc5a294..bc155e3361d 100644 --- a/apps/sim/lib/execution/remote-sandbox/pi-lifetime.test.ts +++ b/apps/sim/lib/execution/remote-sandbox/pi-lifetime.test.ts @@ -127,9 +127,14 @@ describe('resolvePiRunLifetimeMs', () => { '@/lib/execution/remote-sandbox/pi-lifetime' ) - // The async ceiling is 90 minutes, above what E2B will grant, so the - // provider cap still wins. - const timeout = createTimeoutAbortController(90 * 60 * 1000) + // The deadline must be strictly past the ceiling for the ceiling to win. + // Passing exactly `PI_SANDBOX_MAX_LIFETIME_MS` made this a coin flip: the + // remaining budget is `deadline - Date.now()`, so it decays below the ceiling + // as soon as one millisecond of test time elapses, and `Math.min` then + // returns the remaining budget instead (`expected 5399999 to be 5400000`). + // An equal deadline also isn't the case the name describes — the run has to + // outlive the ceiling, not match it. + const timeout = createTimeoutAbortController(PI_SANDBOX_MAX_LIFETIME_MS + 60_000) expect(resolvePiRunLifetimeMs(timeout.signal)).toBe(PI_SANDBOX_MAX_LIFETIME_MS) timeout.cleanup()