Repository navigation
Conversation
The V1 session importer copies legacy rows into session_v2 with a fixed column list that includes path, metadata, cost, tokens_*, agent, and model. V1 databases last migrated before those columns were added fail the whole migration with SQLiteError: no such column: path on every startup, leaving the migration.v1-v2 marker stuck in the sessions phase. Read the legacy session table's columns with pragma_table_info and copy only the columns it actually has, letting session_v2 defaults fill the rest, mirroring how opencode-next.db imports already project missing nullable columns. Fixes anomalyco#54009
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: |
There was a problem hiding this comment.
This looks good. I ran the reproduction script from #54009 against the CLI from source. On the base branch, every start logs no such column: path and the marker stays at sessions. With this change the migration completes, the legacy session is copied into session_v2 with defaults for the missing columns, and the marker reaches completed. The v1-migration tests (27 pass) and the packages/core typecheck both pass.
I also checked that session_v2.permission is nullable with no default, so leaving it out still clears V1 permission state as before. Column names come from a fixed list, are filtered against pragma_table_info and are quoted with sql.identifier. I have no concerns.
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Issue for this PR
Closes #54009
Type of change
What does this PR do?
The V1→V2 data migration fails on every startup with
SQLiteError: no such column: pathwhen the legacysessiontable predates newer columns. The per-session transaction (including the cursor checkpoint) rolls back, themigration.v1-v2marker stays stuck in thesessionsphase, and the import is retried and fails again on every server start.Root cause:
v1-migration.bun.tscopies each legacy row intosession_v2with a fixedINSERT ... SELECTcolumn list that unconditionally referencespath,metadata,cost,tokens_*,agent, andmodelon the source table. V1 databases last migrated before those columns were added do not have them, so statement preparation fails. Theopencode-next.dbimport already handles this class of problem throughselectNextRows(pragma-based column projection); the legacy copy had no equivalent.The fix reads the legacy
sessiontable's columns withpragma_table_infobefore the copy loop and builds theINSERT ... SELECTfrom only the columns the table actually has. Missing columns are omitted from the insert sosession_v2defaults fill them (cost/tokens_*default to0, nullable columns toNULL).permissionwas previously inserted explicitly asNULLand now falls back to its default, preserving the intentional clearing of V1 permission state.How did you verify your code works?
imports legacy V1 sessions from tables missing newer columns) that creates a legacysessiontable withoutpath,metadata,cost,tokens_*,agent, andmodel— the shape observed in the issue — with one session, message, and part row. It verifies the migration completes,session_v2receives defaults for the missing columns with agent/model derived from message data, the projectedsession_messagerow is written, and the marker reaches{"phase":"completed"}.packages/core/test/v1-migration.test.tsrun: 27 pass, 0 fail.bun typecheckinpackages/corepasses.Note: the local pre-push
bun run checkcould not run on Windows because oxlint fails to load its TypeScript plugin via Node ESM (Unknown file extension ".ts"); that failure is environmental and unrelated to this change.Screenshots / recordings
Not a UI change.
Checklist