{"record":{"id":"16b7df5b1a15ab47","repo":"stanfordnlp/CoreNLP","slug":"between-when-the-incoming-edge-was-found-and-now","errorCode":null,"errorMessage":"Between when the incoming edge was found and now, the edge was somehow deleted","messagePattern":"Between when the incoming edge was found and now, the edge was somehow deleted","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/SetPhraseHead.java","lineNumber":142,"sourceCode":"                                                        edgeOut.getWeight(),\n                                                        edgeOut.isExtra());\n      boolean success = sg.removeEdge(edgeOut);\n      if (!success) {\n        throw new RuntimeException(\"Between when the outgoing edge was found and now, the edge was somehow deleted\");\n      }\n      sg.addEdge(newEdge);\n      modified = true;\n    }\n\n    for (SemanticGraphEdge edge : relocateEdges) {\n      SemanticGraphEdge newEdge = new SemanticGraphEdge(newHead,\n                                                        edge.getTarget(),\n                                                        edge.getRelation(),\n                                                        edge.getWeight(),\n                                                        edge.isExtra());\n      boolean success = sg.removeEdge(edge);\n      if (!success) {\n        throw new RuntimeException(\"Between when the incoming edge was found and now, the edge was somehow deleted\");\n      }\n      sg.addEdge(newEdge);\n      modified = true;\n    }\n\n    for (SemanticGraphEdge edge : deleteEdges) {\n      boolean success = sg.removeEdge(edge);\n      if (!success) {\n        throw new RuntimeException(\"Between when the internal phrase edge was found and now, the edge was somehow deleted\");\n      }\n      modified = true;\n    }\n    for (IndexedWord other : matchedNodes) {\n      if (other == newHead)\n        continue;\n\n      found: {\n        for (SemanticGraphEdge existingEdge : sg.getAllEdges(newHead, other)) {","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/SetPhraseHead.java#L124-L160","documentation":"In SetPhraseHead.evaluate(), incoming edges to the old head are re-created with a new source; before rebuilding each one, sg.removeEdge(edge) must succeed. A false return means the incoming edge disappeared between discovery and removal, so the operation throws this RuntimeException to avoid silently corrupting the dependency graph.","triggerScenarios":"Calling evaluate() when the SemanticGraph's incoming edges were removed by a prior operation in the same ssurgeon pass, or the edge objects were collected from a stale/different graph instance.","commonSituations":"Chaining multiple Ssurgeon operations where an earlier operation (e.g. another SetPhraseHead or DeleteGraph) deletes edges into the head; re-running a test that mutated a shared SemanticGraph fixture.","solutions":["Re-run the semgrex match before applying the edit so edge references reflect the current graph","Order ssurgeon operations so nothing removes incoming edges before SetPhraseHead runs","Reset/reload the SemanticGraph between repeated test invocations of the same rule","Verify removeEdge on your SemanticGraph implementation matches the exact edge instance"],"exampleFix":"// before: reusing edges matched before other edits\nfor (SemanticGraphEdge e : matchedEdges) { applyEdit(sg, e); }\n// after: re-match after each mutating step\nSemgrexMatcher sm = pattern.matcher(sg);\nif (sm.find()) { SetPhraseHead op = ...; op.evaluate(sg, sm); }","handlingStrategy":"try-catch","validationCode":"// confirm all incoming edges to the head are present before evaluate\nfor (SemanticGraphEdge e : collectedIncoming) {\n  if (sg.getEdge(e.getSource(), e.getTarget(), e.getRelation()) == null) throw new IllegalStateException(\"stale edge\");\n}","typeGuard":null,"tryCatchPattern":"try { op.evaluate(sg, sm); } catch (RuntimeException e) { if (e.getMessage().contains(\"incoming edge was somehow deleted\")) { /* re-match and retry on fresh graph */ } else { throw e; } }","preventionTips":["Order pipeline operations so nothing deletes incoming edges before SetPhraseHead runs","Re-run semgrex matching after any other mutating operation","Reset graph fixtures between test runs instead of reusing mutated SemanticGraphs"],"tags":["ssurgeon","semgraph","invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}