fix: parse OpenCode sessions from SQLite storage (opencode.db)#170
Open
felipetruman wants to merge 1 commit into
Open
fix: parse OpenCode sessions from SQLite storage (opencode.db)#170felipetruman wants to merge 1 commit into
felipetruman wants to merge 1 commit into
Conversation
Newer OpenCode versions migrate the JSON file layout into a single opencode.db SQLite database, which left the parser reading zero sessions. Read the db via the node:sqlite builtin (lazy-loaded and skipped gracefully when unavailable), re-attaching the column-stored ids to the JSON payloads and reusing the existing session assembly. Legacy JSON sessions still win on id collisions.
Author
|
@microsoft-github-policy-service agree |
This was referenced Jul 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Problem
Newer OpenCode versions migrate session storage from the legacy JSON file layout (
storage/session/global/*.json+storage/message/+storage/part/) into a single SQLite database at~/.local/share/opencode/opencode.db. After that migration thestorage/tree is left nearly empty, soparseOpenCodeSessionssilently reports zero OpenCode sessions on any machine running a current OpenCode build.On my machine this meant 1,143 real OpenCode sessions were invisible to the coach while Claude Code and Codex sessions were picked up fine.
Fix
parser-opencode.ts: readopencode.dbvia thenode:sqlitebuiltin (Node >= 22.5). The db stores the same JSON payloads as the legacy files indatacolumns, minus the id fields, which live in dedicated columns — the reader re-attaches them (message.id/session_id,part.id/message_id/session_id) and surfaces the nestedmodel.modelIDas the flatmodelIDthe parser expects. Session rows are plain columns and are mapped to the existingOcSessionshape.assembleOpenCodeSession()and shared by both the legacy JSON path and the new SQLite path, so request building, token accounting, and devcontainer detection stay identical.node:sqliteis loaded lazily viaprocess.getBuiltinModuleand the SQLite source is skipped gracefully when the builtin is unavailable (e.g. older extension hosts). The db is opened read-only and failures fall back to whatever was already parsed, mirroringreadJsonSafe's tolerance.findOpenCodeDirsnow also qualifies an install where onlyopencode.dbexists and thestorage/dir is already gone.Testing
opencode.db(vianode:sqlite) with a user → assistant exchange and asserts sessions, requests, token counts, flat model id, and workspace root are parsed; skips when the builtin is unavailable.tsc --noEmitclean. ESLint: no new errors or warnings inparser-opencode.ts.opencode.db: 0 → 1,143 sessions parsed, with Claude Code and Codex counts unchanged.Related Issues
Fixes #84
Checklist
npm run checkpasses (typecheck + lint + spellcheck + knip + tests) — 1214 tests, cspell 0 issues, knip clean,tsc --noEmitclean, ESLint 0 errorsopencode.db)