Skip to content

Missing migration for project_state.updated_at breaks all transforms on pre-existing DBs (SQLiteError: no such column: updated_at, MC-S06 refusals) #628

Description

@procodingtools

Short description

getProjectState() in 0.44.4/0.45.0 selects an updated_at column that only exists in fresh installs (CREATE TABLE IF NOT EXISTS). No ALTER TABLE/ensureColumn migration ships for pre-existing context.db files, so every transform throws SQLiteError: no such column: updated_at and turns get hard-refused with MC-S06 DegradedPassRefusalError. Fix: add ensureColumn(db, "project_state", "updated_at", "INTEGER NOT NULL DEFAULT 0") to the migration path. Workaround: run that ALTER TABLE manually (verified working).

What happened?

On any context.db created before the updated_at column was added to
project_state, every transform that reads project state fails with:

SQLiteError: no such column: updated_at
    at prepare (bun:sqlite)
    at getProjectState (…/dist/index-16ny736w.js)
    at getGlobalUserProfileVersion / readCurrentM0SnapshotMarkersUncached / materializeM0 / injectM0M1 …

The degraded pass then refuses the turn outright:

v2 refusal: interrupting the turn before the provider request arm=blocking-transform-error
cause="DegradedPassRefusalError: This request was not sent: Magic Context could not finish preparing it … (MC-S06)"

Observed on 0.44.4 and 0.45.0 (latest at time of report). In our logs
the error fired 2,000+ times across two days, with 3 hard MC-S06 blocks in one
day — opencode looked completely dead to the user.

Root cause

getProjectState() unconditionally selects the new column:

SELECT project_path, project_memory_epoch, project_user_profile_version, updated_at
FROM project_state WHERE project_path = ?

Fresh installs are fine because the base schema
(CREATE TABLE IF NOT EXISTS project_state (…)) includes
updated_at INTEGER NOT NULL DEFAULT 0. But there is no migration that adds
the column to existing databases
— no ALTER TABLE project_state … and no
ensureColumn(db, "project_state", "updated_at", …) anywhere in the dist bundle
(the ensureColumn helper exists and is used ~300 times for other tables, just
never for this one). Old DBs keep the 3-column table:

0|project_path|TEXT|0||1
1|project_memory_epoch|INTEGER|0|0|0
2|project_user_profile_version|INTEGER|0|0|0

The schema migrations table confirms the DB is fully migrated (v94, latest) —
the migration simply doesn't exist.

Suggested fix

Add the same one-liner used for every other late-added column, e.g. in the
migration/startup path:

ensureColumn(db, "project_state", "updated_at", "INTEGER NOT NULL DEFAULT 0");

Workaround (for anyone hitting this now)

sqlite3 /root/.local/share/cortexkit/magic-context/context.db \
  "ALTER TABLE project_state ADD COLUMN updated_at INTEGER NOT NULL DEFAULT 0;"

(back up context.db first — verified to fully resolve the failures, including
the MC-S06 refusals, with no restart required)

Environment

  • @cortexkit/opencode-magic-context@0.45.0 (also reproduced on 0.44.4)
  • opencode v2.0.24, Linux, bun:sqlite backend
  • DB at ~/.local/share/cortexkit/magic-context/context.db (~217 MB, migrations through v94)

Diagnostics

Plugin version

0.55.0

OpenCode version

2.0.24

Platform

No response

Client

Unknown

Log output (optional)

Activity

  1. magic-alfonso commented on Oct 7, 2026

    @magic-alfonso

    Thanks for the detailed report, and for posting the workaround.

    I checked how project_state has been created across Magic Context's history. The table arrived with migration v22, and every path that creates it (the base schema, the v22 migration and the startup setup) has always created it with updated_at. No later migration rebuilds or alters the table. So no released version should produce the three-column table you saw, and I'd like to find out what created it before shipping a repair.

    Could you share three things?

    1. The table definition SQLite stored. After your ALTER TABLE it will show the extra column at the end, which is fine:
      sqlite3 ~/.local/share/cortexkit/magic-context/context.db "SELECT sql FROM sqlite_master WHERE name='project_state'"
    2. When the early migrations ran:
      sqlite3 ~/.local/share/cortexkit/magic-context/context.db "SELECT version, description, datetime(applied_at/1000,'unixepoch') FROM schema_migrations WHERE version <= 24 ORDER BY version"
    3. Whether anything other than Magic Context has written to this context.db: another tool, a script, a fork, or an agent running SQL. Also, which Magic Context version did you first install?

    The form also says plugin version 0.55.0, which doesn't exist. I assume it's 0.45.0, as in your report.

    With the column added, that database shouldn't hit this again.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions