Files
coder/coderd/wsbuilder
Steven Masley 36ea6eaf80 fix(coderd): do not narrow the parameter set on non-start builds (#29102)
Fixes part of #29099
([ENG-3324](https://linear.app/codercom/issue/ENG-3324)).

## What this does

Only a start build may narrow the stored set. A stop or delete build
does not change which parameters a workspace has.

## Why

A stop or delete build re-resolves the workspace parameters and deletes
every stored value the render did not return.

- When a template version's `cached_module_files` is NULL the renderer
cannot load modules, and the parameters are dropped. Any `restart` or
`coder update`, uses the broken version for `stop` and all parameters
are removed before the fixed `start`.
  - This can happen on any broken template version

## Scope

This does not fix a start build that resolves against a version with a
NULL module cache, which still truncates. That is the completeness-aware
discard loop described in the issue, and it lands separately.

## Tests

- `TestResolveParameters/UnmatchedValues` covers all three transitions
at the resolver level.
- `TestDynamicParametersModuleCachePurged` is an end-to-end regression
test: create a workspace with a module declared parameter, remove the
module cache, stop, and assert the value survives. It fails on `main`.

<details>
<summary>Implementation plan</summary>

### Problem

`dynamicparameters.ResolveParameters` ends with an unconditional discard
loop (`coderd/dynamicparameters/resolver.go`) that deletes every stored
value whose parameter is absent from the render output. With a NULL
module cache the render is incomplete, `preview` reports
`module_not_loaded` at warning severity, and the reduced parameter set
is treated as authoritative.

`wsbuilder.getParameters()` is transition-agnostic, so a stop build
persists that truncated set. `cli/update.go` stops first against the
workspace's current version, then starts against the active version, and
the start build reads the truncated set via `getLastBuildParameters()`.

### Coverage

| Case | Fixed here |
|---|---|
| `coder update`, old version purged, active version healthy | yes |
| Workspace sits on a purged version, autostop then autostart | no,
needs the discard loop fix |
| `require_active_version` where the active version is purged | no,
needs the discard loop fix |

### Changes

1. `resolver.go`: gate the discard loop on the build transition.
Ephemeral trimming, immutability, monotonicity, and default backfill are
unchanged.
2. `wsbuilder.go`: pass `b.trans`. Single non-test caller.

### Deliberate calls

- `delete` is treated like `stop`. Neither transition changes which
parameters a workspace has, and it keeps the condition to one
comparison.
- The transition is passed rather than a second boolean flag, so the
call site stays unambiguous next to `firstBuild`.

</details>

---

🤖 Authored by Coder Agents on behalf of @Emyrk.
2026-09-08 11:01:59 -05:00
..