Skip to content

Commit 59e2b12

Browse files
lcclaude
andcommitted
fix(code-index): route Bedrock embedder through the system proxy
The proxy fix for the chat provider never reached the code-index embedder, which built its own BedrockRuntimeClient without a request handler. Behind a corporate proxy Node resolves DNS locally and indexing fails with ENOTFOUND. Co-Authored-By: Claude Opus 5 <[email protected]>
1 parent 9ec139c commit 59e2b12

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import type { MockedFunction } from "vitest"
22
import { BedrockRuntimeClient, InvokeModelCommand } from "@aws-sdk/client-bedrock-runtime"
33

4+
import { NodeHttpHandler } from "@smithy/node-http-handler"
5+
import { HttpProxyAgent } from "http-proxy-agent"
6+
import { HttpsProxyAgent } from "https-proxy-agent"
7+
48
import { BedrockEmbedder } from "../bedrock"
59
import { MAX_ITEM_TOKENS, INITIAL_RETRY_DELAY_MS } from "../../constants"
10+
import { getSystemProxyUrl } from "../../../../utils/networkProxy"
611

712
import { clearAllMocks } from "../../../../test-utils/reset"
813

@@ -26,6 +31,17 @@ vitest.mock("@aws-sdk/credential-providers", () => ({
2631
fromIni: vitest.fn().mockReturnValue(Promise.resolve({})),
2732
}))
2833

34+
vitest.mock("../../../../utils/networkProxy", () => ({
35+
getSystemProxyUrl: vitest.fn().mockReturnValue(undefined),
36+
}))
37+
vitest.mock("@smithy/node-http-handler", () => ({
38+
NodeHttpHandler: vitest.fn().mockImplementation(function (options: unknown) {
39+
return { options }
40+
}),
41+
}))
42+
vitest.mock("http-proxy-agent", () => ({ HttpProxyAgent: vitest.fn() }))
43+
vitest.mock("https-proxy-agent", () => ({ HttpsProxyAgent: vitest.fn() }))
44+
2945
// Mock TelemetryService
3046
vitest.mock("@roo-code/telemetry", () => ({
3147
TelemetryService: {
@@ -114,6 +130,42 @@ describe("BedrockEmbedder", () => {
114130
}),
115131
)
116132
})
133+
134+
it("should tunnel through the system proxy when one is configured", () => {
135+
// The embedder built in beforeEach already consumed these mocks.
136+
vitest.mocked(getSystemProxyUrl).mockReturnValue("http://proxy.corp.local:3128")
137+
vitest.mocked(NodeHttpHandler).mockClear()
138+
139+
new BedrockEmbedder("us-east-1", "test-profile", "amazon.titan-embed-text-v2:0")
140+
141+
expect(HttpProxyAgent).toHaveBeenCalledWith("http://proxy.corp.local:3128")
142+
expect(HttpsProxyAgent).toHaveBeenCalledWith("http://proxy.corp.local:3128")
143+
144+
// Both agents must reach the handler: a client that tunnels only https still
145+
// resolves http DNS locally, which is the ENOTFOUND this fix is about.
146+
expect(NodeHttpHandler).toHaveBeenCalledOnce()
147+
// The constructor accepts options or a provider function; only the object form is used here.
148+
const handlerArg = vitest.mocked(NodeHttpHandler).mock.calls[0][0]
149+
const handlerOptions = typeof handlerArg === "function" ? undefined : handlerArg
150+
expect(handlerOptions?.httpAgent).toBe(vitest.mocked(HttpProxyAgent).mock.instances[0])
151+
expect(handlerOptions?.httpsAgent).toBe(vitest.mocked(HttpsProxyAgent).mock.instances[0])
152+
153+
// ...and the handler must reach the client.
154+
const clientConfig = vitest.mocked(BedrockRuntimeClient).mock.calls.at(-1)?.[0]
155+
expect(clientConfig?.requestHandler).toBe(vitest.mocked(NodeHttpHandler).mock.instances[0])
156+
})
157+
158+
it("should not install a request handler when no proxy is configured", () => {
159+
vitest.mocked(getSystemProxyUrl).mockReturnValue(undefined)
160+
vitest.mocked(NodeHttpHandler).mockClear()
161+
162+
new BedrockEmbedder("us-east-1", "test-profile", "amazon.titan-embed-text-v2:0")
163+
164+
expect(NodeHttpHandler).not.toHaveBeenCalled()
165+
expect(BedrockRuntimeClient).toHaveBeenLastCalledWith(
166+
expect.not.objectContaining({ requestHandler: expect.anything() }),
167+
)
168+
})
117169
})
118170

119171
describe("createEmbeddings", () => {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { BedrockRuntimeClient, InvokeModelCommand, InvokeModelCommandInput } from "@aws-sdk/client-bedrock-runtime"
22
import { fromIni, fromNodeProviderChain } from "@aws-sdk/credential-providers"
3+
import { NodeHttpHandler } from "@smithy/node-http-handler"
4+
import { HttpProxyAgent } from "http-proxy-agent"
5+
import { HttpsProxyAgent } from "https-proxy-agent"
6+
import { getSystemProxyUrl } from "../../../utils/networkProxy"
37
import { IEmbedder, EmbeddingResponse, EmbedderInfo } from "../interfaces"
48
import {
59
MAX_BATCH_TOKENS,
@@ -40,10 +44,21 @@ export class BedrockEmbedder implements IEmbedder {
4044
// If profile is specified, use it; otherwise use default credential chain
4145
const credentials = this.profile ? fromIni({ profile: this.profile }) : fromNodeProviderChain()
4246

47+
// Behind a corporate proxy, Node resolves DNS locally before tunneling and Bedrock
48+
// endpoints fail with ENOTFOUND. The proxy agents use CONNECT so the proxy resolves
49+
// the hostname instead, matching the chat provider in src/api/providers/bedrock.ts.
50+
const proxyUrl = getSystemProxyUrl()
51+
4352
this.bedrockClient = new BedrockRuntimeClient({
4453
userAgentAppId: `ZooCode#${Package.version}`,
4554
region: this.region,
4655
credentials,
56+
...(proxyUrl && {
57+
requestHandler: new NodeHttpHandler({
58+
httpAgent: new HttpProxyAgent(proxyUrl),
59+
httpsAgent: new HttpsProxyAgent(proxyUrl),
60+
}),
61+
}),
4762
})
4863

4964
this.defaultModelId = modelId || getDefaultModelId("bedrock")

0 commit comments

Comments
 (0)