Repository navigation
Conversation
OpenCode 2.x reads sessions from session_v2 and session_message, not the legacy session, message, and part tables. The legacy-shaped writes were invisible to session/resume and broke the v1 to v2 migration on every start, because that migration selects a path column the exporter's hardcoded 1.2.x schema never created. The exporter now detects the schema generation before writing. Against session_v2 it writes one session row, session_message rows with parts embedded in a content array, and the event_sequence watermark, mirroring the shapes OpenCode's own migration produces. The whole export runs in a single transaction so a failure cannot leave a partial session row, the directory column is normalized to forward slashes to match the form v2 compares against on lookup, and path is stored as the session directory relative to the git root. The project is resolved from the git root worktree with the global fallback instead of fabricating project rows, and an uninitialized database skips the raw export entirely rather than creating tables OpenCode does not expect.
BambinoSK
requested a deployment
to
fuzzing-gate
October 21, 2026 13:06 — with
GitHub Actions
Waiting
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This branch is waiting to be deployed
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.
Fixes #1198.
Problem
OpenCodeClientExporterexported the agent-switch session intoopencode.dbusing the OpenCode 1.2.x schema (legacysession,message,parttables via raw JDBC). Against OpenCode 2.x the exported sessions were invisible tosession/resume(-32602 session not found, falling back to conversation-history injection), and the plugin-created legacy tables broke v2's boot-time v1 migration on every start (SQLiteError: no such column: path).What this PR does
session_v2table means v2 storage, a legacysessiontable keeps the old 1.x path unchanged, and an uninitialized database skips the raw export entirely instead of fabricating tables OpenCode does not expect.session_v2row,session_messagerows with parts embedded in acontentarray, and theevent_sequencewatermark, mirroring the row shapes OpenCode's own v1-to-v2 migration produces. The whole export runs in a single transaction,directoryis normalized to forward slashes to match the form v2 compares against on lookup,pathis stored as the session directory relative to the git root, and the version string is copied from the newest existing session so exported rows are indistinguishable from native ones.globalid, instead of insertingprojectrows. v2's session lookup is by id plus adirectorycomparison, so this is sufficient forsession/resume.Notes for reviewers
The v2 storage schema is a private internal of OpenCode (no supported import API exists on the ACP or HTTP surface), so this PR keeps the existing coupling but tracks the current shapes; the issue this fixes is exactly the cost of that coupling drifting. The legacy 1.x path is intentionally untouched for older OpenCode installs. Schema details were validated against a live OpenCode 2.0.32 database: row shapes,
event_sequencewatermarks, and project id derivation. Two files changed, +751/-24.Verification
OpenCodeClientExporterTest: 61/61 pass, including new SQLite round-trip tests for the v2 path (session row, message payloads, watermark, no legacy tables created), a legacy-database regression guard, an uninitialized-database skip test, a git-root subdirpathtest, and theglobalproject fallback.:plugin-core:buildPluginsucceeds.session/resumeloads it (previously-32602 session not found), and the newsession_v2row matches native rows in project, directory, version, and message shapes.Closes #1198