diff --git a/packages/qvac-lib-infer-parakeet/parakeet.js b/packages/qvac-lib-infer-parakeet/parakeet.js index 318ecaf74c..87e8fc87a2 100644 --- a/packages/qvac-lib-infer-parakeet/parakeet.js +++ b/packages/qvac-lib-infer-parakeet/parakeet.js @@ -45,6 +45,10 @@ const state = Object.freeze({ STOPPED: 'stopped' }) +function nextSafeId (current) { + return current >= Number.MAX_SAFE_INTEGER ? 1 : current + 1 +} + function createParakeetError (code, message, cause = undefined) { // @qvac/error expects an options object, while the local fallback class // accepts positional args. Support both call shapes. @@ -211,9 +215,8 @@ class ParakeetInterface { throw new Error('Cannot set new job: a job is already set or being processed') } - // Only replace the active job after the native runner accepts it. this._activeJobId = currentJobId - this._nextJobId += 1 + this._nextJobId = nextSafeId(this._nextJobId) this._bufferedAudio = [] this._setState(state.PROCESSING) return currentJobId @@ -377,7 +380,7 @@ class ParakeetInterface { return false } this._activeJobId = currentJobId - this._nextJobId += 1 + this._nextJobId = nextSafeId(this._nextJobId) this._setState(state.PROCESSING) return accepted } catch (error) { diff --git a/packages/qvac-lib-infer-whispercpp/whisper.js b/packages/qvac-lib-infer-whispercpp/whisper.js index 2c26408b73..7a7650a5e0 100644 --- a/packages/qvac-lib-infer-whispercpp/whisper.js +++ b/packages/qvac-lib-infer-whispercpp/whisper.js @@ -12,6 +12,10 @@ const state = Object.freeze({ const END_OF_INPUT = 'end of job' +function nextSafeId (current) { + return current >= Number.MAX_SAFE_INTEGER ? 1 : current + 1 +} + /** * An interface between Bare addon in C++ and JS runtime. */ @@ -265,7 +269,7 @@ class WhisperInterface { } this._activeJobId = currentJobId - this._nextJobId += 1 + this._nextJobId = nextSafeId(this._nextJobId) this._bufferedAudio = [] this._setState(state.PROCESSING) return currentJobId @@ -335,7 +339,7 @@ class WhisperInterface { async runJob (data) { try { this._activeJobId = this._nextJobId - this._nextJobId += 1 + this._nextJobId = nextSafeId(this._nextJobId) this._setState(state.PROCESSING) const accepted = this._binding.runJob(this._handle, { ...data, @@ -360,7 +364,7 @@ class WhisperInterface { startStreaming (config = {}) { try { this._activeJobId = this._nextJobId - this._nextJobId += 1 + this._nextJobId = nextSafeId(this._nextJobId) this._setState(state.PROCESSING) this._binding.startStreaming(this._handle, config) } catch (err) {