Skip to content

Commit f26198b

Browse files
lcclaude
andcommitted
fix(code-index): stop reconstructing the Bedrock host for the proxy check
The NO_PROXY destination added in the previous commit guessed bedrock-runtime.<region>.amazonaws.com (.com.cn for cn-*). The SDK does not resolve the host that way: its ruleset has four templates (fips and dualstack variants), only two of the eight partitions use amazonaws.com, and AWS_ENDPOINT_URL* or endpoint_url in the shared config can override the host outright. Matching that would mean reimplementing the ruleset. Pass no destination instead, so the proxy applies whenever one is configured. This is the trade src/api/providers/bedrock.ts already documents for the default managed endpoint, so the two Bedrock clients now behave the same. Co-Authored-By: Claude Opus 5 <[email protected]>
1 parent 3ab43c6 commit f26198b

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

‎src/services/code-index/embedders/__tests__/bedrock.spec.ts‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ describe("BedrockEmbedder", () => {
108108
})
109109

110110
describe("constructor", () => {
111+
afterEach(() => {
112+
// clearAllMocks() keeps implementations, so a proxy stub would leak into later tests.
113+
vitest.mocked(getSystemProxyUrl).mockReturnValue(undefined)
114+
})
115+
111116
it("should initialize with provided region, profile and model", () => {
112117
expect(embedder.embedderInfo.name).toBe("bedrock")
113118
})
@@ -138,8 +143,8 @@ describe("BedrockEmbedder", () => {
138143

139144
new BedrockEmbedder("us-east-1", "test-profile", "amazon.titan-embed-text-v2:0")
140145

141-
// The runtime host is passed so NO_PROXY can exclude a directly-reachable endpoint.
142-
expect(getSystemProxyUrl).toHaveBeenLastCalledWith("https://bedrock-runtime.us-east-1.amazonaws.com")
146+
// No destination is passed: the SDK resolves the host, so it cannot be guessed here.
147+
expect(getSystemProxyUrl).toHaveBeenLastCalledWith()
143148

144149
// keepAlive reuses the tunnel across the one-request-per-text embedding calls.
145150
expect(HttpProxyAgent).toHaveBeenCalledWith("http://proxy.corp.local:3128", { keepAlive: true })
@@ -157,12 +162,9 @@ describe("BedrockEmbedder", () => {
157162
// ...and the handler must reach the client.
158163
const clientConfig = vitest.mocked(BedrockRuntimeClient).mock.calls.at(-1)?.[0]
159164
expect(clientConfig?.requestHandler).toBe(vitest.mocked(NodeHttpHandler).mock.instances[0])
160-
})
161-
162-
it("should resolve the China partition host for cn- regions", () => {
163-
new BedrockEmbedder("cn-north-1", "test-profile", "amazon.titan-embed-text-v2:0")
164165

165-
expect(getSystemProxyUrl).toHaveBeenLastCalledWith("https://bedrock-runtime.cn-north-1.amazonaws.com.cn")
166+
// Pinning an endpoint here would break FIPS, dualstack and non-default partitions.
167+
expect(clientConfig).not.toHaveProperty("endpoint")
166168
})
167169

168170
it("should not install a request handler when no proxy is configured", () => {

‎src/services/code-index/embedders/bedrock.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ export class BedrockEmbedder implements IEmbedder {
4848
// endpoints fail with ENOTFOUND. The proxy agents use CONNECT so the proxy resolves
4949
// the hostname instead, matching the chat provider in src/api/providers/bedrock.ts.
5050
//
51-
// The SDK resolves the runtime host internally, so it is rebuilt here to let NO_PROXY
52-
// exclude a directly-reachable endpoint. `cn-*` regions live in the China partition.
53-
const endpointSuffix = this.region.startsWith("cn-") ? "amazonaws.com.cn" : "amazonaws.com"
54-
const proxyUrl = getSystemProxyUrl(`https://bedrock-runtime.${this.region}.${endpointSuffix}`)
51+
// No destination is passed for the NO_PROXY check: the SDK resolves the host itself
52+
// from the partition, FIPS/dualstack flags and endpoint overrides, so it cannot be
53+
// reconstructed here. As in the chat provider, the proxy applies whenever one is set.
54+
const proxyUrl = getSystemProxyUrl()
5555

5656
// Embeddings are sent one request per text, so keep the tunnel open between them.
5757
const agentOptions = { keepAlive: true }

0 commit comments

Comments
 (0)