~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Move downloader.download_with_result outside the database session in download_resource (#6560, #6564).
Previously, wrapping _download_pdf inside get_user_db_session(...) pinned a checked-out connection
from QueuePool across multi-second HTTP transfers, exhausting the pool and starving concurrent FastAPI
request handlers under bulk downloads. Pre-download checks now execute in a brief transaction, the
HTTP transfer runs outside any session, and short transactions stage the DownloadAttempt and document
records only after download completion. The success path now commits document staging and download
queue status separately, widening a crash window that can strand a PROCESSING queue row (recoverable
via re-run).
Follow-up review fixes:
- Flush the new
DownloadTrackerrow before expunging it on the pre-download path, so theDownloadAttempt.url_hashforeign key is satisfied on first-time downloads (with FK enforcement the prior code raisedFOREIGN KEY constraint failed). - Snapshot
target_resource.titleinto a plain local before staging commit so post-commit text production does not lazy-refresh and re-checkout a QueuePool connection immediately before the arXiv network call / CPU extraction. - Wrap the new-tracker INSERT in
session.begin_nested()so the unconditional pre-blocksession.commit()releases the QueuePool connection without conflating the pre-check write with any caller-staged row on the shared thread-local session. The savepoint scopes the pre-check's only write so a failure inside it cannot drag the caller's outer transaction with it, and the structural change is pinned bytest_pre_check_savepoint_scopes_new_tracker_write. - Stop passing the raw exception text through
sanitize_error_for_client()to the caller-visibleskip_reason. That function scrubs credential shapes only and explicitly does not strip SQL text, target URLs, or dependency internals — the SQLAlchemyIntegrityErroron the staging path surfacedINSERT INTO document_collections ...verbatim into the retry-manager and bulk-stream SSE messages. The exception is now mapped to a fixed safe token via_client_safe_download_message()(e.g.database_constraint,network_reset,pdf_parse_failed); the full sanitized text is preserved server-side inDownloadAttempt.error_messageandlogger.exceptionfor debugging. The same mapping now covers the sibling text-extraction failure paths (_try_arxiv_text_extraction,_try_api_text_extraction,_fallback_pdf_extraction, whoseFailed to save textstrings flow intodownload_as_textand the bulk-stream SSEerrorfield) and the HTML downloader's exception path (via the sharedsecurity.client_safe_errorstable, which both call sites import so the copies cannot drift again); the CWE-209 guard comments inweb/routers/library.pynow state the fixed-token guarantee instead of claimingsanitize_error_for_client()-scrubbed is safe.FailureClassifiernow recognises the token vocabulary (network_timeout→timeout30-min instead ofunknown_error1h, plus the database/pdf/filesystem_error:/download_error:shapes), andRetryManager.record_attemptpasses single-token skip_reasons through aserror_typeinstead of collapsing them to the literal"str". The HTML downloader's tokenized failure logs the exception class (exc_class=) for operators while still never loggingstr(e)or the traceback. - Added
test_first_time_download_persists_tracker_before_attempt_with_fk_on(FK-ON engine) andtest_download_sqlalchemy_exception_does_not_leak_sql_in_skip_reasonto pin the two follow-up fixes. The FK-ON test is mutation-verified for the combined savepoint+flush invariant (removing both fails withFOREIGN KEY constraint failed); the explicitsession.flush()alone is defense-in-depth over the savepoint-exit auto-flush, and the leak test is mutation-verified against restoringsanitize_error_for_client(str(e)).