From c5c08b0089fff484521843973c8501ed6d462e06 Mon Sep 17 00:00:00 2001 From: Harold Kim Date: Thu, 9 Jul 2026 09:59:45 +0000 Subject: [PATCH] fix: check cancellation status before tearing down terminal session store and connection registry Moves deleteBySetupSessionId and closeBySetupSessionId to fire only after the non-terminal status guard, so terminal resources are not torn down when a forced delete is rejected due to a failed custom-image session cancellation. Co-Authored-By: Paperclip --- server/src/routes/environments.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server/src/routes/environments.ts b/server/src/routes/environments.ts index 55f02b1d008..1f03d012bd1 100644 --- a/server/src/routes/environments.ts +++ b/server/src/routes/environments.ts @@ -335,17 +335,17 @@ export function environmentRoutes( sessionId: overview.activeSession.id, reason: "environment_deleted", }); - environmentCustomImageTerminalSessionStore.deleteBySetupSessionId(overview.activeSession.id); - environmentCustomImageTerminalConnectionRegistry.closeBySetupSessionId( - overview.activeSession.id, - "environment_deleted", - ); if (cancelled.status === "failed" || ACTIVE_CUSTOM_IMAGE_SETUP_STATUSES_FOR_DELETE.has(cancelled.status)) { throw conflict( "Environment delete could not cancel the active custom image setup session. Retry after the failed setup cleanup is resolved.", { setupSessionId: cancelled.id }, ); } + environmentCustomImageTerminalSessionStore.deleteBySetupSessionId(overview.activeSession.id); + environmentCustomImageTerminalConnectionRegistry.closeBySetupSessionId( + overview.activeSession.id, + "environment_deleted", + ); } } }