Skip to content

fix(acp): bypass HTTP proxy for localhost SDK client requests#31096

Open
SXongin wants to merge 1 commit into
anomalyco:devfrom
SXongin:fix/acp-no-proxy
Open

fix(acp): bypass HTTP proxy for localhost SDK client requests#31096
SXongin wants to merge 1 commit into
anomalyco:devfrom
SXongin:fix/acp-no-proxy

Conversation

@SXongin
Copy link
Copy Markdown

@SXongin SXongin commented Jun 6, 2026

Issue for this PR

Closes #31091

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When http_proxy/https_proxy environment 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 to 127.0.0.1 through the proxy. The proxy cannot reach localhost, causing all internal API calls to fail silently.

This manifests as session/new returning -32603 Internal error: OpenCode service failure with data: { service: "directory" }.

Root cause: The SDK client uses globalThis.fetch(), which respects http_proxy/https_proxy env vars. The 5 parallel API calls in loadDirectorySnapshot() (config.providers, app.agents, command.list, app.skills, config.get) all route to 127.0.0.1 and get proxied.

Fix: Set NO_PROXY=127.0.0.1,localhost before creating the SDK client, ensuring localhost requests bypass the proxy. This follows the same pattern as the existing process.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:7890 set:

  • Before: session/new fails with -32603
  • After: session/new succeeds, returns sessionId, full model list, and available commands
  • opencode run mode remains unaffected (uses internal Effect runtime, not HTTP)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] ACP session/new fails with 'Internal error: OpenCode service failure' on Linux (WSL)

1 participant