Skip to content

Write HTML. Render video. Built for agents.

fix(engine): classify a broken encoder pipe as io, not authoring

Vance Ingalls95cbf566347b
diff --git a/packages/engine/src/services/captureFailure.test.ts b/packages/engine/src/services/captureFailure.test.ts
index b326374dcd..4d27b3b5fe 100644
--- a/packages/engine/src/services/captureFailure.test.ts
+++ b/packages/engine/src/services/captureFailure.test.ts
@@ -69,6 +69,20 @@ describe("classifyCaptureFailure", () => {
expect(Object.isFrozen(failure.workerDiagnostics[0]?.lines)).toBe(true);
});
+ it("classifies a broken encoder pipe as io, not authoring", () => {
+ // The streaming encoder's stdin write fails this way when ffmpeg dies
+ // first. Bucketed as authoring, PostHog blamed the composition for a host
+ // event and the cohort could not be root-caused.
+ for (const code of ["EPIPE", "EOF", "ECONNRESET"]) {
+ const withCode = Object.assign(new Error(`write ${code}`), { code });
+ expect(classifyCaptureFailure(withCode).kind).toBe("io");
+ // Flattened through a worker-pool message boundary the code is lost;
+ // the message alone must still classify.
+ expect(classifyCaptureFailure(new Error(`[Parallel] write ${code}`)).kind).toBe("io");
+ }
+ expect(classifyCaptureFailure(new Error("write to EPIPEline")).kind).toBe("authoring");
+ });
+
it("classifies repeated operation text in linear time", () => {
const repeatedCopy = "copy".repeat(25_000);
diff --git a/packages/engine/src/services/captureFailure.ts b/packages/engine/src/services/captureFailure.ts
index c47153b215..b252fc16cc 100644
--- a/packages/engine/src/services/captureFailure.ts
+++ b/packages/engine/src/services/captureFailure.ts
@@ -125,10 +125,24 @@ function hasIoOperationFailure(message: string): boolean {
);
}
+/**
+ * A write to a pipe whose reader has gone: EPIPE on darwin/linux, EOF on
+ * win32 (libuv reports a closed named pipe as UV_EOF), ECONNRESET on a
+ * socket. All three mean the streaming encoder died under us, which is an io
+ * fact about the host, not an authoring defect in the composition.
+ */
+const BROKEN_PIPE_MESSAGE = /\bwrite (?:EPIPE|EOF|ECONNRESET)\b/;
+
function ioError(error: unknown, message: string): boolean {
const code = error instanceof Error ? (error as NodeJS.ErrnoException).code : undefined;
return (
- Boolean(code && /^(?:EACCES|EEXIST|EIO|EMFILE|ENFILE|ENOENT|ENOSPC|EPERM|EROFS)$/.test(code)) ||
+ Boolean(
+ code &&
+ /^(?:EACCES|ECONNRESET|EEXIST|EIO|EMFILE|ENFILE|ENOENT|ENOSPC|EOF|EPERM|EPIPE|EROFS)$/.test(
+ code,
+ ),
+ ) ||
+ BROKEN_PIPE_MESSAGE.test(message) ||
hasIoOperationFailure(message)
);
}