Skip to content

gh release create always blames the missing workflow scope on any 404 #14063

Closed

Description

@williammartin

Describe the bug

When gh release create receives an HTTP 404, it checks whether the token carries the workflow scope and, if not, replaces the error with a hint about requesting that scope. The scope check is broken, so it reports "no workflow scope" for essentially every OAuth token — including tokens that plainly do have the scope.

Two consequences:

  1. Users are told to run gh auth refresh -s workflow when they already have workflow. Running it changes nothing, so there is no way to make the message go away.
  2. More importantly, the real reason for the 404 is masked. A typo in the repo name, a repo that does not exist, or a lack of push access all surface as a scope problem instead of HTTP 404: Not Found.

The cause is in tokenHasWorkflowScope in pkg/cmd/release/create/http.go:

return slices.Contains(strings.Split(scopes, ","), "workflow")

The X-Oauth-Scopes response header is comma-space separated, so splitting on , alone yields elements with a leading space: ["gist", " project", " read:org", " repo", " user", " workflow"]. Only the first element ever matches a bare scope name, and the header lists scopes in sorted order, so workflow is effectively never first. The comparison therefore fails no matter what the token holds.

Other scope parsers in this repo already account for this — generateScopesSuggestion in api/client.go does strings.TrimSpace(s) on each element, and the pkg/cmd/auth/status tests stub the header as "repo, read:org" with the space. tokenHasWorkflowScope is the one place that omits the trim.

Affected version

gh version 2.96.0 (2026-07-02)
https://github.com/cli/cli/releases/tag/v2.96.0

Also reproduces on a build of current trunk.

Steps to reproduce the behavior

Authenticate with an OAuth token that includes the workflow scope (gh auth login via the web flow grants it by default; gh auth refresh -s workflow otherwise), then point gh release create at a repository that does not exist:

$ GH_DEBUG=api GH_REPO=cli/definitely-not-a-real-repo-wm-9f3a gh release create v0.0.0 --notes test

A single run shows the whole problem — the scope the token actually has, the real reason for the failure, and the conclusion gh draws instead.

Expected vs actual behavior

Expected: because the token has the workflow scope, the scope-specific hint should be suppressed and the underlying error reported, e.g. HTTP 404: Not Found (https://api.github.com/repos/cli/definitely-not-a-real-repo-wm-9f3a/releases).

Actual: the 404 is swallowed and replaced with a workflow-scope hint that does not apply and cannot be acted on.

Note the hint is genuinely useful in the case it was written for: creating a release whose tag introduces workflow file changes does 404 without the workflow scope, and the API gives no other signal. The problem is only that the guard meant to limit the hint to that case never holds.

Logs

$ GH_DEBUG=api GH_REPO=cli/definitely-not-a-real-repo-wm-9f3a gh release create v0.0.0 --notes test
[git tag --list v0.0.0 --format=%(contents)]
* Request at 2026-08-04 15:34:04.695914 +0200 CEST m=+0.020581376
* Request to https://api.github.com/repos/cli/definitely-not-a-real-repo-wm-9f3a/releases
> POST /repos/cli/definitely-not-a-real-repo-wm-9f3a/releases HTTP/1.1
> Host: api.github.com
> Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
> Authorization: token ████████████████████
> Content-Length: 68
> Content-Type: application/json; charset=utf-8
> Time-Zone: Europe/Amsterdam
> User-Agent: GitHub CLI 2.96.0 Agent/github_copilot_app_agent
> X-Github-Api-Version: 2022-11-28

{
  "body": "test",
  "draft": false,
  "prerelease": false,
  "tag_name": "v0.0.0"
}

< HTTP/2.0 404 Not Found
< 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, Warning
< Content-Security-Policy: default-src 'none'
< Content-Type: application/json; charset=utf-8
< Date: Tue, 04 Aug 2026 13:34:04 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-Api-Version-Selected: 2022-11-28
< X-Github-Edge-Region: fra
< X-Github-Media-Type: github.v3; param=merge-info-preview.nebula-preview; format=json
< X-Github-Request-Id: 869B:13D926:7E44EFB:789D20F:6A71EA4C
< X-Oauth-Client-Id: Ov23ctr1Udn5GokVCVJf
< X-Oauth-Scopes: gist, project, read:org, repo, user, workflow
< X-Ratelimit-Limit: 15000
< X-Ratelimit-Remaining: 14978
< X-Ratelimit-Reset: 1785850871
< X-Ratelimit-Resource: core
< X-Ratelimit-Used: 22
< X-Xss-Protection: 0

{
  "message": "Not Found",
  "documentation_url": "https://docs.github.com/rest/releases/releases#create-a-release",
  "status": "404"
}

* Request took 239.281167ms
! Failed to create release, "workflow" scope may be required.
To request it, run:
gh auth refresh -h github.com -s workflow

Three things to note in that transcript:

  • X-Oauth-Scopes on the failing response ends in workflow, so the token has the scope and the header carrying that fact reached gh intact. Note the , separator.
  • The body says "message": "Not Found" — the repository does not exist. That is the error the user needed to see.
  • gh nevertheless prints the workflow-scope hint and discards the 404.

Suggested fix

Trim each element before comparing, matching what api/client.go already does:

for _, s := range strings.Split(scopes, ",") {
    if strings.TrimSpace(s) == "workflow" {
        return true
    }
}
return false

Worth adding a test case with the realistic "repo, workflow" spacing — the existing fixtures for this function use unspaced values such as repo,read:org,workflow, which is why the bug was not caught.

Activity

  1. added
    bug
    on Aug 4, 2026
  2. added
    needs-triage
    on Aug 4, 2026
  3. cli-triage commented on Aug 4, 2026

    @cli-triage

    This is a well-documented bug in tokenHasWorkflowScope in pkg/cmd/release/create/http.go. The comma-space-separated X-Oauth-Scopes header is split on , alone, leaving leading spaces on each element except the first, so workflow is never matched. No duplicates found.

    Suggesting priority-2 (affects multiple users, no workaround, masks real errors like 404s from typos or missing repos) and gh-release (scoped to the release command).

    Generated by Issue Triage (skills-driven) for #14063 · sonnet46 · 20.7 AIC · ⌖ 5.08 AIC · ⊞ 6.6K · ◷

  4. added
    gh-release
    priority-3
    and removed
    needs-triage
    on Aug 4, 2026
  5. added a commit that references this issue on Aug 4, 2026
    92ae1de
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

    buggh-releasepriority-3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions