Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/app/api/agents/[agentName]/next-task/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import {
import { isBacklogLane, getBacklogLane } from "@/lib/lane-config";
import { isRenovateIssue } from "@/lib/agent-queue";
import { fetchAgentQueueData } from "@/lib/agent-queue-fetch";
import { applyRenovateIssueExclusion } from "@/lib/issue-filters";
import {
applyRenovateIssueExclusion,
applyUmbrellaIssueExclusion,
buildGroomingStateExclusionWhere,
} from "@/lib/issue-filters";

export async function GET(
request: Request,
Expand All @@ -37,6 +41,20 @@ export async function GET(
repository: { enabled: true },
};
applyRenovateIssueExclusion(issueWhere);
applyUmbrellaIssueExclusion(issueWhere);

// Exclude issues already groomed recently or currently blocked/not-ready
const groomingStateWhere = buildGroomingStateExclusionWhere(24);
if (groomingStateWhere.AND) {
const existing = issueWhere.AND;
if (Array.isArray(existing)) {
existing.push(...groomingStateWhere.AND);
} else if (existing) {
issueWhere.AND = [existing, ...groomingStateWhere.AND];
} else {
issueWhere.AND = groomingStateWhere.AND;
}
}

const issues = await prisma.issue.findMany({
where: issueWhere,
Expand All @@ -47,6 +65,9 @@ export async function GET(
url: true,
labels: true,
currentLane: true,
groomedAt: true,
notReadyReason: true,
blockedReason: true,
repository: { select: { fullName: true } },
},
orderBy: { number: "asc" },
Expand Down
39 changes: 39 additions & 0 deletions src/lib/issue-filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,45 @@ export function applyRenovateIssueExclusion(where: Record<string, unknown>): voi
appendIssueWhere(where, buildRenovateIssueExclusionWhere());
}

/**
* Build a Prisma where clause that excludes umbrella issues (issues with the
* "umbrella" label or titles starting with "Weekly tech debt audit:").
*/
export function buildUmbrellaIssueExclusionWhere() {
return {
NOT: {
OR: [
{ labels: { has: "umbrella" } },
{ title: { startsWith: "Weekly tech debt audit:", mode: "insensitive" } },
],
},
};
}

export function applyUmbrellaIssueExclusion(where: Record<string, unknown>): void {
appendIssueWhere(where, buildUmbrellaIssueExclusionWhere());
}

/**
* Build a Prisma where clause that excludes issues already groomed within the
* given cooldown (default 24h) or currently blocked/not-ready.
*/
export function buildGroomingStateExclusionWhere(cooldownHours: number = 24) {
const cutoff = new Date();
cutoff.setHours(cutoff.getHours() - cooldownHours);

return {
AND: [
// Not recently groomed (or never groomed)
{ OR: [{ groomedAt: null }, { groomedAt: { lt: cutoff } }] },
// Not currently blocked
{ blockedReason: null },
// Not currently marked not-ready
{ notReadyReason: null },
],
};
}

export const DEFAULT_DONE_RETENTION_DAYS = 7;

export function getDoneRetentionDays(): number {
Expand Down