fix(runner): retry MCP init for slow Python startup
Some checks failed
CI / Lint (push) Has been cancelled
CI / Typecheck (push) Has been cancelled
CI / Broker tests (Postgres) (push) Has been cancelled
CI / Docker build (linux/amd64) (push) Has been cancelled

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Alejandro Gutiérrez
2026-04-08 15:37:04 +01:00
parent c327c282e3
commit 4ae6a86bf6

View File

@@ -278,15 +278,18 @@ const server = createServer(async (req, res) => {
const svc2 = { name, sourcePath: svcSourcePath, runtime: svcRuntime, env: svcEnv || {}, process: null, pid: null, tools: [], status: "running", pending: new Map(), logs: [], restarts: 0, healthFailures: 0, _npxBin: uvxBinPath }; const svc2 = { name, sourcePath: svcSourcePath, runtime: svcRuntime, env: svcEnv || {}, process: null, pid: null, tools: [], status: "running", pending: new Map(), logs: [], restarts: 0, healthFailures: 0, _npxBin: uvxBinPath };
services.set(name, svc2); services.set(name, svc2);
spawnService(svc2); spawnService(svc2);
await new Promise(r => setTimeout(r, 1500)); // Python MCPs take longer to start — retry init with backoff
try { let initErr = null;
svc2.tools = await initMcp(svc2); for (let attempt = 0; attempt < 3; attempt++) {
console.log(`[runner] ${name} ready (uvx), ${svc2.tools.length} tools`); await new Promise(r => setTimeout(r, 1500 + attempt * 1000));
return json(res, 200, { status: "running", tools: svc2.tools }); try {
} catch (e) { svc2.tools = await initMcp(svc2);
svc2.status = "failed"; svc2.logs.push(`MCP init failed: ${e.message}`); console.log(`[runner] ${name} ready (uvx), ${svc2.tools.length} tools`);
return json(res, 500, { error: e.message, logs: svc2.logs.slice(-10) }); return json(res, 200, { status: "running", tools: svc2.tools });
} catch (e) { initErr = e; }
} }
svc2.status = "failed"; svc2.logs.push(`MCP init failed after 3 attempts: ${initErr?.message}`);
return json(res, 500, { error: initErr?.message, logs: svc2.logs.slice(-10) });
} else if (!svcSourcePath) { } else if (!svcSourcePath) {
return json(res, 400, { error: "one of sourcePath, gitUrl, or npxPackage required" }); return json(res, 400, { error: "one of sourcePath, gitUrl, or npxPackage required" });
} }