Repository navigation
Closed
Description
Context
publish_plan in packages/api/mcp/toolsPlanning.ts claims the draft by setting status = 'executing', then creates one GitHub issue per plan task in a loop. If anything throws inside the loop (GitHub 422 on a label, a rate limit, policy.repository rejecting a revoked grant, a SQLite busy error while inserting plan_issues), the error escapes to McpOperations.run, which recorded OUTCOME_UNKNOWN. Two problems follow, both observed in practice:
- No failure detail — solved generically by the error envelope issue, but
publish_planshould add which task index and which step failed and how many issues were already created. - The draft is stuck in
executingforever. Every laterpublish_planfails withPRECONDITION_FAILED: Plan is already published or busy,update_planrefuses it, and there is no supported way out. That is why "two plans failed to publish several times".
Requirements
- Validate the plan before claiming the draft; an invalid plan fails with
PLAN_INVALID(stagevalidation) anddetails.incomplete = [{ index, title, missing: ['body'|'implementation'|...] }]. Nothing is claimed. - Remember the status the draft had before the claim (
draft/review/approved). - Wrap each issue creation and each
plan_issuesinsert. On failure:- If zero issues were created: restore the previous status (conditional on
status = 'executing'and unchangedmcp_revision) and throwPUBLISH_FAILEDwithstagefrom the classified cause,retryablefrom the cause (e.g. rate limit → true), anddetails: { failedIndex, failedTitle, step: 'create_issue' | 'record_issue' | 'authorize', createdIssues: [] , cause: { code, message } }. - If some issues were created: keep
executing, persistcontext_config.publication = { state: 'partial', operationId, created: [{index, number, url}], failedIndex, failedAt, cause }, and throwPUBLISH_PARTIAL(stagegithub,retryable: false) with the same details and a message telling the caller to callpublish_planagain withresume: true.
- If zero issues were created: restore the previous status (conditional on
- Add optional
resume: boolean(defaultfalse) topublish_plan. Withresume: true, the tool accepts a draft that isexecutingand haspublication.state === 'partial'; it skips indexes already recorded inplan_issues/publication.created, and before creating each remaining issue checks GitHub for an existing issue carrying the marker<!-- propr-mcp:<originalOperationId>:<index> -->(search the repository issue list filtered by thepropr-plannedlabel, newest first, bounded to 100) so an issue created during an uncertain network failure is adopted instead of duplicated.expectedRevisionmust still match. - On success, clear
publicationand setexecutedas today; return{ planId, issues, resumed: boolean, adopted: number[] }. get_planexposespublication(state, created count, failedIndex, cause) so the caller can see a stuck/partial plan without reading receipts.
Implementation Specification
- Edit
packages/api/mcp/toolsPlanning.ts(publish_plan,get_plan). - New small helper in the same file or
packages/api/mcp/planPublication.ts:findMarkedIssue(principal, repository, operationId, index). - Use
McpErroroptions (stage,retryable,details) from the error envelope issue. - Tests: extend the planning MCP test (or new
packages/api/test/mcpPublishPlan.test.ts) with a fakeprincipal.github.requestthat fails on the 2nd issue, then succeeds on resume; and one that fails on the 1st issue and proves the draft returned toreview.
Acceptance Criteria
- A GitHub 422 on the first issue returns
PUBLISH_FAILEDwithdetails.failedIndex === 0anddetails.cause.code === 'GITHUB_REJECTED'; the draft is back to its previous status and can be published again. - A failure on the second of three issues returns
PUBLISH_PARTIALwith one created issue;get_planshowspublication.state === 'partial'. -
publish_plan({ resume: true })creates only the remaining issues, adopts a marked issue that already exists on GitHub, and ends withstatus === 'executed'and threeplan_issuesrows (no duplicates). -
resume: trueon a draft that is not partially published fails withPRECONDITION_FAILEDand a message explaining why. - Invalid plans fail with
PLAN_INVALIDbefore any claim.
Created by ProPR AI Planner
Activity
propr-dev commentedon Sep 28, 2026
Suggested Implementation:
Implementation Approach
We keep publication a single MCP tool but make its failure modes explicit and recoverable. The alternatives were (a) a background publisher job, rejected as a much larger change that still needs the same recovery semantics, and (b) a separate
reset_plan_publicationtool, rejected because it lets a caller "unstick" a draft that may already have public issues, creating duplicates. A resume that adopts marker-tagged issues is safe precisely because every issue body already carries<!-- propr-mcp:<operationId>:<index> -->.We roll back the claim only when we know nothing was created (zero successful POSTs and the failure happened before or on the first POST with a classified, non-transport error). If the very first POST failed with a transport error, it may have been created, so we treat it as partial with
created: []and requireresume, which will adopt it via the marker.File:
packages/api/mcp/planPublication.ts(new file)Why this file: Keeps the marker search and publication-state helpers out of the already long planning tool file and makes them reusable by the resume path and tests.
File:
packages/api/mcp/toolsPlanning.tsWhy this file: Hosts
publish_planandget_plan. All changes are local to those two tools.Add small local helpers near the top of the file:
File:
packages/api/test/mcpPublishPlan.test.ts(new file)Why this file: Publication recovery is the scenario that previously failed in production; it needs a regression test with a controllable GitHub fake.
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-sol2596/gpt-5.6-sol-mcp-publish_plan-record-p-20260929-1217-j5w2593-epic-mcp-observability-cf6issue-2596-20260929-1217-gpt-5.6-sol-j5w🔍 Track Task Execution
fix(ai): Resolve issue #2596 - MCP publish_plan: record per-issue fai…
fix(ai): Resolve issue #2596 - MCP publish_plan: record per-issue fai…