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

IteratorGen.svelte's generateIteratorExpr() deep-copies the flow and computes DFS id order of flow.value.modules, then looks up the currently selected component id. If selectionManager.getSelectedId() is not among module ids, it throws 'Could not find the selected id in the flow'.

Source

Thrown at frontend/src/lib/components/copilot/IteratorGen.svelte:44

		Object.keys(arg ?? {}).length === 0 ||
			(arg.type === 'static' && !arg.value) ||
			(arg.type === 'javascript' && !arg.expr)
	)

	let abortController = new AbortController()
	const { flowStore, selectionManager } = getContext<FlowEditorContext>('FlowEditorContext')

	async function generateIteratorExpr() {
		if (generatedContent.length > 0 || loading) {
			return
		}
		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 user = `I'm building a workflow which is a DAG of script steps.
The current step is ${selectionManager.getSelectedId()} and represents a for-loop. You can find the details of all the steps below:
${flowDetails}
Determine the iterator expression to pass either from the previous results or the flow inputs. Here's a summary of the available data:
<available>
${YAML.stringify(availableData)}</available>
Reply with the most probable answer, do not explain or discuss.

View on GitHub (pinned to e474e8803c)

Solutions

  1. Re-select the target flow step in the editor so getSelectedId() matches an existing module id
  2. Verify the flow has no unsaved/pending edits that removed the selected step (reload flow if needed)
  3. Check the selected element is a flow module (not a flow input or panel element) before invoking generation

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

Prevention

When it happens

Trigger: Triggering AI iterator generation while the selected id points to an element outside the flow's module tree (e.g. a flow-level input, a static/for-loop child not in modules, or a stale selection after flow edits).

Common situations: Selection pointing at a branch/loop child id removed by an undo; selection on a non-module UI element; flow edited concurrently so the selected id no longer exists.

Related errors


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