Parent umbrella issue: #408
Source audit: Weekly tech debt audit: dispatch - 2026-06-17
Source audit date: 2026-06-17
Original recommendation
P2 — Extract shared queue-fetching logic between agents/[agentName]/queue/route.ts and agents/[agentName]/next-task/route.ts so lane-config and lease-filter changes apply to both.
Matched top finding
The two routes share issue-fetching, lease-filtering, PR-fix-queue-fetching, and queue-building logic. next-task then takes the first item and wraps it in an AgentTask. As the lane configuration work lands (#381-#388), the two will need to be updated in lockstep. A shared helper that returns { rankedQueue, prFixItems } would let next-task and queue evolve together.
Evidence:
src/app/api/agents/[agentName]/queue/route.ts:14-87 and src/app/api/agents/[agentName]/next-task/route.ts:90-150 are structurally similar.
- Both call
prisma.issue.findMany({ where: { state: "open", repository: { enabled: true } }, select: { ... linkedPrHealth ... } }) with the same select shape.
- Both call
findLeasedIssueIds(agentName) and listQueuedPrFixItems(asPrFixQueueClient(prisma), { lane }).
Parent umbrella issue: #408
Source audit: Weekly tech debt audit: dispatch - 2026-06-17
Source audit date: 2026-06-17
Original recommendation
P2 — Extract shared queue-fetching logic between
agents/[agentName]/queue/route.tsandagents/[agentName]/next-task/route.tsso lane-config and lease-filter changes apply to both.Matched top finding
The two routes share issue-fetching, lease-filtering, PR-fix-queue-fetching, and queue-building logic.
next-taskthen takes the first item and wraps it in anAgentTask. As the lane configuration work lands (#381-#388), the two will need to be updated in lockstep. A shared helper that returns{ rankedQueue, prFixItems }would letnext-taskandqueueevolve together.Evidence:
src/app/api/agents/[agentName]/queue/route.ts:14-87andsrc/app/api/agents/[agentName]/next-task/route.ts:90-150are structurally similar.prisma.issue.findMany({ where: { state: "open", repository: { enabled: true } }, select: { ... linkedPrHealth ... } })with the sameselectshape.findLeasedIssueIds(agentName)andlistQueuedPrFixItems(asPrFixQueueClient(prisma), { lane }).