Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

perf(web): drop two workflow step hops before desktop recording dispatch

Richie McIlroybf8ec6f659ca
diff --git a/apps/web/__tests__/unit/finalize-desktop-recording.test.ts b/apps/web/__tests__/unit/finalize-desktop-recording.test.ts
index f5461d3d9..3ecc873e4 100644
--- a/apps/web/__tests__/unit/finalize-desktop-recording.test.ts
+++ b/apps/web/__tests__/unit/finalize-desktop-recording.test.ts
@@ -1115,6 +1115,40 @@ describe("workflow retry lifetime", () => {
);
});
+ it.each([
+ ["uses the generation it was started with", "generation", 0],
+ ["looks the job up when started without a generation", undefined, 1],
+ ])("%s", async (_name, generation, lookups) => {
+ withCurrent({
+ state: "queued",
+ leaseExpiresAt: null,
+ attemptId: null,
+ attemptCount: 0,
+ });
+ mocks.env.mockReturnValue({ WEB_URL: "https://self-hosted.test" });
+ const result = await finalizeDesktopRecordingWorkflow({
+ videoId,
+ userId,
+ generation,
+ });
+ expect(result).toEqual({
+ success: false,
+ reason: "media-server-unconfigured",
+ });
+ expect(mocks.ensure).toHaveBeenCalledTimes(lookups);
+ expect(mocks.defer).toHaveBeenCalledOnce();
+ });
+
+ it("reports a missing media server from the dispatch step without dispatching", async () => {
+ mocks.env.mockReturnValue({ WEB_URL: "https://self-hosted.test" });
+ await expect(startDesktopRecordingJob(fixture)).resolves.toEqual({
+ status: "media-server-unconfigured",
+ });
+ expect(mocks.defer).toHaveBeenCalledOnce();
+ expect(mocks.fetch).not.toHaveBeenCalled();
+ expect(mocks.sourceUrls).not.toHaveBeenCalled();
+ });
+
it("preserves the self-hosted playback fallback without issuing a verified cleanup receipt", async () => {
withCurrent({
state: "queued",
diff --git a/apps/web/workflows/finalize-desktop-recording.ts b/apps/web/workflows/finalize-desktop-recording.ts
index 2caeb0482..8677f1f17 100644
--- a/apps/web/workflows/finalize-desktop-recording.ts
+++ b/apps/web/workflows/finalize-desktop-recording.ts
@@ -116,7 +116,8 @@ export async function finalizeDesktopRecordingWorkflow(
): Promise<WorkflowResult> {
"use workflow";
- const generation = await ensureWorkflowJob(payload);
+ // Every step costs a queue hop (~0.7 s in prod), so skip the lookup when the caller already knows the generation.
+ const generation = payload.generation ?? (await ensureWorkflowJob(payload));
let completedJobId: string | undefined;
let mediaServerUnavailable = false;
let retainedAttempt: DesktopRecordingAttempt | undefined;
@@ -145,12 +146,12 @@ export async function finalizeDesktopRecordingWorkflow(
if (committed !== "ready") {
return { success: false, reason: committed };
}
- if (await completeWithoutMediaServerIfUnavailable(attempt)) {
- mediaServerUnavailable = true;
- break;
- }
const started = await startDesktopRecordingJob(attempt);
if (typeof started === "object") {
+ if (started.status === "media-server-unconfigured") {
+ mediaServerUnavailable = true;
+ break;
+ }
if (started.status === "capacity") {
retainedAttempt = attempt;
await sleep(started.retryAfterMs);
@@ -342,8 +343,6 @@ async function advanceDesktopRecordingAttempt(
async function completeWithoutMediaServerIfUnavailable(
attempt: DesktopRecordingAttempt,
): Promise<boolean> {
- "use step";
-
if (serverEnv().MEDIA_SERVER_URL) return false;
const deferred = await deferWithoutMediaServer(attempt);
if (deferred) {
@@ -456,9 +455,14 @@ export async function startDesktopRecordingJob(
| undefined
| { status: "deferred" }
| { status: "capacity"; retryAfterMs: number }
+ | { status: "media-server-unconfigured" }
> {
"use step";
+ if (await completeWithoutMediaServerIfUnavailable(attempt)) {
+ return { status: "media-server-unconfigured" };
+ }
+
const current = await getProcessingState(attempt);
if (!current || current.attemptId !== attempt.attemptId || !current.source) {
throw new Error("Recording processing attempt was superseded");