fix(turns): align info.TaskEnvironmentID with the resolved env after fallback

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.
This commit is contained in:
José Almeida
2026-05-14 00:06:06 +01:00
parent ac7309fd14
commit e6195f3fc0
@@ -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
}