Registry Mirror
Skip to content

Conversation

@babakks

@babakks babakks commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Part of the refreshable tokens work (epic github/gh-cli-and-desktop#349). Stacked on top of #14672.

Description

All auth subcommands are excluded from telemetry, so today we have no signal about how people authenticate. As we roll out refreshable (expiring) credentials, we want to understand the environment gh auth login and gh auth refresh run in: whether an expiring credential was requested and whether one was received, whether gh is the configured git credential helper, which git protocol is in use, where the credential is stored, and how the sign-in ended.

This change records a dedicated auth_invocation event from the login and refresh code paths. Every other auth subcommand (status, logout, token, switch, setup-git, gitcredential) stays excluded. Importantly, login and refresh do not emit the generic command_invocation event either: the whole auth subtree is suppressed with DisableTelemetryForSubcommands, and login/refresh report only the richer auth_invocation. So each of those two commands reports exactly one telemetry event, with no duplicate command_invocation alongside it, and the remaining auth subcommands report nothing.

auth_invocation is begun directly in the command's run, independent of the command_invocation annotation gate, and the whole invocation is sampled at 100%.

New event type:

  • auth_invocation

Dimensions on that event:

  • auth_command: which command recorded the event, either login or refresh.
  • expiring_requested: whether an expiring, refreshable token was requested (the effective intent after flags and config), true or false.
  • expiring_received: whether the server actually issued an expiring, refreshable token, true or false.
  • git_protocol: the git operations protocol selected for the host, one of https, ssh, or unset. login reports the protocol it resolved (interactive selection or the --git-protocol flag), reporting unset for a non-interactive login with no flag. refresh reads the host config, which defaults to https, so it never reports unset.
  • git_credential_helper_before: the configured git credential helper for the host before login reconfigured it, one of ours (gh), other (a non-gh helper), none, or error when the helper could not be read.
  • git_credential_helper_after: the configured git credential helper after the command completed, same four values. For non-interactive and SSH sign-ins no setup runs, so this equals _before.
  • expiring_setup_cred_helper_cancelled: whether the user cancelled the sign-in at the expiring credential-helper prompt, true or false. Only true can be relied upon as a real event: it is set exactly when the user cancels at that prompt. false is the default dimension value and also covers every invocation that never reached the prompt (non-expiring logins, refreshes, and logins where gh is already the helper), so it must not be read as "the user was asked and chose not to cancel".
  • storage_type: where the credential was stored, keyring (a secure store was used) or plaintext.
  • auth_success: whether a credential was stored successfully, true or false.

On an expiring login where gh is not already the credential helper, the flow explains the consequence of not configuring gh (git will not learn about refreshed tokens and HTTPS git operations will start to fail once the token expires) as a standard gh warning, then asks a short decision question: set gh up as the helper, continue without it, or cancel the sign-in. Telemetry only needs to know whether the user cancelled, which is why expiring_setup_cred_helper_cancelled is a single boolean rather than a record of the full prompt response.

Recording is best effort: a nil recorder results in no event, and a failed read of the configured helper is reported as the error category rather than failing the command. The event is dropped entirely for GitHub Enterprise Server hosts.

Key design notes

  • Helper telemetry covers every sign-in path, not just interactive HTTPS. The configured-helper read is decoupled from the credential prompt. We read it up front (a plain, non-interactive git config read keyed by hostname) and record git_credential_helper_before/_after unconditionally, before the prompt gate. Previously these were only recorded inside the interactive HTTPS block, so we had no helper signal for exactly the cohort we most want to understand: non-interactive (non-TTY) and SSH sign-ins, where gh never prompts. We deliberately do not cache the read: it is a cheap local process invocation, and reading it independently in the telemetry step and inside Prompt keeps the sequence undictated, so Prompt keeps the git-not-installed abort it relies on. Nothing mutates git config between the two reads, so they stay consistent.
  • One dedicated event rather than extra dimensions on command_invocation, mirroring the existing attachment_invocation pattern, so the auth-specific context stays self contained.
  • The git credential helper state is categorical (ours / other / none, plus error when the read fails) rather than a boolean, so we can distinguish "no helper" from "a non-gh helper" and from "could not tell".
  • Telemetry records only the cancellation, surfaced through a typed error. We only care whether the user bailed out of the expiring credential-helper prompt, so instead of logging every prompt response we record a single boolean. GitCredentialFlow.Prompt returns ErrExpiringSetupCredHelperCancelled when the user cancels at that prompt; the login flow records the dimension and then translates it into the usual cmdutil.CancelError, so the caller can observe the specific outcome without changing the user-facing cancellation behavior.
  • Enterprise is doubly excluded: BeginAuthTelemetry drops the event for IsEnterprise hosts, and the global mightBeGHESUser gate already disables the whole telemetry service for likely-GHES users. With command_invocation suppressed across the auth subtree, no auth telemetry can escape that gate.

How did you test this change?

Unit tests cover the event end to end: the dimensions and their values, the enterprise drop, the nil-recorder and nil-helper no-op paths, and the git_protocol unset mapping (pkg/cmd/auth/shared/telemetry_test.go), plus the login and refresh flows recording through the shared helper, including the expiring-login cancellation recording expiring_setup_cred_helper_cancelled=true (pkg/cmd/auth/shared/login_flow_test.go, pkg/cmd/auth/refresh/refresh_test.go). go test ./... and make lint pass.

For a live check, build the binary and run a login or refresh with telemetry logged to stderr:

GH_TELEMETRY=log ./bin/gh auth login --expiring
GH_TELEMETRY=log ./bin/gh auth refresh --expiring

The auth_invocation event and its dimension values are printed at the end of the run. On an expiring login where gh is not the configured helper, the warning is printed followed by the short decision prompt; choosing Cancel aborts the sign-in and records expiring_setup_cred_helper_cancelled=true.

Notes for reviewers

Start at pkg/cmd/auth/shared/telemetry.go (the event, BeginAuthTelemetry, and the Record* methods for each dimension), then pkg/cmd/auth/auth.go (the DisableTelemetryForSubcommands wiring that suppresses command_invocation for the whole subtree), then the record call sites in pkg/cmd/auth/shared/login_flow.go and pkg/cmd/auth/refresh/refresh.go, and pkg/cmd/auth/shared/git_credential.go for the expiring prompt and the ErrExpiringSetupCredHelperCancelled seam.

Authorship and follow-up

Who wrote this:

  • A human wrote it.
  • An agent wrote it under close human direction.
  • An agent wrote it independently, and no human has guided the implementation beyond the initial prompt.

Who answers review comments:

  • @babakks will read and reply directly.
  • An agent will draft replies and @babakks will read them before they are posted.
  • Nobody has explicitly committed to replying.

@babakks
babakks requested a review from a team as a code owner October 13, 2026 22:54
@babakks
babakks requested review from tidy-dev and williammartin and removed request for a team and tidy-dev October 13, 2026 22:54
@babakks babakks changed the title Refreshable tokens: capture auth_invocation telemetry on login and refresh Refreshable tokens: capture auth_invocation telemetry on login and refresh Oct 13, 2026
@babakks
babakks added this pull request to stack #14457 October 13, 2026 22:54
CherryLemon added a commit to CherryLemon/gh-tideline that referenced this pull request Oct 15, 2026
A Ctrl+click on HelperConfig in cli/cli#14673 lists its three
declarations, with the sticky header pinning loginRun. It was taken
read-only from a release build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 16, 2026 10:30
@babakks
babakks force-pushed the babakks/refresh-token-telemetry branch from 866284b to b181002 Compare October 16, 2026 10:30
@babakks
babakks removed the request for review from williammartin October 16, 2026 10:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Telemetry wiring and authentication coverage remain incomplete, helper inspection violates best-effort behavior, and non-interactive output changes unexpectedly.

5 open findings
What changed in this PR

Adds authentication telemetry to support the refreshable-token rollout, building on the expiring-credential preference work.

Changes:

  • Passes telemetry recorders into login and refresh.
  • Adds auth events covering credential intent, helper state, prompts, storage, and outcomes.
  • Adds expiring-login prompts and telemetry tests.
File Description
pkg/​cmd/​root/​root.go Passes the recorder into auth commands.
pkg/​cmd/​auth/​shared/​telemetry.go Defines auth events and dimension updates.
pkg/​cmd/​auth/​shared/​telemetry_test.go Tests event dimensions and gating.
pkg/​cmd/​auth/​shared/​login_flow.go Records login outcomes and adds enterprise warnings.
pkg/​cmd/​auth/​shared/​login_flow_test.go Tests login telemetry and warnings.
pkg/​cmd/​auth/​shared/​git_credential.go Tracks helper state and expiring-login decisions.
pkg/​cmd/​auth/​shared/​git_credential_test.go Tests helper prompts and setup.
pkg/​cmd/​auth/​refresh/​refresh.go Records refresh context and outcomes.
pkg/​cmd/​auth/​refresh/​refresh_test.go Tests refresh telemetry with isolated helpers.
pkg/​cmd/​auth/​login/​login.go Forwards telemetry and configures sampling.
pkg/​cmd/​auth/​login/​login_test.go Updates constructor calls and helper fakes.
pkg/​cmd/​auth/​auth.go Wires recorders into login and refresh.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pkg/cmd/auth/auth.go Resolved
Comment thread pkg/cmd/auth/login/login.go Resolved
Comment thread pkg/cmd/auth/shared/git_credential.go Resolved
Comment thread pkg/cmd/auth/shared/login_flow.go Resolved
Comment thread pkg/cmd/auth/shared/telemetry.go Resolved
@babakks
babakks requested a review from williammartin October 16, 2026 11:02

@williammartin williammartin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks!

Comment thread pkg/cmd/auth/shared/git_credential.go Resolved

@williammartin williammartin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks!

fmt.Fprintf(opts.IO.ErrOut, "%s You were already logged in to this account\n", cs.WarningIcon())
}

authEvent.RecordSuccess()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit

I think auth_success would be more precise if recorded immediately after successful persistence.

A temporary regression test saved the credential, then failed git setup, but auth_success remained false:

$ go test ./pkg/cmd/auth/shared -run '^TestReview' -count=1
...
--- FAIL: TestReviewStoredCredentialRemainsSuccessfulWhenGitSetupFails (0.00s)
...
                         expected: "true"
                         actual  : "false"
...

That makes this measure whole-command success rather than credential storage when later setup fails. Non blocking, but recording it after successful persistence would make the dimension match its documented meaning.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the upcoming PR.

}

authEvent.RecordStorage(insecureStorageUsed)
authEvent.RecordExpiringReceived(refreshableCredential != nil)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit

I think expiring_received would be more precise if recorded before storage.

A temporary regression test returned a refreshable token, then failed storage, but expiring_received was absent:

$ go test ./pkg/cmd/auth/shared -run '^TestReview' -count=1
...
--- FAIL: TestReviewIssuedTokenIsRecordedWhenStorageFails (0.00s)
...
                         expected: "true"
                         actual  : ""
...

The server's issuance outcome is independent of local persistence. Non blocking, but recording it when the auth flow returns would preserve that distinction.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the upcoming PR.

@babakks babakks mentioned this pull request Oct 16, 2026
2 of 6 tasks
JackTPatterson added a commit to JackTPatterson/octet that referenced this pull request Oct 18, 2026
…ommands

Builders and parsers for the Code tab's T3 Code parity: GraphQL viewed
marks (read with pullRequest.files, written with markFileAsViewed and
unmarkFileAsViewed), REST review comments grouped by line, and the
review POST body with LEFT/RIGHT line comments. Fixtures are trimmed
from real read-only gh api output for octet#36 and cli/cli#14673.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@babakks
babakks force-pushed the babakks/refresh-token-telemetry branch 9 times, most recently from 4122556 to fa169d9 Compare October 21, 2026 11:08
Base automatically changed from babakks/refresh-token-prefer-expiring-config to trunk October 21, 2026 11:18
An expiring token can only be refreshed when gh is the git credential
helper, so an interactive HTTPS login with expiring credentials now
presents an up-front prompt offering to configure gh, continue without
it, or cancel. The choice is driven by the expiring intent rather than
the token the server returns, and Setup honors it without re-prompting.

When expiring credentials are requested against a GitHub Enterprise
Server host, which may not support them, a warning notes the token may
not be expiring.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ac178b5a-5b62-49bd-9e83-4796c7ddec46
babakks and others added 3 commits October 21, 2026 12:18
Emit a dedicated auth_invocation event for gh auth login and
gh auth refresh. It captures the auth command, whether an expiring
credential was requested and received, the resolved git protocol, the
git credential helper category before and after, the storage type, the
gh as credential helper prompt response, and overall success.

Detect the configured credential helper before showing the prompt so
helper telemetry also covers non interactive and SSH flows. Auth
subcommands now emit only auth_invocation and no longer send the generic
command_invocation event.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ac178b5a-5b62-49bd-9e83-4796c7ddec46
… helpers

DetectConfiguredHelper discarded the read error and mapped a failed lookup to
"none", making an unavailable inspection indistinguishable from a genuinely
absent helper. Capture the error and report a distinct "error" category, and
preserve it in ResultingHelperCategory when no setup replaced the helper.
Detection failures still never fail authentication.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ac178b5a-5b62-49bd-9e83-4796c7ddec46
Replace the four-valued gh_as_cred_helper_prompt_resp telemetry dimension
with a boolean expiring_setup_cred_helper_cancelled that captures the one
response we care about: whether the user cancelled the sign-in at the
expiring credential-helper prompt.

Polish that prompt to print its long explanation as a warning, like other
gh warnings, followed by a short decision question. GitCredentialFlow.Prompt
now returns the typed ErrExpiringSetupCredHelperCancelled on cancellation,
and the login flow records the dimension before translating it into
cmdutil.CancelError. The PromptResult enum, whose value distinctions nothing
consumed anymore, is removed in favour of a plain error return.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ac178b5a-5b62-49bd-9e83-4796c7ddec46
@babakks
babakks force-pushed the babakks/refresh-token-telemetry branch from fa169d9 to 0452816 Compare October 21, 2026 11:18
@babakks
babakks merged commit abf0e0c into trunk Oct 21, 2026
11 checks passed
@babakks
babakks deleted the babakks/refresh-token-telemetry branch October 21, 2026 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants