You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Sessions orphaned when git repo is initialized in existing opencode directory #16812
Sessions created before a git repository has commits are stored under project_id = "global". When a commit is made and opencode resolves a real project ID (the root commit SHA), the migrateFromGlobal() function is supposed to reassign those sessions but it fails silently.
Root cause
migrateFromGlobal() in project.ts has two bugs:
FK constraint violation: It runs before the target project row is inserted into the project table. The session.project_id column has a foreign key constraint referencing project.id, so the UPDATE is rejected. The .catch() handler on the work() call swallows the error silently.
One-shot gate: It only runs inside the if (!row) branch — i.e., the first time a project ID row is created. Sessions that accumulate under "global" after the real project row already exists are never migrated.
Expected behavior
Sessions created before git init / first commit should appear in the session list after the project transitions from "global" to a real project ID.
Plugins
No response
OpenCode version
1.2.24
Steps to reproduce
In an empty directory (eg mkdir /tmp/test && cd /tmp/test)
Start opencode, chat, create one or more sessions, exit opencode
This issue might be a duplicate of existing issues. Please check:
After upgrading to OpenCode v1.2.21, previous sessions disappear from the TUI session list. #16579: Same root cause — migrateFromGlobal() silently failing to reassign sessions from project_id = "global" to a real project ID. That issue was triggered by upgrading to v1.2.21, while this one is triggered by initializing git after sessions already exist, but the underlying bug appears identical.
manually updating the affected session.project_id rows from global to the new project id made the missing chats reappear immediately
So this is not only a "git init after sessions already exist" case. The same global -> project migration path can fail in normal use and orphan visible history.
Activity
github-actions commentedon Mar 9, 2026
This issue might be a duplicate of existing issues. Please check:
migrateFromGlobal()silently failing to reassign sessions fromproject_id = "global"to a real project ID. That issue was triggered by upgrading to v1.2.21, while this one is triggered by initializing git after sessions already exist, but the underlying bug appears identical.opencode sessionscommand fails to list historical sessions when run inside a Git repository #15678: Related — sessions not visible when running inside a git repo due to project ID mismatch.c-w-xiaohei commentedon Mar 11, 2026
I hit the same underlying bug on v1.2.21 (Linux/WSL, desktop app) with an existing repo at
/home/c_w_xiaohei/workspace.What happened:
project_id = "global"to the new project id.FOREIGN KEY constraint failedand loggedfailed to migrate sessions from global to project.globaland the new project id, so the session list looked like history had disappeared.Local evidence:
~/.local/share/opencode/log/2026-03-11T180424.logsession.project_idrows fromglobalto the new project id made the missing chats reappear immediatelySo this is not only a "git init after sessions already exist" case. The same
global -> projectmigration path can fail in normal use and orphan visible history.-- by OpenCode, after local investigation
fix: migrate sessions from global to git project after init