{"record":{"id":"844ffee26422117f","repo":"gastownhall/beads","slug":"applygraph-final-cycle-check-w","errorCode":null,"errorMessage":"applyGraph: final cycle check: %w","messagePattern":"applyGraph: final cycle check: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/domain/issue.go","lineNumber":1292,"sourceCode":"\t\t\tfor _, nd := range node.Deps {\n\t\t\t\tdep, err := types.NewGraphNodeDependency(keyToID[node.Key], nd.Type, nd.Target, keyToID)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn GraphApplyResult{}, fmt.Errorf(\"applyGraph: node %q: %w\", node.Key, err)\n\t\t\t\t}\n\t\t\t\tif (dep.Type == types.DepParentChild) != parentPhase {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif err := u.depRepo.Insert(ctx, dep, actor, DepInsertOpts{UseWispsTable: useWisp}); err != nil {\n\t\t\t\t\treturn GraphApplyResult{}, fmt.Errorf(\"applyGraph: node %q: adding dep to %q: %w\", node.Key, nd.Target, err)\n\t\t\t\t}\n\t\t\t\tif types.IsSchedulingEdge(dep.Type) {\n\t\t\t\t\tnewSchedulingEdges = append(newSchedulingEdges, [2]string{dep.IssueID, dep.DependsOnID})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tif cyclePath, err := u.depRepo.CycleThroughEdges(ctx, newSchedulingEdges); err != nil {\n\t\treturn GraphApplyResult{}, fmt.Errorf(\"applyGraph: final cycle check: %w\", err)\n\t} else if cyclePath != \"\" {\n\t\treturn GraphApplyResult{}, fmt.Errorf(\"applyGraph: dependency cycle would be created: %s\", cyclePath)\n\t}\n\n\t// Pass 5 — apply deferred assignees.\n\tfor i, assignee := range pendingAssignees {\n\t\tif assignee == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\tid := keyToID[plan.Nodes[i].Key]\n\t\tif err := u.issueRepo.Update(ctx, id, map[string]any{\"assignee\": assignee}, actor, IssueTableOpts{UseWispsTable: useWisp}); err != nil {\n\t\t\treturn GraphApplyResult{}, fmt.Errorf(\"applyGraph: node %q: defer assignee: %w\", plan.Nodes[i].Key, err)\n\t\t}\n\t}\n\n\treturn GraphApplyResult{IDs: keyToID}, nil\n}\n","sourceCodeStart":1274,"sourceCodeEnd":1310,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/domain/issue.go#L1274-L1310","documentation":"After all nodes and edges are inserted, applyGraph runs a final CycleThroughEdges check over the newly added scheduling edges; this error wraps a failure of that cycle-detection query itself (not the discovery of a cycle). The apply is aborted because the safety check could not complete.","triggerScenarios":"CycleThroughEdges returning a query/storage error — Dolt query failure, connectivity problem, or an internal error traversing the dependency graph — during the final validation pass of graph apply.","commonSituations":"Database connectivity drops mid-apply; very large graphs timing out the cycle query; corrupted or inconsistent dependency tables; running against a Dolt server under load.","solutions":["Read the wrapped error to see whether it's connectivity, timeout, or a query error.","Retry the apply once the database is reachable (inserted edges may need rollback/cleanup if the apply is not transactional).","For large graphs, reduce batch size or ensure the dep table indexes support the cycle query.","Verify dependency table integrity (bd doctor / storage checks) if errors persist."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Cheap local cycle pre-check on the plan's scheduling edges before apply\nif cycle := findCycle(planEdgesToAdjacency(plan.Edges)); cycle != \"\" {\n    return fmt.Errorf(\"plan has cycle: %s\", cycle)\n}","typeGuard":null,"tryCatchPattern":"if err := bd.GraphApply(ctx, plan); err != nil {\n    if strings.Contains(err.Error(), \"final cycle check\") {\n        // transient storage failure during validation — safe to retry after cleanup\n        return retryWithBackoff(func() error { return bd.GraphApply(ctx, plan) })\n    }\n    return err\n}","preventionTips":["Ensure stable DB connectivity for the duration of apply","Keep graphs small enough for fast cycle queries","Run bd doctor storage checks if cycle-check errors recur"],"tags":["go","cycle-detection","storage","database"],"backgroundTag":"cycle-check-query-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}