Skip to content

fix(kb): reindex waits out a cold local embed model (don't fail the first try)#32

Merged
SecureCloudGroup merged 1 commit into
mainfrom
fix-reindex-cold-model
Jul 12, 2026
Merged

fix(kb): reindex waits out a cold local embed model (don't fail the first try)#32
SecureCloudGroup merged 1 commit into
mainfrom
fix-reindex-cold-model

Conversation

@SecureCloudGroup

Copy link
Copy Markdown
Owner

Diagnosis (from your logs)

Reindex/embeddings used a 15s timeout, but a cold local embed model takes far longer to load on its first request. bifrost recorded the (eventually successful) embeds completing at request_duration_ms: 51748, 47845, 32945 — ~50s for oMLX to load bge-m3-mlx-fp16. So:

  1. First reindex → app cuts the connection at 15s while oMLX is still loading → 0 embedded, 1 failed. (oMLX keeps loading in the background — that's why bifrost logs those requests finishing at 51s.)
  2. Second reindex → oMLX now warm → embeds return fast → succeeds.

Exactly your "failed first, worked on the second try." It's the embedding-path twin of the Phase 0 chat cold-load fix (#25) — I raised the timeout for the chat/agent path but not for embeddings.

Fix

  • embed_doc takes a per-embed timeout. The backfill path (reindex_pending — used by the manual Reindex button and the scheduler's auto/eager reindex) uses a generous 120s so a cold model is waited out instead of cut at 15s. (bifrost's per-provider timeout is already 300s from feat(routing): dedicated Agent-tasks model route + cold-load timeout fix #25 — the upstream ceiling.)
  • Interactive embed-on-add / rename stay at 15s (fail fast, best-effort) so an upload never blocks minutes on a cold model — the doc is stored and the backfill embeds it.
  • gateway.embed now passes the timeout per-request and surfaces an httpx timeout as a clean 504 instead of a raw error.

Net effect: a single Reindex click now succeeds on a cold model, and the automatic background reindex will also backfill a just-uploaded doc without you having to click twice.

Tests

Timeout threads through embed_doc; reindex uses the long timeout while embed-on-add stays fast; a gateway timeout wraps to 504. Full backend suite green (650), ruff clean.

Verified by log analysis + plumbing tests; worth confirming on your next genuinely-cold start.

…irst try)

Reindex/embeddings used a 15s timeout, but a cold local embed model (e.g. MLX/oMLX
loading bge-m3) takes ~50s on its first request. So the first reindex was cut off at
15s and failed, the model finished loading in the background, and only the SECOND
(warm) reindex worked — exactly the "failed first, worked on the second try" seen in
the logs (bifrost recorded those embeds completing at 51s/47s/32s).

This is the embedding-path twin of the Phase 0 chat cold-load fix:
- embed_doc takes a per-embed `timeout`; the backfill path (reindex_pending, used by
  the manual /api/kb/reindex route AND the scheduler's auto/eager reindex) uses a
  generous 120s so a cold model is waited out. bifrost's per-provider timeout (300s)
  is the real upstream ceiling.
- Interactive embed-on-add / rename stay at 15s (fail fast; best-effort, backfilled
  later) so an upload never blocks minutes on a cold model.
- gateway.embed now passes the timeout per-request and surfaces an httpx timeout as a
  clean 504 instead of a raw error.

Tests: timeout threads through embed_doc; reindex uses the long timeout while embed-on-add
stays fast; a gateway timeout wraps to a 504. Full suite green (650).
@SecureCloudGroup SecureCloudGroup merged commit 89a7682 into main Jul 12, 2026
7 checks passed
@SecureCloudGroup SecureCloudGroup deleted the fix-reindex-cold-model branch July 12, 2026 20:51
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.

1 participant