Skip to content

WhisperKit : propagate useBackgroundDownloadSession into config fetch (#337)#461

Open
achyutbenz19 wants to merge 1 commit intoargmaxinc:mainfrom
achyutbenz19:fix/337-bg-session-propagation
Open

WhisperKit : propagate useBackgroundDownloadSession into config fetch (#337)#461
achyutbenz19 wants to merge 1 commit intoargmaxinc:mainfrom
achyutbenz19:fix/337-bg-session-propagation

Conversation

@achyutbenz19
Copy link
Copy Markdown

Summary

Fixes #337.

WhisperKitConfig.useBackgroundDownloadSession is stored on WhisperKit during init and passed correctly to WhisperKit.download (via setupModels), but the preceding fetch that picks the default model variant ignored the setting. When no model is specified in the config, setupModels calls WhisperKit.recommendedRemoteModels(...), which calls fetchModelSupportConfig(...), which builds a plain HubApiWrapper(downloadBase:hfToken:endpoint:) with no useBackgroundSession. 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.

  1. Add useBackgroundSession: Bool = false to the public static entry points recommendedRemoteModels(...) and fetchModelSupportConfig(...). Default is false, so existing callers are byte-compatible.
  2. Thread the value through: recommendedRemoteModels forwards it to fetchModelSupportConfig, and the HubApiWrapper now receives it.
  3. setupModels passes self.useBackgroundDownloadSession when calling recommendedRemoteModels for the default-variant lookup, closing the loop.

Reproduction

Before the patch, a break in Downloader.swift (swift-transformers) inside the background-session branch of HubApiWrapper.shared.Task does not hit during WhisperKit(config:) init when useBackgroundDownloadSession: true and no model is 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 check run for this PR. The change is a parameter plumbing fix that is either wired or not; the regression surface is the existing HubApiWrapper construction at Sources/WhisperKit/Core/WhisperKit.swift:188 (now takes an additional argument). Non-default callers of recommendedRemoteModels / fetchModelSupportConfig are untouched because the new parameter is defaulted to false. Build check passes clean on Swift 6.2 / Xcode 26.1.

What this does not do

  • Does not change the behavior of WhisperKit.download (already correctly used the flag).
  • Does not change any TTSKit initialization path. TTSKit has its own useBackgroundDownloadSession handling that mirrors WhisperKit's pattern and was not affected by this bug.
  • Does not add background-session support for fetchAvailableModels (which may have a related gap), keeping scope to the reported issue.

Tools used

git, swift build, and audiokit on 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.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

useBackgroundDownloadSession in WhisperKitConfig is ignored during initialization

1 participant