Skip to content

pr create --as-user <login> reports not a collaborator despite valid host gh access #159

Closed

Description

@JounQin

Summary

gcb pr create --as-user JounQin fails with GraphQL: must be a collaborator (createPullRequest) even though the host gh account is the correct user and has push access.

Environment

  • gcb version: 0.11.0 (host broker)
  • host broker had the target repository added to its allowlist and was reloaded
  • ~/.config/gh-JounQin was created/available to the host broker

Steps

  1. Host gh is authenticated as the intended account and can read/write the repository:
    • gh api user returns that account
    • repository permissions include push: true
  2. Run:
gcb pr create --as-user JounQin \
  --repo <owner>/<repo> \
  --head <branch> \
  --base next \
  --title "..." \
  --body-file ...

Actual

error: the host broker could not do it: pull request create failed:
GraphQL: must be a collaborator (createPullRequest)

The same command without a host login (--as-user) fails earlier with:

403 ... needs the pull_requests: write permission on both the app and this installation

Expected

--as-user <login> should perform the request with that host account's credentials, which already have push/collaborator access, and create the PR.

Notes

  • The repository allowlist was updated and the host broker reloaded before retrying.
  • No tokens or secrets are included here.

Activity

  1. git-credential-broker commented on Nov 12, 2026

    @git-credential-broker
    Contributor

    Checked the host route: it passes --head through to gh pr create unchanged, sets GH_CONFIG_DIR=~/.config/gh-<login> and GH_HOST=github.com, and runs in the checkout/channel it is serving.

    must be a collaborator (createPullRequest) is about the head repository, not necessarily push access to --repo. With a bare --head <branch>, gh infers the head repository from the checkout it runs in; if the host broker is serving a different checkout (or the global channel), that can resolve to a repository where JounQin is not a collaborator, even though --repo push access is fine.

    To narrow it down, could you share sanitized:

    • the exact --head value (a bare branch or <remote>:<branch>)
    • git remote -v and the current branch in the checkout where the request ran
    • whether the branch is pushed to the target repo or to JounQin's fork
    • whether the same flags work when run directly on the host from a checkout of the target:
      gh pr create --repo <owner>/<repo> --head <branch> --base next --title ...

    If the branch is in a fork, --head <remote>:<branch> (where that remote points at the fork) should make the head explicit; a bare branch leaves it to the host checkout's remote.

  2. git-credential-broker commented on Nov 12, 2026

    @git-credential-broker
    Contributor

    Sanitized details from the failing case:

    • --head value: fix/list-item-indent (bare branch)
    • target repo: mdx-js/eslint-mdx
    • branch is pushed to both mdx-js/eslint-mdx and JounQin/eslint-mdx
    • target repo permissions for the host gh identity: push: true
    • host checkout remotes: origin, upstream; origin points at the fork, and there is no remote named mdx-js

    Observed failures:

    # bare head
    GraphQL: must be a collaborator (createPullRequest)
    
    # origin:fix/list-item-indent
    GraphQL: Head sha can't be blank, Base sha can't be blank,
    No commits between mdx-js:next and JounQin:fix/list-item-indent
    
    # mdx-js:fix/list-item-indent
    error: no remote named "mdx-js" here, so "mdx-js:fix/list-item-indent"
    cannot be resolved; this checkout has: origin, upstream
    

    Direct host checks with the same login:

    gh api user -> JounQin
    repo permissions -> push: true
    

    So the branch exists and the account can push, but the host route still resolves the create request as a non-collaborator. One hypothesis: the host broker process has GH_TOKEN set, which overrides GH_CONFIG_DIR and therefore --as-user <login>; another is that the head repository resolution is still using the fork/current checkout. No tokens or private paths are included here.

  3. git-credential-broker commented on Nov 12, 2026

    @git-credential-broker
    Contributor

    Follow-up: I changed the host checkout's origin to point at mdx-js/eslint-mdx and retried with a matching head:

    gcb pr create --as-user JounQin \
      --repo mdx-js/eslint-mdx \
      --head origin:fix/list-item-indent ...

    It still fails with:

    GraphQL: must be a collaborator (createPullRequest)
    

    So with origin matching the target repo, the head remote resolution is no longer the differentiator; the request still appears to reach GitHub as an identity without collaborator access. I restored origin to its previous fork URL afterward. No credentials or private paths included.

  4. git-credential-broker commented on Nov 12, 2026

    @git-credential-broker
    Contributor

    With origin pointing at mdx-js/eslint-mdx and --head origin:... still failing, the head-resolution hypothesis no longer explains it: the head repository is already explicit. That points at the token/identity gh actually uses, or at the token's permissions, rather than at --head.

    Could you run the create directly on the host with the same account environment gcb is supposed to use:

    env -u GH_TOKEN -u GITHUB_TOKEN -u GH_ENTERPRISE_TOKEN -u GITHUB_ENTERPRISE_TOKEN \
      GH_CONFIG_DIR="$HOME/.config/gh-JounQin" \
      GH_HOST=github.com \
      gh pr create --repo mdx-js/eslint-mdx \
        --head origin:fix/list-item-indent --base next \
        --title test --body test

    and also, in the host broker's own environment (sanitized):

    env | grep '^GH_' || true
    GH_CONFIG_DIR="$HOME/.config/gh-JounQin" gh auth status

    Two outcomes:

    • If the direct command fails the same way, the gh-JounQin credential cannot create pull requests. push: true only proves contents write; a fine-grained token can still lack Pull requests: write, and GitHub's GraphQL reports that as must be a collaborator. gh auth status should show the token type/scopes.
    • If the direct command succeeds but gcb fails, the host broker is injecting a different token (for example an inherited GH_TOKEN that overrides GH_CONFIG_DIR) and I will trace that path.

    I reverted the uncommitted head-owner change rather than shipping a fix for a cause the new evidence rules out.

  5. git-credential-broker commented on Nov 12, 2026

    @git-credential-broker
    Contributor

    The app-installation limitation is exactly why --as-user <login> routes through gcb host, so this should work without installing the App. I rechecked the repo/branches: mdx-js/eslint-mdx does have next and fix/list-item-indent, so the target branch is real.

    With origin changed to the target and --head origin:... still failing, the remaining likely cause is the credential the host gh actually uses, not head resolution. Could you run these on the host with the same config directory the broker selects:

    env -u GH_TOKEN -u GITHUB_TOKEN -u GH_ENTERPRISE_TOKEN -u GITHUB_ENTERPRISE_TOKEN \
      GH_CONFIG_DIR="$HOME/.config/gh-JounQin" \
      GH_HOST=github.com \
      gh api user --jq .login
    
    env -u GH_TOKEN -u GITHUB_TOKEN -u GH_ENTERPRISE_TOKEN -u GITHUB_ENTERPRISE_TOKEN \
      GH_CONFIG_DIR="$HOME/.config/gh-JounQin" \
      GH_HOST=github.com \
      gh pr create --repo mdx-js/eslint-mdx \
        --head mdx-js:fix/list-item-indent --base next \
        --title test --body test

    If the first prints a login other than JounQin, GH_CONFIG_DIR is not selecting the account the broker thinks it is. If the second still says must be a collaborator, the gh-JounQin token itself lacks Pull requests: write (a fine-grained token can have contents write and still fail this), or is not SSO-authorized for the org; gh auth status will name the token/scopes. If the second succeeds, the broker is injecting a different environment and I will trace that path.

    Please do not paste tokens; login, token type and scopes are enough.

  6. git-credential-broker commented on Nov 12, 2026

    @git-credential-broker
    Contributor

    I can verify this from the broker without touching the host shell, and it changes the diagnosis.

    Against the same repository via the host route:

    gcb gh pr list --repo mdx-js/eslint-mdx --author @me --state all --as-user JounQin
    # (empty)
    
    gcb gh pr list --repo mdx-js/eslint-mdx --author JounQin --state all --as-user JounQin
    # JounQin's pull requests, including #659, #658, #657, ...

    Via the broker person route:

    gcb gh pr list --repo mdx-js/eslint-mdx --author @me --state all --as-user
    # the same JounQin's pull requests

    So the host route really is not running as JounQin, independently of --head and App installation. This is an account-selection bug on the host, not a head-resolution bug.

    The candidate is GH_CONFIG_DIR: the host gh is selecting a config directory that does not carry JounQin's token, or the token is being read from a keyring/config that GH_CONFIG_DIR does not isolate. Please run on the host:

    GH_CONFIG_DIR="$HOME/.config/gh-JounQin" GH_HOST=github.com gh api user --jq .login
    GH_CONFIG_DIR="$HOME/.config/gh-JounQin" GH_HOST=github.com gh auth status

    The first must print JounQin; if it does not, ~/.config/gh-JounQin is not the account the broker thinks it is. If it does, the broker's HOME/GH_CONFIG_DIR differs from the shell's, and that is the path I need to fix.

    I am not shipping a head change; the host-route evidence rules it out.

  7. git-credential-broker commented on Nov 12, 2026

    @git-credential-broker
    Contributor

    Root cause found on the host, and the PR route is working again.

    ~/.config/gh-JounQin was a symlink to ~/.config/gh (created 2026-11-13 02:14:50). The default config was logged in as i1stG, not JounQin, and i1stG has push: false on mdx-js/eslint-mdx. GH_CONFIG_DIR selected the directory but not the active user, so --as-user JounQin silently ran as i1stG.

    Recovery, without switching the default account:

    • replaced the symlink with a real ~/.config/gh-JounQin
    • logged JounQin in there once (GH_CONFIG_DIR=~/.config/gh-JounQin gh auth login)
    • default ~/.config/gh still stays on i1stG

    Verified:

    GH_CONFIG_DIR=~/.config/gh-JounQin gh api user --jq .login   # JounQin
    # host route @me now returns JounQin's PRs
    # permissions.push for mdx-js/eslint-mdx is true

    Then the original command opened:

    mdx-js/eslint-mdx#660

    I also added a guard in #160: the host broker reads the account directory's hosts.yml and refuses when its active github.com user is not the requested login, instead of acting as the wrong person.

    On “why did it change”: the current hosts.yml has only i1stG and was last written 2026-11-11 07:44; the symlink dates from 02:14 today. There is no shell-history record of a logout/switch at that time, so the exact earlier overwrite cannot be reconstructed from what remains. The durable fix is per-account real directories (or gh auth token --user <login> + a per-command GH_TOKEN), never a symlink to the default config.

    Do not switch accounts to work around this: gh only has one active account per host, but separate GH_CONFIG_DIR values let each identity coexist.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions