Summary
After upgrading from V1 (1.18.30) to V2 (2.0.25), every session previously created in a directory that is not inside a git repository disappears from the TUI and from opencode session list. The sessions are still present and intact in the database; they are orphaned because V2 assigns such a directory a brand-new project instead of reusing the shared global project that V1 used.
This is V1 data becoming unreachable without any error, so it reads as data loss until you inspect the DB.
Environment
- opencode version: 2.0.25 (upgraded from 1.18.30_2)
- OS: Darwin 27.0.0, arm64
- Terminal: Apple_Terminal,
TERM=xterm-256color, COLORTERM=truecolor
- Shell:
/bin/zsh
- Install/channel: homebrew (
brew upgrade opencode), latest channel
- Active plugins:
[email protected]
Reproduction
-
On V1, create sessions in a directory that is not inside a git repository, e.g. ~/src. V1 records these with projectID=global and a path relative to /:
message=created projectID=global directory=/Users/<user>/src path=Users/<user>/src version=1.17.3
-
Upgrade to V2.
-
cd ~/src && opencode session list
-
Open the TUI in the same directory and use /sessions (or Ctrl+O, which shows "recent sessions and projects together").
Expected Behavior
Sessions created before the upgrade stay visible in the directory they were created in. The migration guide states V2 has exactly three intentional breaking changes (plugin API, server API, cli.json) and that other supported V1 functionality is intended to remain compatible, so project resolution for non-git directories should not regress.
Actual Behavior
opencode session list in ~/src returned 1 session, while the database held 225 sessions with directory=/Users/<user>/src.
V1 assigned every session outside a git repo to one shared global project (worktree=/), storing the directory as a path. V2 instead created a new project for ~/src at upgrade time, so those 225 sessions no longer belong to the project the directory now resolves to:
select project_id, count(*) from session_v2
where directory = '/Users/<user>/src' group by project_id;
-- global 225
-- 5137767e095037c6c9e3f72abd56e101fa2a3e0e 1 <- created at upgrade time
The distribution was identical in the pre-upgrade session table, so the migration itself copied the rows correctly — the breakage is in project resolution, not in data migration.
V2 appears to create a project row on demand for any non-git directory it is launched in. Launching a single command in two further directories created two more project rows:
| Directory |
global sessions |
Project after V2 |
~/src |
225 |
5137767e… (new, created at upgrade time) |
~/ |
87 |
b10b62cb… (new) |
/ |
0 |
e22c0bef… (new) |
The global project row still exists, but no directory resolves to it, so the 316 sessions bound to it became unreachable. Sessions in git repositories are unaffected — they kept their project IDs and still list correctly.
A side effect of the same behaviour: ~60 stray project rows were created for arbitrary non-git directories during a single session that ran commands in various directories (e.g. ~/src/assets, ~/src/config, ~/src/layout, ~/src/sections, ~/src/snippets, ~/src/templates).
Additional Context
The regression was observable during the upgrade and was misread as a false alarm. Running the V2 binary at upgrade time, before relaunching the TUI, produced:
session list: EMPTY ... 1.3GB DB of sessions but V2 `session list` shows nothing.
This was then attributed to "~/src itself isn't a project with its own sessions", after other directories happened to list rows — those directories only listed because they are git projects. The post-migration verification consequently reported sessions as verified on the wrong evidence. Worth noting because it makes this a silent regression rather than something a user would catch from a visible error.
Notes on the data:
session_v2.path holds the V1 relative path (Users/<user>/src) and must be cleared when a session's directory becomes its own project root, otherwise it is still filtered out.
- Subagent sessions (
parent_id is not null) are bound to the same project as their parent, and are not listed by session list regardless.
- Numbers here are from a large real database: 373 sessions / 27,959 messages, 316 of them in the orphaned
global project.
Workaround that restored access (applied directly to the database, since no TUI-side control exists for this):
UPDATE session_v2
SET project_id = '<project id whose canonical path is the session directory>',
path = NULL
WHERE project_id = 'global' AND directory = '<session directory>';
After this, opencode session list in ~/src went from 1 to 112 root sessions, and in ~/ from 0 to 39. This is a data repair the user should not have to perform; ideally V2 would fall back to the existing global project for directories without a git root, or migrate global sessions to the project their directory resolves to.