Skip to content

Windows: gh-aw self-upgrade fails and leaves extension unrecoverable (manifest wiped) #27272

Closed as not planned

Description

@ericsciple

Summary

On Windows, the auto-upgrade triggered from inside gh aw (e.g. gh aw upgrade) fails with Access is denied on gh-aw.exe, and — worse — leaves the extension in a half-wiped state where every subsequent gh extension upgrade gh-aw fails with unable to retrieve latest version for extension "aw". The only recovery is gh extension remove gh-aw && gh extension install github/gh-aw.

Reported by @shanselman in Slack. Observed on gh 2.90.0, gh-aw v0.68.1 upgrading to v0.68.3.

Symptoms

Checking gh-aw extension version...
ℹ Upgrading gh-aw extension from v0.68.1 to v0.68.3...
[aw]: failed to remove previous extension update state: unlinkat C:\Users\scott\AppData\Local\GitHub CLI\extensions\gh-aw\gh-aw.exe: Access is denied.
X Failed upgrading extension aw: some extensions failed to upgrade
✗ failed to upgrade gh-aw extension
  exit status 1

> gh extension upgrade gh-aw
X Failed upgrading extension aw: unable to retrieve latest version for extension "aw"
> gh extension upgrade github/gh-aw
X Failed upgrading extension aw: unable to retrieve latest version for extension "aw"

Remove + reinstall recovers.

Suspected root cause

Two things compound:

1. cli/cli destructively wipes the install directory on Windows

In cli/cli pkg/cmd/extension/manager.go, every install/upgrade/remove path first calls cleanExtensionUpdateDir(name):

func (m *Manager) cleanExtensionUpdateDir(name string) error {
    if err := os.RemoveAll(m.UpdateDir(name)); err != nil {
        return fmt.Errorf("failed to remove previous extension update state: %w", err)
    }
    return nil
}

Where:

  • updateDir = StateDir()/extensions
  • installDir = DataDir()/extensions

On Linux/macOS, XDG splits these. On Windows, go-gh/pkg/config resolves both StateDir() and DataDir() to %LOCALAPPDATA%\GitHub CLI (see config.go StateDir/DataDir). So UpdateDir("gh-aw") == installDir + "/gh-aw" — the same folder that contains the running gh-aw.exe and its manifest.yml.

os.RemoveAll deletes the non-locked contents first (notably manifest.yml, written by writeManifest(targetDir, ...) in the same manager.go), then errors out when it hits the running gh-aw.exe with Access is denied. With manifest.yml gone, LatestVersion() returns "", which is exactly the second error:

if latestVersion := f.LatestVersion(); latestVersion == "" {
    return fmt.Errorf("unable to retrieve latest version for extension %q", name)
}

The reported name "aw" (not "gh-aw") matches normalizeExtension's short-name handling. This is a latent cli/cli bug (likely since cli/cli#9934); we should also file against cli/cli.

2. gh-aw's rename+retry workaround is Linux-only

pkg/cli/update_extension_check.go already handles the "running binary can't be replaced" case for Linux (ETXTBSY) with a rename-to-.bak + retry + restore dance, but explicitly bails on all other OSes:

// First attempt failed.
if runtime.GOOS != "linux" {
    // On non-Linux systems there is nothing more to try.
    return false, "", fmt.Errorf("failed to upgrade gh-aw extension: %w", firstErr)
}

Windows has the exact same class of problem (can't unlink a running .exe) and is actually more amenable to the rename workaround than Linux: NTFS allows renaming a running executable, and Go's os.Rename maps to MoveFileEx, which works on locked binaries. Lifting the gate would let the existing workaround run on Windows.

The tricky bit is ordering: on Windows the damage happens inside cli/cli's cleanExtensionUpdateDir (called before the binary write), not inside the binary-write step itself. So a reactive retry after the first failure isn't quite enough — by the time gh-aw retries, manifest.yml is already gone and gh extension upgrade can't look up the repo. We likely need to rename proactively on Windows before the first gh extension upgrade invocation, and probably also back up manifest.yml so we can restore it if the upgrade aborts.

Proposed fix (in this repo)

  1. Remove the runtime.GOOS != "linux" early-return in upgradeExtensionIfOutdated.
  2. On Windows, apply the rename workaround proactively (before the first gh extension upgrade call), not reactively. Reason: cli/cli's cleanExtensionUpdateDir (destructive RemoveAll on the install folder) runs early and damages manifest.yml before returning.
  3. Before invoking gh extension upgrade, snapshot manifest.yml and restore it if the upgrade fails, so a failed self-upgrade on Windows no longer leaves the extension unrecoverable by gh extension upgrade alone.
  4. If the upgrade still fails on Windows, surface a clear actionable error pointing at gh extension remove gh-aw && gh extension install github/gh-aw as recovery.

Related / follow-up

  • File a companion cli/cli issue: on Windows, updateDir collides with installDir so cleanExtensionUpdateDir destructively wipes the installed extension's folder. Fix at the cli/cli layer would make the problem go away for every binary extension, not just gh-aw.

Repro

  1. Install gh-aw on Windows at an older version (e.g. v0.68.1).
  2. Run any gh aw command that triggers the version check + auto-upgrade (e.g. gh aw upgrade).
  3. Observe the Access is denied failure.
  4. Observe that gh extension upgrade gh-aw and gh extension upgrade github/gh-aw both now fail with unable to retrieve latest version for extension "aw".
  5. Recover with gh extension remove gh-aw && gh extension install github/gh-aw.

Environment

  • OS: Windows
  • gh: 2.90.0 (2026-04-16)
  • gh-aw: v0.68.1 → attempting v0.68.3

Activity

  1. ericsciple commented on Apr 20, 2026

    @ericsciple
    MemberAuthor

    Duplicate of #27269 (filed ~10 minutes earlier — I missed it). Ported the suspected root cause over there: #27269 (comment)

  2. locked and limited conversation to collaborators on Apr 20, 2026
  3. unlocked this conversation on Apr 20, 2026
  4. locked and limited conversation to collaborators on Apr 20, 2026
  5. unlocked this conversation on Apr 20, 2026
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