ubiquitous-invention/plans/Plan-agent-coordination/Epic-task-as-runnable-unit/Epic-task-as-runnable-unit.md
Randall Stillwell b2aff2045b feat(mcp): claim_task tool + register claim/complete pair
Pairs with the parallel complete_task commit. claim_task opens an
agent_runs row, flips status to in_progress only when it's safe
(ready/draft → in_progress, never overwriting a deliberate
blocked/done/in_progress), and returns the resolved workflow prompt
+ source level. Idempotent re-claim by the same actor returns the
existing run with reused=true and refreshes notes only — started_at
is sacred. Different-actor re-claim errors with ALREADY_CLAIMED
naming the existing actor and run id.

Tenancy fence: if the backlog item exists but in a different workspace
than the resolved handle, we refuse with "doesn't belong to workspace"
rather than 404. Prevents cross-tenant existence fishing.

All three writes (run insert + status flip + audit insert) happen in
one db.transaction() so a partial claim is unreachable.

tools/index.ts now registers both claim_task and complete_task.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-02 22:23:05 -05:00

2 KiB

kind slug title plan_slug status priority tenant_id cursor_epic_id updated_at
epic task-as-runnable-unit Task as runnable unit — workflow prompts and a runs table agent-coordination ready P2 global null 2026-06-01

Epic objective

Every backlog item can carry a workflow prompt; every agent session against a task gets recorded in a runs table. These two changes are the foundation that claim_task / complete_task build on.

In scope / out of scope

In scope

  • Schema additions for workflow prompts.
  • New runs table + tRPC router.
  • Minimal UI for editing the prompt and viewing recent runs.

Out of scope

  • The actual MCP tools (next epic).
  • Orchestrator process (deferred epic).
Task Link
Add workflow prompt to backlog items ./Task-add-workflow-prompt-to-backlog-items.md
Runs table and tRPC router ./Task-runs-table-and-trpc-router.md

Dependencies

  • Depends on: Plan-daily-driver-finish (don't extend stubs).
  • Blocks: Epic-mcp-claim-complete.

Acceptance criteria

  • A task row can store an optional workflow prompt that overrides the epic/plan default. (Schema column workflow_prompt, parser plumbing, slug-based inheritance walk all shipped.)
  • An agent_runs row captures started_at, finished_at, actor_user_id, outcome, tokens_input, tokens_output, tokens_total, notes, error, and metadata. (One column more than the spec — added tokens_total because Symphony's "absolute totals win" rule needs explicit storage.)
  • Minimal UI lets an operator read recent runs at /[workspaceSlug]/settings/runs. Prompt-editing UI is deferred to Task-workflow-prompt-task-detail-ui.md because apps/web doesn't yet have a backlog-item detail panel.

Proposed timeline

Phase Window Notes
Schema + procedures Day 1 Columns, table, tRPC router.
UI surfacing Day 2 Inline prompt editor, recent-runs panel.