From f4159e25e446e7ada763e2e70b3abeb70edbeb41 Mon Sep 17 00:00:00 2001 From: "commitperclip[bot]" <284812584+commitperclip[bot]@users.noreply.github.com> Date: Fri, 13 Nov 2026 12:58:03 -0600 Subject: [PATCH] fix: Remove the unused OpenCode remote config guard and document host staging (#20045) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit > [!NOTE] > Opened by Prospector's automated issue-fix pipeline. A maintainer reviews and decides; nothing here merges on its own. > [!WARNING] > This change crosses a trust boundary. See Risks. ## Thinking Path - Issue #17372 reports a defect in paperclipai/paperclip. - Root cause, as the fixing agent read it: The helper's unused targetIsRemote guard contradicted both callers, which intentionally stage configuration on the host and transfer it to remote targets as xdgConfig. - This pull request: Remove the unused OpenCode remote config guard and document host staging ## What Changed - `packages/adapters/opencode-local/src/server/runtime-config.ts`: Remove the unused option and contradictory guard while preserving both callers' staging behavior. - `packages/adapters/opencode-local/src/server/runtime-config.test.ts`: Add a regression for isolated staging, generated configuration, cleanup, and operator config preservation. Confirmed failure before the fix; all 50 focused tests pass afterward. Typecheck was started but has not returned a result. - `packages/adapters/opencode-local/README.md`: Document host staging for local and remote execution, remote asset transfer, path replacement, and host cleanup. ## Verification - Reproducing test(s), added in this PR: `packages/adapters/opencode-local/src/server/runtime-config.test.ts` - They fail on the base commit and pass with the fix, each twice in a fresh sandbox. - 3 independent attempts wrote 3 reproductions; this fix passes every one of them. - The repository's compile command passes with the fix applied. - 9 existing test file(s) near the change passed. - The full test suite passes except for the 16 file(s) that already fail on the base commit. ## Risks - Written by an automated pipeline, not a person: review it as you would an outside contribution. - Risk tier of the touched paths: 2. - It crosses a trust boundary. Check each crossing against what the issue asked for, and against who asked: - validation (packages/adapters/opencode-local/src/server/runtime-config.ts:107): Removes the targetIsRemote early-return check that prevented host configuration staging when explicitly set, although neither production caller supplies it. ## Model Used - codex:gpt-6.1-sol, opus, sonnet (Anthropic Claude, via Claude Code; OpenAI, via the Codex CLI), writing and checking the change in an isolated sandbox. - opus (Anthropic Claude, via Claude Code), reviewing it independently. ## Linked Issues Fixes #17372 #17372 also mentions, without asking this fix for it: - The remote per-run directory is never removed. (The report explicitly says: “Related but distinct: #14527 covers the remote per-run directory never being removed.”) A search of paperclipai/paperclip's open and closed pull requests found no other pull request that names #17372. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [ ] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with 'Fixes: #' / 'Closes #' / 'Refs #' OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub '#NNN' / 'github.com/paperclipai/paperclip' URLs) - [ ] My branch name describes the change (e.g. 'docs/...', 'fix/...') and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [ ] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [ ] I will address all Greptile and reviewer comments before requesting merge Co-authored-by: commitperclip[bot] <284812584+commitperclip[bot]@users.noreply.github.com> --- packages/adapters/opencode-local/README.md | 13 +++++++++++ .../src/server/runtime-config.test.ts | 23 +++++++++++++++++++ .../src/server/runtime-config.ts | 14 ----------- 3 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 packages/adapters/opencode-local/README.md diff --git a/packages/adapters/opencode-local/README.md b/packages/adapters/opencode-local/README.md new file mode 100644 index 00000000000..13c7bdd4441 --- /dev/null +++ b/packages/adapters/opencode-local/README.md @@ -0,0 +1,13 @@ +# OpenCode local adapter + +## Runtime configuration + +`prepareOpenCodeRuntimeConfig` stages an isolated OpenCode configuration directory +on the host for both local and remote execution targets. It copies the operator +configuration and applies the runtime provider and permission settings. Its +returned `XDG_CONFIG_HOME` points to that host directory. + +For remote execution, `execute` and `testEnvironment` pass the staged directory +to `prepareAdapterExecutionTargetRuntime` as the `xdgConfig` asset. They replace +`XDG_CONFIG_HOME` with the asset's remote destination before running OpenCode. +The helper's cleanup function removes the host staging directory. diff --git a/packages/adapters/opencode-local/src/server/runtime-config.test.ts b/packages/adapters/opencode-local/src/server/runtime-config.test.ts index c1c96bbf893..de8d940743e 100644 --- a/packages/adapters/opencode-local/src/server/runtime-config.test.ts +++ b/packages/adapters/opencode-local/src/server/runtime-config.test.ts @@ -34,6 +34,29 @@ async function makeConfigHome(initialConfig?: Record) { } describe("prepareOpenCodeRuntimeConfig", () => { + it("stages isolated configuration for remote asset transfer even with remote target metadata", async () => { + const configHome = await makeConfigHome({ theme: "system" }); + const input = { + env: { XDG_CONFIG_HOME: configHome }, + config: { model: "gateway/test-model" }, + targetIsRemote: true, + }; + const prepared = await prepareOpenCodeRuntimeConfig(input); + expect(prepared.env.XDG_CONFIG_HOME).not.toBe(configHome); + cleanupPaths.add(prepared.env.XDG_CONFIG_HOME); + expect(JSON.parse(await fs.readFile( + path.join(prepared.env.XDG_CONFIG_HOME, "opencode", "opencode.json"), "utf8", + ))).toMatchObject({ + theme: "system", + permission: "allow", + provider: { gateway: { models: { "test-model": {} } } }, + }); + await prepared.cleanup(); + await expect(fs.stat(prepared.env.XDG_CONFIG_HOME)).rejects.toMatchObject({ code: "ENOENT" }); + expect(JSON.parse(await fs.readFile(path.join(configHome, "opencode", "opencode.json"), "utf8"))) + .toEqual({ theme: "system" }); + }); + it("stages a relocatable sandbox shell hook without changing the parent environment", async () => { const configHome = await makeConfigHome({ plugin: ["operator-plugin"], permission: { bash: "ask" } }); const input = { env: { XDG_CONFIG_HOME: configHome }, config: { dangerouslySkipPermissions: false }, sandboxToolOomPreference: true }; diff --git a/packages/adapters/opencode-local/src/server/runtime-config.ts b/packages/adapters/opencode-local/src/server/runtime-config.ts index 9dc6ec4208b..1b25d1e1dd0 100644 --- a/packages/adapters/opencode-local/src/server/runtime-config.ts +++ b/packages/adapters/opencode-local/src/server/runtime-config.ts @@ -107,24 +107,10 @@ async function readJsonObject(filepath: string): Promise export async function prepareOpenCodeRuntimeConfig(input: { env: Record; config: Record; - targetIsRemote?: boolean; sandboxToolOomPreference?: boolean; }): Promise { const skipPermissions = asBoolean(input.config.dangerouslySkipPermissions, true); - // For remote execution targets the host XDG_CONFIG_HOME path is meaningless - // (and actively harmful — it leaks a macOS-only path into the remote Linux - // env). Callers that need to ship a runtime opencode config to the remote - // box do that via prepareAdapterExecutionTargetRuntime in execute.ts; this - // host-fs helper is local-only. - if (input.targetIsRemote) { - return { - env: input.env, - notes: [], - cleanup: async () => {}, - }; - } - const sourceConfigDir = path.join(resolveXdgConfigHome(input.env), "opencode"); const runtimeConfigHome = await fs.mkdtemp(path.join(os.tmpdir(), "paperclip-opencode-config-")); const runtimeConfigDir = path.join(runtimeConfigHome, "opencode");