Skip to content

fix: handle 404 errors in checkWritePermissions for non-user actors#1030

Open
MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
MaxwellCalkin:fix/check-write-permissions-non-user-404
Open

fix: handle 404 errors in checkWritePermissions for non-user actors#1030
MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
MaxwellCalkin:fix/check-write-permissions-non-user-404

Conversation

@MaxwellCalkin
Copy link

Summary

Fixes #1018

checkWritePermissions calls octokit.repos.getCollaboratorPermissionLevel() with github.actor as the username. When the actor is a non-user entity like Copilot (from a Copilot-initiated pull_request_review), this API returns a 404 because Copilot is not a regular GitHub user.

The existing bot bypass only checks for actors ending in [bot], but Copilot does not follow that naming convention.

Changes

  • src/github/validation/permissions.ts: Added 404 error handling in the catch block. When the collaborator permissions API returns a 404 (indicating the actor is not a GitHub user), the function now logs an informational message and returns true instead of throwing. Non-404 errors continue to throw as before.

  • test/permissions.test.ts: Added 4 new test cases:

    • 404 from API for Copilot actor returns true
    • 404 from API for any non-user actor name returns true
    • Non-404 errors (e.g., generic Error) still throw
    • 500 server errors still throw

Why this approach

Rather than maintaining a hardcoded list of non-user actor names (which would need updating as GitHub adds new system actors), this fix catches the 404 response that GitHub already returns when an actor is not a user. This is robust against future non-user actors being added by GitHub.

This is consistent with how other parts of the codebase handle 404s from GitHub APIs (e.g., branch-cleanup.ts, update-claude-comment.ts).

Test plan

  • All 17 permissions tests pass (including 4 new ones)
  • Full test suite passes (19 pre-existing Windows-specific failures unrelated to this change)
  • Verify with a Copilot-triggered pull_request_review workflow

The collaborator permissions API returns 404 for actors like "Copilot"
that are not regular GitHub users. Previously, only actors ending in
"[bot]" were bypassed, causing workflows triggered by Copilot reviews
to fail with "Copilot is not a user" errors.

This adds 404 error handling in the catch block so that non-user actors
are recognized and allowed through, matching the existing behavior for
[bot] actors.

Fixes anthropics#1018

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

checkWritePermissions fails with 404 for non-user actors like Copilot

1 participant