Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(web): report a retried recording whose workflow did not start
Richie McIlroyd2860a1d77f4
diff --git a/apps/web/__tests__/unit/admin-retry-blocked-recordings.test.ts b/apps/web/__tests__/unit/admin-retry-blocked-recordings.test.tsindex 21fe24955..cf78e0824 100644--- a/apps/web/__tests__/unit/admin-retry-blocked-recordings.test.ts+++ b/apps/web/__tests__/unit/admin-retry-blocked-recordings.test.ts@@ -3,28 +3,63 @@ import { beforeEach, describe, expect, it, vi } from "vitest";const mocks = vi.hoisted(() => ({user: vi.fn(),retry: vi.fn(),- queue: vi.fn(),+ state: vi.fn(),+ ensure: vi.fn(),+ attach: vi.fn(),+ dispatchFailure: vi.fn(),+ start: vi.fn(),}));vi.mock("@cap/database/auth/session", () => ({ getCurrentUser: mocks.user }));+vi.mock("@cap/database", () => ({ db: vi.fn() }));+vi.mock("@cap/database/schema", () => ({ users: {}, videos: {} }));vi.mock("@cap/env", () => ({serverEnv: () => ({ WEB_URL: "https://cap.test" }),}));vi.mock("@/lib/messenger/constants", () => ({MESSENGER_ADMIN_EMAIL: "[email protected]",}));+vi.mock("workflow/api", () => ({ start: mocks.start }));+vi.mock("@/workflows/finalize-desktop-recording", () => ({+ finalizeDesktopRecordingWorkflow: vi.fn(),+}));+vi.mock("@/lib/transcribe", () => ({ transcribeVideo: vi.fn() }));+vi.mock("@/lib/ai-generation-entitlement", () => ({+ isAiGenerationEnabledForUser: vi.fn(),+}));vi.mock("@/lib/desktop-recording-jobs", () => ({retryBlockedDesktopRecording: mocks.retry,-}));-vi.mock("@/lib/desktop-segments-finalization", () => ({- queueDesktopSegmentsFinalization: mocks.queue,+ getProcessingState: mocks.state,+ ensureSegmentProcessingJob: mocks.ensure,+ isDesktopRecordingJobRecoverable: () => true,+ attachWorkflowRun: mocks.attach,+ recordWorkflowDispatchFailure: mocks.dispatchFailure,+ DesktopRecordingSourceBlockedError: class extends Error {},+ SourceCommitPendingError: class extends Error {},}));import { adminRetryBlockedRecordings } from "@/actions/admin/retry-blocked-recordings";+const source = { kind: "mp4" };+let current: Record<string, unknown>;+beforeEach(() => {vi.clearAllMocks();mocks.user.mockResolvedValue({ email: "[email protected]" });- mocks.queue.mockResolvedValue("queued");+ mocks.retry.mockResolvedValue({+ status: "queued",+ ownerId: "owner1",+ previousErrorCode: "processing-budget-exhausted",+ });+ current = { state: "retry", source, errorCode: null };+ mocks.ensure.mockImplementation(async () => ({+ job: { generation: "generation", ...current },+ created: false,+ }));+ mocks.state.mockImplementation(async () => ({ ...current }));+ mocks.start.mockResolvedValue({ runId: "run" });+ mocks.dispatchFailure.mockImplementation(async () => {+ current = { ...current, errorCode: "workflow-dispatch-failed" };+ });});describe("admin retry of blocked recordings", () => {@@ -44,58 +79,59 @@ describe("admin retry of blocked recordings", () => {expect(mocks.retry).not.toHaveBeenCalled();});- it("queues retryable recordings once each and reports the rest without starting them", async () => {- mocks.retry.mockImplementation(async ({ videoId }: { videoId: string }) =>- videoId === "blocked1"- ? {- status: "queued",- ownerId: "owner1",- previousErrorCode: "processing-budget-exhausted",- }- : videoId === "missing1"- ? { status: "not-found" }- : { status: "not-retryable", state: "verified", errorCode: null },- );- const results = await adminRetryBlockedRecordings(- "https://cap.so/s/blocked1\nmissing1, verified1 blocked1",- );- expect(results).toEqual([+ it("starts the finalize workflow for a released recording", async () => {+ expect(await adminRetryBlockedRecordings("blocked1")).toEqual([{- input: "https://cap.so/s/blocked1",+ input: "blocked1",videoId: "blocked1",status: "queued",- detail: "was processing-budget-exhausted; queued",+ detail: "was processing-budget-exhausted",shareUrl: "https://cap.test/s/blocked1",},- { input: "missing1", videoId: "missing1", status: "not-found" },- {- input: "verified1",- videoId: "verified1",- status: "not-retryable",- detail: "verified",- },]);- expect(mocks.retry).toHaveBeenCalledTimes(3);- expect(mocks.queue).toHaveBeenCalledTimes(1);- expect(mocks.queue).toHaveBeenCalledWith({+ expect(mocks.start).toHaveBeenCalledOnce();+ expect(mocks.attach).toHaveBeenCalledWith({videoId: "blocked1",- userId: "owner1",+ generation: "generation",+ workflowRunId: "run",});});- it("reports a failed workflow start instead of throwing", async () => {- mocks.retry.mockResolvedValue({- status: "queued",- ownerId: "owner1",- previousErrorCode: "source-invalid",- });- mocks.queue.mockRejectedValue(new Error("Workflow dispatch failed"));+ it("reports a workflow that failed to start instead of claiming it was queued", async () => {+ mocks.start.mockRejectedValue(new Error("Workflow API unavailable"));expect(await adminRetryBlockedRecordings("blocked1")).toEqual([{input: "blocked1",- status: "failed",- detail: "Workflow dispatch failed",+ videoId: "blocked1",+ status: "dispatch-failed",+ detail: "the workflow did not start; automatic recovery will retry it",+ shareUrl: "https://cap.test/s/blocked1",},]);+ expect(mocks.dispatchFailure).toHaveBeenCalledOnce();+ });++ it("handles each video once and reports the rest without starting them", async () => {+ mocks.retry.mockImplementation(async ({ videoId }: { videoId: string }) =>+ videoId === "blocked1"+ ? {+ status: "queued",+ ownerId: "owner1",+ previousErrorCode: "source-invalid",+ }+ : videoId === "missing1"+ ? { status: "not-found" }+ : { status: "not-retryable", state: "verified", errorCode: null },+ );+ const results = await adminRetryBlockedRecordings(+ "https://cap.so/s/blocked1\nmissing1, verified1 blocked1",+ );+ expect(results.map(({ videoId, status }) => [videoId, status])).toEqual([+ ["blocked1", "queued"],+ ["missing1", "not-found"],+ ["verified1", "not-retryable"],+ ]);+ expect(mocks.retry).toHaveBeenCalledTimes(3);+ expect(mocks.start).toHaveBeenCalledOnce();});});diff --git a/apps/web/actions/admin/retry-blocked-recordings.ts b/apps/web/actions/admin/retry-blocked-recordings.tsindex 0112f9910..6b723f5ff 100644--- a/apps/web/actions/admin/retry-blocked-recordings.ts+++ b/apps/web/actions/admin/retry-blocked-recordings.ts@@ -2,7 +2,10 @@import { serverEnv } from "@cap/env";import { parseAdminVideoId, requireAdmin } from "@/lib/admin-access";-import { retryBlockedDesktopRecording } from "@/lib/desktop-recording-jobs";+import {+ getProcessingState,+ retryBlockedDesktopRecording,+} from "@/lib/desktop-recording-jobs";import { queueDesktopSegmentsFinalization } from "@/lib/desktop-segments-finalization";const MAX_RECORDINGS_PER_REQUEST = 25;@@ -10,7 +13,13 @@ const MAX_RECORDINGS_PER_REQUEST = 25;export type RetryBlockedRecordingResult = {input: string;videoId?: string;- status: "queued" | "not-found" | "not-retryable" | "failed";+ status:+ | "queued"+ | "dispatch-failed"+ | "already-processing"+ | "not-found"+ | "not-retryable"+ | "failed";detail?: string;shareUrl?: string;};@@ -58,12 +67,29 @@ export async function adminRetryBlockedRecordings(videoId,userId: retried.ownerId,});+ const shareUrl = `${serverEnv().WEB_URL}/s/${videoId}`;+ if (queued === "queued") {+ results.push({+ input: entry,+ videoId,+ status: "queued",+ detail: `was ${retried.previousErrorCode}`,+ shareUrl,+ });+ continue;+ }+ // The job was just reset with no workflow, so "already-processing" means the start failed+ // unless another run claimed it first.+ const current = await getProcessingState({ videoId });+ const dispatchFailed = current?.errorCode === "workflow-dispatch-failed";results.push({input: entry,videoId,- status: "queued",- detail: `was ${retried.previousErrorCode}; ${queued}`,- shareUrl: `${serverEnv().WEB_URL}/s/${videoId}`,+ status: dispatchFailed ? "dispatch-failed" : "already-processing",+ detail: dispatchFailed+ ? "the workflow did not start; automatic recovery will retry it"+ : `was ${retried.previousErrorCode}; another workflow already owns it`,+ shareUrl,});} catch (error) {results.push({