Skip to content

Handle missing PR-head refs in centralized slash-command dispatch#41835

Closed
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-slash-command-dispatching
Closed

Handle missing PR-head refs in centralized slash-command dispatch#41835
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-slash-command-dispatching

Conversation

Copilot AI commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Centralized slash-command routing can fail for PR-originated events when the computed dispatch ref (PR head branch) is not available to workflow_dispatch in the target repo context. This change makes dispatch resilient by retrying on a safe default branch ref instead of aborting routing.

  • Dispatch fallback for PR ref mismatches

    • In route_slash_command.cjs, dispatchWorkflow(...) now detects 422 errors with missing-ref semantics ("No ref found for").
    • When detected, it resolves a fallback branch ref and retries dispatch once with that ref.
  • Fallback ref resolution

    • Added resolveDefaultBranchRef(ref) to derive fallback in priority order:
      1. context.payload.repository.default_branch
      2. repos.get(...).data.default_branch
      3. "main" as final fallback
    • Added small helpers to normalize and validate fallback refs so retries only occur when the fallback is usable and different from the failed ref.
  • Error classification clarity

    • Added isMissingWorkflowDispatchRefError(error) to isolate ref-not-found failures from other 422 conditions (e.g., disabled workflow), preserving existing behavior for unrelated errors.
  • Regression coverage

    • Added a focused test in route_slash_command.test.cjs for PR issue-comment routing:
      • first dispatch attempt fails on PR head ref not found,
      • second attempt retries on default branch and succeeds.
if (isMissingWorkflowDispatchRefError(error)) {
  const fallbackRef = await resolveDefaultBranchRef(ref);
  if (!fallbackRef) throw new Error(...);
  await github.rest.actions.createWorkflowDispatch({ workflow_id, ref: fallbackRef, inputs, headers });
}

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot the agentic commands dispatcher code is not properly capturing the pr Number

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

🤖 PR Triage — §28282332784

Field Value
Category bug
Risk medium
Score 53/100 (impact 30 + urgency 18 + quality 5)
Action defer

Rationale: Draft PR with no CI yet. Slash-command dispatch resilience fix (164 additions, 2 files with tests) is meaningful but needs to leave draft status and pass CI before review.

Generated by 🔧 PR Triage Agent · 74.7 AIC · ⌖ 8.27 AIC · ⊞ 5.4K ·

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants