Skip to content

fix: handle non-user actors (e.g. Copilot) in permission and actor checks#1144

Open
krislavten wants to merge 1 commit intoanthropics:mainfrom
krislavten:fix/handle-non-user-actor-permission-check
Open

fix: handle non-user actors (e.g. Copilot) in permission and actor checks#1144
krislavten wants to merge 1 commit intoanthropics:mainfrom
krislavten:fix/handle-non-user-actor-permission-check

Conversation

@krislavten
Copy link
Copy Markdown

Summary

GitHub Apps like Copilot SWE Agent set GITHUB_ACTOR to a value (e.g. "Copilot") that is neither a valid GitHub user nor ends with [bot]. This causes two independent crashes in the action:

  1. checkWritePermissions (permissions.ts): calls the collaborator permission API → 404 "Copilot is not a user"
  2. checkHumanActor (actor.ts): calls octokit.users.getByUsername() → 404 before reaching the allowed_bots check

Root Cause

Both functions assume the actor is either a real GitHub user or a [bot]-suffixed app. Some GitHub Apps (Copilot, and potentially future ones) use a plain name as GITHUB_ACTOR that doesn't match either pattern.

Fix

permissions.ts:

  • Check allowed_bots before calling the collaborator API, so known bots skip the API entirely
  • Catch "is not a user" 404 errors and fall back to allowed_bots check instead of crashing

actor.ts:

  • Move allowed_bots check before the octokit.users.getByUsername() call
  • Catch 404 errors and provide a clear error message telling the user to add the bot to allowed_bots

Tests

Added 11 new test cases covering:

  • Non-[bot] actor in allowed_bots list (both pre-API and 404 fallback paths)
  • Wildcard * for non-[bot] actors
  • Non-[bot] actor NOT in allowed_bots (returns false / clear error message)
  • Case-insensitive matching
  • Non-404 errors still propagate correctly

All 664 existing tests continue to pass.

Closes

Related

🤖 Generated with Claude Code

…ecks

GitHub Apps like Copilot SWE Agent set GITHUB_ACTOR to a value (e.g.
"Copilot") that is neither a valid GitHub user nor ends with "[bot]".
This caused two independent crashes:

1. checkWritePermissions (permissions.ts): called the collaborator
   permission API which returns 404 "is not a user" for non-user actors.
2. checkHumanActor (actor.ts): called the Users API first, which 404s,
   before ever reaching the allowed_bots check.

Fix both by:
- Checking allowed_bots BEFORE making API calls, so known bots skip the
  API entirely.
- In permissions.ts, catching "is not a user" 404 errors and falling
  back to the allowed_bots list instead of crashing.
- In actor.ts, catching 404 errors and providing a clear error message
  telling the user to add the bot to allowed_bots.

Closes anthropics#900, anthropics#903, anthropics#1018, anthropics#1133

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.

1 participant