Repository navigation
Description
Context
review_pull_request, fix_review_findings, run_ultrafix and comment_on_pull_request (all in packages/api/mcp/toolsPullRequests.ts) share a mutation schema that requires expectedHead: /^[0-9a-f]{40}$/. Every call therefore needs a preceding get_pull_request just to fetch the SHA, doubling round trips for the most common operations.
For these commands the pin gives little real safety: they are append-only — they post a comment that queues work, and the worker acts on whatever the head is when it starts, which can already be newer than the pinned SHA. The guarantee is largely illusory.
The pin does protect against acting on unseen code for merge_pull_request, update_pull_request_branch and stop_ultrafix (a moved head may be a human fix the loop should still see), and for revert_pull_request_commit and set_pull_request_model (not in scope to change). Those keep it required.
Requirements
- Split the schema:
appendOnlyMutation(expectedHead optional) forreview_pull_request,fix_review_findings,run_ultrafix,comment_on_pull_request; the existingmutation(required) stays for everything else. - When
expectedHeadis supplied: behaviour is unchanged — mismatch still fails withSTALE_HEAD(now withdetails: { expectedHead, currentHead }andstage: 'precondition'). - When omitted: the head is read from the pull request fetched by the tool itself (the tool already fetches it), no extra request.
- Every receipt of these four tools includes
resolvedHead(the SHA acted on) andheadSource: 'caller' | 'server'. The hidden marker comment keeps using the resolved head (head:<sha>), so review/fix tracking and stale-finding detection work identically. - For
fix_review_findings, the stale-review check (review.matchesCurrentHead === false→STALE_FINDINGS) keeps comparing against the current head, whether supplied or resolved. - Idempotency:
expectedHeadomitted vs supplied are different argument payloads; the existingIDEMPOTENCY_CONFLICTsemantics are unchanged. Document that retries must repeat the same arguments. - Tool descriptions state: "expectedHead is optional; when omitted the current head at call time is used and returned as resolvedHead. Supply it to require that no new commits arrived since you read the PR."
merge_pull_request,update_pull_request_branch,stop_ultrafixdescriptions explicitly say expectedHead is required and why.- Update
docs/mcp.md("Act on it, at an exact head") anddocs/mcp-coverage.mdrows accordingly.
Implementation Specification
- Edit
packages/api/mcp/toolsPullRequests.tsonly (plus the two docs files). - Extend
packages/api/test/fixtures/mcpPullRequestWrites.js/tstests (verifyPullRequestWrites) or add cases inpackages/api/test/mcpPullRequests.test.ts.
Acceptance Criteria
-
comment_on_pull_requestwithoutexpectedHeadposts once, and the receipt hasresolvedHead === <current head>andheadSource === 'server'; the posted body ends withhead:<current head> -->. -
run_ultrafixwith a staleexpectedHeadstill fails withSTALE_HEAD, anddetails.currentHeadis present. -
merge_pull_request,update_pull_request_branchandstop_ultrafixwithoutexpectedHeadfail schema validation (INVALID_INPUT). - The tools/list schema for the four append-only tools lists
expectedHeadas optional. - Only one
GET /pulls/{n}is made per call in both modes.
Created by ProPR AI Planner
Activity
propr-dev commentedon Sep 28, 2026
Suggested Implementation:
Implementation Approach
We make the pin optional, not removed: callers that want the stronger precondition keep it, and existing clients that always send it see no behaviour change. The server resolves the head from the PR it already fetches, so omitting it costs nothing extra. Reporting
resolvedHead+headSourcekeeps the receipt honest about exactly which revision was targeted — the caller loses no information versus pinning.Keeping the requirement for merge/update-branch/stop_ultrafix follows the request: those act on (or stop acting on) the current code and a moved head may mean a human change the caller has not seen.
File:
packages/api/mcp/toolsPullRequests.tsWhy this file: All four append-only tools and the shared
pull()helper live here.resolveFixSelectionalready takesheadfrom the caller; passresolvedHead(which equalspr.head.shawhen omitted, or the verified pinned SHA when supplied — identical after theSTALE_HEADcheck):Update the three pinned tools' descriptions to explain the requirement, e.g. for
stop_ultrafix:(
merge_pull_request: "expectedHead is required: merging must never include commits you have not reviewed."update_pull_request_branch: "expectedHead is required so a concurrent push is not silently merged over.")File:
docs/mcp.mdWhy this file: The operator walkthrough currently says "Every write takes the
expectedHeadyou just read"; that is no longer true and would push agents into the extra round trip.File:
packages/api/test/mcpPullRequests.test.tsWhy this file: Existing PR surface tests and the
verifyPullRequestWritesfixture already drive these tools against a 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-sol2599/gpt-5.6-sol-mcp-pr-commands-make-expe-20260929-1729-lpd2593-epic-mcp-observability-cf6issue-2599-20260929-1729-gpt-5.6-sol-lpd🔍 Track Task Execution
fix(ai): Resolve issue #2599 - MCP PR commands: make expectedHead opt…
fix(ai): Resolve issue #2599 - MCP PR commands: make expectedHead opt…