Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

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

Tómas Pálsson5e4ecbc24c1b
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 } }),