Repository navigation
Description
Description
Summary
Two independent projects whose root directories are two git worktrees of the same bare repo contaminate each other: worktree discovery registers each project's sibling worktree directory (and the bare repo path) into the other, already existing project. Both projects' session lists then show each other's sessions, and opening a session from the wrong project context renders only its title with no messages. The underlying data is fully intact (PRAGMA integrity_check = ok, all message rows present).
Environment
- opencode version: 2.2.2 (desktop app
/Applications/OpenCode.app, background service; the affected sessions date back to app version 1.18.18 and were migrated forward) - OS: Darwin 27.2.0 (darwin arm64), macOS, case-insensitive APFS
- Terminal: Desktop app (OpenCode.app 2.2.2)
- Shell: /bin/bash
- Install/channel: latest
- Active plugins: none
Expected Behavior
- A directory that is already the root of an existing project must not be silently registered as a worktree directory of another project (or, alternatively, the whole repo family should consistently map to exactly one project).
- A session listed in a project should render its messages when opened, or not be listed there at all.
- A bare repo path whose discovery fails (
Worktree.DirectoryUnavailableError— expected for bare repos) probably should not be registered as a project directory at all.
Actual Behavior
project_directorycross-registration between two pre-existing projects, re-created on every discovery pass. Manually deleting the wrong rows only helps until the next discovery.- Session opened from the wrong project context: title only, zero messages rendered — although
session_messageholds 63 intact rows (53 assistant / 9 user / 1 system) andPRAGMA integrity_checkreturnsok. - Log floods with 61 ×
WARN worktree discovery failed ... Worktree.DirectoryUnavailableErrorfor the bare repo path on every discovery pass.
Evidence (redacted, read-only queries against ~/.local/share/opencode/opencode.db):
project_directory rows after discovery (project B root = ~/work/B, project A root = ~/work/A):
project_id directory type
13a2…(B) /Users/<user>/MyWORK/<org>/B main
13a2…(B) /Users/<user>/cm_java/BARE.git
13a2…(B) /Users/<user>/MyWORK/<org>/A git_worktree <-- other project's root
13a2…(B) /Users/<user>/MyWork/<org>/B git_worktree <-- case-variant duplicate of its own root
92c2…(A) /Users/<user>/MyWORK/<org>/A git_worktree (original, correct row)
92c2…(A) /Users/<user>/cm_java/BARE.git
92c2…(A) /Users/<user>/MyWork/<org>/B git_worktree
Note: git records a case-variant worktree path (…/MyWork/… while the actual directory is …/MyWORK/…) on case-insensitive APFS; both variants end up registered as separate directories.
Intact data for the "title only" session:
session_v2: id=ses_116f2ad9effeuXvpDOnfzslXQL, project_id=92c2…(A),
directory=/Users/<user>/MyWORK/<org>/A, created-by-version=1.18.18
session_message: 63 rows (53 assistant, 9 user, 1 system), data JSON fully intact
session_part: 0 rows for ALL sessions on this install (parts are inline in
session_message.data), for reference
Relevant log lines (redacted):
timestamp=2026-10-31T08:04:31.952Z level=INFO message="spawning process"
command=/opt/homebrew/bin/git args=["worktree","list","--porcelain"]
cwd=/Users/<user>/MyWORK/<org>/B role=server
timestamp=2026-10-31T08:05:24.036Z level=WARN message="worktree discovery failed"
directory=/Users/<user>/cm_java/BARE.git error=Worktree.DirectoryUnavailableError role=server
Additional Context
- Workaround attempts that did NOT help: configuring different remote aliases/remotes for the two worktrees. Discovery only follows the local
.gitgitdir pointer (git worktree list), so remote configuration is irrelevant. - Manual cleanup of the wrong
project_directoryrows un-mixes the session lists temporarily; the next discovery pass re-adds them. - The DB file is large (~1.6 GB) but healthy; this is not corruption.
- Real-world setup where this occurred: two long-lived projects developed as sibling worktrees of one shared bare repo, running since app version ~1.18, now on 2.2.2.
Plugins
none
OpenCode version
2.2.2 (desktop)
Steps to reproduce
- Create one bare repo with two worktrees in separate directories:
git init --bare ~/repos/BARE.git git -C ~/repos/BARE.git worktree add ~/work/A main git -C ~/repos/BARE.git worktree add ~/work/B dev
- Open
~/work/Ain OpenCode → project A is created with root~/work/A. Create some sessions. - Open
~/work/B→ project B is created with root~/work/B. - Trigger worktree discovery again (reopen either project, or restart the service). The server runs
git worktree list --porcelainfrom the project directory, which lists ALL worktrees of the repo. - Inspect
project_directoryin~/.local/share/opencode/opencode.db: project B now also contains~/work/A(typegit_worktree) and the bare repo path; project A likewise gained~/work/Band the bare path. - Both projects' session lists now show each other's sessions.
- Open a session that belongs to project A from project B's session list: only the title renders; no messages load.
Screenshot
No response
Operating System
Darwin 27.2.0 (darwin arm64), macOS
Terminal
iTerm2
Activity
opencodejr commentedon Oct 31, 2026
Thanks for the detailed report. I reproduced the cross-registration on 2.2.2 through the server API, and it still happens on the latest
dev(45920000).What I did (the script below runs it):
AandB.A, then added an https remote and openedB. That gave two separate projects.AandBin the database.After the refresh, project A's worktree list contains
B(project B's root), and project B's containsA. Both also containBARE.git, and every refresh of it logsworktree discovery failed … Worktree.DirectoryUnavailableError. As you describe, the rows come back on each refresh. On this version they are stored in theworktreetable.I didn't check the desktop symptoms: the shared session lists and sessions opening with only a title. I also couldn't reproduce the duplicate path that differs only in capitals, since that needs a case-insensitive filesystem like APFS.
Related: #59371 (sessions split across several project rows for one worktree), #58108 (sibling worktrees showing up in the session picker) and #57989 (the same
DirectoryUnavailableErrorlog spam, for non-git folders).Reproduction script (repro.sh)
Run it:
bash repro.shrishikeshgowdakk commentedon Nov 3, 2026
Submitted a fix in #61493 with reproduction unit and integration tests covering bare repository exclusion and foreign worktree pruning.