-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Problem
Workspace template updates that occur when dynamic parameters are enabled bypass the stop-before-start logic, causing agent reconnection failures and inconsistent behavior.
Root Cause
PR #18425 introduced stop-before-start logic for template updates, but when dynamic parameters support was added, a new code path was created that bypasses this logic:
site/src/api/api.ts:2331-2338 - Dynamic parameters path directly starts workspace without stopping first:
if (isDynamicParametersEnabled) {
try {
return await this.postWorkspaceBuild(workspace.id, {
transition: "start", // ❌ No stop first
template_version_id: activeVersionId,
rich_parameter_values: newBuildParameters,
});
site/src/api/api.ts:2370-2384 - Legacy path correctly stops first:
// Stop the workspace if it is already running.
if (workspace.latest_build.status === "running") {
const stopBuild = await this.stopWorkspace(workspace.id);
const awaitedStopBuild = await this.waitForBuild(stopBuild);
// ... handle cancellation
}
Additionally, changeWorkspaceVersion
(line 2254) never had the stop-first logic at all, regardless of dynamic parameters.
Why Stop-First is Required
As documented in #17840:
- Template updates regenerate agent tokens
- Without a stop+start, resources with
ignore_changes
(like prebuilds) don't get recreated - Old agent tokens become invalid, but the agent container continues using them
- This causes agent disconnection and requires manual workspace restart
Proposed Solution
Apply stop-before-start logic to both:
- The dynamic parameters path in
updateWorkspace
- The
changeWorkspaceVersion
function
See #17840 for the original reasoning behind stop-before-start behavior.