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(mcp): read the project again when a waiting transcription starts

EtienneLescotd98ca3761557
diff --git a/electron/mcp/openscreen-mcp-server.ts b/electron/mcp/openscreen-mcp-server.ts
index 169a7482f..2e8ab44a5 100644
--- a/electron/mcp/openscreen-mcp-server.ts
+++ b/electron/mcp/openscreen-mcp-server.ts
@@ -682,13 +682,20 @@ export function createToolRunner(deps: McpToolDeps): McpToolRunner {
}
const whisper = deps.transcribe;
if (!whisper) return textResult("Transcription is not available here.", true);
- const started = whisperQueue.then(() =>
- whisper({
- sourcePath: asset.originalPath,
+ const started = whisperQueue.then(async () => {
+ // Read again once it is this call's turn: a vocabulary set while it waited counts.
+ const current = await deps.projects
+ .getProjectForUpdate(targetId)
+ .then((read) => read.document)
+ .catch(() => document);
+ const media = current.assets.find((a) => a.id === asset.id);
+ if (!media) throw new Error(`Asset ${asset.id} was removed from the project.`);
+ return whisper({
+ sourcePath: media.originalPath,
language: language === "auto" ? undefined : language,
- prompt: document.project.vocabulary,
- }),
- );
+ prompt: current.project.vocabulary,
+ });
+ });
whisperQueue = started.catch(() => undefined);
let response: SttTranscribeResponse;
try {
diff --git a/electron/mcp/transcribe-tool.test.ts b/electron/mcp/transcribe-tool.test.ts
index 32bc4670e..d51803347 100644
--- a/electron/mcp/transcribe-tool.test.ts
+++ b/electron/mcp/transcribe-tool.test.ts
@@ -169,6 +169,28 @@ describe("transcribe, on a project's file", () => {
expect((await pending).isError).toBeUndefined();
});
+ it("primes a waiting transcription with the vocabulary set while it waited", async () => {
+ await projects.saveProject(fixtureDocument("proj_1"));
+ const running: Array<(response: SttTranscribeResponse) => void> = [];
+ const { run, transcribe } = runnerWith(
+ () =>
+ new Promise((resolve) => {
+ running.push(resolve);
+ }),
+ );
+ const first = run(TRANSCRIBE_TOOL, { projectId: "proj_1" });
+ await vi.waitFor(() => expect(running).toHaveLength(1));
+ const second = run(TRANSCRIBE_TOOL, { projectId: "proj_1", language: "fr" });
+ await run("createCheckpoint", { projectId: "proj_1" });
+ await run("setVocabulary", { projectId: "proj_1", vocabulary: "Vulkan" });
+ running.shift()?.(SPEECH);
+ await first;
+ await vi.waitFor(() => expect(running).toHaveLength(1));
+ expect(transcribe).toHaveBeenLastCalledWith(expect.objectContaining({ prompt: "Vulkan" }));
+ running.shift()?.(SPEECH);
+ await second;
+ });
+
it("survives a restore to a checkpoint made before it", async () => {
await projects.saveProject(fixtureDocument("proj_1"));
const { run } = runnerWith(async () => SPEECH);