From e6195f3fc0e25f748b29f02a8b0f9dd57731863b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Almeida?= Date: Thu, 14 May 2026 00:06:06 +0100 Subject: [PATCH] fix(turns): align info.TaskEnvironmentID with the resolved env after fallback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GetWorkspaceInfoForSession initializes info.TaskEnvironmentID from session.TaskEnvironmentID, then resolves the env — first by that ID, falling back to GetTaskEnvironmentByTaskID when the session's ID points to a stale/missing row. When the fallback kicks in, the resolved env has a different ID, but applyTaskEnvironmentToWorkspaceInfo was only updating info.TaskEnvironmentID when it was empty. So downstream reconcilers received metadata + path from one env keyed by a different env's ID. Always overwrite info.TaskEnvironmentID with env.ID inside the apply function — once we've picked an env to spread, the info should identify that env consistently. --- apps/backend/internal/task/service/service_turns.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/backend/internal/task/service/service_turns.go b/apps/backend/internal/task/service/service_turns.go index d7ca50ac8a..6febd61c8d 100644 --- a/apps/backend/internal/task/service/service_turns.go +++ b/apps/backend/internal/task/service/service_turns.go @@ -395,9 +395,14 @@ func (s *Service) GetWorkspaceInfoForSession(ctx context.Context, taskID, sessio } func applyTaskEnvironmentToWorkspaceInfo(info *lifecycle.WorkspaceInfo, env *models.TaskEnvironment) { - if info.TaskEnvironmentID == "" { - info.TaskEnvironmentID = env.ID - } + // Always align info.TaskEnvironmentID with the env we resolved against. + // When session.TaskEnvironmentID points to a stale/missing env, the + // caller falls back to GetTaskEnvironmentByTaskID and ends up with a + // different env.ID. Previously we only updated info.TaskEnvironmentID + // when it was empty, so the metadata + path here would come from env + // while the ID still pointed at the stale row — a mismatch downstream + // reconcilers and progress events would key off the wrong env. + info.TaskEnvironmentID = env.ID if info.WorkspacePath == "" { info.WorkspacePath = env.WorkspacePath }