{"record":{"id":"a6cbf13c90138ca2","repo":"windmill-labs/windmill","slug":"could-not-find-the-selected-id-in-the-flow-a6cbf1","errorCode":null,"errorMessage":"Could not find the selected id in the flow","messagePattern":"Could not find the selected id in the flow","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"frontend/src/lib/components/copilot/PredicateGen.svelte","lineNumber":45,"sourceCode":"\tlet instructions = $state('')\n\tlet instructionsField: HTMLInputElement | undefined = $state(undefined)\n\t$effect(() => {\n\t\tinstructionsField && setTimeout(() => instructionsField?.focus(), 100)\n\t})\n\n\tlet abortController = $state(new AbortController())\n\tconst { flowStore, selectionManager } = getContext<FlowEditorContext>('FlowEditorContext')\n\n\tconst dispatch = createEventDispatcher()\n\n\tasync function generatePredicate() {\n\t\tabortController = new AbortController()\n\t\tloading = true\n\t\tconst flow: Flow = JSON.parse(JSON.stringify(flowStore.val))\n\t\tconst idOrders = dfs(flow.value.modules, (x) => x.id)\n\t\tconst upToIndex = idOrders.indexOf(selectionManager.getSelectedId())\n\t\tif (upToIndex === -1) {\n\t\t\tthrow new Error('Could not find the selected id in the flow')\n\t\t}\n\n\t\tconst flowDetails =\n\t\t\t'Take into account the following information for never tested results:\\n<flowDetails>\\n' +\n\t\t\tyamlStringifyExceptKeys(sliceModules(flow.value.modules, upToIndex, idOrders), ['lock']) +\n\t\t\t'</flowDetails>'\n\t\ttry {\n\t\t\tconst availableData = {\n\t\t\t\tresults: pickableProperties?.priorIds,\n\t\t\t\tflow_input: pickableProperties?.flow_input\n\t\t\t}\n\t\t\tconst user = `I'm building a workflow which is a DAG of script steps.\nThe current step is ${selectionManager.getSelectedId()} and is a branching step (if-else). \nThe user wants to generate a predicate for the branching condition.\nHere's the user's request: ${instructions}\nYou can find the details of all the steps below:\n${flowDetails}\n","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/frontend/src/lib/components/copilot/PredicateGen.svelte#L27-L63","documentation":"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().","triggerScenarios":"Same as 606: selected id absent from the flow module tree when AI predicate generation is invoked.","commonSituations":"Stale selection after deleting/renaming a step; selecting a subcomponent inside a for-loop/branch not exposed in modules DFS; concurrent flow edits.","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"],"exampleFix":"null","handlingStrategy":"validation","validationCode":"const idOrders = dfs(flowStore.val.value.modules, (x) => x.id)\nif (!idOrders.includes(selectionManager.getSelectedId())) {\n  console.warn('Selection not found in flow; re-select a step')\n  return\n}","typeGuard":"function selectionInFlow(flow: Flow, selectedId: string | undefined): boolean {\n  return !!selectedId && dfs(flow.value.modules, (x) => x.id).includes(selectedId)\n}","tryCatchPattern":"try {\n  await generatePredicate()\n} catch (e) {\n  if (e.message === 'Could not find the selected id in the flow') {\n    console.warn('Re-select a flow step and retry predicate generation')\n  } else throw e\n}","preventionTips":["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"],"tags":["copilot","flow-editor","stale-selection"],"backgroundTag":"selected-node-not-in-flow","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}