fix(acp): bypass HTTP proxy for localhost SDK client requests#31096
Open
SXongin wants to merge 1 commit into
Open
fix(acp): bypass HTTP proxy for localhost SDK client requests#31096SXongin wants to merge 1 commit into
SXongin wants to merge 1 commit into
Conversation
The ACP command starts an internal HTTP server and creates an SDK client that calls back to 127.0.0.1. When http_proxy/https_proxy environment variables are configured (common for users behind proxies/VPNs), the SDK's fetch() routes localhost requests through the proxy, which fails because the proxy cannot reach the loopback address. This causes session/new (and all other internal ACP API calls) to fail with -32603 Internal error: OpenCode service failure (service: directory). Fix: set NO_PROXY=127.0.0.1,localhost before creating the SDK client, matching the existing pattern of setting process.env.OPENCODE_CLIENT. Closes anomalyco#31091
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #31091
Type of change
What does this PR do?
When
http_proxy/https_proxyenvironment variables are set (common for users behind corporate proxies, VPNs, or in regions requiring proxy for external API access), the ACP command's internal SDK client routes requests to127.0.0.1through the proxy. The proxy cannot reach localhost, causing all internal API calls to fail silently.This manifests as
session/newreturning-32603 Internal error: OpenCode service failurewithdata: { service: "directory" }.Root cause: The SDK client uses
globalThis.fetch(), which respectshttp_proxy/https_proxyenv vars. The 5 parallel API calls inloadDirectorySnapshot()(config.providers, app.agents, command.list, app.skills, config.get) all route to127.0.0.1and get proxied.Fix: Set
NO_PROXY=127.0.0.1,localhostbefore creating the SDK client, ensuring localhost requests bypass the proxy. This follows the same pattern as the existingprocess.env.OPENCODE_CLIENT = "acp"in the same handler.How did you verify your code works?
Tested on Arch Linux (WSL) with
http_proxy=http://172.21.208.1:7890set:session/newfails with-32603session/newsucceeds, returnssessionId, full model list, and available commandsopencode runmode remains unaffected (uses internal Effect runtime, not HTTP)Checklist