Fix transaction conflict in TryResurrectParent (bd-58c0)

Refactored resurrection functions to accept optional *sql.Conn parameter:
- Added tryResurrectParentWithConn() internal function
- Added tryResurrectParentChainWithConn() internal function
- Updated CreateIssue to use conn-based resurrection
- Updated EnsureIDs to use conn-based resurrection

This eliminates 'database is locked' errors when resurrection
happens inside an existing transaction.

Fixes bd-58c0
This commit is contained in:
Steve Yegge
2025-11-04 17:00:37 -08:00
parent c5865bc77e
commit 3cb2e790a9
4 changed files with 47 additions and 24 deletions

View File

@@ -189,17 +189,18 @@ func (s *SQLiteStorage) EnsureIDs(ctx context.Context, conn *sql.Conn, prefix st
// For hierarchical IDs (bd-a3f8e9.1), ensure parent exists
if strings.Contains(issues[i].ID, ".") {
// Try to resurrect entire parent chain if any parents are missing
resurrected, err := s.TryResurrectParentChain(ctx, issues[i].ID)
// Use the conn-based version to participate in the same transaction
resurrected, err := s.tryResurrectParentChainWithConn(ctx, conn, issues[i].ID)
if err != nil {
return fmt.Errorf("failed to resurrect parent chain for %s: %w", issues[i].ID, err)
}
if !resurrected {
// Parent(s) not found in JSONL history - cannot proceed
// Parent(s) not found in JSONL history - cannot proceed
lastDot := strings.LastIndex(issues[i].ID, ".")
parentID := issues[i].ID[:lastDot]
parentID := issues[i].ID[:lastDot]
return fmt.Errorf("parent issue %s does not exist and could not be resurrected from JSONL history", parentID)
}
}
}
}
usedIDs[issues[i].ID] = true
}