Conversation
When Desktop, CLI, or a plugin migrate the shared opencode.db forward, an older binary that opens the same file will now die at startup with a clear error instead of silently proceeding and crashing inside a SQL query handler. The guard computes the set difference (completed IDs in DB) - (known IDs in binary). A non-empty result means the DB was advanced by a newer runtime; Effect.die surfaces the unknown migration IDs and suggests two remedies: upgrade or isolate via OPENCODE_DB. Closes anomalyco#49177 Closes anomalyco#38471 Closes anomalyco#35403
MdTanwer
marked this pull request as ready for review
September 15, 2026 20:11
Why this mattersShared EvidenceTip
Confirms scope — fail fast on DB-ahead-of-binary. Happy to help land as-is. Ask (design, light) — prospective
|
This was referenced Sep 15, 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.
Issue for this PR
Closes #49177
Closes #38471
Closes #35403
Type of change
What does this PR do?
Desktop, CLI (
opencode-aivia npm), and plugins share a single SQLite file (opencode.db). Any runtime that opens the file first can advance the schema via migrations. When an older binary opens the same file afterward, it used to silently succeed at startup and then crash mid-prompt with an opaque SQL error —SQL logic error,no such column: replacement_seq, etc. — depending on which direction the version skew went.The fix is a single guard block added in
applyOnly()insidepackages/core/src/database/migration.ts, placed after the legacy journal seeding and before the apply loop. It computes:If non-empty, the DB was migrated by a newer runtime and this binary can't safely use it. We call
Effect.dieimmediately with a clear message that names the unknown migrations and suggests two remedies: upgrade the binary, or isolate withOPENCODE_DB.This is consistent with how the rest of
apply()handles invalid DB states — two otherEffect.diecalls already exist for different invariants.All three related issues share the same root cause: no check for DB-ahead-of-binary. #49177 was CLI-ahead-of-Desktop, #38471 was Desktop-ahead-of-CLI (specifically the
20260622142730_simplify_session_context_epochmigration that droppedreplacement_seq/revision/agent), and #35403 was CLI-ahead-of-plugin.How did you verify your code works?
bun typecheckinpackages/core→ exit 0Database.node→layerFromPath→layer→DatabaseMigration.apply→applyOnly→ guard fires before any SQL query runsScreenshots / recordings
No UI change.
Checklist