Repository navigation
Closed
Description
Context
run_ultrafix, review_pull_request, comment_on_pull_request, create_task, publish_plan, etc. all return a durable receipt (operationId). The receipt is stored in mcp_operations (packages/api/mcp/operations.ts) with a single free-form state column whose values mix transport concepts (posted, queued, unknown, browser_required) with outcome concepts (completed, failed). get_operation (in packages/api/mcp/tools.ts) re-derives a best-effort state on every poll through trackTaskSubmission, trackExecution and trackCancellation, but:
- it never records when the work started or finished;
- it does not persist the transitions it discovers, so a later poll after Redis/job cleanup can regress to
unknown; - the artefacts the operation produced (task id, pull request, issue numbers, comment id) are scattered across
result,result.continuationandtargetState; - there is no way to list receipts, so a caller who "fired three ultrafix runs in a row" and lost the ids cannot ask "what did I start in the last hour and did any of it finish?".
This issue introduces an explicit, persisted lifecycle. It depends on the error envelope from the previous issue (failures are stored as envelopes).
Requirements
- Add persisted lifecycle columns to
mcp_operations:lifecycle(accepted|running|completed|failed|cancelled|unknown),accepted_at,started_at,finished_at(epoch ms),failure(JSON envelope),artifacts(JSON),progress(JSON). Backfill existing rows fromstatein the migration. - The public lifecycle is separate from the legacy
statefield, which stays for backwards compatibility. Mapping of the legacy value on creation/finish:running(in-flight synchronous call),accepted,posted,queued,browser_required→acceptedcompleted→completedfailed→failedunknown→unknown
McpOperationsgains monotonic transition helpers:markStarted(id, at?),recordArtifacts(id, partial),recordProgress(id, progress),finish(id, outcome, failure?). Transitions must never move backwards (completed/failed/cancelledare terminal;runningnever returns toaccepted). Use conditionalUPDATE ... WHERE lifecycle IN (...)so concurrent pollers cannot race.project()returns a newlifecycleblock on every receipt:Timestamps are ISO 8601 strings in the projection.{ "lifecycle": { "state": "running", "acceptedAt": "...", "startedAt": "...", "finishedAt": null, "failure": null, "artifacts": { "taskId": "...", "pullRequest": { "repository": "a/b", "number": 42, "url": "..." } }, "progress": null } }get_operationpersists what the trackers discover: oncereceipt.targetStateshows the task inprocessing/claude_execution/post_processing→markStarted; terminal task states →finish; artefacts discovered (taskId,pr_number, issue numbers,commentId) →recordArtifacts. Cancellation receipts resolving tocancellation: 'confirmed'→finish(sourceId, 'cancelled')on the source operation.- New read-only tool
list_operations(scoperead): filterstool(exact name),lifecycle(one of the states oractive= accepted+running),sinceMinutes(1..10080, default 1440),repository; paginated (offset,limit≤ 50), newest first; scoped to the caller'sowner_id+grant_idexactly likeget_operation. Each item is the same projection asget_operationwithout re-running trackers (cheap), plus a hintrefreshWith: "get_operation". - Documented guarantee in the tool description: "accepted" means the request was recorded and handed to the backend; "running" means execution was observed; the loop/receipt is only
completedwhen the backend reached a terminal success state.
Implementation Specification
- New migration
packages/core/src/db/migrations/20261001000000_add_mcp_operation_lifecycle.js. - Edit
packages/api/mcp/operations.ts: extendOperationinterface,run()writeslifecycle/accepted_at, add transition helpers, extendproject(). - Edit
packages/api/mcp/tools.ts: inget_operation, after the trackers run, call a newsyncLifecycle(operations, row, receipt); add thelist_operationstool. - New helper
packages/api/mcp/operationLifecycle.tswithlifecycleFromLegacy,artifactsFromReceipt,syncLifecycle(pure mapping + calls intoMcpOperations). - Tests: extend
packages/api/test/mcpOperations.test.tswith lifecycle transitions and add alist_operationstest.
Acceptance Criteria
- New receipts include
lifecycle.state === 'accepted'andacceptedAt. - Polling a
create_taskreceipt while the associated task isprocessingpersistsstartedAt; a later poll after the taskcompletedreportscompletedwithfinishedAtandartifacts.taskId, even iftask_historyrows are later pruned. - A
failedreceipt exposeslifecycle.failureequal to the stored error envelope. - Transitions are monotonic under two concurrent
get_operationcalls (test withPromise.all). -
list_operations({ tool: 'run_ultrafix', lifecycle: 'active' })returns only the caller's still-open ultrafix receipts; another grant sees none of them. - Migration up/down works on SQLite and existing rows are backfilled.
Created by ProPR AI Planner
Activity
propr-dev commentedon Sep 28, 2026
Suggested Implementation:
Implementation Approach
We persist a small, explicit state machine next to the legacy
statecolumn instead of reinterpretingstate. Reusingstatewas rejected because existing clients (andcancel_operation) branch on values likeposted/queued, and changing their meaning would silently break them. A separatelifecyclecolumn is additive: old clients ignore it, new clients get a stable five-state model.Transitions are written by whoever observes them first (usually a
get_operationpoll) using conditional updates. This avoids adding a background sweeper (more moving parts, needs its own lease) while still making observations durable, so a receipt cannot regress when task history is cleaned up or a job is removed from BullMQ.File:
packages/core/src/db/migrations/20261001000000_add_mcp_operation_lifecycle.js(new file)Why this file: The lifecycle must survive restarts and be queryable for
list_operations; that requires real columns with an index on(owner_id, grant_id, lifecycle, created_at).File:
packages/api/mcp/operationLifecycle.ts(new file)Why this file: Keeps the pure mapping rules (legacy state → lifecycle, receipt → artefacts) out of the already-large
tools.tsand makes them unit-testable.File:
packages/api/mcp/operations.tsWhy this file: It owns the
mcp_operationstable. Transition helpers belong here so every writer uses the same monotonic SQL.File:
packages/api/mcp/tools.tsWhy this file:
get_operationis where trackers run; it must now persist their observations.list_operationssits next to it.Also, in
cancel_operation/trackCancellation: when the cancellation receipt resolves withresult.cancellation === 'confirmed', callawait operations.finish(sourceOperationId, 'cancelled')for the source receipt.File:
packages/api/test/mcpOperations.test.tsWhy this file: Existing durability tests live here; lifecycle monotonicity must be tested at the same level with a real SQLite file.
propr-dev commentedon Sep 29, 2026
🤖 AI processing has started for this issue using codex agent with gpt-5.6-sol model.
I'll analyze the problem and work on a solution. This may take a few minutes.
Processing Details:
codexgpt-5.6-sol2594/gpt-5.6-sol-mcp-give-operation-receip-20260929-0054-naw2593-epic-mcp-observability-cf6issue-2594-20260929-0054-gpt-5.6-sol-naw🔍 Track Task Execution
fix(ai): Resolve issue #2594 - MCP: give operation receipts a readabl…