Repository navigation
Description
Context
The user-contributed request: "When a PR transitions to AI-done, automatically assign it to the user who created the original issue." Plus: "Optionally request a GitHub review from the assigned user", "Preserve existing manually assigned users and avoid duplicate requests", and "Keep the feature optional and disabled by default."
The configuration landed in the previous task. This task performs the assignment.
The right place is performPostProcessing in src/jobs/issueJobPostProcessing.ts, specifically the point where the pull request has been created and the labels are swapped from AI-processing to AI-done:
await safeUpdateLabels({ ... }, [AI_PROCESSING_TAG], [AI_DONE_TAG]);
That is literally the "transitions to AI-done" moment the request describes. Assigning there means the assignment is bound to the transition rather than to a webhook that may be delivered twice or not at all.
Two correctness requirements drive the design. "Preserve existing manually assigned users" means the write must be additive, which setTaskAssignees's default mode: 'add' already is. "Avoid duplicate requests" means a re-run - a retried job, a replacement attempt, a reopened pull request - must not request review again from someone who already has a pending request, and must not re-notify someone who is already assigned.
Review requests need a rule the request does not state: GitHub refuses a review request from the pull request's own author. On a ProPR instance the author is the app, so this is usually fine, but on a ProPR-created PR where the resolved assignee happens to be the author, the request must be skipped rather than failing the job.
Requirements
- Add
src/github/prAutoAssignment.tsexportingautoAssignImplementationPullRequest(options):- Resolve the policy with
resolveRepositoryAutoAssignment; return immediately when disabled. - Resolve the target: the repository default assignee if set, otherwise the source issue's author.
- Skip bot authors (a login ending in
[bot]), because assigning ProPR's own app to its own pull request is noise. - Assign additively through
setTaskAssignees, so manual assignees survive. - Request a review from the resolved assignee when configured, skipping anyone already requested and the pull request's own author.
- Be idempotent: a second call for the same pull request and head performs no GitHub writes.
- Never throw: a failed assignment must not fail a successful implementation.
- Resolve the policy with
- Call it from
performPostProcessing, after the label swap and afterhandleCreatedPlanIssuePR, so Ultrafix and auto-merge arming are unaffected. - Record the outcome on the task timeline as a history metadata event so it is visible on the task detail page.
- Guard idempotency with a Redis key scoped to repository, pull request and head SHA, so a new head after follow-up is a new opportunity (used by the next task) while a retry of the same state is not.
- Log every decision - skipped, assigned, already assigned, review requested, review skipped - at
infowith the reason. - Tests covering the disabled default, the issue-author path, the override path, bot skipping, additive preservation, idempotency, review-request deduplication, the self-review-request skip and failure isolation.
Implementation Specification
Files added
src/github/prAutoAssignment.tstest/prAutoAssignment.test.ts
Files modified
src/jobs/issueJobPostProcessing.ts- invoke after the label swap.
Step-by-step
- Write the module. Short-circuit on the disabled policy before any GitHub call, so the default costs nothing.
- Resolve the issue author from the already-fetched
currentIssueDatawhere available, falling back to a single issue read, to avoid a redundant request. - Claim the idempotency key with
SET NX EXbefore writing, and release it on failure so a transient error can be retried. - For the review request, read
GET /pulls/{n}/requested_reviewersand subtract the existing requests and the pull request author before callingPOST /requested_reviewers. - Invoke from
performPostProcessinginside atry/catchthat only logs, and record the timeline event. - Add the test file.
Acceptance Criteria
npm run typecheck,npm run lintand the server tests pass.- With the repository option off (the default), implementation behaviour is unchanged and no assignment-related GitHub call is made.
- With it on, a completed implementation assigns the pull request to the source issue's author.
- With
autoAssignDefaultAssigneeset, that login is assigned instead of the issue author. - A bot issue author is skipped, with the reason logged; with a default assignee configured, that assignee is still used.
- An assignee a human added manually before completion is still assigned afterwards.
- A second post-processing pass for the same pull request and head performs no GitHub writes and logs the already-assigned reason.
- With
autoAssignRequestReviewon, a review is requested from the assignee; a second pass requests nothing; an already-pending request is not duplicated; the pull request's own author is never requested. - A GitHub failure during assignment or the review request is logged and the implementation still completes with its pull request and
AI-donelabel. - The task timeline shows an assignment event, visible on the task detail page.
Created by ProPR AI Planner
Activity
propr-dev commentedon Oct 8, 2026
Suggested Implementation:
Implementation Approach
Where to hook. The request says "when a PR transitions to AI-done". There were two candidates:
performPostProcessing. Chosen. The label swap there is the transition, the issue author is already in hand fromcurrentIssueData, and the task id is available for the timeline event. It runs in both intake modes because it is not event-driven at all.Idempotency key. The guard is
(repository, pull request, head SHA)rather than(repository, pull request). That choice is what makes the next task possible: after a follow-up pushes a new commit, the head changes, so the same pull request becomes a fresh opportunity to re-assign - which the request explicitly wants ("After follow-up work completes, ensure the PR is assigned appropriately again") - while a retried job on the same head is correctly suppressed. Keying on the pull request alone would make re-assignment after follow-up impossible; keying on nothing would re-notify on every retry.Additive assignment.
setTaskAssigneesdefaults tomode: 'add', and this path relies on that default rather than passing it, so that "preserve existing manually assigned users" holds by construction. Areplacehere would delete a reviewer a teammate assigned while the agent was running.Bot authors. A ProPR-created issue is often authored by the app itself, and assigning
propr-dev[bot]to its own pull request produces a meaningless assignment and a pointless notification. Skipping bot logins is a small rule with a visible benefit. A configured default assignee still applies, because that is an explicit operator choice rather than an inference from the issue.Review requests. GitHub rejects a review request from the pull request's own author with a 422. That has to be checked rather than caught, because a caught 422 is indistinguishable from other validation failures and would log misleadingly. Existing pending requests are also subtracted before the call - GitHub tolerates a duplicate request but re-notifies, which is precisely the "avoid duplicate requests" the request names.
Failure isolation. The whole thing is wrapped so it can only log. An implementation that produced a correct pull request must never be reported as failed because an assignment did not stick; the pull request is the deliverable and the assignment is a convenience on top of it.
File:
src/github/prAutoAssignment.ts(new file)Why this file: keeps the policy resolution, the target resolution, the idempotency guard and the review-request rules in one place, so the next task can reuse exactly the same function for the follow-up path. Putting this logic inline in
issueJobPostProcessing.tswould mean duplicating it inprCommentPostExecution.tsand letting the two drift.File:
src/jobs/issueJobPostProcessing.tsWhy this file: the label swap here is the
AI-donetransition the request names, and the issue author and task id are both already in scope. Hooking the same moment that performs the transition means the assignment happens once per transition, in both webhook and polling intake, without depending on a delivery that could arrive twice or never.@@ in performPostProcessing, after handleCreatedPlanIssuePR and the label swap await safeUpdateLabels( { octokit, owner: issueRef.repoOwner, repo: issueRef.repoName, issueNumber: issueRef.number, logger: correlatedLogger }, [AI_PROCESSING_TAG], [AI_DONE_TAG] ); + // Runs after the label swap - this is the "transitions to AI-done" + // moment - and after handleCreatedPlanIssuePR, so Ultrafix startup and + // auto-merge arming keep their existing ordering and are unaffected by + // an assignment failure. + if (postProcessingResult?.pr?.number && commitResult) { + const outcome = await autoAssignImplementationPullRequest({ + repoOwner: issueRef.repoOwner, + repoName: issueRef.repoName, + pullRequestNumber: postProcessingResult.pr.number, + // The head the assignment decision is bound to: a later + // follow-up pushes a new commit and becomes a new opportunity. + headSha: commitResult.commitHash, + taskId: taskId || `${issueRef.repoOwner}-${issueRef.repoName}-${issueRef.number}`, + // Already fetched, so the common path costs no extra read. + issueAuthorLogin: currentIssueData.data.user?.login ?? null, + issueNumber: issueRef.number, + opportunity: 'implementation_done', + redis: redisClient, + log: correlatedLogger, + }); + // Recorded on the timeline so the task detail page can show who + // was assigned and why, rather than leaving it only in logs. + if (taskId && stateManager && outcome.reason !== 'disabled') { + await stateManager.updateHistoryMetadata(taskId, TaskStates.POST_PROCESSING, { + event: 'assignment.auto', + autoAssignment: outcome, + }).catch(error => correlatedLogger.warn({ error: (error as Error).message }, 'Could not record the automatic assignment on the task timeline')); + } + } + } catch (postProcessingError) {Note on
currentIssueData: the post-processing options type already carries{ data: { title: string; labels: Array<{ name: string }> } }. Widen it to includeuser?: { login: string } | nullso the author is available without a second fetch:File:
test/prAutoAssignment.test.ts(new file)Why this file: every requirement in the user request maps to one branch here, and the two that would be noticed in production are the duplicate review request and the clobbered manual assignee. Both are asserted directly against the stub's recorded requests rather than through the return value, because the return value would still look correct if an extra POST had been sent.
propr-dev commentedon Oct 9, 2026
🤖 AI processing has started for this issue using claude agent with claude-opus-5-5 model.
I'll analyze the problem and work on a solution. This may take a few minutes.
Processing Details:
claudeclaude-opus-5-52898/claude-opus-5-5-assign-the-pull-request-w-20261009-1126-gth2888-epic-task-assignment-1m4issue-2898-20261009-1126-claude-opus-5-5-gth🔍 Track Task Execution