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

PredicateGen.svelte's generatePredicate() slices the flow up to the selected step to give the AI context. It throws 'Could not find the selected id in the flow' when the DFS of flow.value.modules does not contain selectionManager.getSelectedId().

Source

Thrown at frontend/src/lib/components/copilot/PredicateGen.svelte:45

	let instructions = $state('')
	let instructionsField: HTMLInputElement | undefined = $state(undefined)
	$effect(() => {
		instructionsField && setTimeout(() => instructionsField?.focus(), 100)
	})

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

	const dispatch = createEventDispatcher()

	async function generatePredicate() {
		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 is a branching step (if-else). 
The user wants to generate a predicate for the branching condition.
Here's the user's request: ${instructions}
You can find the details of all the steps below:
${flowDetails}

View on GitHub (pinned to e474e8803c)

Solutions

  1. Re-select the intended step in the flow editor, then retry predicate generation
  2. Undo/reload the flow if the selected step was removed
  3. Ensure selection targets a top-level module the DFS can reach

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

Prevention

When it happens

Trigger: Same as 606: selected id absent from the flow module tree when AI predicate generation is invoked.

Common situations: Stale selection after deleting/renaming a step; selecting a subcomponent inside a for-loop/branch not exposed in modules DFS; concurrent flow edits.

Related errors


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