Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(stt): keep busy labels timeline-scoped and visible during regeneration

超超超超超级喜欢你的达妮娅c82312665b6b
diff --git a/src/components/ai-edition/CaptionsPane.gating.test.tsx b/src/components/ai-edition/CaptionsPane.gating.test.tsx
index 097a1bf58..91ef8dbd4 100644
--- a/src/components/ai-edition/CaptionsPane.gating.test.tsx
+++ b/src/components/ai-edition/CaptionsPane.gating.test.tsx
@@ -112,6 +112,33 @@ describe("captions pane gating", () => {
expect(screen.getByRole("button", { name: "Transcribing" })).toBeDisabled();
});
+ it("keeps the idle button when only an off-timeline asset is busy", () => {
+ // The gate answers for the timeline's assets; the label must not answer
+ // for the whole bin. A bin asset mid-transcription used to relabel the
+ // still-enabled button with its busy copy.
+ const offTimeline: AxcutAsset = {
+ id: "asset_2",
+ kind: "video",
+ label: "bin-only.mp4",
+ originalPath: "/bin.mp4",
+ durationSec: 8,
+ cameraTrack: null,
+ };
+ const document = documentWith(ASSET);
+ document.assets.push(offTimeline);
+ load(document);
+ useTranscriptionStore.setState({
+ projectId: "proj_1",
+ jobs: { asset_2: { status: "running", language: "auto", manual: false } },
+ });
+ render(
+ <I18nProvider>
+ <CaptionsPane />
+ </I18nProvider>,
+ );
+ expect(screen.getByRole("button", { name: "Transcribe video" })).toBeEnabled();
+ });
+
it("kills the retry on a media with no audio track and explains it", () => {
load(
documentWith({
diff --git a/src/components/ai-edition/CaptionsPane.tsx b/src/components/ai-edition/CaptionsPane.tsx
index a54cb25d1..b425c2ff3 100644
--- a/src/components/ai-edition/CaptionsPane.tsx
+++ b/src/components/ai-edition/CaptionsPane.tsx
@@ -25,7 +25,7 @@ import {
useTranscriptionStore,
} from "@/lib/ai-edition/store/transcriptionStore";
import { useCaptions } from "@/lib/ai-edition/store/useCaptions";
-import { firstBusyView } from "@/lib/ai-edition/transcription/status";
+import { firstTimelineBusyView } from "@/lib/ai-edition/transcription/status";
import { nativeBridgeClient } from "@/native";
import { ColorField } from "./ColorField";
import styles from "./NewEditorShell.module.css";
@@ -105,8 +105,11 @@ export function CaptionsPane() {
const transcriptions = useAssetTranscriptions();
const transcriptionLabel = useTranscriptionLabel();
const isTranscribing = gate.state === "pending";
+ // Timeline-scoped on purpose: the gate below answers for the timeline's
+ // assets, so the label must too — an off-timeline job must not relabel an
+ // enabled button.
const busyLabel = transcriptionBusyLabel(
- firstBusyView(Object.values(transcriptions)) ??
+ firstTimelineBusyView(document, transcriptions) ??
(isTranscribing ? { assetId: "", status: "running", phase: "loading-model" } : undefined),
transcriptionLabel,
);
@@ -256,10 +259,13 @@ export function CaptionsPane() {
>
{/* The cue count is only meaningful while the layer is on — deriving
cues short-circuits when it's off, so a "0 lines" reading there
- would say the transcript is empty when it isn't. */}
- {settings.enabled
- ? t("captions.derivedFromTranscript", { count: cues.length })
- : t("captions.hiddenHint")}
+ would say the transcript is empty when it isn't. While a
+ regeneration is in flight the phase label matters more than the
+ count of cues about to be replaced. */}
+ {busyLabel ??
+ (settings.enabled
+ ? t("captions.derivedFromTranscript", { count: cues.length })
+ : t("captions.hiddenHint"))}
</p>
)}
diff --git a/src/components/ai-edition/NewEditorShell.tsx b/src/components/ai-edition/NewEditorShell.tsx
index 5f9db0166..b2c41aa31 100644
--- a/src/components/ai-edition/NewEditorShell.tsx
+++ b/src/components/ai-edition/NewEditorShell.tsx
@@ -26,6 +26,7 @@ import { useUndoRedoShortcuts } from "@/lib/ai-edition/store/undo";
import { useSequentialTimelineOps } from "@/lib/ai-edition/store/useSequentialTimelineOps";
import { useTimeline } from "@/lib/ai-edition/store/useTimeline";
import { newRegionDurationSec } from "@/lib/ai-edition/timeline/newRegionDuration";
+import { firstTimelineBusyView } from "@/lib/ai-edition/transcription/status";
import { matchesShortcut } from "@/lib/shortcuts";
import { nativeBridgeClient } from "@/native";
import type { AiEditionProjectSummary } from "@/native/contracts";
@@ -159,6 +160,12 @@ export function NewEditorShell() {
.map((v) => v.assetId),
[transcriptions],
);
+ // For the pane-level busy label: timeline-scoped like the gate, so an
+ // off-timeline job cannot relabel controls the gate keeps enabled.
+ const timelineBusyView = useMemo(
+ () => firstTimelineBusyView(document, transcriptions),
+ [document, transcriptions],
+ );
const tl = useTimeline();
// An undo only puts the restored document back in the store and marks it dirty,
// so without this the reverted state never reached disk: close the window and the
@@ -1149,6 +1156,7 @@ export function NewEditorShell() {
trimRanges: document?.timeline?.trimRanges ?? [],
busyAssetIds,
transcriptions,
+ busyView: timelineBusyView,
onSeek: handleSeek,
onAddTrimRange: handleAddTrimRange,
onRemoveTrimRange: handleRemoveTrimRange,
diff --git a/src/components/ai-edition/RightPanes.tsx b/src/components/ai-edition/RightPanes.tsx
index fbc5f84f1..5b7792afe 100644
--- a/src/components/ai-edition/RightPanes.tsx
+++ b/src/components/ai-edition/RightPanes.tsx
@@ -65,7 +65,6 @@ import { formatMs } from "@/lib/ai-edition/timeline/format";
import { locateVirtualPosition } from "@/lib/ai-edition/timeline/virtual-preview";
import {
type AssetTranscriptionView,
- firstBusyView,
type TranscriptGateReason,
} from "@/lib/ai-edition/transcription/status";
import { getAssetPath } from "@/lib/assetPath";
@@ -712,6 +711,7 @@ export function TranscriptPane({
trimRanges,
busyAssetIds,
transcriptions,
+ busyView,
onSeek,
onAddTrimRange,
onRemoveTrimRange,
@@ -731,6 +731,11 @@ export function TranscriptPane({
* background pass, with nothing on screen to say why. */
busyAssetIds: readonly string[];
transcriptions?: Record<string, AssetTranscriptionView>;
+ /** First busy view over the TIMELINE's assets (same scope as `blocked` and
+ * `isTranscribing`) — the pane-level label reads this, never the whole
+ * `transcriptions` record, so an off-timeline job cannot relabel controls
+ * the gate keeps enabled. */
+ busyView?: AssetTranscriptionView;
onSeek: (sec: number) => void;
onAddTrimRange: (target: TrimTarget, startSec: number, endSec: number, reason: string) => void;
onRemoveTrimRange: (trimId: string) => void;
@@ -780,7 +785,7 @@ export function TranscriptPane({
const silentMedia = blocked?.reason === "no-audio";
const transcriptionLabel = useTranscriptionLabel();
const paneBusyLabel = transcriptionBusyLabel(
- firstBusyView(Object.values(transcriptions ?? {})) ??
+ busyView ??
(isTranscribing ? { assetId: "", status: "running", phase: "loading-model" } : undefined),
transcriptionLabel,
);
diff --git a/src/lib/ai-edition/transcription/status.test.ts b/src/lib/ai-edition/transcription/status.test.ts
index 181f83d96..e40636dee 100644
--- a/src/lib/ai-edition/transcription/status.test.ts
+++ b/src/lib/ai-edition/transcription/status.test.ts
@@ -5,6 +5,7 @@ import {
classifyTranscriptionError,
deriveAssetStatus,
firstBusyView,
+ firstTimelineBusyView,
isCpuBackend,
isModelDownloadInFlight,
isPermanentFailure,
@@ -232,53 +233,53 @@ describe("resolveTranscriptGate", () => {
});
});
-describe("transcriptRelevantAssetIds", () => {
- const base = {
- schemaVersion: 7 as const,
- project: {
- id: "proj_1",
- title: "T",
- createdAt: "2026-06-25T10:00:00.000Z",
- updatedAt: "2026-06-25T10:00:00.000Z",
- },
- transcript: null,
- transcripts: [],
- annotations: [],
- zoomRanges: [],
- legacyEditor: null,
- };
-
- function doc(assetIds: string[], clipAssetIds: string[]): AxcutDocument {
- return {
- ...base,
- assets: assetIds.map((id) => ({
- id,
- kind: "video" as const,
- label: id,
- originalPath: `/tmp/${id}.mp4`,
- cameraTrack: null,
+const base = {
+ schemaVersion: 7 as const,
+ project: {
+ id: "proj_1",
+ title: "T",
+ createdAt: "2026-06-25T10:00:00.000Z",
+ updatedAt: "2026-06-25T10:00:00.000Z",
+ },
+ transcript: null,
+ transcripts: [],
+ annotations: [],
+ zoomRanges: [],
+ legacyEditor: null,
+};
+
+function doc(assetIds: string[], clipAssetIds: string[]): AxcutDocument {
+ return {
+ ...base,
+ assets: assetIds.map((id) => ({
+ id,
+ kind: "video" as const,
+ label: id,
+ originalPath: `/tmp/${id}.mp4`,
+ cameraTrack: null,
+ })),
+ timeline: {
+ clips: clipAssetIds.map((assetId, i) => ({
+ id: `clip_${i}`,
+ assetId,
+ sourceStartSec: 0,
+ sourceEndSec: 10,
+ timelineStartSec: i * 10,
+ timelineEndSec: i * 10 + 10,
+ wordRefs: [],
+ origin: "system" as const,
+ reason: "",
})),
- timeline: {
- clips: clipAssetIds.map((assetId, i) => ({
- id: `clip_${i}`,
- assetId,
- sourceStartSec: 0,
- sourceEndSec: 10,
- timelineStartSec: i * 10,
- timelineEndSec: i * 10 + 10,
- wordRefs: [],
- origin: "system" as const,
- reason: "",
- })),
- gaps: [],
- trimRanges: [],
- muteRanges: [],
- speedRanges: [],
- captionRanges: [],
- },
- } as AxcutDocument;
- }
+ gaps: [],
+ trimRanges: [],
+ muteRanges: [],
+ speedRanges: [],
+ captionRanges: [],
+ },
+ } as AxcutDocument;
+}
+describe("transcriptRelevantAssetIds", () => {
it("only counts the assets the timeline plays", () => {
expect(transcriptRelevantAssetIds(doc(["a", "b"], ["a", "a"]))).toEqual(["a"]);
});
@@ -296,6 +297,30 @@ describe("transcriptRelevantAssetIds", () => {
});
});
+describe("firstTimelineBusyView", () => {
+ it("ignores a busy job on an asset the timeline does not play", () => {
+ // "b" is in the bin and mid-transcription, but the timeline only plays
+ // "a" — the timeline-scoped label must stay idle, like the gate does.
+ const views = { b: view("b", "running") };
+ expect(firstTimelineBusyView(doc(["a", "b"], ["a"]), views)).toBeUndefined();
+ });
+
+ it("reports a busy job on a timeline asset", () => {
+ const views = { a: view("a", "running"), b: view("b", "running") };
+ expect(firstTimelineBusyView(doc(["a", "b"], ["a"]), views)?.assetId).toBe("a");
+ });
+
+ it("keeps the empty-timeline fallback: whole-bin jobs count", () => {
+ const views = { b: view("b", "queued") };
+ expect(firstTimelineBusyView(doc(["a", "b"], []), views)?.assetId).toBe("b");
+ });
+
+ it("is quiet when nothing relevant is busy", () => {
+ const views = { a: view("a", "ready") };
+ expect(firstTimelineBusyView(doc(["a"], ["a"]), views)).toBeUndefined();
+ });
+});
+
describe("realtimeSpeed", () => {
// The engine reports RTF (wall-clock / audio, lower is faster); the UI shows
// its reciprocal, which is the figure the POC report headlines.
diff --git a/src/lib/ai-edition/transcription/status.ts b/src/lib/ai-edition/transcription/status.ts
index b74f745cb..8bc98b489 100644
--- a/src/lib/ai-edition/transcription/status.ts
+++ b/src/lib/ai-edition/transcription/status.ts
@@ -82,6 +82,24 @@ export function firstBusyView(
return list.find((v) => v.status === "running") ?? list.find((v) => v.status === "queued");
}
+/**
+ * First busy view among the assets the timeline actually plays — the same
+ * scope every transcript-dependent gate uses (`transcriptRelevantAssetIds`).
+ * A job on an off-timeline asset must not relabel a timeline-scoped button
+ * that stays enabled: label and gate have to answer about the same assets.
+ */
+export function firstTimelineBusyView(
+ document: AxcutDocument | null,
+ views: Record<string, AssetTranscriptionView>,
+): AssetTranscriptionView | undefined {
+ const relevant: AssetTranscriptionView[] = [];
+ for (const id of transcriptRelevantAssetIds(document)) {
+ const view = views[id];
+ if (view) relevant.push(view);
+ }
+ return firstBusyView(relevant);
+}
+
/**
* A media that has no audio track (or one Whisper cannot read) will fail the
* same way on every attempt, so that verdict is worth remembering: it is