Tasks such as bulk_update_documents moved a document's files once for its manual post_save and again for every save its workflows made, each time taking the global media lock.
All tasks now run through FileMoveScopedTask, which opens a file move scope around the task body, including when the task raises. bulk_update_documents flushes after each document so long bulk edits still make steady progress.
A tag PATCH moved files from inside the tags.set() transaction while holding the document row lock. A concurrent save holding media.lock and waiting on that row deadlocked with it, and every later save on the instance queued behind media.lock until the webserver restarted.
FileMoveMiddleware opens a file move scope around every request, in sync or async mode, so each changed document is moved once after the view returns and never while a transaction holds row locks.
Each save of a document moved its files on the spot, so one logical change could move them several times, and moves could run inside another open transaction.
defer_file_moves() opens a ContextVar-backed scope. Inside it, move requests are recorded and the outermost scope moves each document once on exit, or on commit if a transaction is still open. A failing move is logged and does not stop the others. Outside any scope moves stay immediate.
The file move receiver refreshed the caller's own instance from the database, which wiped unsaved in-memory changes. It ran on every m2m_changed action including pre_add and pre_remove, wrote modified even when nothing moved, and its no-move branch skipped trashed documents.
The move body now lives in documents.file_moves.move_files_for_document. It skips documents without a filename before taking media.lock, then takes the lock with a 300 second timeout, loads a fresh instance by pk, writes only when a filename column changes, and returns the instance. The receiver ignores reverse and pre_* m2m actions and copies just the final filename columns back onto the caller's instance.
Every caller built its own FileLock on media.lock, so code already holding it could not call into code that takes it again without blocking itself. That made it impossible to take media.lock before opening a transaction in paths that also attach files or move files inside that transaction.
media_lock() hands out one FileLock instance per path with per-thread hold counts, so a thread re-enters while other threads and processes stay excluded. All media.lock call sites now use it.
A full save() of a Document instance loaded before another process moved its file wrote the old filename back. The DB then pointed at a path that no longer existed, and recovery only worked when the recomputed path happened to match the file's real location.
Document.save() now leaves filename and archive_filename out of full saves on existing rows. Writers that own those columns opt in with write_file_paths=True or an explicit update_fields. A full save of a row deleted elsewhere now raises instead of re-inserting it.
They are built from a patched fork that carries
upstream PRs including NEON on Linux arm64, memory-safety fixes and
performance improvements for both reading and cosine ranking
* Enhancement: Answer chat questions from all retrieved chunks in one LLM call
The chat response synthesizer packed the retrieved chunks using the embedding
chunk size as its limit, so nothing merged and each question took 3 to 6
sequential LLM calls. Use the configured context size as the limit instead,
so the chunks share one prompt.
If the server rejects the larger prompt with a 400, log a warning naming
PAPERLESS_AI_LLM_CONTEXT_SIZE and retry once with the embedding chunk size,
as before. The retry only happens before anything has streamed.
* Fne, annotate chat synthesizer llm as LLM
* Fix: stream AI chat natively async so a disconnect cancels the LLM request
The chat answer was a sync generator wrapped for ASGI, pulling each chunk
through sync_to_async(next). A client disconnect cancelled the response
task, but the worker thread waiting on the LLM could not be interrupted,
so the upstream request kept generating the whole answer for nobody.
Make stream_chat_with_documents an async generator. All the blocking setup
(ORM queries, the index read lock and its thread-bound sqlite connection,
the query embedding, building the LLM client) moves into one sync
_prepare_chat called once through sync_to_async, which also hands the DB
connection back before the answer streams. The answer then streams through
llama-index's asynthesize over the pinned async httpx clients, so a
disconnect cancels the LLM request directly. The view returns the async
generator as is, replacing the sync-to-async wrapper.
The async pinned transport resolved hostnames with a blocking getaddrinfo
on the event loop, which would stall the whole worker on slow DNS now that
chat uses it in the web server. Resolve in a thread instead, and add the
async counterparts of the existing transport tests.
* Ensures all the resources are closed even in odd cases and not just by gc
* Chore: remove unused is_file_ext_supported
Nothing in production called it, only its own test.
* Chore: remove unused Tag.parent_pk
It was an alias of tn_parent_id used only by two test asserts, which now use tn_parent_id directly.
* Chore: remove unused SanityCheckMessages summary properties
has_global_issues was never referenced and total_issue_count was only asserted in tests. The two private issue counters that fed it are removed as well, and the tests assert on has_error and has_warning instead.
* Chore: remove unused DocumentViewSet._has_document_permissions
It duplicated has_document_operation_permissions and had no callers.
* Chore: remove legacy DocumentParser base class
Parsers are resolved through the parser registry and ParserProtocol now, and nothing referenced this class. Its now unused imports are removed too.
* Chore: remove unused ColorField and DeprecatedColors
No serializer used ColorField, and DeprecatedColors was only referenced by it.
* Chore: remove unused RtlLanguageException
A leftover from the old tesseract parser, nothing referenced it.
* Chore: remove unused TASK_WORKERS setting
An alias of CELERY_WORKER_CONCURRENCY that nothing read. PAPERLESS_TASK_WORKERS is unchanged.
* Chore: remove unused GNUPG_HOME setting
Nothing read it. The mail GPG code uses EMAIL_GNUPG_HOME.
* Chore: remove unused test helpers
Drops the shared_samples_dir fixture, MailAttachmentMock, _SHORT_TEXT and _make_extract_text, none of which any test used.
* Chore: restrict uv lock environments to supported architectures
Limit the lock to Linux x86_64, Linux aarch64 and macOS arm64. Locked
versions are unchanged; only the unused wheel entries are removed.
* Chore: restrict uv lock environments to CPython
Add platform_python_implementation == 'CPython' to each supported
environment so the lock only resolves for interpreters we actually run on.
Basically PyPy was never supported anyway
Return a constant 10 character mask instead.
Move ObfuscatedPasswordField into paperless/fields.py so core no longer
imports it from paperless_mail, and add is_obfuscated_password() to
replace the five checks