Skip to content

Commit 3ab43c6

Browse files
lcclaude
andcommitted
fix(code-index): honor NO_PROXY and reuse the proxy tunnel
Rebuild the Bedrock runtime host so NO_PROXY can exclude a directly-reachable endpoint, and keep the tunnel open between the one-request-per-text embedding calls, matching the handler's own default agents. Co-Authored-By: Claude Opus 5 <[email protected]>
1 parent 59e2b12 commit 3ab43c6

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,12 @@ describe("BedrockEmbedder", () => {
138138

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

141-
expect(HttpProxyAgent).toHaveBeenCalledWith("http://proxy.corp.local:3128")
142-
expect(HttpsProxyAgent).toHaveBeenCalledWith("http://proxy.corp.local:3128")
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")
143+
144+
// keepAlive reuses the tunnel across the one-request-per-text embedding calls.
145+
expect(HttpProxyAgent).toHaveBeenCalledWith("http://proxy.corp.local:3128", { keepAlive: true })
146+
expect(HttpsProxyAgent).toHaveBeenCalledWith("http://proxy.corp.local:3128", { keepAlive: true })
143147

144148
// Both agents must reach the handler: a client that tunnels only https still
145149
// resolves http DNS locally, which is the ENOTFOUND this fix is about.
@@ -155,6 +159,12 @@ describe("BedrockEmbedder", () => {
155159
expect(clientConfig?.requestHandler).toBe(vitest.mocked(NodeHttpHandler).mock.instances[0])
156160
})
157161

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")
164+
165+
expect(getSystemProxyUrl).toHaveBeenLastCalledWith("https://bedrock-runtime.cn-north-1.amazonaws.com.cn")
166+
})
167+
158168
it("should not install a request handler when no proxy is configured", () => {
159169
vitest.mocked(getSystemProxyUrl).mockReturnValue(undefined)
160170
vitest.mocked(NodeHttpHandler).mockClear()

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,23 @@ export class BedrockEmbedder implements IEmbedder {
4747
// Behind a corporate proxy, Node resolves DNS locally before tunneling and Bedrock
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.
50-
const proxyUrl = getSystemProxyUrl()
50+
//
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}`)
55+
56+
// Embeddings are sent one request per text, so keep the tunnel open between them.
57+
const agentOptions = { keepAlive: true }
5158

5259
this.bedrockClient = new BedrockRuntimeClient({
5360
userAgentAppId: `ZooCode#${Package.version}`,
5461
region: this.region,
5562
credentials,
5663
...(proxyUrl && {
5764
requestHandler: new NodeHttpHandler({
58-
httpAgent: new HttpProxyAgent(proxyUrl),
59-
httpsAgent: new HttpsProxyAgent(proxyUrl),
65+
httpAgent: new HttpProxyAgent(proxyUrl, agentOptions),
66+
httpsAgent: new HttpsProxyAgent(proxyUrl, agentOptions),
6067
}),
6168
}),
6269
})

0 commit comments

Comments
 (0)