Skip to content

fix(fetch): preserve localhost hostname without rewriting to 127.0.0.1 (#13339) - #13387

Open
patrickswedish wants to merge 1 commit into
continuedev:mainfrom
patrickswedish:fix/fetch-preserve-localhost-13339
Open

patrickswedish wants to merge 1 commit into
continuedev:mainfrom
patrickswedish:fix/fetch-preserve-localhost-13339

Conversation

@patrickswedish

@patrickswedish patrickswedish commented Oct 15, 2026 •

Copy link
Copy Markdown

Summary

Resolves #13339

In fetchwithRequestOptions (packages/fetch/src/fetch.ts), url.host and url.hostname were unconditionally rewritten from "localhost" to "127.0.0.1". In environments with WSL2, IPv6 loopback (e.g., servers bound strictly to [::1]:8080), containerized networks, or virtual host routing, rewriting localhost to 127.0.0.1 causes connection attempts to fail with connect ECONNREFUSED 127.0.0.1:8080.

Furthermore, if the caller passed a URL instance into fetchwithRequestOptions, url.hostname = "127.0.0.1" mutated the caller's URL in place.

Changes

  1. Preserve localhost: Removed unconditional mutations of url.host and url.hostname to "127.0.0.1" in packages/fetch/src/fetch.ts, allowing the runtime/OS resolver to handle loopback address resolution cleanly.
  2. Prevent Caller Object Mutation: Cloned input URL objects via new URL(url_.toString()) if passed as an instance.
  3. Align Default apiBase: Updated LlamaCpp default apiBase in core/llm/llms/LlamaCpp.ts from "http://127.0.0.1:8080/" to "http://localhost:8080/", matching all other local providers (Ollama, LMStudio, HuggingFaceTEI, etc.).
  4. End-to-End Test: Added test in packages/fetch/src/fetch.e2e.test.ts verifying that localhost is preserved on outgoing requests and caller URL instances are not mutated.

Test Plan

  • Ran Vitest E2E suite in packages/fetch: verified should preserve localhost hostname without rewriting to 127.0.0.1 (#13339) passes cleanly.
  • Verified outgoing Host header retains localhost:<PORT>.
  • Ran full unit test battery in packages/fetch.

continuedev#13339)

fetchwithRequestOptions unconditionally rewrote url.host and url.hostname from localhost to 127.0.0.1. In environments involving WSL2, IPv6 loopback (e.g. servers bound to [::1]), containers, or custom virtual host routing, rewriting localhost to 127.0.0.1 causes requests to fail with ECONNREFUSED.

This commit:

- Preserves the caller-configured localhost hostname in packages/fetch/src/fetch.ts without mutating it to 127.0.0.1.

- Clones input URL instances to prevent in-place mutation of caller objects.

- Aligns LlamaCpp default apiBase to http://localhost:8080/ consistent with all other local providers.

- Adds an end-to-end test verifying localhost is preserved on outgoing requests.

Closes continuedev#13339

Signed-off-by: Patrick Ribbsaeter <patrickswedish@gmail.com>
@patrickswedish
patrickswedish requested a review from a team as a code owner October 15, 2026 23:39
@patrickswedish
patrickswedish requested review from sestinj and removed request for a team October 15, 2026 23:39

This branch has not been deployed

No deployments
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.

Continue appears to rewrite a configured localhost API base URL to 127.0.0.1. (WSL)

1 participant