fix: remove nextRun recalculation from getAgents() that blocked cron
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 42s

The getAgents() function was recalculating nextRun to future dates when
it found past values. This prevented the cron scheduler from ever
finding due agents (nextRun <= now was always false since getAgents
had already pushed it to the future).

Also fix toast polling: use null sentinel for agents without initial
actions so first execution is still detected. Limit cron to 3 agents
per cycle and add logging.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-04-26 13:00:55 +02:00
parent 1b4c6123c2
commit f0999263a0
3 changed files with 14 additions and 30 deletions

View File

@@ -46,10 +46,12 @@ export async function POST(request: NextRequest) {
return NextResponse.json({ success: true, executed: 0 })
}
console.log(`[CronAgents] Found ${dueAgents.length} due agent(s)`)
const results: { id: string; success: boolean; error?: string }[] = []
// Execute agents sequentially to avoid overwhelming the AI provider
for (const agent of dueAgents) {
// Execute agents sequentially (max 3 per cycle) to avoid overwhelming the AI provider
for (const agent of dueAgents.slice(0, 3)) {
try {
const { executeAgent } = await import('@/lib/ai/services/agent-executor.service')
const result = await executeAgent(agent.id, agent.userId)