🧹 fix: Let File Deletes Succeed When the Code API No Longer Serves the Ref's Profile - #16671
Merged
danny-avila merged 3 commits intoOct 4, 2026
Conversation
…e Ref's Profile deleteCodeEnvFile rethrew every error except 404. A deployment that only serves the stateful profile answers a default-profile delete with 409 execution_profile_mismatch on every retry, so the file landed in failedFileIds, its record and agent references stayed, and agents holding it aborted every code turn with "Failed to provision N file(s) to the code environment". The mismatch is now handled like an absent object: logged, and the delete proceeds. Other 409s, 5xx, auth and network errors still fail the delete.
Contributor
|
👋 Thanks for the contribution! LibreChat merges all changes into Nothing is needed from you; your commits, reviews and discussion are unchanged. If the diff now shows files you did not touch, rebase onto git remote add upstream https://github.com/LibreChat-AI/LibreChat.git
git fetch upstream dev
git rebase upstream/dev
git push --force-with-leaseMaintainers: apply the |
danny-avila
approved these changes
Oct 4, 2026
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.
Summary
A file that was provisioned to a code environment cannot be deleted once the Code API stops serving the profile its
codeEnvRefwas recorded under.deleteCodeEnvFilerethrows every error except a 404. A deployment that only serves thestatefulprofile answers adefault-profile delete with409 execution_profile_mismatch, and it does so on every retry.processDeleteRequesttherefore puts the file infailedFileIds, the record and its agent references stay, and the user is told the delete partly failed no matter how often they try. Because the agent keeps the reference, a file whose local bytes are already gone also makes every later code turn abort withFailed to provision N file(s) to the code environment; aborting tool execution rather than running without them.This PR treats
409 execution_profile_mismatchon delete the way a 404 is already treated. It logs that the object is unreachable on this deployment and lets the delete proceed, so the record and the agent references are removed. Every other failure (other 409s, 5xx, auth and network errors) still fails the delete, so the sweep's park-and-retry behaviour is unchanged.We hit this in production after moving a deployment to a stateful-only self-hosted Code API. Users retried deleting agent template files dozens of times; each attempt logged a local
ENOENT(benign) followed by the 409.Type of change
Testing
New cases in
api/server/services/Files/Code/crud.spec.js. A409 execution_profile_mismatchnow resolves; it failed before the fix. A 409 with any other error code still rejects. The existing 500 case still rejects.npx jest server/services/Files/Code/ server/services/Files/process.spec.js server/services/Files/process.integration.spec.js: 6 suites, 325 tests passed.Risk / compatibility
The behaviour changes only for a 409 whose body is
execution_profile_mismatch. In that case the sandbox object may remain on a deployment that can no longer serve it, which is the same trade-off the 404 branch already makes for a misconfigured base URL. The mismatch is logged with the profile so that it can be traced. This PR does not change how provisioning picks a profile.