Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (codex,agy,claude,ollama): non-blocking /status runtime probe + hardening
[._.]/ Adam Eivy6700fa1798c5
diff --git a/client/src/pages/VideoGen.jsx b/client/src/pages/VideoGen.jsxindex 8b487c348d..3c7d1c3fd3 100644--- a/client/src/pages/VideoGen.jsx+++ b/client/src/pages/VideoGen.jsx@@ -1354,8 +1354,9 @@ export default function VideoGen() {if (!host.chip && !host.os && ids.length === 0) return null;return (<div className="text-[10px] text-gray-500 flex flex-wrap items-center gap-x-2 gap-y-0.5">- {host.chip && <span title="Host chip">{host.chip}</span>}- {host.os && <span title="Operating system">· {host.os}</span>}+ {(host.chip || host.os) && (+ <span title="Host chip + OS">{[host.chip, host.os].filter(Boolean).join(' · ')}</span>+ )}{ids.map((id) => {const fp = runtimes[id] || {};if (fp.error) {diff --git a/scripts/_runner_common.py b/scripts/_runner_common.pyindex d134e15584..2e602d3f61 100644--- a/scripts/_runner_common.py+++ b/scripts/_runner_common.py@@ -127,11 +127,13 @@ def _resolve_pkg_version(pkg: str) -> "str | None":except PackageNotFoundError:continueexcept Exception:- return None+ # An odd/transient metadata error on one spelling shouldn't skip the+ # remaining variants — keep trying, give up (None) only after all do.+ continuereturn None-def build_runtime_fingerprint(runtime_id: str, packages, extra=None) -> dict:+def build_runtime_fingerprint(runtime_id: str, packages, extra_versions=None) -> dict:"""Build a runtime-fingerprint dict — which runtime + resolved packageversions + chip/os/python — so a render (or a bug report) self-documents theexact numerical stack it ran on. Garbled/"mosaic" video output is often a@@ -147,6 +149,13 @@ def build_runtime_fingerprint(runtime_id: str, packages, extra=None) -> dict:v = _resolve_pkg_version(pkg)if v is not None:versions[pkg] = v+ # Caller-supplied versions that aren't pip distributions (e.g. the CUDA+ # toolkit version from torch.version.cuda) — merge into `versions` so they+ # render in the same list the log + /status UI already show, instead of a+ # top-level field nothing displays.+ for name, val in (extra_versions or {}).items():+ if val is not None:+ versions[name] = valfp = {"runtime": runtime_id,"versions": versions,@@ -155,19 +164,17 @@ def build_runtime_fingerprint(runtime_id: str, packages, extra=None) -> dict:"os": platform.platform(),"python": platform.python_version(),}- if extra:- fp.update({k: v for k, v in extra.items() if v is not None})return fp-def emit_runtime_fingerprint(runtime_id: str, packages, extra=None) -> dict:+def emit_runtime_fingerprint(runtime_id: str, packages, extra_versions=None) -> dict:"""Print a single `RUNTIME:<json>` line to stderr — the channel PortOS'svideoGen line handler (makeVideoGenLineHandler) parses to stamp thefingerprint onto the render job + history record. Best-effort: never raises(a fingerprint failure must not abort a render). Returns the dict it emitted(or {} on failure) so callers can also log it locally if they want."""try:- fp = build_runtime_fingerprint(runtime_id, packages, extra)+ fp = build_runtime_fingerprint(runtime_id, packages, extra_versions)print(f"RUNTIME:{json.dumps(fp)}", file=sys.stderr, flush=True)return fpexcept Exception as err: # pragma: no cover - defensivediff --git a/scripts/generate_win.py b/scripts/generate_win.pyindex 3db7745125..63c7e33c01 100644--- a/scripts/generate_win.py+++ b/scripts/generate_win.py@@ -84,7 +84,7 @@ def main():# to a specific torch+CUDA/diffusers stack on this GPU.emit_runtime_fingerprint('win', ['torch', 'diffusers', 'transformers'],- extra={'cuda': getattr(torch.version, 'cuda', None)},+ extra_versions={'cuda': getattr(torch.version, 'cuda', None)},)# The current LTX-Video 0.9.5 diffusers pipelines only accept a single# conditioning image, so --last-image is forward-compat only. Tailor thediff --git a/server/routes/videoGen.js b/server/routes/videoGen.jsindex 754ed185ce..67fc1a4128 100644--- a/server/routes/videoGen.js+++ b/server/routes/videoGen.js@@ -208,8 +208,11 @@ router.get('/status', asyncHandler(async (_req, res) => {// installed BYOV runtime — so the UI can show the exact numerical stack and// bug reports for garbled/"mosaic" output carry the version info that makes// them actionable (#1325). Best-effort: a venv that fails to probe reports- // `{ error }` and never blocks the rest of the status payload.- runtime: await resolveRuntimeFingerprint(),+ // `{ error }` and never blocks the rest of the status payload. The resolver+ // is already non-throwing (each probe resolves to `{ error }`), but guard+ // with a catch as defense-in-depth so a runtime-block failure can never+ // reject the whole /status response.+ runtime: await resolveRuntimeFingerprint().catch(() => null),});}));diff --git a/server/services/videoGen/local.js b/server/services/videoGen/local.jsindex 4bd5cfa456..5089995816 100644--- a/server/services/videoGen/local.js+++ b/server/services/videoGen/local.js@@ -210,43 +210,61 @@ export function assertByovRuntimeInstalled(runtimeId) {);}-// Cache successful runtime fingerprints per BYOV runtime for the life of the-// process. Package versions only change on a reinstall, so a hit is stable;-// errors (timeout / spawn-fail / unparseable) are NOT cached so a freshly-// finished install reflects on the next /status. invalidate on (re)install.+// Cache runtime fingerprints per BYOV runtime for the life of the process.+// An entry holds EITHER a resolved fingerprint object (success — stable until a+// reinstall) OR the in-flight Promise while a probe runs, so overlapping+// /status calls await one shared probe instead of spawning a stampede of python+// children. Errors (timeout / spawn-fail / unparseable) are NOT cached — the+// entry is dropped on failure so a freshly finished install reflects on the+// next /status. invalidate on (re)install.const fingerprintCache = new Map();export function invalidateRuntimeFingerprintCache(runtimeId) {if (runtimeId) fingerprintCache.delete(runtimeId); else fingerprintCache.clear();}+// Max bytes of probe stdout to buffer — the fingerprint JSON is a few hundred+// bytes; cap it so a misbehaving venv that spews warnings to stdout can't bloat+// the Node heap. A truncated payload simply fails to parse → { error }.+const FINGERPRINT_STDOUT_CAP = 64 * 1024;+// Run the standalone probe in one installed BYOV venv → its fingerprint object// ({ runtime, versions, chip, os, python }) or { error } on any failure.// Best-effort and bounded (15s SIGKILL) so a wedged venv can't hang /status.async function probeRuntimeFingerprint(runtimeId) {const info = BYOV_RUNTIME_INFO[runtimeId];if (!info || !existsSync(info.venvPython)) return null;- if (fingerprintCache.has(runtimeId)) return fingerprintCache.get(runtimeId);- const result = await new Promise((resolve) => {- let out = '';- const child = spawn(- info.venvPython,- [RUNTIME_FINGERPRINT_SCRIPT, runtimeId, ...(info.fingerprintPackages || [])],- { env: safeChildProcessEnv(), stdio: ['ignore', 'pipe', 'ignore'] },- );- const timer = setTimeout(() => { if (!child.killed) child.kill('SIGKILL'); resolve({ error: 'timeout' }); }, 15000);- child.stdout.on('data', (c) => { out += c.toString(); });- child.on('close', (code) => {- clearTimeout(timer);- if (code !== 0) return resolve({ error: `exit ${code}` });- // The probe prints exactly one JSON line; take the last non-empty line- // defensively in case a venv import prints a stray warning to stdout.- const lastLine = out.trim().split('\n').filter(Boolean).pop() || '';- try { resolve(JSON.parse(lastLine)); } catch { resolve({ error: 'unparseable' }); }+ // A resolved object OR an in-flight Promise both short-circuit here; only a+ // missing/dropped entry (undefined) triggers a fresh probe.+ const cached = fingerprintCache.get(runtimeId);+ if (cached !== undefined) return cached;+ const inFlight = (async () => {+ const result = await new Promise((resolve) => {+ let out = '';+ const child = spawn(+ info.venvPython,+ [RUNTIME_FINGERPRINT_SCRIPT, runtimeId, ...(info.fingerprintPackages || [])],+ { env: safeChildProcessEnv(), stdio: ['ignore', 'pipe', 'ignore'] },+ );+ const timer = setTimeout(() => { if (!child.killed) child.kill('SIGKILL'); resolve({ error: 'timeout' }); }, 15000);+ child.stdout.on('data', (c) => { if (out.length < FINGERPRINT_STDOUT_CAP) out += c.toString(); });+ child.on('close', (code) => {+ clearTimeout(timer);+ if (code !== 0) return resolve({ error: `exit ${code}` });+ // The probe prints exactly one JSON line; take the last non-empty line+ // defensively in case a venv import prints a stray warning to stdout.+ const lastLine = out.trim().split('\n').filter(Boolean).pop() || '';+ try { resolve(JSON.parse(lastLine)); } catch { resolve({ error: 'unparseable' }); }+ });+ child.on('error', () => { clearTimeout(timer); resolve({ error: 'spawn-failed' }); });});- child.on('error', () => { clearTimeout(timer); resolve({ error: 'spawn-failed' }); });- });- if (result && !result.error) fingerprintCache.set(runtimeId, result);- return result;+ // Keep successful results cached; drop the in-flight entry on failure so the+ // next request re-probes (don't cache errors).+ if (result && !result.error) fingerprintCache.set(runtimeId, result);+ else fingerprintCache.delete(runtimeId);+ return result;+ })();+ fingerprintCache.set(runtimeId, inFlight);+ return inFlight;}// Host runtime fingerprint computed in Node — cheap, always present (no python).@@ -262,16 +280,32 @@ export function hostRuntimeFingerprint() {}// Full runtime block for GET /api/video-gen/status: the Node-side host info plus-// per-installed-BYOV-runtime resolved package versions (probed in parallel,-// cached, best-effort). Surfaces "what am I running" so a garbled-output bug-// report carries the exact numerical stack without running a render (#1325).+// per-installed-BYOV-runtime resolved package versions. Surfaces "what am I+// running" so a garbled-output bug report carries the exact numerical stack+// without running a render (#1325).+//+// NON-BLOCKING: /status is the page-load probe that populates the models list ++// install/runtime gates, so it must never wait on a python fingerprint probe (a+// cold or wedged venv could otherwise stall the whole Video Gen page for up to+// the 15s probe timeout). We therefore return host info immediately plus only+// the fingerprints already resolved in cache, and kick off a background warm for+// any uncached installed runtime so its versions appear on the next /status.export async function resolveRuntimeFingerprint() {- const ids = Object.keys(BYOV_RUNTIME_INFO).filter(isByovRuntimeInstalled);- const entries = await Promise.all(ids.map(async (id) => [id, await probeRuntimeFingerprint(id)]));- return {- host: hostRuntimeFingerprint(),- runtimes: Object.fromEntries(entries.filter(([, v]) => v)),- };+ const runtimes = {};+ for (const id of Object.keys(BYOV_RUNTIME_INFO)) {+ if (!isByovRuntimeInstalled(id)) continue;+ const cached = fingerprintCache.get(id);+ if (cached && typeof cached.then !== 'function') {+ // A resolved fingerprint object (never an error — errors aren't cached).+ runtimes[id] = cached;+ } else if (cached === undefined) {+ // Not cached and not already in flight — warm it in the background; the+ // result lands in the cache for a subsequent /status. Fire-and-forget.+ probeRuntimeFingerprint(id).catch(() => {});+ }+ // An in-flight Promise means a warm is already running — skip (don't await).+ }+ return { host: hostRuntimeFingerprint(), runtimes };}export const listVideoModels = () => getVideoModels();diff --git a/server/services/videoGen/local.test.js b/server/services/videoGen/local.test.jsindex a1854ddd60..170ac59c54 100644--- a/server/services/videoGen/local.test.js+++ b/server/services/videoGen/local.test.js@@ -1080,12 +1080,14 @@ describe('runtime fingerprint (/status)', () => {expect(fp.node).toBe(process.version);});- it('resolveRuntimeFingerprint returns a host block + a per-runtime map', async () => {- // `runtimes` only contains BYOV runtimes whose venv is installed; whether- // any are present depends on the machine (CI: none; a dev box may have- // some). Assert the shape — host always present, every runtime entry is- // either a resolved fingerprint or a best-effort `{ error }` — rather than- // a specific machine's install set.+ it('resolveRuntimeFingerprint returns host info immediately + only resolved runtimes (non-blocking)', async () => {+ // /status must not block on probes, so resolveRuntimeFingerprint never+ // awaits a probe: `runtimes` contains only fingerprints already resolved in+ // cache (uncached installed runtimes are warmed in the background). Whether+ // any are present depends on the machine (CI: none; a dev box warms async),+ // so assert the shape — host always present, every included runtime entry is+ // a resolved fingerprint with a `versions` object and NO `error` (errors are+ // never cached) — rather than a specific machine's install set.const { resolveRuntimeFingerprint } = await import('./local.js');const block = await resolveRuntimeFingerprint();expect(block.host).toBeDefined();@@ -1093,7 +1095,8 @@ describe('runtime fingerprint (/status)', () => {expect(block.runtimes && typeof block.runtimes === 'object').toBe(true);for (const [id, fp] of Object.entries(block.runtimes)) {expect(typeof id).toBe('string');- expect(fp.error !== undefined || typeof fp.versions === 'object').toBe(true);+ expect(fp.error).toBeUndefined();+ expect(typeof fp.versions).toBe('object');}});