fix: add missing /sessions/{session_id}/objects/{file_id} endpoint for LibreChat file freshness check#71
Open
gafda wants to merge 2 commits into
Open
Conversation
* Implement GET /sessions/{session_id}/objects/{file_id} to return file object metadata.
* Include lastModified timestamp for active sessions.
* Ensure compatibility with LibreChat's getSessionInfo.
* Add tests for the new endpoint to validate functionality and error handling.
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a new LibreChat-compatible endpoint GET /sessions/{session_id}/objects/{file_id} that returns file object metadata (notably lastModified) used by LibreChat's getSessionInfo to decide whether to re-upload a file.
Changes:
- New
get_session_objectroute handler insrc/api/files.pyreturning{name, lastModified}and 404 when file missing. - Accepts (but does not enforce)
kind/id/versionquery params for parity with LibreChat'sbuildCodeEnvDownloadQuery. - Unit tests covering existing file, missing file (404), and query param acceptance.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/api/files.py | Adds the new endpoint with session-aware lastModified derivation and 404 fallback. |
| tests/unit/test_librechat_contract.py | Adds TestGetSessionObject covering success, not-found, and query-param scenarios. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Rename 'id' param to 'resource_id' with alias='id' to avoid shadowing builtin - Log warning on session retrieval failure instead of silent except pass - Return 500 for unexpected errors instead of misleading 404 - Assert ACTIVE branch timestamp is close to now in test - Add test case for inactive session with last_activity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
LibreChat's
getSessionInfo(inprocess.js) callsGET /sessions/{session_id}/objects/{file_id}?kind=user&id={userId}to verify whether previously-uploaded files are still active in the code environment before priming them into the sandbox.KubeCodeRun lacked this route entirely, so every call returned 404. This caused LibreChat to treat every file as expired, triggering a re-upload cycle on every turn. Users experienced repeated "you haven't uploaded any file" errors and had to retry messages multiple times until the session state aligned.
Fix
Added
GET /sessions/{session_id}/objects/{file_id}endpoint that returns{ name, lastModified }, satisfying LibreChat's freshness check. The endpoint:last_activitytimestamp for active sessions (matching the existing/files/{session_id}summary logic)kind,id,versionquery params for LibreChat compatibility (not enforced server-side)Evidence (LibreChat calling this endpoint)
LibreChat's
getSessionInfo()inapi/server/services/Files/Code/process.js:681builds:This is invoked from two call sites:
primeCodeFiles(process.js:933) — checks freshness of every previously-uploaded file before each code execution turn.primeSkillFiles(packages/api/src/agents/skillFiles.ts:118) — checks freshness of skill-primed files.If the endpoint returns 404 (missing),
getSessionInforeturnsnull, LibreChat treats the file as expired, and attempts a re-upload cycle. With KubeCodeRun lacking this route, every turn triggered this cycle, explaining the repeated "you haven't uploaded any file" error and the flood of 404s in logs.The
checkIfActive()function (process.js:661) checks thatlastModifiedis less than 23 hours old. For active sessions, we returndatetime.now(UTC)which always satisfies this constraint.