Skip to content

Conversation

@deansheather
Copy link
Member

@deansheather deansheather commented Nov 12, 2025

Problem

The prepWorkspaceBuild() function in cli/create.go was unconditionally executing dry-runs for all workspace actions. This caused unnecessary delays and "Planning workspace..." messages during coder start and coder restart commands when they should only happen during coder create and coder update.

Root Cause

The prepWorkspaceBuild() function is shared code called by:

  • create command - passes WorkspaceCreate action ✅ dry-run IS desired
  • update command - passes WorkspaceUpdate action ✅ dry-run IS desired
  • start command - passes WorkspaceStart action (or WorkspaceUpdate as fallback) ❌ dry-run NOT desired for WorkspaceStart
  • restart command - passes WorkspaceRestart action ❌ dry-run NOT desired
  • scaletest commands - pass WorkspaceCreate action ✅ dry-run IS desired

Solution

Wrapped the dry-run section (lines 580-627) in a conditional that only executes when args.Action == WorkspaceCreate || args.Action == WorkspaceUpdate.

This skips dry-run for WorkspaceStart and WorkspaceRestart actions while preserving it for creation and explicit updates.

Changes

  • Added conditional check around the entire dry-run logic block
  • Added clarifying comment explaining the intent
  • Changed from unconditional execution to: if args.Action == WorkspaceCreate || args.Action == WorkspaceUpdate { ... }

Impact

Command Action Type Dry-run Before Dry-run After Status
coder create WorkspaceCreate ✅ Yes ✅ Yes Unchanged
coder update WorkspaceUpdate ✅ Yes ✅ Yes Unchanged
coder start (normal) WorkspaceStart ❌ Yes (bug) ✅ No Fixed
coder start (template changed) WorkspaceUpdate ✅ Yes ✅ Yes Unchanged (correct behavior)
coder restart WorkspaceRestart ❌ Yes (bug) ✅ No Fixed
scaletest WorkspaceCreate ✅ Yes ✅ Yes Unchanged

Testing

Code compiles successfully

go build -o /dev/null ./cli/...

All relevant tests pass locally

cd cli && go test -run "TestCreate|TestStart|TestRestart|TestUpdate" -v
PASS
ok      github.com/coder/coder/v2/cli   3.337s

All CI checks pass

  • test-go-pg (ubuntu, macos, windows) ✅
  • test-go-pg-17 ✅
  • test-go-race-pg ✅
  • test-e2e ✅
  • All other checks ✅

Behavior Changes

Before:

  • Users running coder start would see "Planning workspace..." and wait for unnecessary dry-run completion
  • Users running coder restart would experience unnecessary dry-run overhead

After:

  • coder start (simple start) skips dry-run entirely (faster, more intuitive)
  • coder start (with template update) still shows dry-run (correct - user needs to see what's changing)
  • coder restart skips dry-run entirely (faster, more intuitive)
  • coder create maintains existing dry-run behavior (shows "Planning workspace..." and resource preview)
  • coder update maintains existing dry-run behavior (shows "Planning workspace..." and resource preview)

Verification

Manual testing should verify:

  1. coder create still shows "Planning workspace..." ✅
  2. coder update still shows "Planning workspace..." ✅
  3. coder start (simple start) does NOT show "Planning workspace..." ✅
  4. coder restart does NOT show "Planning workspace..." ✅

The prepWorkspaceBuild() function was unconditionally executing
dry-runs for ALL workspace actions. This caused unnecessary delays
and "Planning workspace..." messages during 'coder start' and
'coder restart' commands.

This change wraps the dry-run section (lines 580-627) in a
conditional that only executes when args.Action == WorkspaceCreate.

Impact:
- 'coder create' - Still performs dry-run (unchanged)
- 'coder start' - Now skips dry-run (fixed)
- 'coder restart' - Now skips dry-run (fixed)
- scaletest commands - Still perform dry-run (unchanged)

Fixes the bug where starting/restarting workspaces would execute
unnecessary provisioner dry-runs, improving performance and UX.
@deansheather deansheather force-pushed the dean-fix-starts-dry-run branch from c1cb734 to 0b24b30 Compare November 12, 2025 22:35
@deansheather deansheather merged commit a8f2a8a into main Nov 12, 2025
27 checks passed
@deansheather deansheather deleted the dean-fix-starts-dry-run branch November 12, 2025 22:48
@github-actions github-actions bot locked and limited conversation to collaborators Nov 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants