Repository Public
1/**2 * Child process of the crash suite. Runs the real engine (real kernel, real tools, scripted provider) on3 * DATABASE_URL and SIGKILLs ITSELF when step KILL_SEQ of RUN_ID reaches KILL_BOUNDARY. Without a kill it4 * exits 0 once the run is terminal or waiting on the owner.5 */6import { createKernel, runWorkerLoop } from '@aos/kernel';7import { agentLogic } from '../../src/index.js';8import { scriptedProvider } from '../../src/testkit/index.js';9import { SCENARIOS } from './scenario.js';1011const env = process.env;12const runId = env.RUN_ID ?? '';13const killSeq = Number(env.KILL_SEQ ?? -1);14const killBoundary = env.KILL_BOUNDARY ?? '';15const k = createKernel({ databaseUrl: env.DATABASE_URL, dataDir: env.DATA_DIR, poolMax: 6 });16const provider = scriptedProvider(SCENARIOS[env.SCENARIO ?? 'main'] ?? [], { logFile: env.LOG_FILE });17const ac = new AbortController();1819const loop = runWorkerLoop({20 kernel: k,21 logic: agentLogic({ kernel: k, provider: () => provider, workspaceRoot: env.WORKSPACE_ROOT, denyOwnerFolders: false, extraDenyRead: [] }),22 signal: ac.signal,23 concurrency: 1,24 leaseMs: Number(env.LEASE_MS ?? 700),25 heartbeatMs: 150,26 pollMs: 40,27 inlineSleepMs: 100,28 janitorMs: false,29 dailyBudgetUsd: null,30 stopGraceMs: 3000,31 workerId: `crash-${process.pid}`,32 hooks: {33 boundary: (b) => {34 if (b.runId === runId && b.seq === killSeq && b.boundary === killBoundary) process.kill(process.pid, 'SIGKILL');35 },36 },37});3839const timer = setInterval(() => {40 k.pool.query('SELECT status FROM runs WHERE id = $1', [runId]).then(41 (r) => {42 const status = (r.rows[0] as { status?: string } | undefined)?.status;43 if (status && status !== 'queued' && status !== 'running') ac.abort();44 },45 () => undefined,46 );47}, 40);4849await loop;50clearInterval(timer);51await k.close();52process.exit(0);53