diegosouzapw/OmniRoute · error

Extracted video frame changed before it could be read

Error message

Extracted video frame changed before it could be read

What it means

TOCTOU guard while reading extracted frames: the file's size changed between stat() and readFile(), so the stat-based bounds no longer apply. Indicates concurrent modification or a still-running ffmpeg writing the frame.

Solutions

  1. Verify frame sizes after ffmpeg fully exits before reading
  2. Retry the read once after a short delay if the writer may still be flushing
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at src/lib/guardrails/videoBridgeRuntime.ts:950 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25). Data as JSON: /api/errors/0992aa034670b8ec. Report an issue: GitHub.

Appendix: source

Thrown at src/lib/guardrails/videoBridgeRuntime.ts:950

  let totalBytes = 0;
  const sizes: number[] = [];
  for (const frame of frames) {
    const metadata = await stat(frame.path);
    if (!metadata.isFile() || metadata.size < 1 || metadata.size > maxFrameBytes) {
      throw new Error("Extracted video frame byte limit exceeded");
    }
    totalBytes += metadata.size;
    if (totalBytes > maxTotalBytes) {
      throw new Error("Extracted video total frame byte limit exceeded");
    }
    sizes.push(metadata.size);
  }

  const output: Buffer[] = [];
  for (let index = 0; index < frames.length; index++) {
    const bytes = await readFile(frames[index].path);
    if (bytes.byteLength !== sizes[index]) {
      throw new Error("Extracted video frame changed before it could be read");
    }
    output.push(bytes);
  }
  return output;
}

export async function extractVideoFramesFromBytes(
  bytes: Uint8Array,
  options: {
    frameCount: number;
    focusWindow?: VideoFocusBounds | null;
    maxDurationSeconds: number;
    runner?: VideoCommandRunner;
    samplingPolicy?: VideoSamplingPolicy;
    signal?: AbortSignal;
    timeoutMs: number;
  }
): Promise<{

View on GitHub (pinned to a179ffed5b)