Skip to content

Commit 56ef7fd

Browse files
Dhtsteipete
authored andcommitted
fix(memory-host-sdk): use TRUSTED_ENV_PROXY mode in withRemoteHttpResponse
When a HTTP/HTTPS proxy is configured via environment variables (HTTPS_PROXY, HTTP_PROXY, ALL_PROXY), the withRemoteHttpResponse function now passes mode=TRUSTED_ENV_PROXY to fetchWithSsrFGuard. This causes DNS resolution to skip the local resolver and route through the configured proxy, fixing 'fetch failed' errors for remote memory embeddings (including GitHub Copilot embeddings) in proxy environments (e.g. Clash TUN, corporate proxies). Previously, without an explicit mode, fetchWithSsrFGuard defaulted to STRICT mode which performs local DNS pre-resolution via resolvePinnedHostnameWithPolicy(), failing in proxy environments where DNS must go through the proxy. Fixes: #52162
1 parent de652af commit 56ef7fd

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

packages/memory-host-sdk/src/host/remote-http.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { fetchWithSsrFGuard } from "../../../../src/infra/net/fetch-guard.js";
1+
import { fetchWithSsrFGuard, GUARDED_FETCH_MODE } from "../../../../src/infra/net/fetch-guard.js";
2+
import { hasProxyEnvConfigured } from "../../../../src/infra/net/proxy-env.js";
23
import type { SsrFPolicy } from "../../../../src/infra/net/ssrf.js";
34

45
export function buildRemoteBaseUrlPolicy(baseUrl: string): SsrFPolicy | undefined {
@@ -31,6 +32,9 @@ export async function withRemoteHttpResponse<T>(params: {
3132
init: params.init,
3233
policy: params.ssrfPolicy,
3334
auditContext: params.auditContext ?? "memory-remote",
35+
// FIX: When env proxy is configured, skip local DNS resolution and route through the proxy
36+
// This fixes remote embedding/copilot memory search failing with "fetch failed" in proxy environments
37+
mode: hasProxyEnvConfigured() ? GUARDED_FETCH_MODE.TRUSTED_ENV_PROXY : undefined,
3438
});
3539
try {
3640
return await params.onResponse(response);

src/memory-host-sdk/host/remote-http.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { fetchWithSsrFGuard } from "../../infra/net/fetch-guard.js";
1+
import { fetchWithSsrFGuard, GUARDED_FETCH_MODE } from "../../infra/net/fetch-guard.js";
2+
import { hasProxyEnvConfigured } from "../../infra/net/proxy-env.js";
23
import { ssrfPolicyFromHttpBaseUrlAllowedHostname, type SsrFPolicy } from "../../infra/net/ssrf.js";
34

45
export const buildRemoteBaseUrlPolicy = ssrfPolicyFromHttpBaseUrlAllowedHostname;
@@ -17,6 +18,9 @@ export async function withRemoteHttpResponse<T>(params: {
1718
init: params.init,
1819
policy: params.ssrfPolicy,
1920
auditContext: params.auditContext ?? "memory-remote",
21+
// FIX: When env proxy is configured, skip local DNS resolution and route through the proxy
22+
// This fixes remote embedding/copilot memory search failing with "fetch failed" in proxy environments
23+
mode: hasProxyEnvConfigured() ? GUARDED_FETCH_MODE.TRUSTED_ENV_PROXY : undefined,
2024
});
2125
try {
2226
return await params.onResponse(response);

0 commit comments

Comments
 (0)