Skip to content

Downgrade v2 → 1.19.0 also breaks: "no such column: project_id" on migrated DB makes all v1 sessions return 500 (still in release, not just dev) #55555

Closed as duplicate

Description

@GeomaticaNet

Descripción

Migrar de 1.19.0 → 2.0.29 (channel latest) y luego volver a 1.19.0 deja la base de datos en un estado híbrido del que la 1.19 no se recupera: todas las sesiones existentes devuelven HTTP 500 Unexpected server error. Check server logs for details. al abrirlas.

Entorno: Linux, bun 1.4.2, opencode serve --service.

Qué hace la v2 que rompe el downgrade

Diff de esquema entre una DB recién creada por 1.19 y la DB tras migrar con la v2 2.0.29:

  1. La v2 reescribió la tabla workspace con un esquema reducido, eliminando columnas que usa la 1.19:

    Esperado por 1.19 Tras migrar con v2
    id, type, name, branch, directory, extra, project_id, time_used id, provider, binding, created_at, last_used_at
  2. Faltan 3 tablas que la 1.19 espera: data_migration, session_context_epoch, session_input.

  3. La DB queda con ambos esquemas conviviendo: session/message/part (v1) + session_v2/session_message/event/event_sequence/session_inbox/session_pending/instruction_*/kv/__drizzle_migrations (v2).

Error que ve el usuario

  • GET /session (listado) funciona.
  • GET /session/:id y GET /session/:id/message → HTTP 500 para TODAS las sesiones viejas (no es un problema de una sesión específica).

Log del servidor 1.19 tras el downgrade:

level=ERROR message=failed error="SQLiteError: no such column: project_id"
  at Project.migrateProjectId
  at Project.fromDirectory
  at InstanceStore.boot
  at InstanceStore.load
  at Server.listen

Causa raíz

Project.migrateProjectId (que corre cada vez que se resuelve un proyecto desde un directorio) ejecuta:

db.delete(workspace).where(eq(workspace.project_id, previousId))
db.update(workspace).set({ project_id: newId }).where(eq(workspace.project_id, previousId))

Como la v2 borró workspace.project_id, SQLite falla en prepare() con no such column: project_id, la excepción marca la petición como fallida y el endpoint responde 500.

Verificado dos veces:

  1. Tras el downgrade real.
  2. Reproducido de forma aislada con opencode serve de 1.19 contra la DB migrada.

Workaround aplicado

Restaurar solo lo que elimina la v2 (cambios aditivos, no destructivos):

CREATE TABLE data_migration (name TEXT PRIMARY KEY, time_completed INTEGER NOT NULL);
CREATE TABLE session_context_epoch (session_id TEXT PRIMARY KEY, baseline TEXT NOT NULL, snapshot TEXT NOT NULL, baseline_seq INTEGER NOT NULL, FOREIGN KEY (session_id) REFERENCES session(id) ON DELETE CASCADE);
CREATE TABLE session_input (id TEXT PRIMARY KEY, session_id TEXT NOT NULL, prompt TEXT NOT NULL, delivery TEXT NOT NULL, admitted_seq INTEGER NOT NULL, promoted_seq INTEGER, time_created INTEGER NOT NULL, FOREIGN KEY (session_id) REFERENCES session(id) ON DELETE CASCADE);
-- + los 3 índices de session_input

ALTER TABLE workspace ADD COLUMN type TEXT NOT NULL DEFAULT 'local';
ALTER TABLE workspace ADD COLUMN name TEXT NOT NULL DEFAULT '';
ALTER TABLE workspace ADD COLUMN branch TEXT;
ALTER TABLE workspace ADD COLUMN directory TEXT;
ALTER TABLE workspace ADD COLUMN extra TEXT;
ALTER TABLE workspace ADD COLUMN project_id TEXT NOT NULL DEFAULT '';
ALTER TABLE workspace ADD COLUMN time_used INTEGER NOT NULL DEFAULT 0;

Con eso, GET /session/:id vuelve a responder 200 y los mensajes cargan completos.

Sugerencias

  1. La v2 no debería reescribir/borrar columnas de tablas compartidas con la v1 (o debería hacerlo de forma reversible).
  2. Idealmente que el downgrade sea soportado, o al menos que la TUI avise antes de actualizar a la v2 si hay sesiones v1 sin migrar de vuelta.
  3. La migración queda marcada como {"phase":"completed"} en la tabla kv (migration.v1-v2), lo que impide reintentarla: no queda forma de "rehacer" la migración desde la UI.

Relacionados

Activity

  1. opencode-agent commented on Oct 14, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed analysis and the workaround SQL. I think this is a duplicate of #42170. That issue has the same SQLiteError: no such column: project_id from Project.migrateProjectId, with the same cause: the v2 workspace migration replaces the workspace table with the provider/binding shape and drops project_id, and then 1.x fails when it tries to remap project IDs.

    Possible duplicates and related issues, ordered from most to least likely:

    It would help to add your 1.19.0 / 2.0.29 confirmation, the additive (non-destructive) workaround and your suggestions to #42170, especially the point that migration.v1-v2 is marked completed in kv and can't be re-run.

    The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different.

  2. opencode-agent commented on Oct 15, 2026

    @opencode-agent
    Contributor

    We haven't heard back, so I'm closing this as a duplicate of #42170. That issue covers the same no such column: project_id failure in Project.migrateProjectId after the v2 migration rewrites the workspace table.

    Please add your 1.19.0 / 2.0.29 details there, along with the additive workaround and your suggestions (a reversible migration, and the migration.v1-v2 kv entry blocking a re-run). That keeps everything in one place.

    If your problem turns out to be different, reply here and we can reopen this issue.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions