fix(server): stop sending the local directory to a remote OpenCode server #6228
ClosedCDVolvik(GitHub profile, opens in a new tab)wants to merge 5 commits into
main fromrefs/pull/6228/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/server/src/provider/Layers/OpenCodeAdapter.ts line 2815OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1212,3 +1212,4 @@12121212 const client = openCodeRuntime.createOpenCodeSdkClient({12131213 baseUrl: server.url,12141214 directory,1215+ external: server.external,
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/provider/Layers/OpenCodeAdapter.ts lines 1272 to 1277OutdatedResolvedby juliusmarminge@@ -1263,3 +1265,13 @@12631265 ),12641266 )12651267 : undefined;1268+ const adopted = (adoptedRaw ?? undefined) as1269+ | { readonly id: string; readonly directory?: string | null }1270+ | undefined;1271+1272+ // For a remote server the local directory is meaningless — the1273+ // client no longer sends it (#3094) and the adopted session's1274+ // directory is a Linux path that will never equal the Windows1275+ // one. Skip the cwd check and the fork entirely in that case1276+ // so we don't reintroduce the Invalid path failure this PR fixes.1277+ const isRemote = server.external && !isLoopbackBaseUrl(server.url);
- apps/server/src/provider/opencodeRuntime.ts line 209OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -187,0 +189,21 @@189+}190+191+// An externally-configured server can live on another machine, where a local path means192+// nothing: a Windows directory reaching a Linux host produced "Invalid path193+// /var/log/C:\Users\...". A loopback URL is still this machine, so its directory stays194+// meaningful — "external" is not the same thing as "remote". An unparseable URL keeps the195+// directory too, so a malformed setting cannot quietly change what the server receives.196+export function isLoopbackBaseUrl(baseUrl: string): boolean {197+ let hostname: string;198+ try {199+ hostname = new URL(baseUrl).hostname;200+ } catch {201+ return true;202+ }203+204+ const normalized = hostname.toLowerCase().replace(/^\[|\]$/gu, "");205+ return (206+ normalized === "localhost" ||207+ normalized === "::1" ||208+ normalized === "0.0.0.0" ||209+ normalized.startsWith("127.")
- apps/server/src/provider/opencodeRuntime.ts line 688OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -594,15 +635,4 @@594635 );595636596637 const createOpenCodeSdkClient: OpenCodeRuntimeShape["createOpenCodeSdkClient"] = (input) =>597- createOpencodeClient({598- baseUrl: input.baseUrl,599- directory: input.directory,600- ...(input.serverPassword601- ? {602- headers: {603- Authorization: `Basic ${Buffer.from(`opencode:${input.serverPassword}`, "utf8").toString("base64")}`,604- },605- }606- : {}),607- throwOnError: true,608- });638+ createOpencodeClient(buildOpenCodeSdkClientConfig(input));
juliusmarminge closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
4ca0bfb4-e3dc-4cab-831c-3784097226faYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Warning
Your free Security trial is over. An organization admin can activate Security or dismiss this notice.
Comment `@coderabbitai help` to get the list of available commands.