You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 2fa9600
Browse filesBrowse the repository at this point in the historyBrowse files
* Fix race condition in embed_file_upload temp file path
Concurrent uploads with the same filename would write to the same temp
path because embed_file_upload used the filename directly under
RAG_UPLOAD_DIR, unlike embed_file which namespaces under user_id. Two
users uploading "report.pdf" simultaneously would corrupt each other's
data. Add user_id subdirectory to match embed_file's behavior.
* Fix connection leak and event loop blocking in mongo_health_check
Every health check call created a MongoClient, opened a connection pool,
and never closed it. Since health checks run frequently, this leaked
connections continuously. Also, MongoClient() and admin.command() are
blocking I/O calls that were running directly in an async function,
blocking the event loop.
Fix both: wrap blocking calls in asyncio.to_thread() and always close
the client in a finally block.
* Fix validation_exception_handler crash and body echo
request.body() re-reads the entire upload into memory inside the error
handler, and body.decode() raises UnicodeDecodeError on binary/non-ASCII
content, turning a 422 into a 500. The response also echoed potentially
large or sensitive upload content back to the caller. Remove the body
read entirely — the validation errors already contain all useful info.
* Remove dead exception branch in generate_digest
str.encode("utf-8") on a Python str never raises UnicodeEncodeError for
any valid Unicode string. The except branch handled surrogate characters
with an encode-decode-encode round-trip that produces the same result as
encode("utf-8", "ignore") directly. Replace with a single expression.
* Enable EMBEDDING_BATCH_SIZE by default (500)
The batch processing pipeline is fully built but disabled by default
(EMBEDDING_BATCH_SIZE=0). This means large documents embed all chunks in
one blocking call. Set default to 500 to enable streaming embeddings
into the DB while the rest are still being computed — the highest-
leverage memory improvement with zero new code.
* Stream CSV encoding conversion instead of reading entire file
Non-UTF-8 CSV files were read entirely into a single Python string
before writing to the temp file. For large files (e.g. 100MB UTF-16),
this causes unnecessary peak memory allocation. Stream in 64KB chunks
instead.
* Close asyncpg connection pool on shutdown
The pool was created during startup but never closed on shutdown.
Rolling deploys or OOM-killed pods leave connections in idle state until
TCP timeout, consuming PostgreSQL's finite connection limit. Close the
pool cleanly in the lifespan teardown.
* Address review findings: unique temp paths, guarded shutdown, tests
Finding 1: Wrap close_pool() in try/except so an exception doesn't
skip thread_pool.shutdown().
Finding 2+5: Use UUID-suffixed temp filenames via _make_unique_temp_path
in all three upload endpoints (embed, embed-upload, text). This prevents
same-user concurrent upload collisions (not just cross-user). Also moves
save_upload_file_async inside the try/finally block so temp files are
cleaned up even when the save itself fails.
Finding 3+6: Restore tuning guidance comment for EMBEDDING_BATCH_SIZE
explaining the default of 500 and when to increase.
Finding 4: Add tests for _make_unique_temp_path (uniqueness, user
isolation, extension preservation, traversal rejection) and
generate_digest (normal strings, unicode, surrogates, determinism).
* Clean up remaining nits from review
- Drop redundant second validate_file_path call in _make_unique_temp_path;
the UUID suffix is [0-9a-f]{32} with no path separators, so it cannot
escape the already-validated directory. Resolve the path directly.
- Fold os.makedirs into the try/finally block in all three upload
endpoints so an OSError (permissions, disk full) is caught by the
existing error handler instead of propagating as an unhandled 500.
- Fix hardcoded Unix separator in test assertion; use Path.parent.name
instead of string containment check.
0 commit comments