Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(web): size a recording's transfer budget for every automatic attempt

Richie McIlroyfc0ab0cf8a82
diff --git a/apps/web/__tests__/unit/media-processing-budget.test.ts b/apps/web/__tests__/unit/media-processing-budget.test.ts
index 6e58c73ab..dd4c67840 100644
--- a/apps/web/__tests__/unit/media-processing-budget.test.ts
+++ b/apps/web/__tests__/unit/media-processing-budget.test.ts
@@ -1,6 +1,7 @@
import { beforeEach, expect, it, vi } from "vitest";
import {
getMediaProcessingReservation,
+ RECORDING_PROCESSING_ATTEMPTS,
reserveMediaProcessingBudget,
} from "@/lib/media-processing-budget";
@@ -104,18 +105,22 @@ it("reuses an attempt reservation across dispatch retries and midnight", async (
]);
});
-it("still bounds repeated processing of the same immutable source", async () => {
+it("allows every automatic attempt before bounding repeated processing of the same source", async () => {
const input = {
videoId: "video",
generation: "generation",
sourceBytes: 1024 ** 3,
};
- for (let index = 0; index < 3; index++)
+ expect(RECORDING_PROCESSING_ATTEMPTS).toBe(5);
+ for (let index = 0; index < RECORDING_PROCESSING_ATTEMPTS; index++)
await reserveMediaProcessingBudget({
...input,
attemptId: `attempt-${index}`,
});
await expect(
- reserveMediaProcessingBudget({ ...input, attemptId: "attempt-4" }),
+ reserveMediaProcessingBudget({
+ ...input,
+ attemptId: `attempt-${RECORDING_PROCESSING_ATTEMPTS}`,
+ }),
).rejects.toThrow("recording transfer budget exhausted");
});
diff --git a/apps/web/lib/desktop-recording-jobs.ts b/apps/web/lib/desktop-recording-jobs.ts
index b0228443f..a46f632b1 100644
--- a/apps/web/lib/desktop-recording-jobs.ts
+++ b/apps/web/lib/desktop-recording-jobs.ts
@@ -28,6 +28,7 @@ import {
type RecordingVerification,
recordingVerificationSchema,
} from "@/lib/desktop-recording-verification";
+import { RECORDING_PROCESSING_ATTEMPTS } from "@/lib/media-processing-budget";
export const DESKTOP_RECORDING_LEASE_MS = 5 * 60 * 1_000;
export const DESKTOP_RECORDING_SOURCE_RETRY_MS = 60 * 60 * 1_000;
@@ -36,7 +37,7 @@ export const DESKTOP_RECORDING_DELETING = "video-deleting";
export const DESKTOP_RECORDING_SOURCE_REUPLOAD_REQUIRED =
"source-reupload-required";
export const DESKTOP_RECORDING_RETRY_EXHAUSTED = "processing-retry-exhausted";
-const MAX_AUTOMATIC_ATTEMPTS = 5;
+const MAX_AUTOMATIC_ATTEMPTS = RECORDING_PROCESSING_ATTEMPTS;
const RETRY_EXHAUSTED_MESSAGE =
"Processing paused after repeated failures. Your uploaded recording is retained. Please contact support.";
diff --git a/apps/web/lib/media-processing-budget.ts b/apps/web/lib/media-processing-budget.ts
index 0ee62338a..06fb214b1 100644
--- a/apps/web/lib/media-processing-budget.ts
+++ b/apps/web/lib/media-processing-budget.ts
@@ -13,16 +13,21 @@ export class MediaProcessingBudgetError extends Error {
const key = (parts: string[]) =>
createHash("sha256").update(JSON.stringify(parts)).digest("hex");
+// A recording's transfer budget covers every automatic attempt, so the attempt limit (not the
+// budget) decides when processing stops. Media workers read sources in-region, so retries cost time, not egress.
+export const RECORDING_PROCESSING_ATTEMPTS = 5;
+
export function getMediaProcessingReservation(sourceBytes: number) {
if (
!Number.isSafeInteger(sourceBytes) ||
sourceBytes <= 0 ||
- sourceBytes > Number.MAX_SAFE_INTEGER / 12
+ sourceBytes > Number.MAX_SAFE_INTEGER / 20
)
throw new Error("Invalid processing source size");
+ const attemptBytes = sourceBytes * 3 + 16 * MiB;
return {
- attemptBytes: sourceBytes * 3 + 16 * MiB,
- recordingBytes: sourceBytes * 9 + 80 * MiB,
+ attemptBytes,
+ recordingBytes: attemptBytes * RECORDING_PROCESSING_ATTEMPTS,
};
}