fix(core): repair chat session thinkingLevel migration

This commit is contained in:
Phil Larson
2026-07-10 20:43:31 -07:00
committed by gsxdsm
parent 93a93450c2
commit 3ef90bc6fe
2 changed files with 52 additions and 1 deletions

View File

@@ -716,6 +716,40 @@ describe("schema migration", () => {
db.close();
});
it("repairs v140 chat_sessions tables missing thinkingLevel", () => {
const db = new Database(fusionDir);
db.exec("CREATE TABLE IF NOT EXISTS __meta (key TEXT PRIMARY KEY, value TEXT)");
db.exec(`
CREATE TABLE IF NOT EXISTS chat_sessions (
id TEXT PRIMARY KEY,
agentId TEXT NOT NULL,
title TEXT,
status TEXT NOT NULL DEFAULT 'active',
projectId TEXT,
modelProvider TEXT,
modelId TEXT,
createdAt TEXT NOT NULL,
updatedAt TEXT NOT NULL,
cliSessionFile TEXT,
inFlightGeneration TEXT,
cliExecutorAdapterId TEXT
)
`);
db.exec("INSERT INTO __meta (key, value) VALUES ('schemaVersion', '140')");
db.exec("INSERT INTO __meta (key, value) VALUES ('lastModified', '1000')");
db.exec(`INSERT INTO chat_sessions (id, agentId, createdAt, updatedAt) VALUES ('chat-legacy', 'agent-1', '2026-07-11T03:40:00.000Z', '2026-07-11T03:40:00.000Z')`);
db.init();
const columns = db.prepare("PRAGMA table_info(chat_sessions)").all() as Array<{ name: string }>;
expect(columns.map((column) => column.name)).toContain("thinkingLevel");
const row = db.prepare("SELECT id, thinkingLevel FROM chat_sessions WHERE id = 'chat-legacy'").get() as { id: string; thinkingLevel: string | null };
expect(row).toEqual({ id: "chat-legacy", thinkingLevel: null });
expect(db.getSchemaVersion()).toBe(SCHEMA_VERSION);
db.close();
});
it("adds deletedAt column + index when migrating from schema version 86", () => {
const db = new Database(fusionDir);
db.exec("CREATE TABLE IF NOT EXISTS __meta (key TEXT PRIMARY KEY, value TEXT)");

View File

@@ -184,7 +184,7 @@ export function isFts5CorruptionError(error: unknown): boolean {
// ── Schema Definition ────────────────────────────────────────────────
const SCHEMA_VERSION = 140;
const SCHEMA_VERSION = 141;
const TASKS_FTS_AUTOMERGE = 8;
const TASKS_FTS_CRISISMERGE = 16;
@@ -1521,6 +1521,7 @@ export const MIGRATION_ONLY_TABLE_SCHEMAS: Record<string, Record<string, string>
projectId: "TEXT",
modelProvider: "TEXT",
modelId: "TEXT",
thinkingLevel: "TEXT",
createdAt: "TEXT NOT NULL",
updatedAt: "TEXT NOT NULL",
cliSessionFile: "TEXT",
@@ -5656,6 +5657,22 @@ export class Database {
});
}
if (version < 141) {
/*
* FNXC:Chat-ThinkingLevelRepair 2026-07-11-03:40:
* Some live project databases reached schemaVersion 140 without the
* chat_sessions.thinkingLevel column, which made POST /api/chat/sessions
* fail with "table chat_sessions has no column named thinkingLevel".
* Re-run the additive column repair under a fresh schema version so
* already-v140 databases converge instead of being skipped forever.
*/
this.applyMigration(141, () => {
if (this.hasTable("chat_sessions")) {
this.addColumnIfMissing("chat_sessions", "thinkingLevel", "TEXT");
}
});
}
}
/**