feat(schedules): run scheduled jobs in a per-job sandbox microVM

This commit is contained in:
Chris Scott committed 2026-10-25 14:49:38 -04:00
1 parent 11a2661cc6
commit 070cb2f729
28 files changed
+1069 -83

No files matched your search

@@ -6,6 +6,7 @@ import migration015 from '../../src/db/migrations/015-schedule-worktree-isolatio
import migration021 from '../../src/db/migrations/021-drop-schedule-run-workspace-id'
import migration022 from '../../src/db/migrations/022-schedule-runs-session-index'
import migration024 from '../../src/db/migrations/024-schedule-runs-viewed-at'
import migration202610251900 from '../../src/db/migrations/202610251900-schedule-sandbox-config'
describe('schedule migrations', () => {
it('creates schedule jobs with nullable interval minutes in v7', () => {
@@ -288,3 +289,31 @@ describe('migration 024 - schedule runs viewed at', () => {
db.close()
})
})
describe('migration 202610251900 - schedule sandbox config', () => {
it('adds the nullable sandbox_config column and is idempotent', () => {
const db = new Database(':memory:')
db.run('CREATE TABLE schedule_jobs (id INTEGER PRIMARY KEY, name TEXT)')
migration202610251900.up(db)
migration202610251900.up(db)
const columns = (db.prepare('PRAGMA table_info(schedule_jobs)').all() as { name: string }[]).map((column) => column.name)
expect(columns).toContain('sandbox_config')
db.close()
})
it('drops the column on rollback', () => {
const db = new Database(':memory:')
db.run('CREATE TABLE schedule_jobs (id INTEGER PRIMARY KEY, name TEXT)')
migration202610251900.up(db)
migration202610251900.down(db)
const columns = (db.prepare('PRAGMA table_info(schedule_jobs)').all() as { name: string }[]).map((column) => column.name)
expect(columns).not.toContain('sandbox_config')
db.close()
})
})
@@ -36,6 +36,7 @@ describe('schedule permission config persistence', () => {
mcpServers: [],
branch: null,
workspaceMode: 'worktree',
sandbox: null,
nextRunAt: Date.now() + 3600000,
...overrides,
})
@@ -108,4 +109,25 @@ describe('schedule permission config persistence', () => {
expect(updated!.prompt).toBe('Updated prompt')
expect(updated!.permissionConfig).toEqual(config)
})
it('round-trips a sandbox config', () => {
const sandbox = { enabled: true, resources: { cpus: 4, memoryMib: 12288 } }
const created = createScheduleJob(db, 1, baseInput({ sandbox }))
expect(created.sandbox).toEqual(sandbox)
const fetched = getScheduleJobById(db, 1, created.id)
expect(fetched).not.toBeNull()
expect(fetched!.sandbox).toEqual(sandbox)
})
it('round-trips a null sandbox config', () => {
const created = createScheduleJob(db, 1, baseInput({ sandbox: null }))
expect(created.sandbox).toBeNull()
const fetched = getScheduleJobById(db, 1, created.id)
expect(fetched).not.toBeNull()
expect(fetched!.sandbox).toBeNull()
})
})
+4
View File
@@ -117,6 +117,7 @@ describe('schedule database queries', () => {
mcpServers: [],
branch: null,
workspaceMode: 'worktree',
sandbox: null,
nextRunAt: Date.UTC(2026, 2, 9, 13, 0, 0),
})
@@ -139,6 +140,7 @@ describe('schedule database queries', () => {
null,
null,
'worktree',
null,
expect.any(Number),
expect.any(Number),
null,
@@ -179,6 +181,7 @@ describe('schedule database queries', () => {
mcpServers: [],
branch: null,
workspaceMode: 'worktree',
sandbox: null,
nextRunAt: null,
})
@@ -199,6 +202,7 @@ describe('schedule database queries', () => {
null,
'worktree',
null,
null,
expect.any(Number),
null,
42,