Merge polecat/Ace: protect pinned from cleanup/compact

This commit is contained in:
Steve Yegge
2025-12-19 01:28:36 -08:00
3 changed files with 46 additions and 12 deletions

View File

@@ -126,6 +126,22 @@ SEE ALSO:
os.Exit(1)
}
// Filter out pinned issues - they are protected from cleanup (bd-b2k)
pinnedCount := 0
filteredIssues := make([]*types.Issue, 0, len(closedIssues))
for _, issue := range closedIssues {
if issue.Pinned {
pinnedCount++
continue
}
filteredIssues = append(filteredIssues, issue)
}
closedIssues = filteredIssues
if pinnedCount > 0 && !jsonOutput {
fmt.Printf("Skipping %d pinned issue(s) (protected from cleanup)\n", pinnedCount)
}
if len(closedIssues) == 0 {
if jsonOutput {
result := map[string]interface{}{

View File

@@ -84,6 +84,7 @@ func (s *SQLiteStorage) GetTier1Candidates(ctx context.Context) ([]*CompactionCa
AND i.closed_at IS NOT NULL
AND i.closed_at <= datetime('now', '-' || CAST(? AS INTEGER) || ' days')
AND COALESCE(i.compaction_level, 0) = 0
AND COALESCE(i.pinned, 0) = 0 -- Exclude pinned issues (bd-b2k)
AND dt.dependent_id IS NULL -- No open dependents
GROUP BY i.id
ORDER BY i.closed_at ASC
@@ -154,6 +155,7 @@ func (s *SQLiteStorage) GetTier2Candidates(ctx context.Context) ([]*CompactionCa
AND i.closed_at IS NOT NULL
AND i.closed_at <= datetime('now', '-' || CAST(? AS INTEGER) || ' days')
AND i.compaction_level = 1
AND COALESCE(i.pinned, 0) = 0 -- Exclude pinned issues (bd-b2k)
AND COALESCE(ec.event_count, 0) >= CAST(? AS INTEGER)
AND NOT EXISTS (
-- Check for open dependents
@@ -196,12 +198,13 @@ func (s *SQLiteStorage) CheckEligibility(ctx context.Context, issueID string, ti
var status string
var closedAt sql.NullTime
var compactionLevel int
var pinned int
err := s.db.QueryRowContext(ctx, `
SELECT status, closed_at, COALESCE(compaction_level, 0)
SELECT status, closed_at, COALESCE(compaction_level, 0), COALESCE(pinned, 0)
FROM issues
WHERE id = ?
`, issueID).Scan(&status, &closedAt, &compactionLevel)
`, issueID).Scan(&status, &closedAt, &compactionLevel, &pinned)
if err == sql.ErrNoRows {
return false, "issue not found", nil
@@ -219,6 +222,11 @@ func (s *SQLiteStorage) CheckEligibility(ctx context.Context, issueID string, ti
return false, "issue has no closed_at timestamp", nil
}
// Pinned issues are protected from compaction (bd-b2k)
if pinned != 0 {
return false, "issue is pinned (protected from compaction)", nil
}
switch tier {
case 1:
if compactionLevel != 0 {

View File

@@ -36,6 +36,11 @@ func insertIssue(ctx context.Context, conn *sql.Conn, issue *types.Issue) error
pinned = 1
}
pinned := 0
if issue.Pinned {
pinned = 1
}
_, err := conn.ExecContext(ctx, `
INSERT OR IGNORE INTO issues (
id, content_hash, title, description, design, acceptance_criteria, notes,
@@ -95,6 +100,11 @@ func insertIssues(ctx context.Context, conn *sql.Conn, issues []*types.Issue) er
pinned = 1
}
pinned := 0
if issue.Pinned {
pinned = 1
}
_, err = stmt.ExecContext(ctx,
issue.ID, issue.ContentHash, issue.Title, issue.Description, issue.Design,
issue.AcceptanceCriteria, issue.Notes, issue.Status,