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
- Re-select the intended step in the flow editor, then retry predicate generation
- Undo/reload the flow if the selected step was removed
- 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
- Click the target step immediately before generating a predicate
- Ensure selection is a flow module, not a flow input or panel element
- Reload the editor after concurrent flow edits
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
- Could not find the selected id in the flow
- Could not find the selected id in the flow
- Could not find the selected id in the flow
- Failed to start test run - testFlow returned undefined
- No flow available to test step from. Please ensure you have
AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03).
Data as JSON: /api/errors/a6cbf13c90138ca2.
Report an issue: GitHub.