Skip to content

bug(python): embedding retry sleeps ~50 minutes on permanent errors (404/400/422) and the delay is uncapped #4541

Closed

Description

@avanish-garg

LanceDB version

0.40.0(also reproduced againstmain` @ 0aa842b by reading the code)

What happened?

retry_with_exponential_backoff (python/python/lancedb/embeddings/utils.py) has two problems:

  1. delay *= exponential_base * (1 + jitter * random.random()) multiplies the delay by 2-4x on every retry,
    and there is no maximum delay.
  2. _is_non_retryable_error only skips AuthenticationError and HTTP 401/403, so permanent client errors
    (400 bad request, 404 model not found, 422) are retried the full max_retries (default 7,
    embeddings/base.py).

So a typo'd model name looks like a hang. With a 404 and 200 random seeds the total sleep before giving up was
min 14 min, median 50 min, max 2.5 h (sleeps like [3.7, 13, 37, 93, 280, 788, 2811] s). With the real OpenAI
client against a local server that returns HTTP 404 "model does not exist": table.add() made 8 requests and
would sleep 29 min, and table.search() made 8 requests and would sleep 71 min.

Expected: permanent errors fail on the first attempt with the provider's message; transient errors are retried
with a bounded backoff.

Also, from table.add() the final error is the confusing
RuntimeError: Arrow error: C Data interface error: Unknown error: ('Maximum number of retries ..., because
the exception is raised inside the reader generator.

Are there known steps to reproduce?

# time.sleep is patched so this runs in seconds and reports the time that would be spent
import random, tempfile
from unittest import mock
import lancedb
from lancedb.embeddings import TextEmbeddingFunction, register
from lancedb.pydantic import LanceModel, Vector

attempts = []

class NotFoundError(Exception):  # same shape as openai.NotFoundError
    status_code = 404

@register("always-404")
class Always404(TextEmbeddingFunction):  # default max_retries=7
    def ndims(self):
        return 4
    def generate_embeddings(self, texts):
        attempts.append(1)
        raise NotFoundError("The model `typo-embed` does not exist")

func = Always404.create()

class Doc(LanceModel):
    text: str = func.SourceField()
    vector: Vector(4) = func.VectorField()

table = lancedb.connect(tempfile.mkdtemp()).create_table("t", schema=Doc)
for label, op in [
    ("table.add", lambda: table.add([{"text": "hello"}])),
    ("table.search", lambda: table.search("hello").limit(1).to_list()),
]:
    random.seed(0)
    attempts.clear()
    sleeps = []
    with mock.patch("time.sleep", sleeps.append):
        try:
            op()
        except Exception as e:
            err = e
    print(f"{label}: attempts={len(attempts)} sleeps={[round(s) for s in sleeps]} "
          f"total={sum(sleeps) / 60:.1f} min\n  error: {str(err)[:110]}")
# main: attempts=8 sleeps=[4, 13, 37, 93, 280, 788, 2811] total=67.1 min

Activity

  1. added
    bug
    on Oct 15, 2026
  2. added a commit that references this issue on Oct 22, 2026
    2d54630
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions