opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Home replaces a selected clone directory with the canonical checkout

Open joe-ieta opened this issue 1 week ago • 1 comments

Description

Home replaces a selected clone directory with the project's canonical checkout when both clones have the same Git origin/project ID. New sessions then open in the first checkout instead of the folder the user chose. A saved second-clone selection can also be cleared on reload before its worktree inventory loads.

Reproduced on dev at d412042beb9821ed61c73466406f7dbfdadc04e0. Related report: #62842; this is the Home selection and new-session path case, with a browser regression covering reload as well.

Steps to reproduce

  1. Clone the same repository to C:/OpenCode/repo and C:/OpenCode/repo-copy.
  2. Open the first clone so it becomes the project's canonical directory.
  3. From Home, use Add project to select repo-copy.
  4. Start a new session and inspect its directory. It uses repo instead of repo-copy.
  5. Restore a saved Home selection pointing to repo-copy and reload. The project list initially contains only the canonical path, so the selection can be cleared before the inventory arrives.

Expected: retain the chosen directory through addition, reload, and new-session creation, while keeping the shared project identity.

OpenCode version

Source checkout of the dev commit above. Reproduced in the Home state machine; verified with a production-build Chromium regression using the repository's mock server harness.

Operating System

Windows 11; Bun 1.4.4; Chromium.

joe-ieta avatar Nov 18 '26 11:11 joe-ieta

Thanks for the detailed report. I could reproduce this on the 2.2.7 release, and it still happens on the latest dev (79bd2c6).

How I tested it

  • Two plain clones of one repo with the same origin, repo and repo-copy, and opencode serve started from repo. The server keeps the two folders apart: looking up repo-copy returns its own path under the same project ID, and the project list holds only the canonical repo.
  • In the web UI, I used Add project on Home to add repo, then repo-copy.

What happened

  • After repo-copy was added, Home's saved selection was /tmp/opencode/clones/repo, and the Projects list showed only repo. It stayed that way after a reload.
  • New session from Home opened a draft whose footer shows /tmp/opencode/clones/repo, not repo-copy (screenshots below).
  • The same happens with the server and the web app run from source on dev.

Two things I could not check. I didn't send a prompt (there are no model credentials here), so the footer path is what shows where the session would run. I also didn't test reloading with a selection already saved as repo-copy, because the add had already replaced it with repo.

The script below reproduces it with Playwright against a running opencode serve.

Related:

  • #62842: same two-clone setup, filed as a request for a warning and a way to change the project's location
  • #55351: the new-session project chip shows the canonical folder for sibling clones
  • #51992 / #51196: new sessions created in the canonical folder or the default location instead of the selected one

Screenshot

Screenshot

Reproduction script (repro.mjs)
// Reproduces anomalyco/opencode#64644 against a real `opencode serve` (v2.2.7) web UI.
// Setup: two plain clones of one repo (same origin) at /tmp/opencode/clones/{repo,repo-copy},
// `opencode serve --port 4096` started from .../repo; its password in /tmp/opencode/pw.
import { chromium } from "playwright"
import fs from "fs"
// SERVER: the opencode server; UI: where the web app is served (same as SERVER for a release,
// or a `vite` dev server of packages/app for a source checkout); PW: file holding the server password.
const url = process.env.SERVER ?? "http://127.0.0.1:4096"
const ui = process.env.UI ?? url
const pw = fs.readFileSync(process.env.PW ?? "/tmp/opencode/pw", "utf8").trim()
const root = "/tmp/opencode/clones"
const b = await chromium.launch()
const ctx = await b.newContext({ viewport: { width: 1400, height: 900 }, recordVideo: { dir: process.env.OUT ?? "/workspace/repro/video" } })
const p = await ctx.newPage()
await p.goto(ui); await p.waitForTimeout(5000)
await p.getByText("Use password").click()
await p.fill("#server-connect-url", url)
await p.fill("#server-connect-password", pw)
await p.getByRole("button", { name: "Connect" }).click()
await p.waitForTimeout(6000)
await p.screenshot({ path: (process.env.OUT ?? "/workspace/repro") + "/connected.png" })
// The vite dev UI also lists a default "This computer" server: select ours.
if (ui !== url) { await p.getByText(new URL(url).host, { exact: true }).first().click(); await p.waitForTimeout(2000) }
const sel = () => p.evaluate(() => Object.entries(localStorage).filter(([k]) => /layout|server/.test(k)).map(([k, v]) => k + " = " + v).join("\n"))
async function add(dir) {
  await p.getByRole("button", { name: "Add project" }).last().click()
  await p.waitForTimeout(800)
  await p.getByPlaceholder(/enter ~\/path/).fill(dir)
  await p.waitForTimeout(800)
  await p.getByRole("button", { name: "Select folder" }).click()
  await p.waitForTimeout(3000)
}
await add(`${root}/repo`)
await p.screenshot({ path: (process.env.OUT ?? "/workspace/repro") + "/after-add-repo.png" })
await add(`${root}/repo-copy`)
await p.screenshot({ path: (process.env.OUT ?? "/workspace/repro") + "/after-add-copy.png" })
console.log("--- storage after adding repo-copy ---\n" + await sel())
console.log("--- body ---\n" + (await p.locator("body").innerText()).slice(0, 800))
await p.goto(ui); await p.waitForTimeout(5000)
await p.screenshot({ path: (process.env.OUT ?? "/workspace/repro") + "/after-reload.png" })
console.log("--- storage after reload ---\n" + await sel())
// Open New session from Home and read which directory the draft uses
await p.getByText("New session").first().click().catch(() => {})
await p.waitForTimeout(3000)
await p.screenshot({ path: (process.env.OUT ?? "/workspace/repro") + "/new-session.png" })
console.log("--- url ---", p.url())
console.log("--- new-session body ---\n" + (await p.locator("body").innerText()).slice(0, 600))
await ctx.close(); await b.close()

Run it: bun repro.mjs

opencodejr[bot] avatar Nov 18 '26 11:11 opencodejr[bot]