{"record":{"id":"018a664d2a014cdc","repo":"alibaba/spring-ai-alibaba","slug":"the-node-s-is-not-present-as-target-in-graph","errorCode":null,"errorMessage":"the node '%s' is not present as target in graph!","messagePattern":"the node '(.+?)' is not present as target in graph!","errorType":"exception","errorClass":"GraphStateException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/ProcessedNodesEdgesAndConfig.java","lineNumber":111,"sourceCode":"\n\t\t\tvar sgEdgeStartTarget = sgEdgeStart.target();\n\n\t\t\tif (sgEdgeStartTarget.id() == null) {\n\t\t\t\tthrow new GraphStateException(format(\"the target for node '%s' is null!\", subgraphNode.id()));\n\t\t\t}\n\n\t\t\tvar sgEdgeStartRealTargetId = subgraphNode.formatId(sgEdgeStartTarget.id());\n\n\t\t\t// Process Interruption (Before) Subgraph(s)\n\t\t\tinterruptsBefore = interruptsBefore.stream()\n\t\t\t\t\t.map(interrupt -> Objects.equals(subgraphNode.id(), interrupt) ? sgEdgeStartRealTargetId\n\t\t\t\t\t\t\t: interrupt)\n\t\t\t\t\t.collect(Collectors.toUnmodifiableSet());\n\n\t\t\tvar edgesWithSubgraphTargetId = edges.edgesByTargetId(subgraphNode.id());\n\n\t\t\tif (edgesWithSubgraphTargetId.isEmpty()) {\n\t\t\t\tthrow new GraphStateException(\n\t\t\t\t\t\tformat(\"the node '%s' is not present as target in graph!\", subgraphNode.id()));\n\t\t\t}\n\n\t\t\tfor (var edgeWithSubgraphTargetId : edgesWithSubgraphTargetId) {\n\n\t\t\t\tvar newEdge = edgeWithSubgraphTargetId.withSourceAndTargetIdsUpdated(subgraphNode, Function.identity(),\n\t\t\t\t\t\tid -> new EdgeValue((Objects.equals(id, subgraphNode.id())\n\t\t\t\t\t\t\t\t? subgraphNode.formatId(sgEdgeStartTarget.id())\n\t\t\t\t\t\t\t\t: id)));\n\t\t\t\tedges.elements.remove(edgeWithSubgraphTargetId);\n\t\t\t\tedges.elements.add(newEdge);\n\t\t\t}\n\t\t\t//\n\t\t\t// Process END Nodes\n\t\t\t//\n\t\t\tvar sgEdgesEnd = processedSubGraphEdges.edgesByTargetId(END);\n\n\t\t\tvar edgeWithSubgraphSourceId = edges.edgeBySourceId(subgraphNode.id()).orElseThrow();","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/ProcessedNodesEdgesAndConfig.java#L93-L129","documentation":"While processing a subgraph node, the library looks for edges in the parent graph whose target is the subgraph node itself. If no such incoming edge exists, the subgraph would be unreachable, so process() throws this GraphStateException.","triggerScenarios":"Adding a subgraph as a node via addNode(\"sub\", innerGraph) but never calling addEdge from any node (or START) to \"sub\" before compiling the parent graph.","commonSituations":"Orphaned subgraph nodes left over after refactoring edge wiring; typos in node ids in addEdge; conditional edges that reference a different node name than the subgraph's registered id.","solutions":["Add an edge to the subgraph node: parent.addEdge(\"previousNode\", \"sub\") or parent.addEdge(START, \"sub\")","Verify the id used in addEdge exactly matches the id given to addNode for the subgraph","For conditional routing, ensure every branch target id matches the subgraph node id","Compile the inner graph and add it as an async node action if you only need its execution, not graph linking"],"exampleFix":"// before\nouter.addNode(\"sub\", innerGraph); // never wired\n// after\nouter.addNode(\"sub\", innerGraph);\nouter.addEdge(StateGraph.START, \"sub\");","handlingStrategy":"validation","validationCode":"if (parent.edges.edgesByTargetId(\"sub\").isEmpty())\n    throw new IllegalStateException(\"subgraph node 'sub' has no incoming edge\");","typeGuard":null,"tryCatchPattern":"try { outer.compile(saver); } catch (GraphStateException e) { if (e.getMessage().contains(\"not present as target\")) { /* add edge to subgraph node */ } else throw e; }","preventionTips":["After addNode for a subgraph, immediately add its incoming edge","Keep node ids in constants to avoid typos","Validate graph reachability (START can reach every node) in tests"],"tags":["graph","subgraph","wiring"],"backgroundTag":"resource-not-found","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}