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

@@ -4,11 +4,25 @@ import (
"context"
"encoding/json"
"fmt"
"strings"
"github.com/steveyegge/beads/internal/storage"
"github.com/steveyegge/beads/internal/types"
)
// 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 {
_, actualParentID, depth := types.ParseHierarchicalID(childID)
if depth == 0 {
return false // Not a hierarchical ID
}
if actualParentID == parentID {
return true
}
return strings.HasPrefix(childID, parentID+".")
}
func (s *Server) handleDepAdd(req *Request) Response {
var depArgs DepAddArgs
if err := json.Unmarshal(req.Args, &depArgs); err != nil {
@@ -18,6 +32,15 @@ func (s *Server) handleDepAdd(req *Request) Response {
}
}
// 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(depArgs.FromID, depArgs.ToID) {
return Response{
Success: false,
Error: fmt.Sprintf("cannot add dependency: %s is already a child of %s (children inherit dependency via hierarchy)", depArgs.FromID, depArgs.ToID),
}
}
store := s.storage
if store == nil {
return Response{