diff --git a/cmd/bd/onboard.go b/cmd/bd/onboard.go index 5edba664..1c77add3 100644 --- a/cmd/bd/onboard.go +++ b/cmd/bd/onboard.go @@ -123,7 +123,7 @@ The old approach of embedding full instructions in AGENTS.md is deprecated because it wasted tokens and got stale when bd upgraded.`, Run: func(cmd *cobra.Command, args []string) { if err := renderOnboardInstructions(cmd.OutOrStdout()); err != nil { - fmt.Fprintf(cmd.ErrOrStderr(), "Error: %v\n", err) + _, _ = fmt.Fprintf(cmd.ErrOrStderr(), "Error: %v\n", err) } }, } diff --git a/internal/storage/sqlite/ids.go b/internal/storage/sqlite/ids.go index 774c6a96..3b3a438e 100644 --- a/internal/storage/sqlite/ids.go +++ b/internal/storage/sqlite/ids.go @@ -223,9 +223,24 @@ func tryResurrectParent(parentID string, issues []*types.Issue) bool { func EnsureIDs(ctx context.Context, conn *sql.Conn, prefix string, issues []*types.Issue, actor string, orphanHandling OrphanHandling, skipPrefixValidation bool) error { usedIDs := make(map[string]bool) - // First pass: record explicitly provided IDs + // First pass: record explicitly provided IDs and check for duplicates within batch for i := range issues { if issues[i].ID != "" { + // Check for duplicate IDs within the batch + if usedIDs[issues[i].ID] { + return fmt.Errorf("duplicate issue ID within batch: %s", issues[i].ID) + } + + // Check if ID already exists in database + var existingCount int + err := conn.QueryRowContext(ctx, `SELECT COUNT(*) FROM issues WHERE id = ?`, issues[i].ID).Scan(&existingCount) + if err != nil { + return fmt.Errorf("failed to check ID existence: %w", err) + } + if existingCount > 0 { + return fmt.Errorf("issue ID already exists: %s", issues[i].ID) + } + // Validate that explicitly provided ID matches the configured prefix (bd-177) // Skip validation during import to allow issues with different prefixes (e.g., from renamed repos) if !skipPrefixValidation {