Skip to content

Support linking GitHub stacked pull requests (gh stack) #2102

Closed

Description

@sentry-junior

Problem

Junior can't create or manage GitHub stacked PRs. Running gh stack from the sandbox fails with a 403. Junior's GitHub egress proxy returns the error before the request reaches GitHub:

POST /repos/{owner}/{repo}/stacks
403 {"error":"Junior does not support this GitHub write request. Use the matching GitHub tool or a supported REST endpoint."}

Reads work: GET /repos/{owner}/{repo}/stacks returns 200.

Why

packages/junior-github/src/egress-policy.ts only allows the sandbox to make GitHub writes listed in githubApiWriteGrantName. None of the /stacks endpoints are listed.

gh stack (github/gh-stack v0.2.1, internal/github/github.go) also makes calls that remain blocked even if /stacks is allowed:

  • REST POST /repos/{owner}/{repo}/stacks, /stacks/{id}/add, and /stacks/{id}/unstack: not allowlisted
  • GraphQL mutations createPullRequest, markPullRequestReadyForReview, and disablePullRequestAutoMerge: sandbox GraphQL mutations are blocked by design
  • PATCH /repos/{owner}/{repo}/pulls/{number} to change base branches: reserved for github_updatePullRequest
  • merge-async: Junior does not merge, by policy

Proposal

Add a typed host-side tool, for example github_linkPullRequestStack, following Junior's existing pattern for writes that create or reshape issues and PRs (GITHUB_BODY_WRITES plus typed github_* tools). It could:

  • accept an ordered list of PR numbers
  • verify that each PR's base is the head branch of the PR below it
  • call the REST stack endpoints through ctx.egress.fetch
  • handle retries safely and record requester attribution like other PR tools

Intended flow: git pushes the branches, github_createPullRequest opens each PR with its base set to the branch below, then github_linkPullRequestStack links them.

Smaller alternative

Allowlist POST /repos/{owner}/{repo}/stacks and /stacks/{id}/(add|unstack) as installation-write in githubApiWriteGrantName, and document them in the github-code skill's api-surface.md. This only enables gh stack link <PR numbers> for PRs that already exist. Passing branch names or using --open would still hit the blocked GraphQL calls, so users would need to know the workaround.

Open question

Not verified: whether GitHub accepts a GitHub App installation token for POST /stacks. The read endpoint asks for pull_requests=read, so writes probably need pull_requests=write, which the App already has for creating PRs. Verify this before implementing either option.

via @szokeasaurusrex.

--

View Junior Session [Sentry]

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions