Skip to content

feat: Refactor new client - #3739

Merged
stevehipwell merged 1 commit into
mainfrom
stevehipwell/refactor-new-client
Nov 23, 2026
Merged

stevehipwell merged 1 commit into
mainfrom
stevehipwell/refactor-new-client

Conversation

@stevehipwell

@stevehipwell stevehipwell commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #3703
Closes #3660
Closes #3562

Refactors the new client implementation (legacy_client = false) to re-aligned it to the original code it was based off. The legacy client is unchanged.


Before the change?

  • The new client implementation (legacy_client = false) lived entirely in internal/ghclient and was configured through option structs.
  • Rate limiting used gofri/go-github-ratelimit, and the REST and GraphQL clients each had their own separate rate-limit state.
  • The concurrency limit wrapped every other transport, so a request held its slot during retry backoff and rate-limit waits.
  • The maximum retry wait was set to retry_delay_ms, so retries effectively used a fixed delay.
  • Caching was always enabled; without cache_path it fell back to a temporary directory. If the cache file was already in use, opening it could block indefinitely.
  • GitHub App clients were kept in an LRU of 8 per client type, so they could be evicted and recreated.
  • There was no response-header timeout.

After the change?

  • The client code is split into internal/httpx (general HTTP transports), internal/ghratelimit (GitHub rate limiting) and internal/ghclient (client and auth wiring), configured through validated option functions.
  • A new built-in rate-limit transport replaces gofri/go-github-ratelimit. It understands GitHub's rate-limit categories, waits instead of failing once a limit is used up, handles secondary limits, and caps how long it will wait. REST and GraphQL share its state.
  • Only requests that are safe to repeat are retried on 5xx, so mutations aren't applied twice. Backoff is exponential with jitter (from retry_delay_ms up to 5 minutes), honours Retry-After, and stops before the context deadline. Retries resend the original request body (if a body can't be replayed directly, it's rewound or buffered as a fallback).
  • The concurrency limit applies only while a request is in flight, not during backoff or rate-limit waits.
  • Caching is only enabled when cache_path is set, and is REST-only. A cache error never fails a request, and a clear error is returned if the cache is already in use by another configuration.
  • Each GitHub App installation's clients are created once and shared, with no eviction.
  • Adds a 60s response-header timeout.
  • Removes the gofri/go-github-ratelimit and hashicorp/golang-lru dependencies.
  • Updated Go to 1.27.
  • Updated github.com/go-jose/go-jose/v4, github.com/hashicorp/terraform-plugin-sdk/v2, github.com/jferrl/go-githubauth, github.com/sethvargo/go-retry, golang.org/x/crypto, golang.org/x/oauth2 & golang.org/x/sync dpendencies
  • Notes:
    • cache_path must be unique per provider configuration, including aliases and concurrent runs. The docs are updated to say so.
    • Because every GraphQL request is a POST, GraphQL requests are not retried on 500/502/504. This can be addressed as a followup.

Pull request checklist

  • Schema migrations have been created if needed (example)
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

Please see our docs on breaking changes to help!

  • Yes
  • No

@stevehipwell stevehipwell added this to the v6.14.0 milestone Nov 19, 2026
@stevehipwell stevehipwell self-assigned this Nov 19, 2026
@stevehipwell stevehipwell added the Type: Feature New feature or request label Nov 19, 2026
@github-actions

Copy link
Copy Markdown

👋 Hi, and thank you for this contribution!

This repo is maintained by GitHub and community members on a best-effort basis. We'll get to this as soon as we can.

You can help us prioritize by joining the discussion on open issues and PRs, sharing details on the changes you need, and reviewing other contributions.


🤖 This is an automated message.

@stevehipwell
stevehipwell force-pushed the stevehipwell/refactor-new-client branch 2 times, most recently from f2496c9 to 85cc582 Compare November 19, 2026 16:23
Signed-off-by: Steve Hipwell <[email protected]>
@stevehipwell
stevehipwell force-pushed the stevehipwell/refactor-new-client branch from 85cc582 to 71ea44c Compare November 19, 2026 16:30
@stevehipwell stevehipwell added acctest For CI / automated testing and removed acctest For CI / automated testing labels Nov 19, 2026
@stevehipwell

Copy link
Copy Markdown
Collaborator Author

The acceptance tests still need fixing (I'm working on that), but they all ran in 30 mins on this branch which looks promising to me.

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

Thanks for putting this together! Splitting httpx, ghratelimit, and ghclient makes the transport stack much easier to follow, and moving the throttle inside the retry and rate-limit waits is a great fix. Looks good to ship!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Feature New feature or request

Projects

None yet

2 participants