Repository navigation
Closed
Description
Context
This is the core of the feature: the worker processor that turns a queued agent_runs row into an ordinary isolated task run and stores its free-form report. No new execution engine is introduced — the executor composes the same building blocks every other job uses:
| Need | Existing building block |
|---|---|
| Durable receipt / task in the Tasks UI | WorkerStateManager.createTaskStateIfAbsent, updateTaskState, markTaskCompleted/Failed |
| Sandboxed checkout | ensureRepoCloned + createWorktreeForIssue + cleanupWorktree (as processTaskImportJob) |
| Model execution in a container | AgentRegistry.getAgentByAlias(...).executeTask(...) |
| Spend cap | RunCostGuard / runWithRunCostGuard with the instance default_max_cost_usd |
| Cancellation | the task id is a normal task, so stopTaskExecution works |
Previous reports (issue 3 lookup) and input files are fed in through the prompt builder from issue 6.
Requirements
- New
src/jobs/processAgentRunJob.tsexportingprocessAgentRunJob(job: Job<AgentRunJobData>)and wire it insrc/worker.ts(processors.processAgentRunJob). - Flow:
- Load the run (
getAgentRunRowById). If its state is notqueued(cancelled/skipped meanwhile) return{ status: 'skipped' }without side effects. - Read the frozen
definition_snapshot. Re-runvalidateAgentDefinitionRuntime; on failure transition tofailedwith the reason. - Create the task:
taskId = agent-run-<runId>-report,issueRef = { number: 0, repoOwner, repoName, type: 'agent-run', title: 'Agent: <name>', subtitle: 'Report run' }for the primary (first) repository. - Transition
queued → runningwithreportTaskId. Anullresult means someone cancelled → clean up and stop. - Prepare the workspace (
src/jobs/agentRuns/workspace.ts):repository_readon: clone the primary repository and create a worktree (branch nameagent-run/<runId>; never pushed). Additional repositories are cloned as shallow read-only copies into.propr/context/<owner>__<repo>/.repository_readoff: an empty temporary directory withgit init(agents expect a git workspace) — no source code is mounted.- Copy input files from
storage/agent-definitions/<definitionId>/into.propr/agent-inputs/.
- Load previous reports (
listPreviousReports(definitionId, { limit: previousReportsLimit, beforeCreatedAt, excludeRunId })), build the prompt (issue 6). - Execute with
agent.executeTask({ worktreePath, issueRef, prompt, model, githubToken, branchName, taskId, toolPolicy })insiderunWithRunCostGuard.toolPolicy(from capabilities) is defined in issue 8; until then pass it and let agents ignore it. - Extract the report with
extractAgentReport. Empty report or failed execution →failedwith the agent error. - Transition
running → report_readywith the report, then calladvanceAfterReport(run)(exported fromsrc/jobs/agentRuns/autonomy.ts; in this issue it implements onlydry_run → completed; issue 10 adds preview/auto). markTaskCompleted(taskId, { notificationRecap })using the first line of the report.finally: remove the worktree/scratch dir. Nothing is committed or pushed.
- Load the run (
- Errors:
UsageLimitError→ runfailedwith "provider usage limit reached; trigger again later" (no auto-requeue: the cost gate in issue 10 prevents most of these). Any other error →failed, taskmarkTaskFailed. - Tests
test/processAgentRunJob.test.tswith injected dependencies (registry, workspace, state manager).
Implementation Specification
- Inject dependencies via a
depsparameter (createAgentRunProcessor(deps)) likehandleDispatchWithDeps, so tests run without Docker/GitHub. - Use the GitHub App installation token (
getAuthenticatedOctokit().auth({ type: 'installation' })) like other jobs; it is already read-only scoped inside agent containers (see execution-safety docs). - Never call any commit/push helper. The branch exists only so
createWorktreeForIssuecan be reused unchanged.
Acceptance Criteria
- A queued run with
repository_readproduces areport_ready → completedrun (dry_run) with the report stored andreport_task_idpointing to a task visible in/api/tasks. - With
repository_readoff the agent workspace contains no repository files. - Previous reports are passed to the prompt builder (assert via injected spy).
- A run cancelled before pickup does nothing (no task, no container).
- Worktree is cleaned up on success and failure; no
git pushis ever invoked.
Created by ProPR AI Planner
Activity
propr-dev commentedon Oct 6, 2026
Suggested Implementation:
Implementation Approach
The executor is a composition of existing pieces, modelled on
processTaskImportJob(which already runs an agent in a temporary worktree without publishing anything). Theagent_runsrow stays the agent-level receipt, while the run's actual execution is a normal task (tasks/task_history), so the Tasks console, live logs, cancellation, LLM logs, spend caps and task-state recovery all work without changes.Dependencies are injected so the orchestration logic (state transitions, cancellation races, cleanup) is tested without Docker. Autonomy dispatch after the report lives in a separate module (
autonomy.ts) so issue 10 can extend it without touching the executor.Trade-off: we create a throwaway branch name for the worktree only to reuse
createWorktreeForIssueunchanged; it is never pushed and is deleted on cleanup.File:
src/jobs/agentRuns/workspace.ts(new file)Why this file: Encapsulates the "repository code read" capability: whether the container sees source code is decided here, in one place.
File:
src/jobs/agentRuns/autonomy.ts(new file)Why this file: One place that decides what happens after a report exists. This issue implements
dry_run; issue 10 extends it topreviewandauto.File:
src/jobs/processAgentRunJob.ts(new file)Why this file: Worker processor for the report phase: receipt bookkeeping around one ordinary isolated agent execution.
Until issue 8 lands, create a stub
src/jobs/agentRuns/toolPolicy.ts:File:
src/worker.tsWhy this file: Registers the processor with the main worker so the queue's existing concurrency, heartbeat and shutdown logic apply.
File:
test/processAgentRunJob.test.ts(new file)Why this file: Exercises the orchestration with fakes: happy path, cancellation race and cleanup.
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-52806/claude-opus-5-5-agents-v1-7-17-report-run-20261006-1606-5i82800-epic-agents-v1-y7tissue-2806-20261006-1606-claude-opus-5-5-5i8🔍 Track Task Execution