Skip to content

Studio: wait for a pending embedding model download instead of failing every linked-folder file - #16722

Merged
danielhanchen merged 5 commits into
unslothai:mainfrom
debojyoti-dev:fix/rag-sync-waits-for-embedder-download-16714
Nov 6, 2026
Merged

danielhanchen merged 5 commits into
unslothai:mainfrom
debojyoti-dev:fix/rag-sync-waits-for-embedder-download-16714

Conversation

@debojyoti-dev

@debojyoti-dev debojyoti-dev commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #16714

What was wrong

When a linked folder synced while the embedding model's Settings transfer was still pending, every file went to the embedder and each one failed the same EmbeddingModelDownloadRequiredError check in _load. All of them were then saved to the folder's failed_files list, which keeps unchanged failed files out of periodic syncs for 6 hours (#13095). The folder stayed at "N files that couldn't be indexed" after the download finished, until a manual Rebuild.

What this changes

  • embeddings.download_required(model): True while the model's pending-download marker is set and the cache-only loader still can't load it. It costs nothing when no transfer is pending. Otherwise it asks the loader, which retires the marker once the cache is complete, so a finished download reads False.
  • folder_sync._reconcile_folder: before ingesting, if there is work and the download is still pending, the job fails with one job-level message ("The embedding model '...' is not downloaded yet. Indexing starts on its own once its Settings download finishes."; a folder with auto sync off is told to sync again instead). No file is marked failed and the existing index is left as it is. The periodic sync then indexes the folder by itself once the transfer lands, with no Rebuild needed.
  • A download-required error that still happens mid-sync (the transfer going pending after the check) is not written to failed_files, so the next sync retries those files. Entries written that way before this change are no longer held back either, so folders already stuck like the one in the report recover on the next periodic sync.
  • The three raise sites now build the message with one shared helper, so the stored error text can be recognized reliably.

Testing

On Windows 11, Ryzen 5600H, RTX 3050 4 GB, Python 3.12:

  • New tests/test_rag_folder_sync_download_pending.py (8 tests): the check skips the loader when nothing is pending, follows a pending transfer to completion, and leaves other load failures to the documents. The sync waits without marking files, then a periodic sync indexes all of them once the download lands. A Rebuild while pending keeps the existing index. Mid-sync download errors aren't held back, but a genuinely bad file still is. Pre-existing stuck entries retry.
  • Real Studio end to end (run.py --api-only, sentence-transformers on CPU, empty HF cache, RAG_FOLDER_SYNC_INTERVAL_S=5): saved unsloth/bge-small-en-v1.5 in Settings (stored with download_pending: true), linked a 40-file folder, then started Studio's own download through POST /api/hub/download and waited, triggering only periodic syncs.
    • main: 40 file(s) could not be indexed, each failing with "is not downloaded yet". After the download completed, the folder still showed 40 failures and 0 documents.
    • this branch: "The embedding model 'unsloth/bge-small-en-v1.5' is not downloaded yet..." with 0 failed files. After the download completed, the folder went idle with 40 documents and 0 failures.
  • Related suites on this branch and on a clean copy of main gave identical results: test_rag_linked_folders, test_rag_folder_sync_retirement, test_rag_folder_scan_filters, test_rag_linked_folder_grant_retry, test_folder_sync_account_rotation, test_embedding_model_settings/resolve/security_gate, test_offline_embedding_minimal, test_openai_embeddings_studio_fallback, test_rag_embed_llama_server, test_rag_embeddings, test_rag_embedding_identity, test_rag_reembed, test_rag_ingestion, test_rag_source_files_indexing, test_conversation_archive, test_rag_reconcile_orphaned. The failures that do occur (symlinks and case-sensitive paths in test_offline_embedding_minimal, test_openai_embeddings_studio_fallback and test_rag_embed_llama_server) happen on clean main too on this Windows machine.
  • ruff check is clean on the changed files.

Not covered: the llama-server embedding backend end to end (no llama-server binary on this machine). Its raise site only switched to the shared message helper.

Follow-up (maintainer)

  • Merged current main (conflict with Studio RAG: reuse one rag.db connection per thread within a linked-folder sync pass #16607's per-thread connection reuse in finish_pending, resolved keeping both).
  • The job-level message no longer says "still downloading": the pending marker is also set when the Settings download was never started, so it now says the model is not downloaded yet.
  • The new test module clears the process-wide embedding resolution memo around each test; without it, 7 tests in test_rag_embed_llama_server.py failed when run after it in one session.
  • Real loader repro (no mocks, CPU, tiny sentence-transformers model, empty HF cache, pending marker set, 40-file folder, then the snapshot lands and the next periodic sync runs): main fails all 40 files and still holds back all 40 after the download; this branch fails 0, then indexes all 40 on the next periodic sync and retires the marker.

…g every linked-folder file

A linked-folder sync that ran while the embedding model's Settings
transfer was still pending sent every file to the embedder, each one
raised EmbeddingModelDownloadRequiredError, and all of them were saved to
the folder's failed-file list, which keeps unchanged failed files out of
periodic syncs for 6 hours. The folder stayed failed after the download
finished until a manual Rebuild.

Before ingesting, the sync now checks whether the model's download is
still pending (embeddings.download_required: free when no transfer is
pending, otherwise asks the cache-only loader). If it is, the job fails
with one job-level "still downloading" message and no file is marked
failed, so the next periodic sync indexes the folder once the transfer
lands. A download-required error that still happens mid-sync is not
saved to the failed-file list, and entries saved that way before this
change are retried.

Fixes unslothai#16714
danielhanchen added a commit that referenced this pull request Nov 5, 2026
…ed-load retry (#16768)

## Summary

`Chat UI Tests (extra)` fails on unrelated PRs several times a day at
the same place, for example #16722, #16741 and the staging run for
#16750:

```
File "tests/studio/playwright_multi_account.py", line 173, in run
    open_login(page)
File "tests/studio/playwright_multi_account.py", line 67, in open_login
    page.goto(url)
playwright._impl._errors.TimeoutError: Page.goto: Timeout 30000ms exceeded.
Call log:
  - navigating to "http://127.0.0.1:18894/login", waiting until "load"
```

#16437 added a recorded retry for exactly this stalled `/login` load,
but it never runs in these failures. None of the failing logs print its
`WARN: /login did not fire load ...` line, and the whole step lasts
about 33 s, i.e. one 30 s timeout. `open_login` gives aborts and
timeouts one shared two-attempt budget: right after a log-out the app's
own 401 redirect (`redirectToAuth`) aborts the first `goto` with
`ERR_ABORTED`, which spends attempt 1, and the stalled load then happens
on attempt 2, where it is fatal.

## Change

`tests/studio/playwright_multi_account.py`, `open_login` only:

- Aborts and timeouts each get their own single retry, so an abort can
no longer use up the retry #16437 added for a stalled load. A second
abort, a second timeout, or any other error still fails the run as
before.
- When the abort came from the app's redirect and that redirect has
already loaded `/login`, the page is used as it is instead of navigating
to `/login` a second time. A redirect that ends anywhere else (for
example `/change-password`) still navigates to `/login`.

Nothing outside this Playwright driver changes.

`tests/studio/test_playwright_multi_account_open_login.py` drives
`open_login` with a scripted page and the real Playwright error types:

| goto outcomes | expected |
|---|---|
| abort, redirect already on `/login` | returns after one goto |
| abort elsewhere, timeout, load | returns after the third goto (the CI
failure) |
| abort to `/change-password`, load | navigates to `/login` |
| two aborts / two timeouts / abort then two timeouts | raises |
| an error other than an abort | raises, no retry |

## Testing

- New test: 7 passed. Against the driver on main: 3 failed, including
`test_a_timeout_after_an_abort_still_gets_its_retry`, the sequence the
CI logs show.
- `tests/test_ci_repo_cpu_shards.py`,
`tests/studio/test_playwright_suites_run_in_ci.py` and
`tests/studio/test_pwsh_calls_use_the_shared_runner.py` pass.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@danielhanchen danielhanchen self-assigned this Nov 6, 2026
# Conflicts:
#	studio/backend/core/rag/folder_sync.py
…pending marker in tests

The pending marker is also set when the user never started the Settings download, so
'still downloading' could wait forever. Folders without auto sync are told to sync again.
The new tests left the process-wide resolution memo pending, which broke 7 llama-server
embedding tests run after them in the same session.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T13:43:46.597871Z 23b7d4f Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: d0e26d3326

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 23b7d4f253

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RAG: indexing during an embedding model download fails every file, permanently

2 participants