WhisperKit : propagate useBackgroundDownloadSession into config fetch (#337)#461
Open
achyutbenz19 wants to merge 1 commit intoargmaxinc:mainfrom
Open
WhisperKit : propagate useBackgroundDownloadSession into config fetch (#337)#461achyutbenz19 wants to merge 1 commit intoargmaxinc:mainfrom
achyutbenz19 wants to merge 1 commit intoargmaxinc:mainfrom
Conversation
WhisperKitConfig.useBackgroundDownloadSession was only applied on the main model download (WhisperKit.download) but not on the preceding remote-config fetch that runs when no model is explicitly specified. The caller's intent was silently dropped for that pre-download step: setupModels invoked recommendedRemoteModels -> fetchModelSupportConfig, both of which built a default HubApiWrapper without the background session flag. Thread a useBackgroundSession parameter through recommendedRemoteModels and fetchModelSupportConfig (default false, so existing callers stay byte-compatible) and pass it from setupModels. The value stored in self.useBackgroundDownloadSession during init is the source of truth. Fixes argmaxinc#337
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #337.
WhisperKitConfig.useBackgroundDownloadSessionis stored onWhisperKitduring init and passed correctly toWhisperKit.download(viasetupModels), but the preceding fetch that picks the default model variant ignored the setting. When nomodelis specified in the config,setupModelscallsWhisperKit.recommendedRemoteModels(...), which callsfetchModelSupportConfig(...), which builds a plainHubApiWrapper(downloadBase:hfToken:endpoint:)with nouseBackgroundSession. The pre-download config fetch therefore always runs on a foreground URLSession, even when the caller asked for background downloads.On iOS this matters: an app suspended mid-launch loses the foreground request, so the subsequent (background) model download never sees the remote config and falls back to the bundled default.
Scope of the change
Sources/WhisperKit/Core/WhisperKit.swift, +8/-3.useBackgroundSession: Bool = falseto the public static entry pointsrecommendedRemoteModels(...)andfetchModelSupportConfig(...). Default isfalse, so existing callers are byte-compatible.recommendedRemoteModelsforwards it tofetchModelSupportConfig, and theHubApiWrappernow receives it.setupModelspassesself.useBackgroundDownloadSessionwhen callingrecommendedRemoteModelsfor the default-variant lookup, closing the loop.Reproduction
Before the patch, a break in
Downloader.swift(swift-transformers) inside the background-session branch ofHubApiWrapper.shared.Taskdoes not hit duringWhisperKit(config:)init whenuseBackgroundDownloadSession: trueand nomodelis set. The config fetch always uses the foreground session.After the patch, the same break hits on the initial config fetch. The background session is now active for the full download sequence: config → snapshot → model files.
Differential matrix
No
audiokit regress checkrun for this PR. The change is a parameter plumbing fix that is either wired or not; the regression surface is the existingHubApiWrapperconstruction atSources/WhisperKit/Core/WhisperKit.swift:188(now takes an additional argument). Non-default callers ofrecommendedRemoteModels/fetchModelSupportConfigare untouched because the new parameter is defaulted tofalse. Build check passes clean on Swift 6.2 / Xcode 26.1.What this does not do
WhisperKit.download(already correctly used the flag).TTSKithas its ownuseBackgroundDownloadSessionhandling that mirrorsWhisperKit's pattern and was not affected by this bug.fetchAvailableModels(which may have a related gap), keeping scope to the reported issue.Tools used
git,swift build, andaudiokiton the other PRs in this series. No audio fixtures used for this one.Disclosure
I am an AI assistant (Anthropic's Claude) helping a user contribute this fix. I verified the patch builds clean; the behavioral assertion comes from tracing the control flow rather than a live iOS repro.