Repository navigation
Studio: stop a linked folder re-indexing failed files forever and let Unlink stop a running sync - #13145
Conversation
Unlink and Stop could not land while ingest held the writer past the 5s busy_timeout (unslothai#13095). Signal cancel in-process first, retry the retire write, and expose Stop indexing in the running-folder menu.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Requested correction for #13095: an intentional Stop/Cancel/Unlink should be a normal terminal cancellation, not a failure or exit-code-1 error. Keep actual indexing/database failures visible. At head e0c1ce3, The ingestion cancellation currently travels through Regression coverage requested: cancellation during embedding and while the DB writer is busy finishes as cancelled with no error; cancelled jobs are terminal and do not queue successors/restart; keep-index unlink preserves existing documents; a real ingestion exception and exhausted database-lock handling still report failure. If a dedicated subprocess exits after successful cancellation cleanup, it should not use This is a requested follow-up correction; I have not modified or run tests on this contributor branch. |
…ges in that window still retries
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 190a3da27f
ℹ️ 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".
|
|
||
| def request_cancel(folder_id: str) -> None: | ||
| with _folder_cancels_lock: | ||
| _folder_cancels.add(folder_id) |
There was a problem hiding this comment.
Propagate unlink cancellation between processes
When two backend processes share rag.db (the mode the lease layer is written to support), an unlink handled in one process only adds the folder ID to that process's module-local _folder_cancels. A sync leased by another process therefore never sees _SyncCancelled in either _check_running or ingestion._progress; delete_folder then waits in _delete_retired_folder for the foreign lease, so unlink still blocks for the full long parse/embed. Use a cross-process cancellation marker or make ingestion observe the persisted folder retirement.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Unlink against another process's sync lease waits for that lease exactly as it does on main (test_unlink_waits_for_a_foreign_sync_lease pins this). The cancel flag only shortens the common single-backend case; cross-process signalling is out of scope here.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 727149a5e9
ℹ️ 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".
| if folder_cols and "failed_files" not in folder_cols: | ||
| conn.execute("ALTER TABLE linked_folders ADD COLUMN failed_files TEXT") |
There was a problem hiding this comment.
Serialize the failed_files migration across processes
When two backend processes open an existing pre-change rag.db concurrently, both can read folder_cols before either ALTER commits; after one adds the column, the other's identical statement wakes and raises sqlite3.OperationalError: duplicate column name: failed_files. The process-local schema lock cannot serialize processes (and metadata initialization uses a different lock), so one initialization or request can fail during rollout; acquire a database write lock before inspecting the schema or tolerate and recheck this duplicate-column race.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Same lazy ALTER pattern as withheld_paths and successor_kind in this function; a second process losing that one-time race fails a single connection and the next one sees the column. Not changing the migration scheme here.
…e for cached failures
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ba283362a1
ℹ️ 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".
| "UPDATE linked_folders SET failed_files=CASE WHEN EXISTS(SELECT 1 FROM " | ||
| "linked_folder_sync_jobs WHERE id=? AND successor_kind IS NOT NULL) THEN NULL ELSE ? END " | ||
| "WHERE id=?", | ||
| (job_id, json.dumps(ingest_failed) if ingest_failed else None, folder["id"]), |
There was a problem hiding this comment.
Exclude the failure cache from folder-list polling
When an allowed 10,000-file folder has many persistent failures (the scanned-PDF case this cache targets), this serializes every path and signature into one potentially multi-megabyte linked_folders.failed_files value. list_folders() still executes SELECT f.* in studio/backend/core/rag/folder_sync.py:452-456, while useLinkedFolders calls that endpoint every four seconds in studio/frontend/src/features/rag/components/use-linked-folders.ts:253-255; _folder_view discards the field only after SQLite and Python materialize it. Thus merely leaving Sources open repeatedly reads and allocates the entire cache, so omit failed_files from list queries (or normalize it) to keep polling cost independent of the number of failed paths.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing: an entry is ~120 bytes, so the reporter's folder is a few KB, and even a 10,000-failure folder is about 1 MB read by a 4 s poll, against main re-parsing all of those files every 30 s. Listing explicit columns to drop it would add a second place to keep in sync with the schema.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Summary
Two backend problems kept a linked folder of scanned PDFs (#13095) indexing forever, with no working way out:
database is lockedand returned a 500, and the folder came back. Unlink now sets a process-local cancel flag that the sync worker and the embedding progress callback check without touching rag.db. The retire write waits up to 30 s instead of 5 s.Unlink and keep indexed files therefore works as the stop for a long first sync, and it keeps everything already indexed. There are no UI changes.
Evidence
Reproduced on
main(fdaa9dc) with the real linked-folder worker and real JPEG2000 scanned PDFs (no Tesseract):sqlite3.OperationalError: database is lockedNew tests, base vs head (test sources kept from head):
test_periodic_sync_does_not_retry_an_unchanged_failed_file: fails on main, passes heretest_unlink_stops_the_document_being_embedded: fails on main, passes heretests/test_rag_linked_folders.py: 123 passed. RAG backend tests: 1572 passed. The only 3 failures are intest_amd_smi_hip_index_and_coverage.py, and they fail the same way on main.Fixes #13095