mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
fix(schedules): retry run sandbox removal after the session sandbox is turned off mid-run
This commit is contained in:
1 parent
060159f10b
commit
b46dd27e5b
2 files changed
+25
-1
No files matched your search
@@ -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) {
|
||||
|
||||
@@ -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 })
|
||||
|
||||
Reference in new issue
Block a user