From 60cf3169fc209f3fa6e972f3af770fec8b6b6208 Mon Sep 17 00:00:00 2001 From: morpheus9393 <140720045+morpheus9393@users.noreply.github.com> Date: Mon, 6 Jul 2026 01:03:07 +0200 Subject: [PATCH] fix(opencode): merge legacy file sessions and SQLite DB instead of short-circuiting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The OpenCode provider's discoverSessions() short-circuited on legacy file-based JSON sessions (storage/session/*.json) and never fell back to the SQLite DB (opencode.db) when any legacy file existed. This caused migrated installs (which keep stale legacy JSON files from before the OpenCode SQLite migration) to report only a tiny fraction of actual usage — the SQLite DB was silently ignored. Replace the either/or short-circuit with a merge of both sources. Per- message dedup via seenKeys (keyed by provider:sessionId:messageId) prevents double-counting sessions that exist in both stores. Fixes #621 --- src/providers/opencode.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/providers/opencode.ts b/src/providers/opencode.ts index 9e529663..651f3cf0 100644 --- a/src/providers/opencode.ts +++ b/src/providers/opencode.ts @@ -55,13 +55,16 @@ export function createOpenCodeProvider(dataDir?: string): Provider { return toolNameMap[rawTool] ?? rawTool }, - // OpenCode 1.1+ stores sessions as file-based JSON; older builds used a - // SQLite DB. Prefer file-based when present, otherwise fall back to the DB - // so pre-migration installs keep reporting. + // OpenCode migrated from file-based JSON (storage/session/*.json) to a + // SQLite DB (opencode.db). After an in-place upgrade, legacy JSON files + // remain on disk while all new data flows into the SQLite DB. Merge both + // sources so migrated installs keep reporting legacy sessions AND pick up + // current SQLite data. Dedup is handled per-message in createSessionParser + // via seenKeys (keyed by `${provider}:${sessionId}:${messageId}`). async discoverSessions(): Promise { const fileSessions = await discoverOpenCodeFileSessions(resolvedDataDir, 'opencode') - if (fileSessions.length > 0) return fileSessions - return discoverSqliteSessions(sqliteConfig) + const sqliteSessions = await discoverSqliteSessions(sqliteConfig) + return [...fileSessions, ...sqliteSessions] }, createSessionParser(source: SessionSource, seenKeys: Set): SessionParser {