anomalyco / anomalyco/opencode
/sessions returns empty despite sessions existing in database (workspace_id = NULL, empty workspace table)
@rekram1-node is already working on this.
Since Jul 22, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
Environment
- OpenCode 1.18.4 (npm)
- Linux / WSL2
- 7 sessions, 281 messages, 893 parts in DB
Steps
- Create multiple sessions over time in a workspace directory
- Run /sessions
- Shows "no sessions" but SELECT COUNT(*) FROM session returns 7
Root Cause
1. All sessions have workspace_id = NULL, workspace table empty
All 7 sessions have workspace_id=NULL. Workspace table has 0 rows.
Migration 20260227213759_add_session_workspace_id added FK column without backfill.
2. V2 state tables all empty
session_message: 0 rows, session_input: 0 rows, session_context_epoch: 0 rows
But message: 281 rows, part: 893 rows, all with valid session_id FKs.
Migration reset_v2_session_state cleared v2 tables without migrating legacy data.
3. Event table uses aggregate_id not session_id
If session listing joins on session_id against events, it fails.
Fix Suggestions
Short-term
Session listing should fall back to directory matching when workspace_id is NULL:
function listSessions(dir) {
let sessions = db.sessions.where({ workspace_id: currentWorkspaceId });
if (!sessions.length) sessions = db.sessions.where({ workspace_id: null, directory: dir });
if (!sessions.length) sessions = db.sessions.all();
return sessions;
}
Medium-term
Backfill workspace entries and link orphaned sessions via SQL migration.
Long-term
Ensure workspace exists and is linked at session creation time.
Impact
Sessions inaccessible via /sessions, /resume, /continue despite intact data.
Database inspection (via sqlite3) shows three compounding issues:
-
All 7 sessions have workspace_id = NULL. The workspace table is
empty (0 rows). Migration 20260227213759_add_session_workspace_id
added the FK column without backfilling existing data. -
V2 state tables (session_message, session_input, session_context_
epoch) are all 0 rows. But the message table has 281 rows and the
part table has 893 rows, all with valid session_id FKs. Migration
reset_v2_session_state cleared v2 tables without migrating legacy data. -
The event table uses aggregate_id not session_id. If /sessions joins
on session_id against events, it will fail silently.
Fix: /sessions should fall back to directory-based matching when
workspace_id is NULL, so sessions are always discoverable regardless
of workspace migration state.
Plugins
none
OpenCode version
1.18.4
Steps to reproduce
- cd /home/samuel/Documents/Opencode\ Workspace
- opencode
- Create a session and do some work
- Quit and restart, or open a new session with /new
- Run /sessions
- Result: reports "no sessions"
- But sqlite3 ~/.local/share/opencode/opencode.db "SELECT COUNT(*) FROM session" returns 7
The bug is consistent — happens every time /sessions is invoked.
Screenshot and/or share link
No response
Operating System
Debian GNU/Linux 13 (trixie), x86_64, kernel 6.12.95
Terminal
xfce4-terminal (xterm-256color, X11)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.