LibreChat/api/server/services/Files/Code
Marco Beretta 654ce897e9
🗄️ fix: Skip Attachments Deleted by Storage Retention Instead of Failing the Turn (#17910)
* fix: Skip Attachments Deleted by Storage Retention Instead of Failing the Turn

A file that storage retention removed from an earlier message made every
later turn of the conversation fail, because the encoders rethrew the
storage miss and the user has no way to remove an attachment from history.

History replay now passes a handler to the encoders, which leave missing
files out of the request and report them; the message's file context tells
the model which files were deleted and were not read. Current-turn
attachments keep the strict error, since the user can remove and re-upload
them. Code Interpreter priming names files missing from storage in the
tool context and only requires resource recovery for other failures.

* refactor: Keep Code Reupload Failure Policy in packages/api

Tally priming reupload failures in createCodeReuploadFailures so the
decision that a file deleted from storage is named instead of requiring
resource recovery lives in TypeScript, and add mock e2e scenarios for a
follow-up after an attachment is deleted from storage.

* fix: Classify Code Files as Deleted Only at the Storage Read

A 404 from the Code API upload was counted as a source file deleted from
storage, which skipped resource recovery. openCodeFileSource marks a miss
where the stored object is read, and only that error counts as deleted.

Move the history replay of attachments with tolerated misses into
replayMessageAttachments so BaseClient only calls it.

* fix: Name Local Code Files Whose Stream Reports a Missing Object

Local storage returns a read stream that raises ENOENT only once read, so
openCodeFileSource now holds a stream until its first chunk or error and
names a miss there. The missing-files context assignment moves into
setMissingCodeFilesContext so both tool loaders only call it.

* fix: Close a Held Code File Stream When Priming Is Cancelled

openCodeFileSource waits for a source stream's first chunk; when that
wait fails, as on cancellation, the caller never receives the stream, so
destroy it before rethrowing instead of leaking its file descriptor.
2026-11-08 23:38:47 +01:00
..
__tests__ 🌳 fix: Preserve Primary Files Until Secondary Cleanup Succeeds (#17228) 2026-10-23 07:00:20 +02:00
crud.js 🌳 fix: Preserve Primary Files Until Secondary Cleanup Succeeds (#17228) 2026-10-23 07:00:20 +02:00
crud.spec.js 🌳 fix: Preserve Primary Files Until Secondary Cleanup Succeeds (#17228) 2026-10-23 07:00:20 +02:00
index.js
preflight.js 🔇 fix: Stop logging an absent create_file target as an error (#15591) 2026-09-04 09:21:24 -04:00
preflight.spec.js 🔇 fix: Stop logging an absent create_file target as an error (#15591) 2026-09-04 09:21:24 -04:00
process.js 🗄️ fix: Skip Attachments Deleted by Storage Retention Instead of Failing the Turn (#17910) 2026-11-08 23:38:47 +01:00
process.spec.js 🗄️ fix: Skip Attachments Deleted by Storage Retention Instead of Failing the Turn (#17910) 2026-11-08 23:38:47 +01:00