Skip to content

[Bug]: Model download sleeps after its final failed attempt #855

Done

Description

@elysiopires

What happened?

ModelManagement.download_model() sleeps after the final failed download attempt, even when its retry counter has reached zero.

With the default retries=3, failed downloads sleep for 3, 9 and 27 seconds. Only the first two sleeps precede another attempt; the last 27 seconds delay the final ValueError without retrying anything. With retries=1, a failed attempt still sleeps for three seconds before returning the error.

Minimal reproduction

This reproducer mocks model downloads and sleep, so it needs no model weights or network access:

from unittest.mock import Mock, patch
from fastembed.common.model_description import BaseModelDescription, ModelSource
from fastembed.common.model_management import ModelManagement

model = BaseModelDescription(
    model="test/missing-model",
    sources=ModelSource(hf="test/missing-model"),
    model_file="model.onnx",
    description="Test fixture",
    license="Apache-2.0",
    size_in_GB=0.0,
)
with patch.object(ModelManagement, "download_files_from_huggingface", side_effect=OSError("unavailable")), patch("fastembed.common.model_management.time.sleep") as sleep:
    try:
        ModelManagement.download_model(model, "/tmp/unused-fastembed-repro", retries=3)
    except ValueError:
        pass
    print(sleep.call_args_list)

Actual: [call(3.0), call(9.0), call(27.0)]

Expected: [call(3.0), call(9.0)]

Run with HF_HUB_OFFLINE unset.

Proposed fix

Sleep only when another attempt remains. Preserve the number of attempts, exponential delays between them, URL fallback, offline behavior and the final exception.

I reproduced this with four regression cases covering one/three attempts, with and without URL fallback. All four fail before the fix because of the extra sleep.

Environment

  • FastEmbed 0.9.1 from current main
  • Python 3.11.9 on macOS
  • Downloads and sleeps mocked; no model downloaded or credentials used

AI assistance: OpenAI Codex. The regression cases were run locally.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions