projects: v2.2.5 creates a second project record for an existing worktree, hiding older sessions from the session list
Summary
Upgrading v2.2.1 → v2.2.5 made OpenCode derive a different project ID for an existing worktree, creating a second project record for the same directory. Sessions created during the v2.2.5/v2.2.6 period — and, it appears, all pre-existing sessions of that directory (their project_id was re-pointed to the new project) — stayed attached to the temporary project. After upgrading to v2.2.7, project resolution went back to the original ID, so the project-scoped session list (opencode session list, TUI session picker) shows only the sessions created after the 2.2.7 upgrade; the entire older history becomes invisible.
Environment
- opencode version: 2.2.7 (issue observed across 2.2.1 → 2.2.5 → 2.2.6 → 2.2.7)
- OS: Darwin 25.6.0 (darwin arm64)
- Terminal: iTerm2 (TERM=xterm-256color, COLORTERM=truecolor)
- Shell: /bin/zsh
- Install/channel: latest
- Active plugins: none in config
Reproduction
- Use OpenCode v2.2.1 in a git project directory; accumulate sessions over days (~160 in my case).
- Upgrade to v2.2.5 and start OpenCode in the same directory.
→ A new
projectrow is created for the same worktree path (DBprojectthen contains two rows with identicalworktree); existing sessions of that directory are re-pointed (session_v2.project_id) to the new project. - Keep using v2.2.5/v2.2.6; new sessions land in the temporary project.
- Upgrade to v2.2.7: project resolution returns to the original (v2.2.1-era) project ID and the original
projectrow is reused for new sessions. - Run
opencode session list(or open the TUI session picker): only the step-4 sessions are listed; the older sessions (in my case 162) are missing because they still reference the orphaned project.
Expected Behavior
A worktree resolves to a single stable project across versions. When re-derivation happens, existing sessions are re-pointed to the resolved (original) project so the session list keeps showing the full directory history.
Actual Behavior
projecttable: two rows for the same worktree — original created 2026-09-28 (v2.2.1 era), temporary created at first v2.2.5 start, 2026-11-05 22:10 UTC.session_v2.project_id: 162 sessions (created 2026-09-28 → 2026-11-10) reference the temporary project, including sessions created before that project row existed — i.e. they were re-pointed on Nov 5, not written under it at creation time.- After the v2.2.7 upgrade (2026-11-10 18:28 UTC) new sessions reference the original project again; the 162 were not re-pointed back.
opencode session list("List top-level sessions in the current project") returned 4 sessions instead of 77.- Directory-scoped
GET /api/session?directory=…still returned all sessions, confirming the data is intact and only project scoping hides it.
Server log evidence (UTC), from ~/.local/share/opencode/log/opencode.log:
- 2026-11-05 22:10 (first v2.2.5 start,
background service starting reason=missing): location boot for the directory rangit rev-parse --git-dir --git-common-dir --show-toplevelandgit remote get-url origin(nooriginremote is configured in the repo), after which snapshot paths switched from~/.local/share/opencode/snapshot/<original-id>/…to~/.local/share/opencode/snapshot/<temporary-id>/…. - 2026-11-10 18:28 (upgrade 2.2.6 → 2.2.7,
reason=version-mismatch): snapshot paths and new sessions reverted to the original project ID.
Additional Context
- Workaround applied manually (for reference, DB was backed up first, service kept running, SQLite WAL):
UPDATE session_v2 SET project_id='<original>' WHERE project_id='<temporary>';plus archiving the orphanedprojectrow and deleting its duplicateworktreerow. Afterwardsopencode session listshows the full history. - Frequency: consistent — the whole pre-2.2.7 session history was hidden from project-scoped lists until the manual fix.
- Suggested server-side fix: when the derived project ID for a directory matches no existing row, check for an existing row with the same worktree and reuse it (or re-point that directory's sessions to the matching row) instead of creating a second project record.
Thanks for the detailed report and the database evidence. I couldn't reproduce this.
What I tried, each time with a fresh, isolated data directory: a git repo with no remote and some sessions on 2.2.1, then upgrades to 2.2.5, 2.2.6 and 2.2.7, creating new sessions after each upgrade and running opencode session list. I did this with a private server (--standalone), with the shared background service, and with a linked git worktree as the working directory. Every time the worktree kept a single project row, no session changed project_id, and opencode session list showed every session.
The project ID logic looks the same in 2.2.1, 2.2.5 and 2.2.7. When there is no remote, the ID is normally the repository's root commit. So the switch on Nov 5 probably depends on something about your repository. These would help narrow it down (no need to share the IDs themselves):
- Does
git rev-list --max-parents=0 HEADin that directory print more than one commit? Does either the original or the temporary project ID match one of them? - Is the directory the main checkout, a linked worktree (
git worktree list) or a submodule? Is there a file namedopencodeinside the git directory (git rev-parse --git-common-dir)? git remote -v: is any remote configured, even one that isn't calledorigin?- Did anything change in the repo around Nov 5: a history rewrite, a merge of unrelated histories, a re-clone, or a move of the folder?
Related issues, in order of how closely they match:
- #59371: a worktree with two
projectrows hides sessions from the folder's list (same symptom; PR #59946 would list both rows' sessions). - #57985: adding a git remote changes the project ID and hides earlier sessions.
- #60857: session diffs fail after a project ID change, because snapshots are stored by project ID.
I'm closing this issue for now because I couldn't reproduce it. On 2.2.1 → 2.2.5 → 2.2.6 → 2.2.7, with a private server, the shared background service and a linked git worktree, each directory kept a single project row and opencode session list showed every session. I was waiting for details about your repository to find what made it switch to a second project ID: more than one root commit, a linked worktree or submodule, a remote not named origin, an opencode file in the git directory, or a history change around Nov 5. Without them I can't narrow it down.
If it happens again, or you can share those details, please reply here and the issue will reopen. Related issues: #59371 (one worktree with two project rows hides sessions; PR #59946) and #57985 (adding a git remote changes the project ID).