feat(deps): detect/prevent child→parent dependency anti-pattern (bd-nim5)

This prevents a common mistake where users add dependencies from child
issues to their parent epics. This creates a deadlock:
- Child can't start (blocked by open parent)
- Parent can't close (children not done)

Changes:
- dep.go: Reject child→parent deps at creation time with clear error
- server_labels_deps_comments.go: Same check for daemon RPC
- doctor/validation.go: New check detects existing bad deps
- doctor/fix/validation.go: Auto-fix removes bad deps
- doctor.go: Wire up check and fix handler

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-12-24 13:03:13 -08:00
parent 566e4f5225
commit ce2b05356a
7 changed files with 379 additions and 0 deletions

View File

@@ -15,6 +15,23 @@ import (
"github.com/steveyegge/beads/internal/utils"
)
// isChildOf returns true if childID is a hierarchical child of parentID.
// For example, "bd-abc.1" is a child of "bd-abc", and "bd-abc.1.2" is a child of "bd-abc.1".
func isChildOf(childID, parentID string) bool {
// A child ID has the format "parentID.N" or "parentID.N.M" etc.
// Use ParseHierarchicalID to get the actual parent
_, actualParentID, depth := types.ParseHierarchicalID(childID)
if depth == 0 {
return false // Not a hierarchical ID
}
// Check if the immediate parent matches
if actualParentID == parentID {
return true
}
// Also check if parentID is an ancestor (e.g., "bd-abc" is parent of "bd-abc.1.2")
return strings.HasPrefix(childID, parentID+".")
}
var depCmd = &cobra.Command{
Use: "dep",
GroupID: "deps",
@@ -107,6 +124,15 @@ Examples:
}
}
// Check for child→parent dependency anti-pattern (bd-nim5)
// This creates a deadlock: child can't start (parent open), parent can't close (children not done)
if isChildOf(fromID, toID) {
fmt.Fprintf(os.Stderr, "Error: Cannot add dependency: %s is already a child of %s.\n", fromID, toID)
fmt.Fprintf(os.Stderr, "Children inherit dependency on parent completion via hierarchy.\n")
fmt.Fprintf(os.Stderr, "Adding an explicit dependency would create a deadlock.\n")
os.Exit(1)
}
// If daemon is running, use RPC
if daemonClient != nil {
depArgs := &rpc.DepAddArgs{