Agent suggestions
Public previewDescription
Describe the bug
gh --version 2.46.0
When I gh pr create -f -r $reviewer in a repository with codeowners, github will automatically request a codeowner review, even if $reviewer is a codeowner. Additionally, sometimes github removes request from one or more of the reviewers I specified!
Steps to reproduce the behavior
This might take multiple attempts. In a repository with multiple codeowners,
gh pr create -fr $reviewer(where $reviewer is a codeowner)- Open up the PR and see
| "$user requested a review from $team as a code owner x minutes ago"
| "$user requested review from $reviewer and $other codeowner (assigned from $team) x minutes ago"
or sometimes
| "$user requested review from $reviewer and $other codeowner (assigned from $team) and removed request fro $reviewer x minutes ago"
Expected vs actual behavior
I would expect that if I request a review from a code owner to not automatically request reviews from new codeowners. I would especially expect that the reviewers I request don't disappear!
Logs
This invocation had two reviewers in it, and one was removed:
"$user requested review from $reviewer1 and $reviewer2 and removed request for $reviewer2"
GH_DEBUG=api gh pr create results
* Request at 2024-09-11 16:45:54.515347457 -0400 EDT m=+2.427704602
* Request to https://api.github.com/graphql
> POST /graphql HTTP/1.1
> Host: api.github.com
> Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
> Authorization: token ████████████████████
> Content-Length: 157
> Content-Type: application/json; charset=utf-8
> Graphql-Features: merge_queue
> Time-Zone: America/New_York
> User-Agent: GitHub CLI 2.46.0
GraphQL query:
query RepositoryResolveMetadataIDs {
u000: user(login:"$reviewer1"){id,login}
u001: user(login:"$reviewer2"){id,login}
}
GraphQL variables: null
< HTTP/2.0 200 OK
< Access-Control-Allow-Origin: *
< Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
< Content-Security-Policy: default-src 'none'
< Content-Type: application/json; charset=utf-8
< Date: Wed, 11 Sep 2024 20:45:54 GMT
< Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
< Server: github.com
< Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
< Vary: Accept-Encoding, Accept, X-Requested-With
< X-Accepted-Oauth-Scopes: repo
< X-Content-Type-Options: nosniff
< X-Frame-Options: deny
< X-Github-Media-Type: github.v4; param=merge-info-preview.nebula-preview; format=json
< X-Github-Request-Id: E298:236D42:970B306:12389EA2:66E20182
< X-Oauth-Client-Id: $not-sure-if-sensitive
< X-Oauth-Scopes: gist, read:org, repo
< X-Ratelimit-Limit: 5000
< X-Ratelimit-Remaining: 4990
< X-Ratelimit-Reset: 1726090479
< X-Ratelimit-Resource: graphql
< X-Ratelimit-Used: 10
< X-Xss-Protection: 0
{
"data": {
"u000": {
"id": "$id1",
"login": "$reviewer1"
},
"u001": {
"id": "$id2",
"login": "$reviewer2"
}
}
}
* Request took 135.91325ms
* Request at 2024-09-11 16:45:54.65150025 -0400 EDT m=+2.563857388
* Request to https://api.github.com/graphql
> POST /graphql HTTP/1.1
> Host: api.github.com
> Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
> Authorization: token ████████████████████
⣾> Content-Length: 390
> Content-Type: application/json; charset=utf-8
> Graphql-Features: merge_queue
> Time-Zone: America/New_York
> User-Agent: GitHub CLI 2.46.0
GraphQL query:
mutation PullRequestCreate($input: CreatePullRequestInput!) {
createPullRequest(input: $input) {
pullRequest {
id
url
}
}
}
GraphQL variables: {"input":{"baseRefName":"main","body":"redacted\n","draft":false,"headRefName":"temp-pr","maintainerCanModify":true,"repositoryId":"R_kgDOHe0SJw","title":"test pr please ignore"}}
⣷< HTTP/2.0 200 OK
< Access-Control-Allow-Origin: *
< Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
< Content-Security-Policy: default-src 'none'
< Content-Type: application/json; charset=utf-8
< Date: Wed, 11 Sep 2024 20:45:55 GMT
< Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
< Server: github.com
< Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
< Vary: Accept-Encoding, Accept, X-Requested-With
< X-Accepted-Oauth-Scopes: repo
< X-Content-Type-Options: nosniff
< X-Frame-Options: deny
< X-Github-Media-Type: github.v4; param=merge-info-preview.nebula-preview; format=json
< X-Github-Request-Id: E298:236D42:970B36C:12389F55:66E20182
< X-Oauth-Client-Id: $not-sure-if-sensitive
< X-Oauth-Scopes: gist, read:org, repo
< X-Ratelimit-Limit: 5000
< X-Ratelimit-Remaining: 4989
< X-Ratelimit-Reset: 1726090479
< X-Ratelimit-Resource: graphql
< X-Ratelimit-Used: 11
< X-Xss-Protection: 0
{
"data": {
"createPullRequest": {
"pullRequest": {
"id": "PR_kwDOHe0SJ857NymJ",
"url": "https://github.com/$owner/$repo/pull/333"
}
}
}
}
* Request took 886.966774ms
* Request at 2024-09-11 16:45:55.538616713 -0400 EDT m=+3.450973862
* Request to https://api.github.com/graphql
> POST /graphql HTTP/1.1
> Host: api.github.com
> Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
> Authorization: token ████████████████████
> Content-Length: 280
> Content-Type: application/json; charset=utf-8
> Graphql-Features: merge_queue
> Time-Zone: America/New_York
> User-Agent: GitHub CLI 2.46.0
GraphQL query:
mutation PullRequestCreateRequestReviews($input: RequestReviewsInput!) {
requestReviews(input: $input) { clientMutationId }
}
GraphQL variables: {"input":{"pullRequestId":"PR_kwDOHe0SJ857NymJ","union":true,"userIds":["$id1","$id2"]}}
⡿< HTTP/2.0 200 OK
< Access-Control-Allow-Origin: *
< Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
< Content-Security-Policy: default-src 'none'
< Content-Type: application/json; charset=utf-8
< Date: Wed, 11 Sep 2024 20:45:56 GMT
< Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
< Server: github.com
< Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
< Vary: Accept-Encoding, Accept, X-Requested-With
< X-Accepted-Oauth-Scopes: repo
< X-Content-Type-Options: nosniff
< X-Frame-Options: deny
< X-Github-Media-Type: github.v4; param=merge-info-preview.nebula-preview; format=json
< X-Github-Request-Id: E298:236D42:970B603:1238A45F:66E20183
< X-Oauth-Client-Id: $not-sure-if-sensitive
< X-Oauth-Scopes: gist, read:org, repo
< X-Ratelimit-Limit: 5000
< X-Ratelimit-Remaining: 4988
< X-Ratelimit-Reset: 1726090479
< X-Ratelimit-Resource: graphql
< X-Ratelimit-Used: 12
< X-Xss-Protection: 0
{
"data": {
"requestReviews": {
"clientMutationId": null
}
},
"extensions": {
"warnings": [
{
"type": "DEPRECATION",
"message": "The id $id1 is deprecated. Update your cache to use the next_global_id from the data payload.",
"data": {
"legacy_global_id": "$id1",
"next_global_id": "U_kgDOAAJf5g"
},
"link": "https://docs.github.com"
}
]
}
}
It looks like gh is sending the CreatePullRequest then immediately afterwards updating the reviewers.
Activity
[-]gh create -fr doesn't play nice with codeowners[/-][+]gh pr create -fr doesn't play nice with codeowners[/+]andyfeller commentedon Sep 11, 2024
@mcmanustfj : thank you for taking the time to follow up on this
gh prexperience! let's dig into this and figure out what is possible.Could you share any information about whether this repository has a repository ruleset or branch protection rule that requires a review from a codeowner in order to merge the PR?
I'm assuming you have one or both in place, which affects how Pull Requests determines the reviewers.
From Require a pull request before merging:
Essentially, Pull Request is strongly opinionated about using the code owners information to handle reviewers, not who you specify. If this rule is not in place, then the subsequent call to assign the reviewers should work.
Additionally, you might also consider assigning additional people using
-a, --assignee login.mcmanustfj commentedon Sep 11, 2024
Just branch protection with "Require reviews from Code owners".
Everyone I specify is also a code owner, the repo only has one code owner group.
andyfeller commentedon Sep 11, 2024
Thanks, that's what I thought.
If you tried creating this PR in the UI, it doesn't act any differently, does it? Meaning, you don't have control over selecting the reviewers; they are automatically assigned based on the code owners file and changes made.
mcmanustfj commentedon Sep 11, 2024
I can select reviewers when creating the PR in the UI, and it has never deselected my selection or add new reviewers (as long as one of my reviewers is a codeowner); I'm pretty confident I would have noticed if it had, and I tried twice just now to check.
In other words, it does act differently, and I would expect
gh pr createto work how the web UI works.mcmanustfj commentedon Sep 11, 2024
this might be because the UI doesn't use the same http api and instead has the requested reviewers in the POST data.
Notably, it shows the "requested review from $a and $b" before saying "requested review from $team as code owner".
This might be a limitation of the HTTP API that gh cli uses, since there's no input for reviewers in the public github api
andyfeller commentedon Sep 12, 2024
@mcmanustfj : that is a good point, 👉 let's see how much of your situation we can recreate in one of my repos as there are multiple factors involved as I'd like to figure this out. 👍
From my experiments below, I see the explicitly specified
-r, --reviewerbeing honored despite an auto assigned code owner from the configured team. 🤔Experiments I ran so far
Experiment conditions
Given the following:
Experiment 1: Creating PR in UI with repo protected by repo ruleset, assigning code owner team members
PR: tinyfists/gh-pr-test#5
Result: the additional reviewer I added is preserved while the code reviewer team has member assigned while preserving team as configured
Experiment 2: Creating PR with
gh pr -f -r USERunder Experiment 1 conditionsPR: tinyfists/gh-pr-test#6
Result: the additional reviewer I added is preserved while the code reviewer team has member assigned while preserving team as configured 🤔
mcmanustfj commentedon Sep 12, 2024
is the user you requested in experiment 2 part of the codeowner team? Also, the behaviour isn't deterministic, sometimes you need to try a couple times to get it to show - additionally, it might be more likely for weird stuff to happen if you request multiple reviewers, but I'm not confident on that
mcmanustfj commentedon Sep 12, 2024
The 'use case' for this is when I want a specific person (or people) who are code owners to review the PR, and not to add extraneous reviewers, since I've already specified a codeowner to review
mcmanustfj commentedon Sep 13, 2024
maybe it's unreliable because when you make a new PR it takes a second for github to auto-assign codeowners, and if the HTTP call to add reviewers resolves before the codeowners resolve, it replaces the reviewers with the codeowners
mcmanustfj commentedon Sep 18, 2024
@andyfeller do you need any more input?
mcmanustfj commentedon Sep 25, 2024
@andyfeller do you have another question?
andyfeller commentedon Oct 7, 2024
@mcmanustfj : apologies for the delay following up while out of office 🙇
No,
enyilwas not a code owner given the lack of the shield icon next to his name. This experiment was intended to show a non-codeowner reviewer would be accepted and not cleared by repo rule.I'd appreciate if you could record a screen capture walking through these unreliable scenarios.
Again, this depends on how you have 1) repository ruleset or 2) branch protection rules setup along with how any codeowner team's review settings are configured.
mcmanustfj commentedon Oct 8, 2024
To confirm, this is specifically happening when the requested reviewer is in the code owner group. My main use case for
gh pr create -fr $revieweris when $reviewer is part of the codeowner group, and the problem is when the PR automatically adds someone else from the codeowner group and sometimes removes whoever I added to the codeowner group.There is no repository ruleset configured, and the branch protection rules are just as follows:

A screen capture wouldn't be very helpful since the action all happens offscreen - I create the PR with a one-line command and then I open the webpage.
As I mentioned in the OP, the failure cases are
| "$user requested a review from $team as a code owner x minutes ago"
| "$user requested review from $reviewer and $other-codeowner (assigned from $team) x minutes ago"
or sometimes
| "$user requested review from $reviewer and $other-codeowner (assigned from $team) and removed request fro $reviewer x minutes ago"
Sometimes it works fine and I just see "$user requested review from $reviewer x minutes ago"
magnush0lm commentedon Nov 10, 2025
I am experiencing what I think is the exact same thing:
gh.exe pr create --body "body_text" --reviewer user1,user2..userN --title "some_title"Warning: 2 uncommitted changes pull request update failed: GraphQL: Could not add requested reviewers to pull request. (requestReviews)The issue seems to be a race condition between Github processing the CODEOWNERS file and gh adding reviewers.
It only happens once in a while (seldom) and we had no issue at all with this before the CODEOWNERS file was introduced.
The PR is made just fine - apart from missing reviewer(s) - giving the impression that creating the PR and adding the reviewers are two different API calls.
When looking in the Github web console (
<org>/<repo>/pull/<number>), sometimes, the resulting PR will only have<my_username> requested review from <user(s)> as code owners, while other times it will have that same text, but with one (or more!)<my_username> requested review from <user(s)>...below.Users already added from CODEOWNERS will sometimes be in the second/added by gh list, other times not, giving additional clues to this being a race condition.
cli-triage commentedon Nov 7, 2026
Partly reproduced on 2.46.0.
Using test data, the command succeeds and creates the pull request before sending a separate reviewer request:
Exit status:
0.The same two-step behavior remains in 2.103.3 and the current source build. The reviewer request is additive, but this test cannot simulate GitHub's asynchronous CODEOWNERS assignment, so it cannot reproduce the intermittent removal itself. Reports from two versions support keeping this open for investigation.
Supporting reports
Duplicate analysis
Label reasoning
Reproduction log
Investigation notes
Generated by issue triage.