Skip to content

fix: use dynamic parameter resolution in the cli#21734

Merged
Emyrk merged 7 commits intomainfrom
dynamic_parameter__cli_fix
Feb 3, 2026
Merged

fix: use dynamic parameter resolution in the cli#21734
Emyrk merged 7 commits intomainfrom
dynamic_parameter__cli_fix

Conversation

@Emyrk
Copy link
Member

@Emyrk Emyrk commented Jan 28, 2026

Closes #19879

What this does

Uses dynamic parameters EvaluateTemplateVersion vs TemplateVersionRichParameters to determine initial parameter state.

This is still not perfect, as dynamic templates are reactive. So if the cli prompts the user for a value, that value can change another parameter. So to fix this holistically, we need fundamentally redesign the parameter logic in the cli to be in a loop. The ux for that is not obvious though, as you might have to re-prompt the user for things they already decided?

For now, this is a stop gap. This handles if the initial parameters are dynamic based on initial inputs (initial args & user context)

Changes Summary (AI generated)

Core Logic (cli/create.go)

  • Added Owner field to prepWorkspaceBuildArgs to support dynamic parameter evaluation
  • Modified prepWorkspaceBuild to check template.UseClassicParameterFlow and conditionally use either:
    • Classic flow: client.TemplateVersionRichParameters() (existing behavior)
    • Dynamic flow: client.EvaluateTemplateVersion() with initial parameter values from CLI inputs

Parameter Resolution (cli/parameterresolver.go)

  • Added InitialValues() method to gather CLI-provided parameter values (from flags, files, presets, last build, etc.) without validating against template parameters. This is required to initialize any dynamic elements of a template off the original input.

Copy link
Member Author

Emyrk commented Jan 28, 2026

@Emyrk Emyrk force-pushed the dynamic_parameter__cli_fix branch from 9bfa44b to c98542a Compare January 28, 2026 19:22
@Emyrk Emyrk force-pushed the org_member_fetch branch 2 times, most recently from f7c8acd to da22b9c Compare January 28, 2026 20:02
@Emyrk Emyrk force-pushed the dynamic_parameter__cli_fix branch 3 times, most recently from c8bc7fb to 374aa14 Compare January 28, 2026 20:17
@Emyrk Emyrk changed the title fix: use dynamic parameter resolution in the cli fix: use dynamic parameter resolution in the cli (create) Jan 28, 2026
@Emyrk Emyrk force-pushed the dynamic_parameter__cli_fix branch 2 times, most recently from 526c413 to 52b13b6 Compare January 30, 2026 17:26
@github-actions
Copy link

github-actions bot commented Jan 30, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@Emyrk Emyrk force-pushed the dynamic_parameter__cli_fix branch from 52b13b6 to f7ccc47 Compare January 30, 2026 17:59
@Emyrk Emyrk marked this pull request as ready for review January 30, 2026 19:59
@Emyrk Emyrk changed the title fix: use dynamic parameter resolution in the cli (create) fix: use dynamic parameter resolution in the cli Jan 30, 2026
@Emyrk Emyrk force-pushed the dynamic_parameter__cli_fix branch from 838493d to 9ba2198 Compare February 2, 2026 16:47
@Emyrk Emyrk force-pushed the dynamic_parameter__cli_fix branch from 9ba2198 to 33ab544 Compare February 3, 2026 15:30
@Emyrk Emyrk force-pushed the dynamic_parameter__cli_fix branch 2 times, most recently from 0de394a to 2b9bd55 Compare February 3, 2026 15:49
@Emyrk Emyrk requested a review from johnstcn February 3, 2026 15:49

func (pr *ParameterResolver) resolveWithLastBuildParameters(resolved []codersdk.WorkspaceBuildParameter, templateVersionParameters []codersdk.TemplateVersionParameter) []codersdk.WorkspaceBuildParameter {
func (pr *ParameterResolver) resolveWithLastBuildParameters(resolved []codersdk.WorkspaceBuildParameter) []codersdk.WorkspaceBuildParameter {
if pr.promptRichParameters {
Copy link
Member

Choose a reason for hiding this comment

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

Calling resolveWithLastBuildParameters in this case feels like a logic error? Nevertheless I'm OK with short-circuiting here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't follow what you are saying 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Why call this function at all if we know ahead of time that we don't want to fetch parameters from the last build?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I see. Do you mean instead to write it as:

	if !pr.promptRichParameters {
		staged = pr.resolveWithLastBuildParameters(staged)
	}

instead?

If so, I'm not changing to code pattern, I just moved some existing code around

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps; the flow just seemed weird to me. Not a blocker in any case.

Copy link
Member Author

Choose a reason for hiding this comment

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

The parameter resolution code is a bit tangled imo. I wanted to avoid trying to untangle it, and just update it to use the dynamic param resolver instead of the static.

"workspace_folder": "/workspace1",
"name": "dev1",
"id": "eb9b7f18-c277-48af-af7c-2a8e5fb42bab",
"subagent_id": "72d17819-ea3b-450a-a502-175886583ecf"
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this change is relevant, see also L35 below.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is strange. I just rebased it, and make gen did this. I assumed I missed something on main. Looking into it

@Emyrk Emyrk force-pushed the dynamic_parameter__cli_fix branch 2 times, most recently from 10bb903 to 1841432 Compare February 3, 2026 17:34
@Emyrk Emyrk force-pushed the dynamic_parameter__cli_fix branch from 1841432 to 7afdcf3 Compare February 3, 2026 17:46
@Emyrk Emyrk force-pushed the dynamic_parameter__cli_fix branch from 7afdcf3 to 92f45cc Compare February 3, 2026 18:10
@Emyrk Emyrk force-pushed the org_member_fetch branch 2 times, most recently from 7d2d291 to dabb755 Compare February 3, 2026 18:27
@Emyrk Emyrk force-pushed the dynamic_parameter__cli_fix branch from 92f45cc to 9d448e6 Compare February 3, 2026 18:27
@Emyrk Emyrk changed the base branch from org_member_fetch to graphite-base/21734 February 3, 2026 18:48
Emyrk added 6 commits February 3, 2026 18:48
When using dynamic parameters, parameters without template defaults are
marked as required. However, users can still provide defaults via CLI
flags (--parameter-default). This change ensures:

1. The default value is shown in the prompt text whenever one is
   provided (via CLI flags), regardless of whether the parameter is
   marked as required.

2. Validation accepts empty input when a CLI default is available,
   substituting the default value before validation runs.
@Emyrk Emyrk force-pushed the graphite-base/21734 branch from dabb755 to 6759b51 Compare February 3, 2026 18:48
@Emyrk Emyrk force-pushed the dynamic_parameter__cli_fix branch from 9d448e6 to 1025e2c Compare February 3, 2026 18:48
@graphite-app graphite-app bot changed the base branch from graphite-base/21734 to main February 3, 2026 18:49
@Emyrk Emyrk force-pushed the dynamic_parameter__cli_fix branch from 1025e2c to d535f5b Compare February 3, 2026 18:49
@Emyrk Emyrk merged commit b1e18f2 into main Feb 3, 2026
28 of 29 checks passed
@Emyrk Emyrk deleted the dynamic_parameter__cli_fix branch February 3, 2026 20:10
@github-actions github-actions bot locked and limited conversation to collaborators Feb 3, 2026
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.

FR: CLI parameter resolver fails for dynamic parameters while API works fine

2 participants