You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This was caused by running a forked dev build (feature/agent-teams) against the production database on both affected machines. The dev build wrote the workspace migration with a different timestamp (1772134200000) than the official release (1772056728000). Due to a known Drizzle migration timestamp ordering bug, when the official v1.2.16 release ran, it skipped the workspace CREATE TABLE migration because a newer timestamp was already recorded -- but the table had never actually been created.
This is not a bug in the official OpenCode releases. However, the underlying Drizzle bug means any contributor testing a local build with divergent migration timestamps will silently corrupt their database.
Workaround: Manually create the missing table (see below) or delete the database and start fresh.
Original issue description (outdated -- kept for reference)
Description
After upgrading to v1.2.17, OpenCode crashes on every startup:
Failed to run the query 'ALTER TABLE `workspace` ADD `type` text NOT NULL;'
Root cause: Migration 20260225215848_workspace (CREATE TABLE workspace) was recorded as applied in __drizzle_migrations during v1.2.16 startup but never actually executed. When v1.2.17 tries to ALTER TABLE workspace (migration 20260303231226_add_workspace_fields), it fails because the table doesn't exist.
Why it failed silently: The exact mechanism is still under investigation. The initial hypothesis was that PRAGMA foreign_keys = ON (set before migrations in db.ts) might cause the CREATE TABLE with a FK constraint to fail silently. However, as discussed in the comments, SQLite FK enforcement only applies to DML operations, not DDL -- so this likely does not explain the failure. The actual cause may be related to how Drizzle's migrator handles errors or how it interacts with databases that have accumulated data over multiple prior versions.
Reproduced on two machines:
Machine
Chip
Result
Mac Studio
Apple M2 Max
Silent migration failure on v1.2.16, crash on v1.2.17
MacBook Pro
Apple M3 Max
Silent migration failure on v1.2.16, crash on v1.2.17
Both machines show the same DB state: migration hash recorded in __drizzle_migrations, but workspace table does not exist. Both databases were built up over several weeks (v1.2.13 through v1.2.15) with real data before hitting v1.2.16.
Additional observation: OpenCode CLI v1.2.15 (installed via Homebrew on the MacBook Pro) still starts fine because it predates the workspace migration entirely (only ships 3 migrations). The bug is only triggered when upgrading through versions that include migration 20260225215848_workspace.
Evidence from DB (MacBook Pro):
__drizzle_migrations: 5 entries (including workspace migration timestamp) -- all "applied"
Workaround: Manually create the table, then start opencode:
cp ~/.local/share/opencode/opencode.db ~/.local/share/opencode/opencode.db.bak
sqlite3 ~/.local/share/opencode/opencode.db "CREATE TABLE \`workspace\` (\`id\` text PRIMARY KEY, \`branch\` text, \`project_id\` text NOT NULL, \`config\` text NOT NULL, CONSTRAINT \`fk_workspace_project_id_project_id_fk\` FOREIGN KEY (\`project_id\`) REFERENCES \`project\`(\`id\`) ON DELETE CASCADE);"
opencode
Suggested fix: Verify DDL execution before recording the migration hash, or add a pre-migration check that detects missing tables whose hashes are already recorded and re-runs them.
Plugins
None
OpenCode version
v1.2.17 (crash) -- silent failure occurred during v1.2.16
Steps to reproduce
Fork the repo and build a local dev build with divergent migration timestamps
Run the dev build against a production database -- migrations are recorded with different timestamps
Upgrade to official v1.2.16 -- Drizzle skips workspace migration (known timestamp ordering bug)
Upgrade to v1.2.17 -- crash on startup
Screenshot and/or share link
Operating System
macOS 15.x (Apple Silicon) -- reproduced on Mac Studio (M2 Max) and MacBook Pro (M3 Max)
Root Cause (resolved)
This was caused by running a forked dev build (
feature/agent-teams) against the production database on both affected machines. The dev build wrote the workspace migration with a different timestamp (1772134200000) than the official release (1772056728000). Due to a known Drizzle migration timestamp ordering bug, when the official v1.2.16 release ran, it skipped the workspaceCREATE TABLEmigration because a newer timestamp was already recorded -- but the table had never actually been created.This is not a bug in the official OpenCode releases. However, the underlying Drizzle bug means any contributor testing a local build with divergent migration timestamps will silently corrupt their database.
Workaround: Manually create the missing table (see below) or delete the database and start fresh.
Original issue description (outdated -- kept for reference)
Description
After upgrading to v1.2.17, OpenCode crashes on every startup:
Root cause: Migration
20260225215848_workspace(CREATE TABLE workspace) was recorded as applied in__drizzle_migrationsduring v1.2.16 startup but never actually executed. When v1.2.17 tries toALTER TABLE workspace(migration20260303231226_add_workspace_fields), it fails because the table doesn't exist.Why it failed silently: The exact mechanism is still under investigation. The initial hypothesis was that
PRAGMA foreign_keys = ON(set before migrations indb.ts) might cause theCREATE TABLEwith a FK constraint to fail silently. However, as discussed in the comments, SQLite FK enforcement only applies to DML operations, not DDL -- so this likely does not explain the failure. The actual cause may be related to how Drizzle's migrator handles errors or how it interacts with databases that have accumulated data over multiple prior versions.Reproduced on two machines:
Both machines show the same DB state: migration hash recorded in
__drizzle_migrations, butworkspacetable does not exist. Both databases were built up over several weeks (v1.2.13 through v1.2.15) with real data before hitting v1.2.16.Additional observation: OpenCode CLI v1.2.15 (installed via Homebrew on the MacBook Pro) still starts fine because it predates the workspace migration entirely (only ships 3 migrations). The bug is only triggered when upgrading through versions that include migration
20260225215848_workspace.Evidence from DB (MacBook Pro):
__drizzle_migrations: 5 entries (including workspace migration timestamp) -- all "applied"workspacetable: does not existsessiontable: hasworkspace_idcolumn (migration tweak: glob should be able to read certain hidden files/dirs #5 succeeded -- simple ALTER, no FK)Log timeline (MacBook Pro):
workspacetable not createdALTER TABLE workspacefailsMigration #4 SQL (
20260225215848_workspace/migration.sql):Workaround: Manually create the table, then start opencode:
Suggested fix: Verify DDL execution before recording the migration hash, or add a pre-migration check that detects missing tables whose hashes are already recorded and re-runs them.
Plugins
None
OpenCode version
v1.2.17 (crash) -- silent failure occurred during v1.2.16
Steps to reproduce
Screenshot and/or share link
Operating System
macOS 15.x (Apple Silicon) -- reproduced on Mac Studio (M2 Max) and MacBook Pro (M3 Max)
Terminal
zsh (Homebrew Cask install)