Skip to content

Commit a38c682

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
fix(pi): preserve Daytona babysit budget
1 parent bba6bf6 commit a38c682

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

apps/sim/executor/handlers/pi/babysit-backend.test.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const {
1212
mockReplyAndResolve,
1313
mockRequestReview,
1414
mockReviewLanded,
15+
mockResolvePiSandboxLifetime,
1516
} = vi.hoisted(() => ({
1617
mockWithPiSandbox: vi.fn(),
1718
mockFetchSnapshot: vi.fn(),
@@ -21,6 +22,7 @@ const {
2122
mockReplyAndResolve: vi.fn(),
2223
mockRequestReview: vi.fn(),
2324
mockReviewLanded: vi.fn(),
25+
mockResolvePiSandboxLifetime: vi.fn(),
2426
}))
2527

2628
vi.mock('@/lib/execution/remote-sandbox', () => ({
@@ -30,6 +32,14 @@ vi.mock('@/lib/execution/cancellation', () => ({
3032
isRedisCancellationEnabled: () => false,
3133
isExecutionCancelled: vi.fn().mockResolvedValue(false),
3234
}))
35+
vi.mock('@/lib/execution/remote-sandbox/pi-lifetime', async (importOriginal) => {
36+
const original =
37+
await importOriginal<typeof import('@/lib/execution/remote-sandbox/pi-lifetime')>()
38+
return {
39+
...original,
40+
resolvePiSandboxLifetimeMs: mockResolvePiSandboxLifetime,
41+
}
42+
})
3343
vi.mock('@/executor/handlers/pi/babysit-github', async (importOriginal) => {
3444
const original = await importOriginal<typeof import('@/executor/handlers/pi/babysit-github')>()
3545
return {
@@ -44,7 +54,11 @@ vi.mock('@/executor/handlers/pi/babysit-github', async (importOriginal) => {
4454
}
4555
})
4656

47-
import { runBabysitPiWithOptions } from '@/executor/handlers/pi/babysit-backend'
57+
import { getMaxExecutionTimeout } from '@/lib/core/execution-limits'
58+
import {
59+
resolveBabysitExecutionBudgetMs,
60+
runBabysitPiWithOptions,
61+
} from '@/executor/handlers/pi/babysit-backend'
4862
import { BABYSIT_ROUND_PATH } from '@/executor/handlers/pi/babysit-round'
4963
import type { PiBabysitRunParams } from '@/executor/handlers/pi/backend'
5064
import { DIFF_PATH } from '@/executor/handlers/pi/cloud-shared'
@@ -195,6 +209,7 @@ function makeRunner(options: {
195209
describe('runBabysitPiWithOptions', () => {
196210
beforeEach(() => {
197211
vi.clearAllMocks()
212+
mockResolvePiSandboxLifetime.mockReturnValue(undefined)
198213
mockFetchDiagnostics.mockResolvedValue(new Map([['check:ci', 'failure output']]))
199214
mockReplyAndResolve.mockResolvedValue({
200215
repliesPosted: 1,
@@ -213,6 +228,10 @@ describe('runBabysitPiWithOptions', () => {
213228
mockReviewLanded.mockResolvedValue(false)
214229
})
215230

231+
it('uses the platform execution budget when the provider has no absolute lifetime', () => {
232+
expect(resolveBabysitExecutionBudgetMs()).toBe(getMaxExecutionTimeout())
233+
})
234+
216235
it('returns clean before sandbox creation when the PR already needs nothing', async () => {
217236
mockFetchSnapshot.mockResolvedValue(snapshot)
218237
mockFetchThreads.mockResolvedValue({

apps/sim/executor/handlers/pi/babysit-backend.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
import { createLogger } from '@sim/logger'
88
import { getErrorMessage } from '@sim/utils/errors'
99
import { truncate } from '@sim/utils/string'
10+
import { getMaxExecutionTimeout } from '@/lib/core/execution-limits'
1011
import { sleepUntilAborted } from '@/lib/data-drains/destinations/utils'
1112
import { isExecutionCancelled, isRedisCancellationEnabled } from '@/lib/execution/cancellation'
1213
import { type PiSandboxRunner, withPiSandbox } from '@/lib/execution/remote-sandbox'
13-
import {
14-
PI_SANDBOX_MAX_LIFETIME_MS,
15-
resolvePiSandboxLifetimeMs,
16-
} from '@/lib/execution/remote-sandbox/pi-lifetime'
14+
import { resolvePiSandboxLifetimeMs } from '@/lib/execution/remote-sandbox/pi-lifetime'
1715
import {
1816
assertBabysitPinned,
1917
type BabysitCheckState,
@@ -513,6 +511,11 @@ function outstandingReason(
513511
return fallback
514512
}
515513

514+
/** Resolves the host-side run budget without imposing E2B's lifetime on other providers. */
515+
export function resolveBabysitExecutionBudgetMs(executionBudgetMs?: number): number {
516+
return executionBudgetMs ?? resolvePiSandboxLifetimeMs() ?? getMaxExecutionTimeout()
517+
}
518+
516519
/** Injectable variant used by deterministic multi-round tests. */
517520
export async function runBabysitPiWithOptions(
518521
params: PiBabysitRunParams,
@@ -540,8 +543,7 @@ export async function runBabysitPiWithOptions(
540543
)
541544
const { signal } = cancellation
542545
const startedAt = Date.now()
543-
const lifetime =
544-
params.executionBudgetMs ?? resolvePiSandboxLifetimeMs() ?? PI_SANDBOX_MAX_LIFETIME_MS
546+
const lifetime = resolveBabysitExecutionBudgetMs(params.executionBudgetMs)
545547
if (lifetime < MIN_ROUND_BUDGET_MS) {
546548
cancellation.cleanup()
547549
throw new Error(

0 commit comments

Comments
 (0)