[OpenCode] fix: Add SQLite support to OpenCode storage scanner#589
Open
DullJZ wants to merge 2 commits intotiann:mainfrom
Open
[OpenCode] fix: Add SQLite support to OpenCode storage scanner#589DullJZ wants to merge 2 commits intotiann:mainfrom
DullJZ wants to merge 2 commits intotiann:mainfrom
Conversation
Author
|
fix issue #576 |
There was a problem hiding this comment.
Findings
- [Major] Rehydrate DB row IDs before emitting OpenCode events — the SQLite queries select
id,session_id, andmessage_id, but the emitted payloads use onlyJSON.parse(...data). OpenCode stores those identifiers in columns, so the launcher receivesmessage.updatedwithoutid/sessionIDandmessage.part.updatedwithoutid/messageID/sessionID;opencodeLocalLauncherthen cannot map roles, dedupe parts, or classify user text correctly. Evidencecli/src/opencode/utils/opencodeStorageScanner.ts:398.
Suggested fix:const info = { ...(JSON.parse(msg.data) as Record<string, unknown>), id: msg.id, sessionID: msg.session_id }; const part = { ...(JSON.parse(partRow.data) as Record<string, unknown>), id: partRow.id, messageID: partRow.message_id, sessionID: partRow.session_id };
- [Major] Keep file fallback active after file-based discovery —
discoverSessionId()can fall back to JSON files when DB lookup fails, butsetActiveSession()andscanMessagesAndParts()switch back to DB whenever the DB opened. That makes compatibility fallback ineffective for an opened-but-incompatible/stale DB and drops the file events that found the session. Evidencecli/src/opencode/utils/opencodeStorageScanner.ts:363.
Suggested fix:type StorageSource = 'database' | 'files'; private activeStorageSource: StorageSource | null = null; if (this.dbReady && this.db) { best = await this.discoverSessionFromDatabase(); if (best) this.activeStorageSource = 'database'; } if (!best && await this.ensureStorageDir()) { best = await this.discoverSessionFromFiles(); if (best) this.activeStorageSource = 'files'; } if (this.activeStorageSource === 'database' && this.dbReady && this.db) { await this.primeSessionFilesFromDatabase(sessionId); } else { await this.primeSessionFilesFromFiles(sessionId); }
Summary
Review mode: initial
- SQLite support currently drops required message/part identifiers and can bypass the JSON fallback after file discovery.
- Missing coverage: no scanner tests for DB-backed messages/parts or DB-present/file-fallback behavior.
Testing
- Not run (automation;
bunis not installed in this runner).
HAPI Bot
There was a problem hiding this comment.
Findings
- [Major] SQLite/file source selection is still not stable. File discovery can still get rebound to DB priming, and seeded
--resumesessions never enter the DB path at all; both leave the scanner on the wrong backend for the rest of the session.
Suggested fix:type StorageSource = 'database' | 'files'; type SessionCandidate = { sessionId: string; score: number; source: StorageSource }; this.activeSessionId = null; if (best) { await this.setActiveSession(best.sessionId, best.source); }
Summary
- Review mode: follow-up after new commits
- Prior identifier rehydration issue is addressed; source selection still has two correctness gaps around DB/file fallback and seeded resume sessions.
- Missing coverage: no scanner tests for DB-present/file-discovered sessions or DB-backed
--resumesessions.
Testing
- Not run (automation; review-only)
HAPI Bot
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.
Files changed: