Skip to content

ci(core): reject downgrade-incompatible database migrations #33898

Closed as not planned

Description

@opencode-agent

Problem

Core database migrations can currently make the user database incompatible with older OpenCode binaries. This breaks downgrade/recovery workflows and version-skewed installs that share the same database.

A recent example is #33378, whose 20260622142730_simplify_session_context_epoch migration dropped:

  • session_context_epoch.agent
  • session_context_epoch.replacement_seq
  • session_context_epoch.revision

After v1.17.10 applies that migration, downgrading to v1.17.9 can fail with SQLiteError: no such column: replacement_seq.

The existing bun packages/core/script/migration.ts --check verifies generated schema/registry consistency, but does not detect backward-incompatible schema changes. Related version-skew failures have also been reported in #31204.

Proposal

Add a migration compatibility check to CI, preferably as part of packages/core/script/migration.ts --check:

  1. Inspect only migrations added by the PR (grandfather existing migration history).
  2. Apply each new migration to the previous schema and compare sqlite_master, pragma_table_info, indexes, and foreign keys before/after.
  3. Fail when an existing table or column is removed or renamed, or when a change makes old writers incompatible (for example, adding a required column without a compatible default).
  4. Statically reject obvious destructive SQL such as DROP COLUMN, DROP TABLE, and table/column renames so failures have a clear message.
  5. Provide an explicit, narrowly scoped compatibility escape hatch for intentionally destructive migrations, requiring review and rationale.

The default migration policy should be expand-contract: stop reading/writing obsolete fields first, but retain their physical columns and compatible defaults for the supported downgrade window.

Acceptance criteria

  • A PR containing ALTER TABLE ... DROP COLUMN ... in a new Core migration fails CI by default.
  • The failure explains that newer databases must remain usable by the supported previous OpenCode version(s).
  • Existing historical migrations do not fail the new check.
  • An explicit reviewed override exists for intentional compatibility breaks.
  • Ideally, CI also includes a smoke test that upgrades a database with the candidate build and then runs the previous released binary against it.

cc @kitlangton

Activity

  1. github-actions commented on Jun 25, 2026

    @github-actions
    Contributor

    This issue doesn't fully meet our contributing guidelines.

    What needs to be fixed:

    • This appears to be a feature/CI improvement request but does not use the Feature Request template. Feature request titles should start with [FEATURE]: and include the required verification checkbox confirming the issue hasn't already been filed.

    Please edit this issue to address the above within 2 hours, or it will be automatically closed.


    This issue might be a duplicate of existing issues. Please check:

    If you believe this was flagged incorrectly, please let a maintainer know.

  2. eersnington commented on Jun 25, 2026

    @eersnington

    Very good clanker.

    I ran into this in a wonderful way. I have opencode excluded from my minimum release requirement within my root bunfig toml and I installed the latest version of opencode. but it didn't install the binaries for macos due to this post install issue i've referenced a while back #30812 (my .npmrc also has a minimum release age set and npm doesnt support exclusions so opencode binaries fail to install that way).

    then I've downgraded to 1.17.9 and then ran into this issue where if I send a message, wait for a response, and then switch mode, and then message again, it crashes with "replacement_seq" sqlite error

    Image
  3. github-actions commented on Jun 25, 2026

    @github-actions
    Contributor

    This issue has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

    Feel free to open a new issue that follows our issue templates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions