Repository navigation
Report credential storage failures during token refresh - #15178
Merged
Merged
Conversation
Delete passed go-keyring's own not-found sentinel through, so callers could not match a missing secret against the package's ErrNotFound. Map it the same way Get already does. Existing callers ignore the Delete error, so their behavior is unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: bbce5a7f-103c-4e67-99c9-2d6dc3f6a02b
When a refresh could not store the renewed credential, or could not remove a credential whose refresh token the server rejected, the user got no indication of why gh kept failing, because callers of the refreshing token methods drop the returned error. Surface both failures as warnings that name the storage error, point to `gh auth login`, and mention sandboxes that may block writes to the system keyring or gh's configuration directory. Make the removal report failures accurately. For a credential read from the keyring, trust the delete error unless the secret was not found, and re-read after a successful delete, since a dismissed Secret Service prompt reports success without deleting anything. Keyring errors stay ignored for plaintext credentials and for the non-expiring slot, where a missing record or an unavailable keyring makes them meaningless. Add a storage_error dimension (none, error or timeout) to the auth_token_refresh event, without the underlying error text, and report rejected_remove_failed whenever the removal fails. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: bbce5a7f-103c-4e67-99c9-2d6dc3f6a02b
babakks
requested review from
BagToad and
tidy-dev
and
a balanced review from Copilot
November 27, 2026 11:44
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Post-delete verification errors and timeouts are silently reported as successful removal, while configuration-write failures can prompt unnecessary reauthentication despite a saved rotated token.
2 open issues
What changed in this PR
This PR makes credential-storage failures visible during GitHub CLI token refresh, helping users recover when renewed credentials cannot be saved or rejected credentials cannot be removed.
Changes:
- Adds warnings for failed credential persistence and removal.
- Checks keyring deletion results and normalizes missing-secret errors.
- Adds storage-error telemetry and tests for failure outcomes and warnings.
| File | Description |
|---|---|
| internal/keyring/keyring.go | Normalizes missing-secret delete errors to the internal ErrNotFound sentinel. |
| internal/config/refreshable.go | Adds storage warnings and checks removal of rejected credentials. |
| internal/config/refreshable_telemetry.go | Classifies storage errors and records them in refresh telemetry. |
| internal/config/refreshable_telemetry_test.go | Covers storage failures, removal outcomes, and warning emission. |
Review effort: Balanced
After a keyring delete reports success, the removal of a rejected credential is verified by reading the secret back. A read that failed for any reason other than a missing record was treated as a confirmed removal, so a locked or hung keyring could hide a credential that survived. Only a missing record now confirms the removal; other read errors, including timeouts, are reported as a failed removal with a warning. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ac178b5a-5b62-49bd-9e83-4796c7ddec46
adamstallard
added a commit
to adamstallard/shared-skills
that referenced
this pull request
Nov 29, 2026
GitHub records a reply in an existing review thread as a review of the newest commit, so a reviewer's "thanks" after a push ended their wait. Only an approval, a change request, or a review with a body or a new comment thread now ends one. This answers design.md's open question and adds the measurement on cli/cli#15178 to the requirement's Rationale entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Bug-hunter: skipped at triage (spec only, no code) Prose: ✓ 768567e:72b366f38a15; cold read: 9 findings, 9 fixed, 0 kept; understood: 3 items, 0 fixed, 0 kept Spec-check: ✓ 768567e 0 errors, 4 checks; validate passed; read deferred to the round's end Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 of 6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
TL;DR: This makes credential storage failures during a token refresh visible, without otherwise changing behaviour. When
ghcannot store a renewed credential or remove a rejected one, it now prints a warning on stderr and records a newstorage_errortelemetry dimension, and failed removals are reported asrejected_remove_failedinstead ofrejected_removed. The same records are written and deleted, and the refresh returns the same credential, status and error, so exit codes and stdout are unchanged. The only runtime change is one extra keyring read, which runs only after a rejected refresh when the delete of a keyring credential reports success, to confirm the credential is really gone.With expiring tokens,
ghrenews the access token when it is about to expire and writes the renewed credential back to where it was stored: the system keyring, orhosts.ymlwhen insecure storage is used. The server rotates the refresh token on every renewal, so the old one stops working as soon as the exchange succeeds. When the server rejects a refresh token,ghremoves the stored credential so later runs stop presenting it, and the user is asked to sign in again.Two failures on this path were invisible to the user:
ghreturned an error, but every caller of the refreshing token methods drops it, so nothing reached stderr.rejected_removedtelemetry outcome was reported even then. A Secret Service delete whose prompt is dismissed also reports success without deleting anything (Secret Service: dismissed prompts are not treated as errors zalando/go-keyring#161).This PR:
gh auth login, with a hint that a sandbox may be blocking writes to the system keyring orgh's configuration directory. Warnings go throughAuthConfig.Warnings(), the same path as the existing "skipped refresh" warning;storage_errordimension (none,errorortimeout) to theauth_token_refreshtelemetry event, and reportsrejected_remove_failedwhenever the removal fails;internal/keyring.Deletereturn the package's ownErrNotFoundfor a missing secret, matchingGet, so the removal can tell "already gone" apart from a failed delete.How did you test this change?
Given a Linux desktop with gnome-keyring serving the Secret Service API
When I called
internal/keyring.Deletefor a service name with no stored secretThen go-keyring returned its
ErrNotFound, and the wrapper returned the package'sErrNotFound(errors.Iswas true)The warnings and the removal checks were not exercised by hand.
Key points
storage_errortelemetry dimension, andrejected_remove_failedreported in cases that used to show up asrejected_removed;ghreads the secret once more to check it is really gone. This only runs on the rejection path, but on a misbehaving keyring that read could prompt or wait for the keyring wrapper's 60 second timeout.storage_errorcarries no error text. Exit codes or D-Bus error names could reveal which credential store is in use, so the dimension only recordsnone,errorortimeout.internal/keyring.Deleteis not a breaking change. The package is internal, every existing caller ignores theDeleteerror, and nothing compared against go-keyring's own sentinel. Success, timeouts and other errors are returned unchanged.Notes for reviewers
Start with
removeCredentialForUserandremoveRejectedCredentialininternal/config/refreshable.go, then the persist failure branch inrefreshCredentialForUser. The table cases inrefreshable_telemetry_test.gocover each outcome, itsstorage_errorvalue and the warning.config.Writeskips files that have not changed, so thehosts.ymlwrite that follows the keyring write cannot fail and a persist failure always means the keyring write failed.Authorship and follow-up
Who wrote this:
Who answers review comments: