Skip to content

Fix bedrock DNS resolution when behind a corporate proxy#906

Open
LouisClt wants to merge 4 commits into
Zoo-Code-Org:mainfrom
LouisClt:fix_bedrock_proxy
Open

Fix bedrock DNS resolution when behind a corporate proxy#906
LouisClt wants to merge 4 commits into
Zoo-Code-Org:mainfrom
LouisClt:fix_bedrock_proxy

Conversation

@LouisClt

@LouisClt LouisClt commented Jul 16, 2026

Copy link
Copy Markdown

When behind a corporate proxy, Node.js resolves DNS locally before contacting the proxy. If the proxy is the only path to the endpoint, the request fails with ENOTFOUND.

HttpsProxyAgent uses CONNECT tunneling so the proxy handles DNS resolution. Configure NodeHttpHandler with HttpsProxyAgent when a system proxy is detected.

I had the need to use bedrock behind a corporate proxy, as there was no fix available, I made one so that I could use it, using Claude code. Here is a proposed PR if you want to merge it to the main branch ...
I reviewed the changes myself, and it seems to be good, but I am no typescript expert so ...

Related GitHub Issue

Closes: #905

Description

Node.js resolves DNS locally before contacting the proxy. When behind a corporate proxy that blocks external DNS, Bedrock calls fail with ENOTFOUND.

This configures NodeHttpHandler with HttpsProxyAgent in BedrockRuntimeClient, which uses CONNECT tunneling so the proxy handles DNS resolution.

Proxy is detected from HTTPS_PROXY/HTTP_PROXY env vars or VS Code http.proxy setting

Test Procedure

Test Procedure

  • Unit tests: pnpm test -- bedrock.spec → 102 passing
  • Windows: Configure proxy in Internet Options, restart VS Code → works automatically

Pre-Submission Checklist

Documentation Updates

[x] No documentation updates are required.

Additional Notes

Get in Touch

I have no discord username for the moment.

Thanks

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes
    • Fixed Amazon Bedrock connectivity when running behind a corporate HTTPS proxy, including improved proxy/DNS resolution.
    • Bedrock now automatically routes requests using system proxy settings from environment variables or VS Code proxy configuration.
    • Ensures proxy routing continues to work correctly when using API key authentication.
  • Tests
    • Added unit and provider tests covering proxy URL detection and Bedrock proxy request handling.
  • Release
    • Published a patch release for the zoo-code package with this fix.

When behind a corporate proxy, Node.js resolves DNS locally before contacting
the proxy. If the proxy is the only path to the endpoint, the request fails
with ENOTFOUND.

HttpsProxyAgent uses CONNECT tunneling so the proxy handles DNS resolution.
Configure NodeHttpHandler with HttpsProxyAgent when a system proxy is detected.
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f6ffdfad-cd32-415d-b333-b75e1e1c9a3a

📥 Commits

Reviewing files that changed from the base of the PR and between efa8f35 and 2c3fd28.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (6)
  • .changeset/itchy-moles-thank.md
  • src/api/providers/__tests__/bedrock.spec.ts
  • src/api/providers/bedrock.ts
  • src/package.json
  • src/utils/__tests__/networkProxy.spec.ts
  • src/utils/networkProxy.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/package.json
  • src/utils/networkProxy.ts
  • src/api/providers/bedrock.ts
  • src/utils/tests/networkProxy.spec.ts
  • src/api/providers/tests/bedrock.spec.ts

📝 Walkthrough

Walkthrough

Bedrock now resolves proxy settings from environment variables or VS Code configuration and routes AWS requests through an HTTPS proxy agent when configured. Tests cover proxy discovery, proxied and direct requests, API-key authentication, dependencies, and the patch changeset.

Changes

Bedrock proxy routing

Layer / File(s) Summary
System proxy discovery
src/utils/networkProxy.ts, src/utils/__tests__/networkProxy.spec.ts
Adds and tests getSystemProxyUrl() with HTTPS/HTTP precedence, VS Code fallback, trimming, empty-value handling, and error tolerance.
Bedrock request-handler integration
src/api/providers/bedrock.ts, src/api/providers/__tests__/bedrock.spec.ts, src/package.json, .changeset/itchy-moles-thank.md
Configures NodeHttpHandler and HttpsProxyAgent when a proxy is available, validates proxy and non-proxy behavior including API-key authentication, and declares the dependencies and patch release.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AwsBedrockHandler
  participant getSystemProxyUrl
  participant HttpsProxyAgent
  participant NodeHttpHandler
  participant BedrockRuntimeClient
  AwsBedrockHandler->>getSystemProxyUrl: Resolve system proxy URL
  getSystemProxyUrl-->>AwsBedrockHandler: Return URL or undefined
  AwsBedrockHandler->>HttpsProxyAgent: Create proxy agent
  AwsBedrockHandler->>NodeHttpHandler: Create request handler
  AwsBedrockHandler->>BedrockRuntimeClient: Set requestHandler
Loading

Suggested reviewers: taltas, navedmerchant

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: fixing Bedrock DNS resolution behind a corporate proxy.
Description check ✅ Passed The description includes the required issue link, change summary, test procedure, checklist, and documentation notes.
Linked Issues check ✅ Passed The proxy-agent Bedrock handler and proxy detection directly address issue #905’s proxy DNS failure.
Out of Scope Changes check ✅ Passed The changes are focused on proxy support, tests, dependency updates, and release notes with no obvious unrelated edits.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@LouisClt
LouisClt force-pushed the fix_bedrock_proxy branch from ad39470 to 204a5da Compare July 16, 2026 10:45

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/utils/networkProxy.ts`:
- Around line 354-360: Update the environment proxy selection in the surrounding
proxy-resolution function to trim the chosen
HTTPS_PROXY/https_proxy/HTTP_PROXY/http_proxy value before returning it, and
treat the trimmed result as unset when blank so resolution can continue to the
fallback path. Preserve the existing HTTPS-over-HTTP precedence.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6711a1da-2a4c-48ec-a911-3f1c9a030d08

📥 Commits

Reviewing files that changed from the base of the PR and between ad39470 and 204a5da.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (5)
  • .changeset/itchy-moles-thank.md
  • src/api/providers/__tests__/bedrock.spec.ts
  • src/api/providers/bedrock.ts
  • src/package.json
  • src/utils/networkProxy.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • .changeset/itchy-moles-thank.md
  • src/package.json
  • src/api/providers/bedrock.ts
  • src/api/providers/tests/bedrock.spec.ts

Comment thread src/utils/networkProxy.ts
Comment on lines +354 to +360
// Standard proxy environment variables (HTTPS takes precedence over HTTP)
const fromEnv =
process.env.HTTPS_PROXY ||
process.env.https_proxy ||
process.env.HTTP_PROXY ||
process.env.http_proxy
if (fromEnv) return fromEnv

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Trim environment proxy values before returning them.

Unlike the VS Code fallback, environment values are not trimmed. A whitespace-only HTTPS_PROXY/HTTP_PROXY value is truthy and will be passed to HttpsProxyAgent as an invalid proxy URL, preventing Bedrock client initialization. Normalize the selected environment value and treat blank values as unset.

Proposed fix
-	const fromEnv =
+	const fromEnv = (
 		process.env.HTTPS_PROXY ||
 		process.env.https_proxy ||
 		process.env.HTTP_PROXY ||
 		process.env.http_proxy
-	if (fromEnv) return fromEnv
+	)?.trim()
+	if (fromEnv) return fromEnv
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Standard proxy environment variables (HTTPS takes precedence over HTTP)
const fromEnv =
process.env.HTTPS_PROXY ||
process.env.https_proxy ||
process.env.HTTP_PROXY ||
process.env.http_proxy
if (fromEnv) return fromEnv
// Standard proxy environment variables (HTTPS takes precedence over HTTP)
const fromEnv = (
process.env.HTTPS_PROXY ||
process.env.https_proxy ||
process.env.HTTP_PROXY ||
process.env.http_proxy
)?.trim()
if (fromEnv) return fromEnv
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/utils/networkProxy.ts` around lines 354 - 360, Update the environment
proxy selection in the surrounding proxy-resolution function to trim the chosen
HTTPS_PROXY/https_proxy/HTTP_PROXY/http_proxy value before returning it, and
treat the trimmed result as unset when blank so resolution can continue to the
fallback path. Preserve the existing HTTPS-over-HTTP precedence.

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions github-actions Bot added awaiting-review PR changes are ready and waiting for maintainer re-review has-conflicts PR has merge conflicts with the base branch and removed awaiting-review PR changes are ready and waiting for maintainer re-review has-conflicts PR has merge conflicts with the base branch labels Jul 16, 2026

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (2)
src/utils/__tests__/networkProxy.spec.ts (2)

351-357: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Prevent potential test pollution by using mockImplementationOnce.

Mocking vscode.workspace.getConfiguration with mockImplementation without explicitly restoring it might cause subsequent tests (like "should not return empty string proxy") to fail or skip their actual configuration checks if they rely on it, depending on the test runner's configuration for mock restoration.

Using mockImplementationOnce ensures the mock only applies to this specific test.

♻️ Proposed refactor
 		it("should handle VS Code API errors gracefully", () => {
-			vi.mocked(vscode.workspace.getConfiguration).mockImplementation(() => {
+			vi.mocked(vscode.workspace.getConfiguration).mockImplementationOnce(() => {
 				throw new Error("VS Code API unavailable")
 			})
 			const result = getSystemProxyUrl()
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/utils/__tests__/networkProxy.spec.ts` around lines 351 - 357, Update the
getSystemProxyUrl error test to configure vscode.workspace.getConfiguration with
mockImplementationOnce instead of mockImplementation, ensuring the thrown API
error applies only to that invocation and does not pollute subsequent tests.

310-334: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Keep proxy env vars isolated Deleting and reassigning process.env here mutates the shared worker environment. Save and restore the original values in afterEach, or switch these cases to vi.stubEnv()/vi.unstubAllEnvs() so this suite doesn’t leak state into other tests.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/utils/__tests__/networkProxy.spec.ts` around lines 310 - 334, Isolate
environment changes in the proxy tests instead of directly deleting and
reassigning shared process.env values. Update the beforeEach/afterEach setup
around getSystemProxyUrl to use vi.stubEnv with vi.unstubAllEnvs, or save and
restore the original HTTPS_PROXY, https_proxy, HTTP_PROXY, and http_proxy values
after each test.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/utils/__tests__/networkProxy.spec.ts`:
- Around line 351-357: Update the getSystemProxyUrl error test to configure
vscode.workspace.getConfiguration with mockImplementationOnce instead of
mockImplementation, ensuring the thrown API error applies only to that
invocation and does not pollute subsequent tests.
- Around line 310-334: Isolate environment changes in the proxy tests instead of
directly deleting and reassigning shared process.env values. Update the
beforeEach/afterEach setup around getSystemProxyUrl to use vi.stubEnv with
vi.unstubAllEnvs, or save and restore the original HTTPS_PROXY, https_proxy,
HTTP_PROXY, and http_proxy values after each test.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: aa135631-358f-48ea-b61a-eda1f1366357

📥 Commits

Reviewing files that changed from the base of the PR and between 204a5da and efa8f35.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • src/api/providers/bedrock.ts
  • src/package.json
  • src/utils/__tests__/networkProxy.spec.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/package.json
  • src/api/providers/bedrock.ts

@LouisClt
LouisClt force-pushed the fix_bedrock_proxy branch from efa8f35 to 2c3fd28 Compare July 21, 2026 14:50
@github-actions github-actions Bot added awaiting-review PR changes are ready and waiting for maintainer re-review and removed has-conflicts PR has merge conflicts with the base branch labels Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review PR changes are ready and waiting for maintainer re-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Bedrock provider does not work behind a proxy

1 participant