// RENDER MODE, AS A WAIT (common/lib/renderPriority.mjs; AGENTS.md "Render // mode"): work that is not heavy enough for the heavy slot but still takes // cores a render the operator is waiting for wants — a taller clip window cut // from a saved copy (the height tier) — waits while the hold is on, the way // the lanes are held. Read as the heavy slot's gate reads it. // // SERVER-ONLY. import { describeRenderPriority, readRenderPriority, renderPriorityFile } from "./renderPriority.mjs"; /** Render mode, as the heavy slot's gate reads it: who holds it, or null. */ export function renderModeHeldNow(): string | null { try { const s = readRenderPriority(renderPriorityFile(process.env, { root: process.cwd() })); return s.held && s.state ? describeRenderPriority(s.state) : null; } catch { return null; // an unreadable state file holds nothing (queue-lock's rule) } } export const RENDER_HOLD_POLL_MS = 30_000; // Wait while `held()` names a holder: one line when the wait starts, one when // it ends. Returns how long it waited (0: not held), or null when `signal` // ended the wait first. export async function waitWhileRenderHeld(opts: { held?: () => string | null; sleep: (ms: number, signal?: AbortSignal) => Promise; onLog: (line: string) => void; what: string; signal?: AbortSignal; pollMs?: number; now?: () => number; }): Promise { const held = opts.held ?? renderModeHeldNow; const now = opts.now ?? Date.now; let by = held(); if (!by) return 0; const start = now(); opts.onLog(` ⏸ ${opts.what}: render mode holds the machine (${by}) — waiting.`); while (by) { if (opts.signal?.aborted) return null; await opts.sleep(opts.pollMs ?? RENDER_HOLD_POLL_MS, opts.signal); if (opts.signal?.aborted) return null; by = held(); } const waited = now() - start; opts.onLog(` ▶ ${opts.what}: render mode ended — waited ${Math.round(waited / 1000)}s.`); return waited; }