fix(schedules): retry run sandbox removal after the session sandbox is turned off mid-run

This commit is contained in:
Chris Scott committed 2026-10-25 16:39:28 -04:00
1 parent 060159f10b
commit b46dd27e5b
2 files changed
+25 -1

No files matched your search

+2 -1
View File
@@ -1663,7 +1663,8 @@ export class ScheduleService {
private async removeRunSandbox(sessionId: string | null): Promise<void> {
const runtime = this.sandbox?.runtime
if (!sessionId || !runtime) return
if (getSessionSandboxMode(this.db, sessionId)?.sandboxed !== true) return
const mode = getSessionSandboxMode(this.db, sessionId)
if (mode?.sandboxed !== true && mode?.source !== 'user') return
try {
await runtime.removeSessionSandbox(sessionId)
} catch (error) {
+23
View File
@@ -1508,6 +1508,29 @@ describe('ScheduleService', () => {
}
})
it('retries sandbox removal when the run session sandbox was turned off during the run', async () => {
for (const [mode, expected] of [
[{ ...SANDBOX_SESSION_MODE, sandboxed: false, source: 'user' }, true],
[{ ...SANDBOX_SESSION_MODE, sandboxed: false, source: 'default' }, false],
] as const) {
mocks.getScheduleJobById.mockReturnValue(sandboxJob)
const stub = createStubScheduleApi({ messages: [] })
const { service, runtime } = makeSandboxService(stub.api)
const runningRun = runWithSession('ses-run-5')
mocks.getScheduleRunById.mockReturnValue(runningRun)
mocks.updateScheduleRun.mockReturnValue({ ...runningRun, status: 'cancelled' })
mocks.getSessionSandboxMode.mockReturnValue(mode)
await service.cancelRun(42, 7, 5)
if (expected) {
expect(runtime.removeSessionSandbox).toHaveBeenCalledWith('ses-run-5')
} else {
expect(runtime.removeSessionSandbox).not.toHaveBeenCalled()
}
}
})
it('leaves the sandbox dependencies untouched for a job without an enabled sandbox', async () => {
for (const sandbox of [null, { enabled: false, resources: SANDBOX_RESOURCES }] as const) {
mocks.getScheduleJobById.mockReturnValue({ ...job, sandbox })