Repository navigation
Closed
Description
Context
The task_drafts_plan_history SQLite trigger (migration 20260928000000_add_task_draft_plan_revisions.js) snapshots the outgoing plan_json into task_draft_plan_revisions on every change, and MCP already has list_plan_revisions, get_plan_revision and restore_plan_revision (packages/api/mcp/toolsPlanning.ts, backed by packages/api/routes/plannerHelpers/planRevisions.ts). What is missing from the request:
- What caused each revision — generation, refinement, manual edit, rename, restore. Today a revision only has
status_before/status_after; after a refinement replaced a full plan with an edit list, there is no way to see "this version came from refinement at 14:02, the one before from generation". - Renames are not recorded (the trigger only fires on
plan_jsonchanges). get_plandoes not expose the history; the caller has to know that the separate revision tools exist.
Requirements
- Migration adds
task_drafts.plan_cause TEXT NULL(cause of the current plan) andtask_draft_plan_revisions.cause TEXT NULL,name_before TEXT NULL,name_after TEXT NULL. Allowed causes:generation,refinement,manual_edit,restore,rename,unknown(legacy rows). - Recreate the
task_drafts_plan_historytrigger so the snapshot row copiesOLD.plan_causeintocause— i.e. each revision row records how that (replaced) version came to be. Keep the existing coalescing and 50-row retention logic from the original migration verbatim; only add the column. - Add trigger
task_drafts_name_history(AFTER UPDATE OF name) inserting a revision row withcause = 'rename',plan_json = OLD.plan_json,name_before = OLD.name,name_after = NEW.name, when the name changed andplan_jsondid not; retention applies. - Every writer sets
plan_causein the same UPDATE that writesplan_json:- generation completion (
persistGenerationCompletioninpackages/core/src/services/...taskPlanningServiceandrunBackgroundGenerationinpackages/api/routes/plannerHelpers/utils.ts) →generation, - refinement (
runBackgroundRefinementinrefineBackground.ts, and the legacycreateRefineHandlerinhandlers/generationHandlers.ts) →refinement, - MCP
update_planand the UI draft update route (plannerRoutes.tsupdateDraft) →manual_edit, restorePlanRevision→restore(and the snapshot row it inserts gets the outgoing plan's cause),create_planwith an initial plan →manual_edit.
- generation completion (
listPlanRevisions/getPlanRevisionreturncause,nameBefore,nameAfter, plus a derivedcurrentCausefor the live plan.get_planoutput addsrevisionHistory: { count, currentCause, latest: [up to 10 summaries: revisionId, cause, replacedAt, issueCount, titles(first 5)] , tools: ['list_plan_revisions','get_plan_revision','restore_plan_revision'] }.- The UI revision list (
propr-ui/src/api/planRevisionsApi.tstypes + the component that renders revisions) shows the cause label; optional but the API type must includecause.
Implementation Specification
- New migration
packages/core/src/db/migrations/20261002000000_add_plan_revision_causes.js. - Edit writers listed above,
planRevisions.ts,toolsPlanning.ts,propr-ui/src/api/planRevisionsApi.ts. - Tests: extend the plan revision tests (search
planRevisionsinpackages/api/test) with each cause, rename recording, andget_plan.revisionHistory.
Acceptance Criteria
- Generate → refine → manual edit → rename → restore produces revision rows whose causes (newest first) are
restore-replacedmanual_edit… exactly as specified: each row'scauseequals the cause of the version it snapshots. - A rename without plan change produces exactly one
renamerow withnameBefore/nameAfter. -
get_planshowsrevisionHistory.currentCause === 'refinement'right after a refinement. - Legacy rows (created before the migration) report
cause: 'unknown'. - Migration down restores the original trigger.
Created by ProPR AI Planner
Activity
propr-dev commentedon Sep 28, 2026
Suggested Implementation:
Implementation Approach
The trigger already captures every plan change, so we attach the cause at the source rather than inferring it. Each writer stamps
task_drafts.plan_causein the same UPDATE that writesplan_json; the trigger copiesOLD.plan_causeinto the snapshot. This keeps capture atomic and complete (no writer can forget to insert a history row — the trigger still does that) and costs one extra column per writer. Inferring cause from status transitions (generating → review= generation) was rejected: manual edits and refinements both goreview → review.Renames get their own tiny trigger because the existing trigger is keyed on
plan_jsonand must not start snapshotting on unrelated column writes.File:
packages/core/src/db/migrations/20261002000000_add_plan_revision_causes.js(new file)Why this file: Schema + trigger changes must be versioned and reversible.
File:
packages/api/routes/plannerHelpers/planRevisions.tsWhy this file: Read/restore helpers used by both REST and MCP; they must surface and set the cause.
(Select
plan_causein thedraftread:.first('plan_json', 'status', 'mcp_revision', 'plan_cause').)Add a helper used by
get_plan:File:
packages/api/mcp/toolsPlanning.tsWhy this file:
update_plan/create_planstampmanual_edit;get_planexposes history.Writers in API and core
Why: The cause must be written by the component that produced the plan.
packages/api/routes/plannerHelpers/refineBackground.ts→ in the successfulpersistActiveRefinementcall addplan_cause: 'refinement'next toplan_json.packages/api/routes/plannerHelpers/handlers/generationHandlers.ts(createRefineHandler) → addplan_cause: 'refinement'to the update that writesplan_json.persistGenerationCompletionin core, search for the update that writesplan_jsonwithstatus: 'review'after generation) → addplan_cause: 'generation'.updateDrafthandler inpackages/api/routes/plannerRoutes.ts) → when the body includesplan_json, addplan_cause: 'manual_edit'. A body that only changesnamemust not touchplan_cause(the rename trigger records it).File:
propr-ui/src/api/planRevisionsApi.tsexport interface PlanRevisionSummary { ... + cause: 'generation' | 'refinement' | 'manual_edit' | 'restore' | 'rename' | 'unknown'; + nameBefore: string | null; + nameAfter: string | null; }In the revision list component, render the cause as a small label (
Generated,Refined,Edited,Restored,Renamed: old → new,—for unknown).Tests
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-sol2605/gpt-5.6-sol-plan-revision-history-rec-20260929-2230-uuu2593-epic-mcp-observability-cf6issue-2605-20260929-2230-gpt-5.6-sol-uuu🔍 Track Task Execution
fix(ai): Resolve issue #2605 - Plan revision history: record what cau…
fix(ai): Resolve issue #2605 - Plan revision history: record what cau…