Repository navigation
Closed
Description
Context
Issue 1 defined the Agents contract in @propr/shared. This issue adds durable storage: one table for saved agent definitions and one for agent runs, plus a core data-access module for definitions (agentDefinitionStore). Run storage and its state machine come in issue 3 so each PR stays reviewable.
An agent run is executed as an ordinary isolated task run (the existing tasks / task_history tables and worker pipeline). The agent_runs row is a thin receipt that links the definition, the trigger and the produced report to the underlying task IDs (report_task_id, action_task_id). We never duplicate task execution state here.
Requirements
- New Knex migration
packages/core/src/db/migrations/20261006000000_create_agent_definitions.jscreating:agent_definitions: id (uuid PK), owner_id, name, description, repositories (JSON text), prompt, attachments (JSON text), agent_alias, model_name, capabilities (JSON text), include_previous_reports (bool, default true), previous_reports_limit (int, default 1), schedule_cron (nullable), schedule_timezone (default'UTC'), schedule_enabled (bool, default false), next_run_at (bigint ms, nullable), autonomy_mode, enabled (bool, default true), revision (int, default 0), created_at, updated_at (bigint ms). Indexes:(owner_id, updated_at),(schedule_enabled, enabled, next_run_at)for the scheduler sweep.agent_runs: id (uuid PK), definition_id (FK → agent_definitions, cascade delete), owner_id, trigger, trigger_source, idempotency_key (nullable), state, autonomy_mode (snapshot), definition_snapshot (JSON text — the definition as it was when triggered), report_task_id, action_task_id, report (text), report_truncated (bool), action_summary, skip_reason, failure_reason, approved_by, deferred_until (bigint, nullable), deferrals (int, default 0), created_at, started_at, reported_at, finished_at, updated_at. Unique(definition_id, idempotency_key); indexes(definition_id, created_at),(owner_id, state),(state, deferred_until).- A matching
downthat dropsagent_runsthenagent_definitions.
- New
packages/core/src/services/agents/agentDefinitionStore.tswithcreateAgentDefinition,getAgentDefinition(id, ownerId),listAgentDefinitions(ownerId, page),updateAgentDefinition(id, ownerId, patch, expectedRevision?),deleteAgentDefinition,setAgentDefinitionAttachments, and a purerowToAgentDefinitionmapper. Every function accepts an optionaldatabase: Knex(defaulting to the shareddb) — the same injection patternepicExecutionQueueuses for tests. updateAgentDefinitionrecomputesnext_run_atwithnextCronOccurrencewhenever schedule or enablement changes, and usesrevisionfor optimistic concurrency (409 on mismatch), mirroring theconfigRevisionpattern used by MCP configuration tools.- Export the store from
packages/core/src/index.ts. - Tests in
test/agentDefinitionStore.test.tsusing an in-memory SQLite db and running the migration.
Implementation Specification
- Store JSON as text (SQLite); parse defensively in the mapper (a corrupt row must not crash list pages — fall back to empty arrays).
- Owner scoping is enforced in the store: every read/update/delete filters by
owner_id. Definitions are private to their owner in v1, like goals and plans. - Timestamps are epoch milliseconds (bigint), consistent with
epic_execution_queuesandmcp_operations. - A definition with
scheduleEnabled=false,enabled=falseor no cron hasnext_run_at = null, so the sweep index stays small.
Acceptance Criteria
-
npm run db:migrateapplies cleanly on an existing database; rollback drops both tables. - Deleting a definition deletes its runs (cascade).
-
updateAgentDefinitionwith a staleexpectedRevisionthrows an error withstatus: 409. - Enabling a schedule sets
next_run_atto the next UTC cron occurrence; disabling clears it. - Another owner's definition is never returned (
getAgentDefinitionreturnsundefined). - Tests pass.
Created by ProPR AI Planner
Activity
propr-dev commentedon Oct 6, 2026
Suggested Implementation:
Implementation Approach
Two tables, one store module. Definitions and runs are separate because a run must keep a frozen
definition_snapshot— editing an agent after triggering it must not change what an in-flight or historical run claims it ran with. Runs reference task IDs rather than copying execution state: the existingtasks/task_historytables remain the durable receipt for the actual isolated execution.Alternatives considered: storing definitions in
system_configsJSON (likerepos_to_monitor) — rejected because definitions are per-owner, need indexed scheduler queries (next_run_at) and cascade-delete to runs. Storing runs insidetasks— rejected because one agent run can span two tasks (report + acting) plus non-executing states (skipped/deferred/awaiting approval).File:
packages/core/src/db/migrations/20261006000000_create_agent_definitions.js(new file)Why this file: Schema for the feature. Indexes are chosen for the three hot queries: the owner's list page, the scheduler's due-definition sweep, and deferred-run retry.
File:
packages/core/src/services/agents/agentDefinitionStore.ts(new file)Why this file: Single data-access layer for definitions. The API, MCP tools and scheduler all go through it, so owner scoping and
next_run_atmaintenance live in one place.File:
packages/core/src/index.tsWhy this file: Public surface for the API, worker and daemon.
File:
test/agentDefinitionStore.test.ts(new file)Why this file: Proves owner scoping, revisions, cascade and schedule maintenance against the real migration.
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-52801/claude-opus-5-5-agents-v1-2-17-database-m-20261006-1319-u632800-epic-agents-v1-y7tissue-2801-20261006-1319-claude-opus-5-5-u63🔍 Track Task Execution