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

StepInputsGen.svelte's generateStepInputs() performs the identical selection check: if the selected id is not found in the DFS order of flow.value.modules, it throws 'Could not find the selected id in the flow' before building AI context.

Source

Thrown at frontend/src/lib/components/copilot/StepInputsGen.svelte:56

	let generatedContent = ''
	let parsedInputs: string[][] = []
	let newFlowInputs: string[] = $state([])

	let abortController = $state(new AbortController())
	async function generateStepInputs() {
		if (Object.keys($generatedExprs || {}).length > 0 || loading) {
			return
		}
		logStepInputFill('all')
		abortController = new AbortController()
		loading = true
		stepInputsLoading?.set(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 all the inputs "${argNames.join(
				'", "'

View on GitHub (pinned to e474e8803c)

Solutions

  1. Re-select the step in the flow editor and retry
  2. Sync the editor with the saved flow (reload) if ids changed
  3. Confirm the target is a flow module visible in the editor tree

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 generateStepInputs()
} catch (e) {
  if (e.message === 'Could not find the selected id in the flow') {
    console.warn('Re-select a flow step and retry step-inputs generation')
  } else throw e
}

Prevention

When it happens

Trigger: Batch step-inputs AI generation triggered while the selected id is absent from the current flow module tree.

Common situations: Selection lost after editor tab switch; flow edited/deleted steps in another pane; selecting a virtual node (flow input/output) rather than a module.

Related errors


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