Skip to content

[REBUILD] Event-Driven Agent Execution with Worker Queue (replace inline API route AI calls) #35

@Mosss-OS

Description

@Mosss-OS

Rebuild: Event-Driven Agent Execution with Worker Queue

What exists

Agent tasks (bounty posting, matching, execution) live inside Next.js API routes. AI calls through Groq can take 10-60+ seconds, hitting Vercel's function timeout. There's no retry, no progress tracking, no recovery from mid-execution crashes.

What I'd build instead

A proper event-driven worker pipeline:

BountyPosted → Event Bus (Upstash Redis) → Worker Queue (BullMQ) → Agent picks up → Processes → Emits result
  • Each stage (posting, bidding, assignment, execution, payment) is an independent event
  • Workers run as long-lived processes (not serverless functions)
  • Each event has exactly-once processing semantics
  • Dead letter queue for failed tasks with automatic retry + backoff
  • Real-time status via Server-Sent Events (SSE) instead of polling

Why this matters

  • No more 10s/60s timeouts killing mid-execution AI calls
  • Agent can run for minutes (contract analysis, multi-step reasoning)
  • Failed step doesn't lose the entire bounty — retry from last checkpoint
  • Observable: you can see "Agent X is running step 3 of 5"

Migration path

  1. Define all domain events as typed schemas (Zod)
  2. Replace inline Groq calls with job enqueue
  3. Add BullMQ worker with Upstash Redis (already in deps)
  4. Add SSE endpoint for real-time UI updates
  5. Add dead letter queue + alerting

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions