Repository navigation
Closed
Description
Context
v1 supports three triggers (UI "Run now", a cron schedule, and an external API/MCP/CLI call), and they all go through one core function: triggerAgentRun. Funnelling every trigger through one function keeps validation, idempotency, repository/model checks and the cost gate (issue 11) in one place. Event-driven behavior (GitHub label, webhook, the user's own cron) is supplied by external automation calling this primitive; ProPR does not watch events in v1.
A trigger creates an agent_runs receipt (issue 3) and enqueues a BullMQ job on the existing github-issue-processor queue. Executing happens in the worker (issue 7). This issue also introduces the job payload types and the deterministic job IDs.
Requirements
- Add job payload types to
packages/core/src/queue/taskQueue.types.ts:AgentRunJobData { runId: string; definitionId: string; ownerId: string; phase: 'report' | 'action'; correlationId: string }and add it to theJobDataunion.
- New
packages/core/src/services/agents/agentRunTrigger.tsexporting:triggerAgentRun({ definition, trigger, triggerSource?, idempotencyKey?, gate? }, deps?)→{ run, created, enqueued }.enqueueAgentRunPhase(run, phase, deps?)— enqueuesprocessAgentRun(phasereport) orprocessAgentAction(phaseaction) with jobIdagent-run-<runId>-<phase>so BullMQ deduplicates double-enqueues.validateAgentDefinitionRuntime(definition)— checks every repository is an enabled monitored repository (loadMonitoredReposRaw) and the agent alias is enabled and supports the model (loadAgents+loadSyntheticAgents, same rule asvalidatePlanImplementationinpackages/api/mcp/tools.ts), and thatpropr_mcpis only requested for supported agent types.
- Behavior of
triggerAgentRun:- Disabled definition → throws
{ status: 409, code: 'AGENT_DISABLED' }. - Runtime validation failure →
{ status: 400, code: 'AGENT_INVALID' }. - Idempotent replay → returns the existing run, does not enqueue again.
- Optional
gatecallback (issue 11 plugs in the cost gate) may return{ action: 'skip', reason }or{ action: 'defer', until, reason }; the run is then created inskipped/deferredstate and not enqueued. - Queue failure after the row exists → transition run to
failedwith a clear reason and rethrow (so the caller sees a definite outcome instead of an orphanedqueuedrow).
- Disabled definition → throws
- Register the new job names in
src/workerFactory.ts(MainJobProcessors.processAgentRunJob,processAgentActionJob) with temporary processors that throwNot implementeduntil issues 7 and 10 land — or land this together with issue 7 if the reviewer prefers. The switch must not fall intoUnknown job type. - Export from
packages/core/src/index.ts. - Tests
test/agentRunTrigger.test.tswith an injected fake queue.
Implementation Specification
- Dependencies are injectable (
{ database, enqueue, loadAgents, loadSyntheticAgents, loadRepos }) likecreateTaskSubmissionRoutesservices, so tests need no Redis. - Job options:
attempts: 1— an agent run is not blindly retried by BullMQ because a failure after the agent ran would re-spend tokens; recovery is an explicit new trigger. - Do not check GitHub user repository access here: core has no request context. The API/MCP layers do that (issues 5 and 13); the scheduler re-checks enablement at run time.
Acceptance Criteria
- Triggering twice with one idempotency key enqueues exactly one job.
- Triggering a definition whose repository was disabled fails with
AGENT_INVALIDand creates no run. - A gate returning
defercreates adeferredrun withdeferred_untiland enqueues nothing. - Enqueue failure leaves the run
failedwithfailureReasonmentioning the queue. - Worker dispatches
processAgentRun/processAgentActionjob names.
Created by ProPR AI Planner
Activity
propr-dev commentedon Oct 6, 2026
Suggested Implementation:
Implementation Approach
One trigger primitive, many callers. REST "run now", the daemon scheduler, the HTTP trigger endpoint, the MCP tool and the CLI all call
triggerAgentRun, so there is exactly one implementation of idempotency, validation, gating and enqueueing. Execution is decoupled through the existing BullMQ queue (github-issue-processor) and the existing main worker — we add two job names rather than a new queue/worker so concurrency limits (WORKER_CONCURRENCY), heartbeats, cancellation and task-state recovery apply automatically.Alternatives: a dedicated
agent-runsqueue — rejected because it would need its own worker, concurrency budget and recovery, i.e. a parallel execution engine, which the request explicitly forbids.File:
packages/core/src/queue/taskQueue.types.tsWhy this file: Job payloads are typed centrally; adding to
JobDatakeeps the worker factory's union exhaustive.File:
packages/core/src/services/agents/agentRunTrigger.ts(new file)Why this file: The single trigger primitive. Everything that can start a run calls it.
File:
src/workerFactory.tsWhy this file: The main worker dispatches by job name; without these cases the worker throws
Unknown job type.Export
AgentRunJobDatafrompackages/core/src/queue/taskQueue.ts(type re-export list) andpackages/core/src/index.ts(queue types list), plus:File:
test/agentRunTrigger.test.ts(new file)Why this file: Verifies the primitive with fake config loaders and queue — no Redis needed.
propr-dev commentedon Oct 6, 2026
🤖 AI processing has started for this issue using claude agent with claude-opus-5-5 model.
I'll analyze the problem and work on a solution. This may take a few minutes.
Processing Details:
claudeclaude-opus-5-52803/claude-opus-5-5-agents-v1-4-17-trigger-pr-20261006-1429-r8l2800-epic-agents-v1-y7tissue-2803-20261006-1429-claude-opus-5-5-r8l🔍 Track Task Execution