Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix(super-tabs): kill a scheduler solver that runs past its limit (#1831)

0xken156f60659e5390
diff --git a/cli/src/superTabs/planCommand.spec.ts b/cli/src/superTabs/planCommand.spec.ts
index dcde91c64..0efb68632 100644
--- a/cli/src/superTabs/planCommand.spec.ts
+++ b/cli/src/superTabs/planCommand.spec.ts
@@ -147,6 +147,22 @@ describe('runSolver', () => {
.toEqual({ error: 'SOLVER_FAILED', detail: expect.stringContaining('The scheduler stopped (exit 1)') })
})
+ // Diego's issue, 2026-10-27: --time-limit is only the solver's own promise. A python3 stuck on an import or in a deadlock
+ // left the plan command waiting forever, and its private copy of the package on disk.
+ it.skipIf(process.platform === 'win32')('a solver that never exits is killed and reported', async () => {
+ const dataDir = temp(), bin = temp()
+ // A first run publishes the package; with a file missing from it, the next run works from a private copy of its own.
+ await runSolver(instance, { dataDir, python: join(bin, 'no-python3') })
+ const [version] = readdirSync(join(dataDir, 'scheduler'))
+ rmSync(join(dataDir, 'scheduler', version!, 'scheduler', 'solver.py'))
+ const hung = join(bin, 'python3')
+ writeFileSync(hung, '#!/bin/sh\nexec sleep 60\n', { mode: 0o755 })
+ const started = Date.now()
+ expect(await runSolver(instance, { dataDir, python: hung, timeoutMs: 200 })).toEqual({ error: 'SOLVER_FAILED', detail: 'timed out' })
+ expect(Date.now() - started).toBeLessThan(2_000)
+ expect(readdirSync(join(dataDir, 'scheduler'))).toEqual([version])
+ }, 10_000)
+
it.skipIf(!hasPython('python3'))('says when OR-Tools is not installed', async () => {
const fake = temp()
mkdirSync(join(fake, 'ortools'))
diff --git a/cli/src/superTabs/planCommand.ts b/cli/src/superTabs/planCommand.ts
index df1a0985f..2d3790e02 100644
--- a/cli/src/superTabs/planCommand.ts
+++ b/cli/src/superTabs/planCommand.ts
@@ -50,7 +50,7 @@ function packageFolder(root: string, files: Record<string, string>): { dir: stri
}
/** Runs `python -m scheduler plan` on [instance], with the package written once per version under the data folder. */
-export async function runSolver(instance: Json, options: { dataDir: string; python?: string; pythonPath?: string[] }): ReturnType<SolverRun> {
+export async function runSolver(instance: Json, options: { dataDir: string; python?: string; pythonPath?: string[]; timeoutMs?: number }): ReturnType<SolverRun> {
const files = schedulerFiles()
const version = createHash('sha256').update(JSON.stringify(files)).digest('hex').slice(0, 16)
const { dir: root, own } = packageFolder(join(options.dataDir, 'scheduler', version), files)
@@ -59,13 +59,23 @@ export async function runSolver(instance: Json, options: { dataDir: string; pyth
const child = spawn(python, ['-m', 'scheduler', 'plan', '--time-limit', String(TIME_LIMIT_SECONDS)], {
cwd: root, env: { ...process.env, PYTHONPATH: [...(options.pythonPath ?? []), root].join(delimiter) }, stdio: ['pipe', 'pipe', 'pipe'],
})
+ // Diego's issue, 2026-10-27: --time-limit is the solver's own promise; a python3 stuck on an import or in a deadlock left
+ // the command waiting forever and its private package copy on disk. Past the limit and a margin to start, it is killed.
+ const timer = setTimeout(() => {
+ child.kill('SIGKILL')
+ resolve({ error: 'SOLVER_FAILED', detail: 'timed out' })
+ }, options.timeoutMs ?? TIME_LIMIT_SECONDS * 1000 + 20_000)
let out = '', err = ''
child.stdout.on('data', chunk => { out += chunk })
child.stderr.on('data', chunk => { err += chunk })
- child.on('error', (error: NodeJS.ErrnoException) => resolve(error.code === 'ENOENT'
- ? { error: 'PYTHON_MISSING', detail: `Python 3 is not installed on this machine (${python}). ${INSTALL}` }
- : { error: 'SOLVER_FAILED', detail: error.message }))
+ child.on('error', (error: NodeJS.ErrnoException) => {
+ clearTimeout(timer)
+ resolve(error.code === 'ENOENT'
+ ? { error: 'PYTHON_MISSING', detail: `Python 3 is not installed on this machine (${python}). ${INSTALL}` }
+ : { error: 'SOLVER_FAILED', detail: error.message })
+ })
child.on('close', code => {
+ clearTimeout(timer)
let value: Json | null = null
try { value = object(JSON.parse(out)) } catch { /* Not JSON: said below with the solver's own words. */ }
if (value && typeof value.error === 'string') resolve({ error: value.error, detail: String(value.detail ?? '') })