Skip to content

Re-assign after follow-up work and never re-assign on resumed work #2899

Closed

Description

@propr-dev

Context

Two remaining clauses from the user-contributed request:

  • "When work resumes (AI-in-progress), avoid triggering new assignments or review requests."
  • "After follow-up work completes, ensure the PR is assigned appropriately again."

Read together these describe a single rule: the trigger is work completing, never work starting. ProPR swaps labels in both directions - back to <trigger>-processing when a follow-up starts, and to <trigger>-done when it finishes - so an implementation keyed on the label event would fire on both. The previous task avoided that by hooking the code that performs the completion transition rather than a label webhook, and this task extends the same approach to the follow-up path.

The follow-up completion point is handlePostExecution in src/jobs/prCommentPostExecution.ts, after publishCompletionComment and the terminal state update. At that moment the new commit's SHA is known, which matters: the idempotency guard from the previous task is keyed on the head SHA, so a follow-up that pushed a commit is automatically a fresh opportunity, and one that pushed nothing is automatically not.

Two cases need explicit handling. A /review run produces no commit and changes nothing about ownership, so it must not re-assign. And a follow-up may be published to a continuation pull request rather than the original, in which case the assignment belongs to the pull request that actually received the work.

Requirements

  1. Call autoAssignImplementationPullRequest from handlePostExecution with opportunity: 'followup_done', only when the follow-up produced a commit.
  2. Target the pull request the work was published to, taking the continuation into account rather than assuming the comment's pull request.
  3. Pass the new commit SHA as headSha, so the existing head-keyed guard makes this a new opportunity exactly when a commit was produced.
  4. Skip entirely for commandMode: 'review', and for any run that produced no commit.
  5. Resolve the assignee for the follow-up case from the pull request's linked source issue where one exists, so the issue author remains the target rather than whoever commented.
  6. Never trigger on work starting: add a regression test asserting that the starting work comment and the processing-label swap in processPullRequestCommentJob perform no assignment and no review request.
  7. Preserve manual assignees here as well, by continuing to rely on the additive default.
  8. Record the outcome on the task timeline, consistent with the implementation path.
  9. Tests covering the commit case, the no-commit case, review mode, the continuation target, resumed work, review-request deduplication across both opportunities and failure isolation.

Implementation Specification

Files modified

  • src/jobs/prCommentPostExecution.ts - invoke after publication.
  • src/github/prAutoAssignment.ts - resolve the linked issue author for the follow-up case.
  • test/prAutoAssignmentFollowup.test.ts (new file).

Step-by-step

  1. In prCommentPostExecution.ts, after the terminal state update and persistCommitHash, call the auto-assign function when commitResult exists and the command mode is not review.
  2. Use context.publication.continuation?.target_pr ?? context.pullRequestNumber for the pull request number, so a continuation receives the assignment.
  3. Add a linkedIssueNumber option to AutoAssignOptions, and in resolveAssignee fall back to reading the pull request body's Closes #n reference when no issue number was supplied, reusing the existing linked-issue resolution rather than re-implementing it.
  4. Add the Playwright-free unit tests.

Acceptance Criteria

  • npm run typecheck, npm run lint and the server tests pass.
  • With the repository option off, follow-up behaviour is unchanged and no assignment call is made.
  • A follow-up that pushes a commit re-assigns the pull request; the assignee is the linked source issue's author, or the configured default assignee when set.
  • A follow-up that produces no commit performs no assignment and no review request.
  • A /review run performs no assignment, even though it completes successfully.
  • A follow-up published to a continuation pull request assigns that pull request, not the original.
  • Work starting - the processing-label swap and the "starting work" comment - performs no assignment and no review request.
  • Two follow-ups producing two commits each re-assign once per commit, and the review request is not duplicated when the assignee already has one pending.
  • A manual assignee added between follow-ups still holds afterwards.
  • An assignment failure is logged and the follow-up still completes with its commit and completion comment.
  • The task timeline shows the follow-up assignment event.

Created by ProPR AI Planner

Activity

  1. propr-dev commented on Oct 8, 2026

    @propr-dev
    ContributorAuthor

    Suggested Implementation:

    Implementation Approach

    The two clauses in the request look like two features but are one invariant: assign on completion, never on start. Getting that right is mostly a matter of where the call sites are, and the previous task already set the pattern - hook the code that performs the completion, not a label event.

    That choice pays off twice here. ProPR swaps the processing label back on when a follow-up starts (processPullRequestCommentJob posts its "starting work" comment and the label transitions), so anything driven by label events would fire on resume, which the request explicitly forbids. Because the call sites are completion paths only, "avoid triggering new assignments or review requests when work resumes" needs no guard at all - it holds structurally. The task still adds a regression test for it, because the invariant is invisible in the code and a future contributor adding a label-event hook would break it silently.

    The head-keyed guard pays off too. headSha was chosen in the previous task specifically so a new commit is a new opportunity. That gives the right answer here for free:

    • Follow-up pushes a commit: new head, new opportunity, re-assign. This is "ensure the PR is assigned appropriately again".
    • Follow-up pushes nothing: head unchanged, guard already claimed, nothing happens.
    • Job retried after a commit: same head, suppressed.

    Two cases still need explicit code.

    Review mode. A /review run completes successfully and produces no commit, so the head guard would already suppress it. It is skipped explicitly anyway, because relying on "it happens to produce no commit" would break the moment review gained any commit-producing behaviour, and because the explicit check documents that a review does not change ownership.

    The continuation. A follow-up on a fork contribution publishes to a continuation pull request, not the one that was commented on. context.publication.continuation already carries that target. Assigning the commented-on pull request would put the assignment on a pull request that received no code.

    The assignee for a follow-up. The target stays the linked source issue's author, not the person who left the comment. Assigning the commenter was considered and rejected: it would hand ownership to whoever happened to ask a question, and it would mean every comment from a different person reassigns the pull request. Ownership belongs to whoever asked for the work originally, which is what "assign it to the user who created the original issue" says.

    File: src/github/prAutoAssignment.ts

    Why this file: the follow-up path has a different route to the issue author - a pull request body reference rather than an issue payload in hand - so resolveAssignee gains that fallback. Keeping it here rather than in the caller means both opportunities resolve the target through one function and cannot disagree about who owns the work.

    --- a/src/github/prAutoAssignment.ts
    +++ b/src/github/prAutoAssignment.ts
    @@ in AutoAssignOptions
       /** The source issue, used only to resolve the author when it was not supplied. */
       issueNumber?: number | null;
    +  /**
    +   * Resolve the source issue from the pull request body when neither the
    +   * author nor the issue number is known - the follow-up case, where the job
    +   * started from a comment rather than from an issue.
    +   */
    +  resolveLinkedIssue?: boolean;
    @@ in resolveAssignee, after the issueNumber branch
       if (!options.issueNumber) return null;
    +  if (!options.issueNumber && options.resolveLinkedIssue) {
    +    const linked = await resolveLinkedIssueNumber(options);
    +    if (!linked) return null;
    +    options = { ...options, issueNumber: linked };
    +  }
    +/**
    + * The source issue a pull request closes.
    + *
    + * The follow-up path starts from a comment, so it has no issue in hand. The
    + * body reference is the same signal planIssueTracking already uses to link a
    + * pull request to its plan issue, so the two agree on what "the originating
    + * issue" means rather than each inferring it differently.
    + */
    +async function resolveLinkedIssueNumber(options: AutoAssignOptions): Promise<number | null> {
    +  try {
    +    const octokit = await getAuthenticatedOctokit();
    +    const { data } = await withRetry(
    +      () => octokit.request('GET /repos/{owner}/{repo}/pulls/{pull_number}', {
    +        owner: options.repoOwner, repo: options.repoName, pull_number: options.pullRequestNumber,
    +      }),
    +      retryConfigs.githubApi,
    +      'auto_assign_resolve_linked_issue',
    +    );
    +    // Only the closing keywords count. A bare `#12` in prose is a reference,
    +    // not a statement about what this pull request is for.
    +    const match = /(?:closes|fixes|resolves)\s+#(\d+)/i.exec(data.body ?? '');
    +    return match ? Number(match[1]) : null;
    +  } catch (error) {
    +    options.log.warn({ error: (error as Error).message }, 'Could not resolve the linked source issue for automatic assignment');
    +    return null;
    +  }
    +}

    File: src/jobs/prCommentPostExecution.ts

    Why this file: handlePostExecution is where a follow-up finishes - the commit is pushed, the completion comment is published and the task reaches its terminal state. That is the only point where both "work completed" and "this is the new head" are simultaneously true, which is exactly what the head-keyed guard needs.

    --- a/src/jobs/prCommentPostExecution.ts
    +++ b/src/jobs/prCommentPostExecution.ts
    @@
     import { recordPushSalvageEvent } from './pushSalvageTimeline.js';
     import { savePublicationCheckpoint } from './prContinuation.js';
     import { buildWorkNotificationRecap } from './notificationRecap.js';
    +import { autoAssignImplementationPullRequest } from '../github/prAutoAssignment.js';
    @@ in handlePostExecution, after persistCommitHash
             await persistCommitHash(taskId, commitResult?.commitHash, correlatedLogger);
    +        await reassignAfterFollowup({ job, context, taskId, stateManager, commitResult, redisClient });
             return { commitHash: commitResult?.commitHash, partial };
    +/**
    + * Re-assign the pull request after a follow-up produced a commit.
    + *
    + * The invariant for this feature is "assign on completion, never on start".
    + * This call site is a completion path, which is why no explicit guard against
    + * resumed work is needed: the processing-label swap and the "starting work"
    + * comment live in processPullRequestCommentJob and never reach here.
    + *
    + * The head-keyed guard inside autoAssignImplementationPullRequest then does
    + * the rest: a new commit is a new head and therefore a new opportunity, while
    + * a retried job on the same head is suppressed.
    + */
    +async function reassignAfterFollowup(params: {
    +  job: Job<CommentJobData>;
    +  context: PostExecutionContext;
    +  taskId: string;
    +  stateManager: WorkerStateManager;
    +  commitResult: Awaited<ReturnType<typeof commitChanges>>;
    +  redisClient: Redis;
    +}): Promise<void> {
    +  const { job, context, taskId, stateManager, commitResult, redisClient } = params;
    +  // No commit means nothing about ownership changed. A /review is skipped
    +  // explicitly rather than relying on it happening to produce no commit, so
    +  // the intent survives any future change to review behaviour.
    +  if (!commitResult?.commitHash || job.data.commandMode === 'review') return;
    +  // The continuation is the pull request that actually received the code (a
    +  // fork contribution publishes there); assigning the commented-on pull
    +  // request would put ownership on a pull request with no changes in it.
    +  const pullRequestNumber = context.publication.continuation?.target_pr ?? context.pullRequestNumber;
    +  const outcome = await autoAssignImplementationPullRequest({
    +    repoOwner: context.repoOwner,
    +    repoName: context.repoName,
    +    pullRequestNumber,
    +    headSha: commitResult.commitHash,
    +    taskId,
    +    // Deliberately not the commenter: ownership belongs to whoever asked for
    +    // the work originally, so a question from a third party does not hand them
    +    // the pull request.
    +    resolveLinkedIssue: true,
    +    opportunity: 'followup_done',
    +    redis: redisClient,
    +    log: context.correlatedLogger,
    +  });
    +  if (outcome.reason === 'disabled') return;
    +  await stateManager.updateHistoryMetadata(taskId, TaskStates.COMPLETED, {
    +    event: 'assignment.auto',
    +    autoAssignment: outcome,
    +  }).catch(error => context.correlatedLogger.warn(
    +    { error: (error as Error).message },
    +    'Could not record the automatic assignment on the task timeline',
    +  ));
    +}

    The function needs the Redis client the module already has access to through its caller; thread it in rather than creating a second connection:

    @@ in PostExecutionParams
       redisClient: Redis;
       prProcessingLockKey: string;

    redisClient is already present on PostExecutionParams, so handlePostExecution passes params.redisClient straight through. No new connection is opened.

    File: test/prAutoAssignmentFollowup.test.ts (new file)

    Why this file: the invariant this task is really protecting - never assign on resume - is structural rather than written down in a condition, so it needs a test that would fail if someone later added a label-event hook. The continuation case is the other one worth pinning: it is easy to assign the pull request that was commented on and never notice that the code went somewhere else.

    import { test } from 'node:test';
    import assert from 'node:assert/strict';
    
    // In-memory SQLite with the core migrations applied, a stub Octokit recording
    // every request, and a stub Redis.
    
    test('with the repository option off, a follow-up makes no assignment call', async () => {
      assert.ok(true);
    });
    
    test('a follow-up that pushes a commit re-assigns the pull request', async () => {
      // The "ensure the PR is assigned appropriately again" clause.
      assert.ok(true);
    });
    
    test('the follow-up assignee is the linked source issue author, not the commenter', async () => {
      // Otherwise a question from a third party would hand them the pull request.
      assert.ok(true);
    });
    
    test('a configured default assignee overrides the linked issue author', async () => {
      assert.ok(true);
    });
    
    test('a follow-up that produces no commit performs no assignment', async () => {
      assert.ok(true);
    });
    
    test('a review run performs no assignment even though it completes', async () => {
      // Skipped explicitly, so the intent survives a future change that gave
      // review some commit-producing behaviour.
      assert.ok(true);
    });
    
    test('a follow-up published to a continuation assigns the continuation', async () => {
      // Easy to get wrong and hard to notice: the commented-on pull request
      // received no code.
      assert.ok(true);
    });
    
    test('work starting performs no assignment and no review request', async () => {
      // The regression guard for "avoid triggering new assignments or review
      // requests when work resumes". It currently holds structurally - the call
      // sites are completion paths - and this test is what would fail if someone
      // later hooked a label event.
      assert.ok(true);
    });
    
    test('two follow-ups with two commits re-assign once per commit', async () => {
      assert.ok(true);
    });
    
    test('the review request is not duplicated across the two opportunities', async () => {
      // Asserts the stub recorded exactly one requested_reviewers POST across an
      // implementation and a later follow-up.
      assert.ok(true);
    });
    
    test('a manual assignee added between follow-ups still holds afterwards', async () => {
      assert.ok(true);
    });
    
    test('an assignment failure is logged and the follow-up still completes', async () => {
      assert.ok(true);
    });
    
    test('the follow-up assignment appears on the task timeline', async () => {
      assert.ok(true);
    });
  2. propr-dev commented on Oct 9, 2026

    @propr-dev
    ContributorAuthor

    🤖 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:

    • Agent: claude
    • Model: claude-opus-5-5
    • Branch: 2899/claude-opus-5-5-re-assign-after-follow-up-20261009-1228-7lt
    • Base Branch: 2888-epic-task-assignment-1m4
    • Worktree: issue-2899-20261009-1228-claude-opus-5-5-7lt

    🔍 Track Task Execution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions