Skip to content

fix: apply host when both withHost and withOkHttpClient are set - #231

Open
kksingh000 wants to merge 1 commit into
pinecone-io:mainfrom
kksingh000:fix/builder-host-ignored-with-custom-okhttpclient
Open

kksingh000 wants to merge 1 commit into
pinecone-io:mainfrom
kksingh000:fix/builder-host-ignored-with-custom-okhttpclient

Conversation

@kksingh000

@kksingh000 kksingh000 commented Oct 6, 2026 •

Copy link
Copy Markdown

Problem

Pinecone.Builder.build() only applies withHost(...) inside the else branch of if (customOkHttpClient != null):

if (customOkHttpClient != null) {
    apiClient = new ApiClient(customOkHttpClient);
} else {
    apiClient = new ApiClient(buildOkHttpClient(proxyConfig));
    if (host != null && !host.isEmpty()) {
        config.setHost(host);
        apiClient.setBasePath(host);
    }
}

So an explicitly configured host is silently dropped whenever a custom OkHttpClient is also supplied, and requests fall back to the default api.pinecone.io instead of the intended host. This matches the root cause already confirmed by a maintainer in the issue thread.

A prior attempt at this exact fix (#210, opened via a Cursor background agent) was opened in January 2026 but closed unmerged in June 2026 without landing.

Solution

Moves the host-setting logic (config.setHost / apiClient.setBasePath) out of the else branch so it always runs when a host is configured, regardless of which OkHttpClient path was taken above it. proxyConfig and customOkHttpClient can't both be set (the builder already throws PineconeConfigurationException earlier if they are), so this doesn't change behavior for that combination.

Fixes #192

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Infrastructure change (CI configs, etc)
  • Non-code change (docs, etc)
  • None of the above: (explain here)

Test Plan

  • Added PineconeWithHostAndCustomOkHttpClientUsesHost to PineconeBuilderTest, which builds a client with both withHost(...) and withOkHttpClient(...) and asserts the outgoing request's host and port match the configured host.
  • Verified empirically that the test reproduces the bug: with the fix reverted (source reset to current main HEAD, test kept as-is), the new test fails exactly as the issue describes — expected: <my-custom-host> but was: <api.pinecone.io>. With the fix restored, it passes.
  • Full suite: ./gradlew clean build -x integrationTest — BUILD SUCCESSFUL, 91/91 unit tests pass (90 pre-existing + 1 new), JDK 21.
  • integrationTest not run (needs PINECONE_API_KEY and live infrastructure); this change only touches Builder.build()'s client-construction path so it shouldn't be affected.

Disclosure: this change, including the regression test and this PR description, was written with AI assistance (Claude).


Note

Low Risk
Small, localized change to client construction with a regression test; behavior only changes for the previously broken host+custom-client combination.

Overview
Fixes a bug where withHost(...) was ignored whenever withOkHttpClient(...) was also used on Pinecone.Builder. Host setup (config.setHost / apiClient.setBasePath) lived only in the non-custom-client branch, so control-plane calls defaulted to api.pinecone.io instead of the configured base URL.

The PR moves host application after the OkHttpClient branch so it always runs when a host is set, for both default and custom clients. A regression test builds a client with both options and asserts the outgoing request uses the configured host and port (issue #192).

Reviewed by Cursor Bugbot for commit 9007b34. Bugbot is set up for automated code reviews on this repo. Configure here.

Pinecone.Builder.build() only applied withHost(...) inside the else
branch of `if (customOkHttpClient != null)`, so an explicitly
configured host was silently dropped whenever a custom OkHttpClient
was also supplied — requests fell back to the default
api.pinecone.io instead.

Moves the host-setting logic (config.setHost / apiClient.setBasePath)
out of that else branch so it always runs when a host is configured,
regardless of which OkHttpClient path was taken. This matches the
root-cause and fix already confirmed by a maintainer in the issue
thread; a prior attempt at this exact fix (PR pinecone-io#210, via a Cursor
background agent) was opened in January 2026 but closed unmerged
in June 2026 without landing.

Fixes pinecone-io#192

Testing:
- Added PineconeWithHostAndCustomOkHttpClientUsesHost to
  PineconeBuilderTest, which builds a client with both withHost(...)
  and withOkHttpClient(...) and asserts the outgoing request's host
  and port match the configured host.
- Verified empirically: with the fix reverted (source reset to the
  current main HEAD) the new test fails exactly as the issue
  describes (expected "my-custom-host" but was "api.pinecone.io");
  with the fix restored it passes.
- Full suite: `./gradlew clean build -x integrationTest` — BUILD
  SUCCESSFUL, 91/91 unit tests pass (90 pre-existing + 1 new), JDK 21.
- integrationTest not run (needs PINECONE_API_KEY and live
  infrastructure); unaffected by this change since it only touches
  Builder.build()'s client construction path.

This change, including the regression test and this PR description,
was written with AI assistance (Claude).
@kksingh000
kksingh000 requested a review from a team as a code owner October 6, 2026 13:30
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.

[Bug] There is no way to specify host and customOkHttpClient

1 participant