Skip to content

Fix pull requests silently disappearing until lazygit is restarted - #5921

Merged
stefanhaller merged 1 commit into
masterfrom
fix-stale-github-token
Aug 12, 2026
Merged

Fix pull requests silently disappearing until lazygit is restarted#5921
stefanhaller merged 1 commit into
masterfrom
fix-stale-github-token

Conversation

@stefanhaller

Copy link
Copy Markdown
Collaborator

A lazygit instance that has been open for a while sometimes stops showing pull requests, and keeps not showing them until you quit and restart it. The cause is that we resolve the GitHub token once per process and then keep using that stale answer.

We get the token from go-gh, which reads gh's hosts.yml on the first call and caches it for the lifetime of the process. gh rewrites that file whenever the active account changes, and keeps the active account's token either in the file or in the system keyring, depending on the account. Once the file changes under us, our snapshot no longer describes reality: either we keep sending a token for an account that is no longer active, or — if the snapshot was taken while a keyring-backed account was active — we find no token at all, drop the remote, and show no pull requests. Nothing is reported to the user, so it looks like PR fetching is simply broken.

Switching accounts with gh auth switch is the easiest way to trigger this, but it isn't limited to multi-account setups: a single account hits the same thing whenever its token is rotated, or moved between the keyring and hosts.yml by a fresh gh auth login.

So ask gh itself for the token on every refresh, with gh auth token --hostname <host>, which resolves it afresh from whichever of the environment, the keyring, or the config file currently holds it. Not passing --secure-storage (which go-gh does internally) also means it stops mattering which of the two the active account uses. go-gh's lookup stays as a fallback for setups without the gh binary, where it still picks up GH_TOKEN and friends; when gh is present it checks those variables itself.

To reproduce on master, with two gh accounts, one with its token in the keyring and one in hosts.yml: start lazygit while the keyring-backed account is active, then run gh auth switch to the other one. The pull request information disappears on the next refresh and doesn't come back until lazygit is restarted. Running gh auth token --secure-storage --hostname github.com by hand at that point prints no oauth token found for github.com.

go-gh reads gh's config file once per process and answers from that
snapshot for the rest of the process's life. gh rewrites the file
whenever the active account changes, and stores the active account's
token either in it or in the system keyring, depending on the account.
A lazygit that has been running for a while therefore consults a
snapshot that no longer describes reality: it either keeps using a
token for an account that is no longer active, or, when the snapshot
was taken while a keyring-backed account was active, finds no token at
all and silently stops showing pull requests until it is restarted.

Asking gh resolves the token afresh on every refresh, from whichever of
the environment, the keyring or the config file currently holds it.
go-gh's lookup stays behind as a fallback for setups without the gh
binary, where it still picks up GH_TOKEN and friends.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@stefanhaller stefanhaller added the bug Something isn't working label Aug 12, 2026
@stefanhaller
stefanhaller merged commit c18a0c6 into master Aug 12, 2026
24 of 27 checks passed
@stefanhaller
stefanhaller deleted the fix-stale-github-token branch August 12, 2026 17:30
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Aug 13, 2026
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [jesseduffield/lazygit](https://github.com/jesseduffield/lazygit) | patch | `v0.64.0` → `v0.64.1` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>jesseduffield/lazygit (jesseduffield/lazygit)</summary>

### [`v0.64.1`](https://github.com/jesseduffield/lazygit/releases/tag/v0.64.1)

[Compare Source](jesseduffield/lazygit@v0.64.0...v0.64.1)

<!-- Release notes generated using configuration in .github/release.yml at v0.64.1 -->

#### What's Changed

This fixes a few regressions that were introduced in the [last release](https://github.com/jesseduffield/lazygit/releases#release-v0.64.0), and some long-standing bugs that I didn't see any reason to hold back until the next big one.

##### Fixes 🔧

- Fix transitions of entering and exiting filtering mode (e.g. by path or author) by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5897](jesseduffield/lazygit#5897)
- Fix race in "Stash staged changes" on git versions before 2.35.0 by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5903](jesseduffield/lazygit#5903)
- Fix several problems with repos whose git dir lives outside the working tree by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5910](jesseduffield/lazygit#5910)
- Update the UI after stash operations in a single frame by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5905](jesseduffield/lazygit#5905)
- Honor the conflict-marker-size gitattribute by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5902](jesseduffield/lazygit#5902)
- Fix hang on quit when confirmOnQuit is true by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5919](jesseduffield/lazygit#5919)
- Fix pull requests silently disappearing until lazygit is restarted by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5921](jesseduffield/lazygit#5921)

##### Maintenance ⚙️

- Don't let integration tests race a background git repack by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5898](jesseduffield/lazygit#5898)
- update Nix flake dependencies by [@&#8203;TyceHerrman](https://github.com/TyceHerrman) in [#&#8203;5894](jesseduffield/lazygit#5894)
- Simplify the run\_integration\_tests.sh script by [@&#8203;stefanhaller](https://github.com/stefanhaller) in [#&#8203;5908](jesseduffield/lazygit#5908)
- Bump actions/setup-go from 6 to 7 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;5843](jesseduffield/lazygit#5843)
- Bump github.com/kyokomi/emoji/v2 from 2.2.13 to 2.2.14 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;5813](jesseduffield/lazygit#5813)
- Bump mheap/github-action-required-labels from 5.5.2 to 5.6.0 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;5769](jesseduffield/lazygit#5769)
- Bump github.com/lucasb-eyer/go-colorful from 1.4.0 to 1.4.1 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;5916](jesseduffield/lazygit#5916)
- Bump JamesIves/github-sponsors-readme-action from 1.6.0 to 1.6.1 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;5917](jesseduffield/lazygit#5917)

**Full Changelog**: <jesseduffield/lazygit@v0.64.0...v0.64.1>

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever MR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4yODguMCIsInVwZGF0ZWRJblZlciI6IjQzLjI4OC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiLCJhdXRvbWF0aW9uOmJvdC1hdXRob3JlZCIsImRlcGVuZGVuY3ktdHlwZTo6cGF0Y2giXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant