Repository navigation
Description
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()/extensionsinstallDir = 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)
- Remove the
runtime.GOOS != "linux"early-return inupgradeExtensionIfOutdated. - On Windows, apply the rename workaround proactively (before the first
gh extension upgradecall), not reactively. Reason:cli/cli'scleanExtensionUpdateDir(destructiveRemoveAllon the install folder) runs early and damagesmanifest.ymlbefore returning. - Before invoking
gh extension upgrade, snapshotmanifest.ymland restore it if the upgrade fails, so a failed self-upgrade on Windows no longer leaves the extension unrecoverable bygh extension upgradealone. - If the upgrade still fails on Windows, surface a clear actionable error pointing at
gh extension remove gh-aw && gh extension install github/gh-awas recovery.
Related / follow-up
- File a companion
cli/cliissue: on Windows,updateDircollides withinstallDirsocleanExtensionUpdateDirdestructively wipes the installed extension's folder. Fix at thecli/clilayer would make the problem go away for every binary extension, not justgh-aw.
Repro
- Install
gh-awon Windows at an older version (e.g. v0.68.1). - Run any
gh awcommand that triggers the version check + auto-upgrade (e.g.gh aw upgrade). - Observe the
Access is deniedfailure. - Observe that
gh extension upgrade gh-awandgh extension upgrade github/gh-awboth now fail withunable to retrieve latest version for extension "aw". - 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
ericsciple commentedon Apr 20, 2026
Duplicate of #27269 (filed ~10 minutes earlier — I missed it). Ported the suspected root cause over there: #27269 (comment)