From c3a1744506e74b733203552dbeded6edac514f68 Mon Sep 17 00:00:00 2001 From: pylrn Date: Mon, 26 Oct 2026 12:37:28 +0530 Subject: [PATCH] fix(transcripts): cap polling delay at remaining timeout budget --- CHANGELOG.md | 4 ++++ package.json | 2 +- src/services/transcripts/index.ts | 14 +++++++++----- tests/unit/transcript.test.ts | 14 ++++++++++++++ 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a132284..61addb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [4.41.8] + +- Fix: cap `waitUntilReady` polling delay at the remaining `pollingTimeout` budget to avoid delaying timeout expiration when `pollingInterval` exceeds remaining timeout + ## [4.41.7] - Add `summarization` to the speech understanding feature requests and responses (`SummarizationRequest`, `SummarizationResponse`): `summary_type`, `headline_length`, `approximate_chapters` and `effort`. The feature was already accepted by the API but missing from the SDK types, so setting it failed to type check diff --git a/package.json b/package.json index 7670770..e6b3e97 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "assemblyai", - "version": "4.41.7", + "version": "4.41.8", "description": "The AssemblyAI JavaScript SDK provides an easy-to-use interface for interacting with the AssemblyAI API, which supports async and real-time transcription.", "engines": { "node": ">=18" diff --git a/src/services/transcripts/index.ts b/src/services/transcripts/index.ts index f3e754c..480c21a 100644 --- a/src/services/transcripts/index.ts +++ b/src/services/transcripts/index.ts @@ -128,11 +128,15 @@ export class TranscriptService extends BaseService { const transcript = await this.get(transcriptId); if (transcript.status === "completed" || transcript.status === "error") { return transcript; - } else if ( - pollingTimeout > 0 && - Date.now() - startTime > pollingTimeout - ) { - throw new Error("Polling timeout"); + } + if (pollingTimeout > 0) { + const elapsed = Date.now() - startTime; + if (elapsed >= pollingTimeout) { + throw new Error("Polling timeout"); + } + const remaining = pollingTimeout - elapsed; + const sleepDelay = Math.min(pollingInterval, remaining); + await new Promise((resolve) => setTimeout(resolve, sleepDelay)); } else { await new Promise((resolve) => setTimeout(resolve, pollingInterval)); } diff --git a/tests/unit/transcript.test.ts b/tests/unit/transcript.test.ts index 4f78829..6eb46d9 100644 --- a/tests/unit/transcript.test.ts +++ b/tests/unit/transcript.test.ts @@ -338,6 +338,20 @@ describe("transcript", () => { fetchMock.resetMocks(); }, 5000); + it("waitUntilReady should cap polling delay at remaining pollingTimeout budget", async () => { + fetchMock.mockResponse(JSON.stringify({ status: "processing" })); + const startTime = Date.now(); + const promise = assembly.transcripts.waitUntilReady(transcriptId, { + pollingInterval: 5_000, + pollingTimeout: 200, + }); + + await expect(promise).rejects.toThrow("Polling timeout"); + const duration = Date.now() - startTime; + expect(duration).toBeLessThan(2_000); + fetchMock.resetMocks(); + }, 5000); + it("create should fail to poll", async () => { fetchMock.mockResponse(JSON.stringify({ status: "queued" })); const promise = assembly.transcripts.create(