LibreChat/api/server/services/Threads
Marco Beretta 8ae65f28dd
⚡ perf: Async Local File Saves and Compile Hot-Path Regexes Once (#16712)
* perf: Async Local File Saves and Compile Hot-Path Regexes Once

* perf: Check Closing Code Fences Without a Per-Length Regex Cache

* test: Build the Delivery Route Config Before Routing Instead of Mutating It

mergeFileConfig now memoizes by config identity, so the CSV fallback tests
must set textFallbackWithoutTools when they build the request config rather
than mutate the object after the agent's routing already merged it.

* fix: Write Local Buffers Atomically So Concurrent Saves Cannot Interleave

Async writeFile calls to one deterministic path (OpenID and SAML avatars)
could truncate and interleave each other. Write through a temp file and a
rename instead, and add scenario specs for local saves and longer closing
fences.

* refactor: Move Local Save Logic Into packages/api

saveLocalBuffer, the temp-upload move and the atomic directory writes now live
in packages/api/src/storage/local.ts and receive their paths from the caller;
the Local strategy in /api keeps its logging and calls through. The traversal
check now runs before any directory is created.

* fix: Copy Moved Uploads Through a Temp File and Rename Into Place

Concurrent async copies to one destination could interleave just like direct
writes, so moveLocalFile now fills a sibling temp file and renames it.

* fix: Contain Every Local Write and Move Inside Its Target Directory

The traversal check that guarded saveLocalBuffer now runs in writeLocalFile
and moveLocalFile too, before any directory is created, and the buffer
save accepts only the images and uploads base paths.

* test: Define the Success Assertion Inside the Local File Saves Scenario

* fix: Give Atomic Write Temp Files a Fixed-Length Name So Long Targets Still Fit

* test: Send Image Dimensions and Read the Message Array in the Local Saves Scenarios
2026-10-04 15:52:55 -04:00
..
index.js
manage.js
manage.retention.spec.js
manage.spec.js
processMessages.spec.js