{"record":{"id":"28c0dfbd9ce3c3fb","repo":"windmill-labs/windmill","slug":"could-not-find-the-selected-id-in-the-flow","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/IteratorGen.svelte","lineNumber":44,"sourceCode":"\t\tObject.keys(arg ?? {}).length === 0 ||\n\t\t\t(arg.type === 'static' && !arg.value) ||\n\t\t\t(arg.type === 'javascript' && !arg.expr)\n\t)\n\n\tlet abortController = new AbortController()\n\tconst { flowStore, selectionManager } = getContext<FlowEditorContext>('FlowEditorContext')\n\n\tasync function generateIteratorExpr() {\n\t\tif (generatedContent.length > 0 || loading) {\n\t\t\treturn\n\t\t}\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 represents a for-loop. You can find the details of all the steps below:\n${flowDetails}\nDetermine the iterator expression to pass either from the previous results or the flow inputs. Here's a summary of the available data:\n<available>\n${YAML.stringify(availableData)}</available>\nReply with the most probable answer, do not explain or discuss.","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/frontend/src/lib/components/copilot/IteratorGen.svelte#L26-L62","documentation":"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'.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Re-select the target flow step in the editor so getSelectedId() matches an existing module id","Verify the flow has no unsaved/pending edits that removed the selected step (reload flow if needed)","Check the selected element is a flow module (not a flow input or panel element) before invoking generation"],"exampleFix":"null","handlingStrategy":"validation","validationCode":"const idOrders = dfs(flowStore.val.value.modules, (x) => x.id)\nif (!idOrders.includes(selectionManager.getSelectedId())) {\n  console.warn('Selected id is not in the flow; re-select a step before AI generation')\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 generateIteratorExpr()\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 generation')\n  } else throw e\n}","preventionTips":["Re-select the step in the flow canvas right before invoking AI generation","Avoid invoking generation from panels whose selection may be stale","Reload the flow after undo/external edits to resync ids"],"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"}