// Picks the likely cause of a failed start out of a container log. Pure, for tests. // "(Worker pid=171) ERROR 10-06 09:50:06 [multiproc_executor.py:1058] " and similar vLLM prefixes. const VLLM_PREFIX = /^\([\w ]+pid=\d+\)\s+(?:[A-Z]+\s+\d\d-\d\d \d\d:\d\d:\d\d\s+\[[^\]]*\]\s*)?/; // A Python exception line ("ValueError: …"), llama.cpp's "error:"/"failed to" lines. const CAUSE = /^(?:[\w.]*(?:Error|Exception): \S|.*\berror: \S|.*\bfailed to (?:load|open|allocate)\b)/i; // Generic wrappers that only say "see above". const WRAPPER = /Engine core initialization failed|See root cause above|exiting due to/i; /** Distinct cause lines in order of first appearance (at most `max`). */ export function errorCauses(lines: string[], max = 3): string[] { const out: string[] = []; for (const raw of lines) { const line = raw.replace(VLLM_PREFIX, "").trim(); if (!CAUSE.test(line) || WRAPPER.test(line) || out.includes(line)) continue; out.push(line.length > 500 ? `${line.slice(0, 500)}…` : line); if (out.length >= max) break; } return out; }