Skip to content

🧹 fix: Let File Deletes Succeed When the Code API No Longer Serves the Ref's Profile - #16671

Merged
danny-avila merged 3 commits into
LibreChat-AI:devfrom
TomasPalsson:fix/code-env-delete-profile-mismatch
Oct 4, 2026
Merged

danny-avila merged 3 commits into
LibreChat-AI:devfrom
TomasPalsson:fix/code-env-delete-profile-mismatch

Conversation

@TomasPalsson

Copy link
Copy Markdown
Contributor

Summary

A file that was provisioned to a code environment cannot be deleted once the Code API stops serving the profile its codeEnvRef was recorded under. deleteCodeEnvFile rethrows every error except a 404. A deployment that only serves the stateful profile answers a default-profile delete with 409 execution_profile_mismatch, and it does so on every retry. processDeleteRequest therefore puts the file in failedFileIds, 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 with Failed to provision N file(s) to the code environment; aborting tool execution rather than running without them.

This PR treats 409 execution_profile_mismatch on 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

  • Bug fix

Testing

New cases in api/server/services/Files/Code/crud.spec.js. A 409 execution_profile_mismatch now 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.

…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.
Copilot AI balanced review requested due to automatic review settings October 2, 2026 14:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

👋 Thanks for the contribution! LibreChat merges all changes into dev first — main only moves at release time — so this pull request's base branch was switched from main to dev automatically.

Nothing is needed from you; your commits, reviews and discussion are unchanged. If the diff now shows files you did not touch, rebase onto dev:

git remote add upstream https://github.com/LibreChat-AI/LibreChat.git
git fetch upstream dev
git rebase upstream/dev
git push --force-with-lease

Maintainers: apply the target: main label and restore the base branch if this one genuinely belongs on main.

@codegraph-librechat codegraph-librechat Bot added the 🗺️ Backend Platform codegraph: the taxonomy area this belongs to (classifier, confidence ≥ 0.9) label Oct 2, 2026
@danny-avila
danny-avila merged commit 5e4ecbc into LibreChat-AI:dev Oct 4, 2026
26 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🗺️ Backend Platform codegraph: the taxonomy area this belongs to (classifier, confidence ≥ 0.9)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants