From 5e4ecbc24c1bfba1ad4ffec5ec46440754da91a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B3mas=20P=C3=A1lsson?= <46539820+TomasPalsson@users.noreply.github.com> Date: Sun, 4 Oct 2026 15:38:31 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20fix:=20Let=20File=20Deletes=20Su?= =?UTF-8?q?cceed=20When=20the=20Code=20API=20No=20Longer=20Serves=20the=20?= =?UTF-8?q?Ref's=20Profile=20(#16671)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- api/server/services/Files/Code/crud.js | 15 ++++++++++-- api/server/services/Files/Code/crud.spec.js | 27 +++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/api/server/services/Files/Code/crud.js b/api/server/services/Files/Code/crud.js index 8e2fec15c2..e6e625f048 100644 --- a/api/server/services/Files/Code/crud.js +++ b/api/server/services/Files/Code/crud.js @@ -72,6 +72,14 @@ async function getCodeOutputDownloadStream(fileIdentifier, identity, req, route } } +/** + * A deployment that no longer serves a ref's profile rejects every retry the same + * way, so failing the delete would leave a record the user can never remove and an + * agent that aborts every code turn on it. + */ +const isProfileMismatch = (error) => + error.response?.status === 409 && error.response?.data?.error === 'execution_profile_mismatch'; + /** * Deletes a file from the Code Environment server. * @@ -148,7 +156,8 @@ async function deleteCodeEnvFile(req, file) { timeout: 15000, }); } catch (error) { - if (error.response?.status !== 404) { + const profileMismatch = isProfileMismatch(error); + if (error.response?.status !== 404 && !profileMismatch) { throw error; } /* Already gone. Logged rather than swallowed: a 404 from a @@ -156,7 +165,9 @@ async function deleteCodeEnvFile(req, file) { * object, and this branch drops the file's record either way. */ logAxiosError({ error, - message: `Code environment object already absent: ${error.message}`, + message: profileMismatch + ? `Code environment no longer serves the ${executionProfile} profile; dropping the unreachable object: ${error.message}` + : `Code environment object already absent: ${error.message}`, }); } } diff --git a/api/server/services/Files/Code/crud.spec.js b/api/server/services/Files/Code/crud.spec.js index 811e2cf6cb..042b6e90a5 100644 --- a/api/server/services/Files/Code/crud.spec.js +++ b/api/server/services/Files/Code/crud.spec.js @@ -366,6 +366,33 @@ describe('Code CRUD', () => { expect(mockAxios).toHaveBeenCalledTimes(1); }); + it('treats objects on a profile the deployment no longer serves as unreachable', async () => { + mockAxios.mockRejectedValue( + Object.assign(new Error('Request failed with status code 409'), { + response: { + status: 409, + data: { + error: 'execution_profile_mismatch', + expected_profile: 'default', + actual_profile: 'stateful', + }, + }, + }), + ); + + await expect(deleteCodeEnvFile(req, file)).resolves.toBeUndefined(); + }); + + it('throws on other conflicts', async () => { + mockAxios.mockRejectedValue( + Object.assign(new Error('conflict'), { + response: { status: 409, data: { error: 'session_busy' } }, + }), + ); + + await expect(deleteCodeEnvFile(req, file)).rejects.toThrow('conflict'); + }); + it('throws when code environment deletion fails', async () => { mockAxios.mockRejectedValue( Object.assign(new Error('unavailable'), { response: { status: 500 } }),