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

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.
This commit is contained in:
Tómas Pálsson 2026-10-04 15:38:31 +00:00 • committed by GitHub
parent 69d88f4930
commit 5e4ecbc24c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 40 additions and 2 deletions

View file

@ -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}`,
});
}
}

View file

@ -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 } }),