windmill-labs/windmill · error · Error

Could not find the selected id in the flow

Error message

Could not find the selected id in the flow

What it means

StepInputGen.svelte's generateStepInput() validates the selection the same way before slicing flow context for the AI; a selected id missing from the DFS-ordered module ids throws 'Could not find the selected id in the flow'.

Source

Thrown at frontend/src/lib/components/copilot/StepInputGen.svelte:77

			$schema: 'https://json-schema.org/draft/2020-12/schema',
			properties,
			required,
			type: 'object'
		}
	}

	async function generateStepInput() {
		if (generatedContent.length > 0 || loading) {
			return
		}
		logStepInputFill('single')
		abortController = new AbortController()
		loading = true
		const flow: Flow = JSON.parse(JSON.stringify(flowStore.val))
		const idOrders = dfs(flow.value.modules, (x) => x.id)
		const upToIndex = idOrders.indexOf(selectionManager.getSelectedId())
		if (upToIndex === -1) {
			throw new Error('Could not find the selected id in the flow')
		}

		const flowDetails =
			'Take into account the following information for never tested results:\n<flowDetails>\n' +
			yamlStringifyExceptKeys(sliceModules(flow.value.modules, upToIndex, idOrders), ['lock']) +
			'</flowDetails>'
		try {
			const availableData = {
				results: pickableProperties?.priorIds,
				flow_input: pickableProperties?.flow_input
			}
			const isInsideLoop = availableData.flow_input && 'iter' in availableData.flow_input
			const user = `I'm building a workflow which is a DAG of script steps.
The current step is ${selectionManager.getSelectedId()}, you can find the details for the step and previous ones below:
${flowDetails}
Determine for the input "${argName}", what to pass either from the previous results or the flow inputs. 
All possibles inputs either start with results. or flow_input. and are followed by the key of the input.
${

View on GitHub (pinned to e474e8803c)

Solutions

  1. Click directly on the target step in the flow canvas, then run generation
  2. Reload the flow in the editor to resync ids, then retry
  3. Ensure the step exists at the top level (or that the DFS includes loop children) before generating

Example fix

null
Defensive patterns

Strategy: validation

Validate before calling

const idOrders = dfs(flowStore.val.value.modules, (x) => x.id)
if (!idOrders.includes(selectionManager.getSelectedId())) {
  console.warn('Selection not found in flow; re-select a step')
  return
}

Type guard

function selectionInFlow(flow: Flow, selectedId: string | undefined): boolean {
  return !!selectedId && dfs(flow.value.modules, (x) => x.id).includes(selectedId)
}

Try / catch

try {
  await generateStepInput()
} catch (e) {
  if (e.message === 'Could not find the selected id in the flow') {
    console.warn('Re-select a flow step and retry step-input generation')
  } else throw e
}

Prevention

When it happens

Trigger: Invoking step-input AI generation with selectionManager.getSelectedId() not present in flow.value.modules (stale/foreign selection).

Common situations: Clicking generate from a panel whose selection was cleared or points to a different view; flow replaced (e.g. after save/reload) invalidating ids; selecting an iterator's internal id.

Related errors


AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03). Data as JSON: /api/errors/e90f9496f5e026ca. Report an issue: GitHub.