Skip to content

feat: evaluate only the parameter/preset/tag closure, with an opt-out - #226

Merged
Emyrk merged 4 commits into
mainfrom
steven/closure
Sep 15, 2026
Merged

Emyrk merged 4 commits into
mainfrom
steven/closure

Conversation

@Emyrk

@Emyrk Emyrk commented Sep 11, 2026

Copy link
Copy Markdown
Member

Evaluates only the coder_parameter / coder_workspace_preset / coder_workspace_tags closure when rendering, with an opt-out. Supersedes #221 (thanks @PushTheLimit); the trivy side is coder/trivy#74.

  • Bumps the trivy pin to a commit with OptionWithResourceClosure, and passes it by default so root resources nothing in the closure references are skipped. On the motivating template EvaluateAll drops from ~2s to ~0.16s.
  • Preview takes opts ...Option. OptionFullEvaluation() evaluates every resource, so coderd can turn the optimization off behind a setting without a new preview release if a template misbehaves.
  • Test_Extract runs every vector in both modes against the same expectations, pinning that parameters, presets, tags, and variables are identical either way. Test_OptionFullEvaluation observes the difference through Output.ModuleOutput.

Behavior notes:

  • Output.ModuleOutput may contain unknown values for root outputs that read pruned resources. Nothing in coderd consumes it.
  • Templates containing .tf.json files skip pruning entirely (trivy's JSON reference extraction is not reliable enough to prune on).

Test coverage for the reference shapes the pruner must see through landed separately in #223 and #224.

Prepared with Coder Agents assistance.

Preview now passes OptionWithResourceClosure to the parser by default so
root resources nothing in the parameter, preset, or tag closure references
are skipped. Preview takes variadic options; OptionFullEvaluation restores
evaluating every resource, so a caller can turn the optimization off
without a new preview release if a template misbehaves.

Test_Extract runs every vector in both modes against the same
expectations. Test_OptionFullEvaluation observes the difference through
Output.ModuleOutput, which is the one output the closure changes.
@Emyrk Emyrk changed the title Steven/closure feat: evaluate only the parameter/preset/tag closure, with an opt-out Sep 11, 2026
@Emyrk
Emyrk marked this pull request as ready for review September 11, 2026 20:42
@Emyrk
Emyrk requested a review from geokat September 11, 2026 20:43

@geokat geokat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, other than the possible race (see comment).

Comment thread preview_test.go Outdated
Both mode subtests wrote tc.unknownTags and tc.expTags on the shared tc,
which the race detector flags.
@Emyrk
Emyrk merged commit c0dfdee into main Sep 15, 2026
4 checks passed
@Emyrk
Emyrk deleted the steven/closure branch September 15, 2026 13:58
Emyrk added a commit to coder/coder that referenced this pull request Sep 17, 2026
Bumps `github.com/coder/preview` to pick up resource closure evaluation (coder/preview#226) and its `OptionFullEvaluation` opt-out. The `coder/trivy` replace moves to the commit that provides `OptionWithResourceClosure` (coder/trivy#74), matching what preview pins.

Behavior is unchanged in this PR: `preview.Preview` now prunes root resources outside the parameter/preset/tag closure by default, and coderd already only reads parameters, presets, and tags from it. The next PR in the stack adds a deployment-level escape hatch.

Prepared with Coder Agents assistance.
Emyrk added a commit to coder/coder that referenced this pull request Sep 17, 2026
…ion (#29356)

**What changed**
Dynamic parameter rendering now evaluates only the coder parameter blocks and what they reference. Other root-module resources are skipped. Parameter, preset, and tag values are unchanged; optimizing rendering on large templates.

**How to revert**
Set `CODER_DYNAMIC_PARAMETERS_FULL_EVALUATION=true` (or `--dynamic-parameters-full-evaluation`) on `coder server` to restore full evaluation. The flag is hidden and needs no restart of workspaces. If you need it, please [open an issue](https://github.com/coder/coder/issues/new) with the template so we can fix the root cause.

**Troubleshooting**
Symptoms would be a parameter default, option list, preset value, or workspace tag that shows as unknown or empty after upgrading, when it was populated before. Confirm by setting the flag above; if the value comes back, report it. Templates written in `.tf.json` are not affected (they always use full evaluation).

**Why**
Rendering re-ran the entire template graph on every parameter change in the workspace form, which dominated latency on large templates. Resources a workspace would create cannot feed a parameter, so evaluating them is wasted work. The optimization lives in coder/preview#226 (coder/trivy#74); this PR adds the deployment-level escape hatch.

---

- `CODER_DYNAMIC_PARAMETERS_FULL_EVALUATION` / `--dynamic-parameters-full-evaluation` (hidden, default `false`) on `DeploymentValues`.
- `dynamicparameters.PreviewOptions(dv)` maps it to `preview.OptionFullEvaluation()`; `dynamicparameters.WithPreviewOptions` threads it through the loader to `preview.Preview`.
- Wired at the three render paths that hold deployment values: the template version tags extractor, the dynamic parameters websocket, and `wsbuilder` builds created from `coderd` (which call `.DeploymentValues(...)`).

Not covered: the autobuild lifecycle executor and the enterprise prebuilds reconciler construct `wsbuilder` without deployment values, so builds started from those paths use preview's default regardless of the flag. Those only re-render for builds, not the keystroke websocket path the optimization targets.

Prepared with Coder Agents assistance.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants