Skip to content

feat(config): add in-place Reload for refreshed reads - #298

Open
babakks wants to merge 3 commits into
trunkfrom
babakks/add-refresh-token-support
Open

babakks wants to merge 3 commits into
trunkfrom
babakks/add-refresh-token-support

Conversation

@babakks

@babakks babakks commented Sep 14, 2026

Copy link
Copy Markdown
Member

Description

Lets gh re-read its configuration from disk in place, which the refreshable-token stack in cli/cli needs to load the latest stored credential before spending a single-use refresh token.

The main addition is config.Reload: it re-reads the gh config files and swaps the entries of the cached *Config under a write lock, so every existing holder of that pointer observes the new values without being handed a new pointer. Like config.Read, Reload is a package-level var, so consumers and tests can replace it. Unwritten in-memory changes are discarded by the refresh, so callers persist first if they need them. deepCopy now takes the read lock so an in-place entries swap cannot race a concurrent read.

Two small drive-by fixes replace deprecated APIs: reflect.Ptr becomes reflect.Pointer, and the unix-socket transport uses DialContext/DialTLSContext instead of the deprecated Dial/DialTLS.

How did you test this change?

Unit tests in pkg/config cover Reload: it refreshes values in place, keeps the same *Config pointer, and discards unwritten changes. Existing tests pass.

@babakks
babakks requested a review from a team as a code owner September 14, 2026 23:35
@babakks
babakks requested review from williammartin and removed request for a team September 14, 2026 23:35
babakks and others added 3 commits September 15, 2026 00:37
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Add Reload, which re-reads the gh config files from disk and refreshes the
config returned by Read in place. Keeping the cached *Config pointer stable
lets every existing holder observe the new values, which keeps auth host and
token resolution (which reads through Read) consistent with callers that
reload under a lock.

Reload is a package-level var, like Read, so consumers and tests can replace it.

Lock deepCopy so the in-place entries swap cannot race a concurrent read.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f5c79efc-51d8-4913-8961-701522797f9e

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.

Copilot review overview

🟡 Changes recommended

The Unix-socket dial hook ignores request cancellation despite adopting the context-aware API.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds in-place configuration reloads so existing *Config holders observe refreshed disk values safely.

Changes:

  • Adds synchronized config.Reload behavior and tests.
  • Replaces deprecated reflection and HTTP transport APIs.
  • Adds locking during configuration copying.
File Description
pkg/​config/​config.go Adds synchronized in-place reload support.
pkg/​config/​config_test.go Tests cached configuration refresh behavior.
pkg/​api/​http_client.go Migrates Unix-socket transport dial hooks.
pkg/​x/​markdown/​accessibility_test.go Replaces deprecated reflection constants.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pkg/api/http_client.go
Comment on lines +239 to 241
dial := func(_ context.Context, network, addr string) (net.Conn, error) {
return net.Dial("unix", socketPath)
}

@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.

Reviewed in the context of the cli/cli refreshable-token stack. The in-place reload behavior supports the lock, reload, re-read, and persist flow used to avoid spending a stale rotating refresh token.

This branch has not been deployed

No deployments
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