{"record":{"id":"3678b05169299db8","repo":"thedotmack/claude-mem","slug":"failed-to-drop-dead-columns-from-pending-messages","errorCode":null,"errorMessage":"Failed to drop dead columns from pending_messages","messagePattern":"Failed to drop dead columns from pending_messages","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/services/sqlite/SessionStore.ts","lineNumber":926,"sourceCode":"    const deadColumns = ['retry_count', 'failed_at_epoch', 'completed_at_epoch'];\n    const toDrop = deadColumns.filter(name => colNames.has(name));\n    if (applied && toDrop.length === 0) return;\n\n    if (toDrop.length > 0) {\n      this.db.run('BEGIN TRANSACTION');\n      try {\n        this.db.run(`DELETE FROM pending_messages WHERE status NOT IN ('pending', 'processing')`);\n        for (const colName of toDrop) {\n          this.db.run(`ALTER TABLE pending_messages DROP COLUMN ${colName}`);\n          logger.debug('DB', `Dropped dead column ${colName} from pending_messages`);\n        }\n        if (!applied) {\n          this.db.prepare('INSERT OR IGNORE INTO schema_versions (version, applied_at) VALUES (?, ?)').run(31, new Date().toISOString());\n        }\n        this.db.run('COMMIT');\n      } catch (error) {\n        this.db.run('ROLLBACK');\n        logger.warn('DB', 'Failed to drop dead columns from pending_messages', {}, error instanceof Error ? error : new Error(String(error)));\n        return;\n      }\n      return;\n    }\n\n    if (!applied) {\n      this.db.prepare('INSERT OR IGNORE INTO schema_versions (version, applied_at) VALUES (?, ?)').run(31, new Date().toISOString());\n    }\n  }\n\n  private initializeSchema(): void {\n    this.db.run(`\n      CREATE TABLE IF NOT EXISTS schema_versions (\n        id INTEGER PRIMARY KEY,\n        version INTEGER UNIQUE NOT NULL,\n        applied_at TEXT NOT NULL\n      )\n    `);","sourceCodeStart":908,"sourceCodeEnd":944,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/8bc631a71a487424b866756e43a6efa4574cc66b/src/services/sqlite/SessionStore.ts#L908-L944","documentation":"Migration v31 runs inside a transaction: it deletes finished pending_messages rows (status outside pending/processing) and then drops several dead columns. Any statement failing triggers ROLLBACK and the version marker is not written, so the whole migration retries on next startup. Only the intended cleanup is affected.","triggerScenarios":"Same constraints as any DROP COLUMN: SQLite below 3.35.0, a locked or read-only DB, or a to-drop column pinned by a trigger/view; the DELETE can also fail on FK enforcement, aborting the batch.","commonSituations":"Older bundled SQLite; concurrent worker startups on one DB file; migration racing a long write transaction elsewhere.","solutions":["Read the attached error to identify which statement failed","Upgrade the runtime to SQLite 3.35+ if the error is DROP COLUMN syntax","Guarantee a writable, unlocked DB with a single worker during startup","Confirm completion later: version 31 present in schema_versions and the dead columns absent from PRAGMA table_info(pending_messages)"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"const { v } = db.prepare('SELECT sqlite_version() AS v').get() as { v: string };\nconst [maj, min] = v.split('.').map(Number);\nconst ok = maj > 3 || (maj === 3 && min >= 35);\nif (!ok) {\n  // the v31 transaction will roll back and retry each start; upgrade the runtime\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure the DB is writable and unlocked during worker startup so the transaction can commit","Upgrade SQLite to 3.35+ before expecting dead-column cleanup to stick","Watch schema_versions for version 31 to confirm the migration eventually lands"],"tags":["sqlite","schema-migration","alter-table","transaction-rollback"],"backgroundTag":"sqlite-drop-column-failed","analyzedSha":"8bc631a71a487424b866756e43a6efa4574cc66b","analyzedAt":"2026-08-20T23:58:13.836Z","contentChangedAt":"2026-08-20T23:58:13.836Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}