refactor(T11522): route memory-sqlite.ts brain domain through openDualScopeDb (E6-L2)#899
Merged
Conversation
…lScopeDb + DDL→Drizzle migrations (E6-L2)
- getBrainDb() delegates open to openDualScopeDb('project') facade (mirrors L1)
- getBrainDbPath() -> resolveDualScopeDbPath('project') (.cleo/cleo.db)
- strip ~15 ensureColumns + ~8 raw CREATE TABLE band-aids from runBrainMigrations
- add brain_task_observations forward migration (only genuinely-uncovered table)
- dual-scope-db opens with allowExtension:true (sqlite-vec on shared handle)
- closeBrainDb/resetBrainDbState evict dual-scope cache
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…d deriver_queue into forward migration (E6-L2) Running the full legacy drizzle-brain folder against the consolidated cleo.db collides: cross-migration rename chain (t1147 brain_v2_candidate -> t1402 RENAME TO brain_observations_staging) hits the final table consolidation already made. Consolidated schema is the brain SSoT; forward migration now adds the only two runtime-legacy tables consolidation skipped (brain_task_observations + unprefixed deriver_queue). Removed runBrainMigrations + now-unused migration-manager imports. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…leo.db contract brain.db-file malformation recovery no longer wired into getBrainDb (brain domain moved to cleo.db; brain-only snapshot-restore would corrupt co-resident domains). recoverMalformedBrainDb primitive still unit-tested in recover-brain-db.test.ts. New contract: getBrainDbPath->cleo.db, getBrainDb opens cleo.db w/ runtime-legacy tables, malformed standalone brain.db is irrelevant + untouched. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…safely (E6-L2) Root cause: consolidated brain_* tables are the exodus-TARGET shape (ISO-8601 text timestamps + enum/format CHECK constraints) — incompatible with the runtime brainSchema (epoch-ms integers). Unlike tasks (legacy 'tasks' != 'tasks_tasks'), brain names collide. Fix: establishLegacyBrainSchema drops the consolidated brain tables and runs legacy drizzle-brain migrations to recreate them in runtime shape. Added forward migrations for brain_task_observations + the 3 inline-only tables (brain_transcript_events/promotion_log/backfill_runs) that had no drizzle-brain migration. closeBrainDb/resetBrainDbState no longer tear down the shared dual-scope handle (broke tasks domain). Liveness guard re-derives brain singleton when the shared handle was closed by the tasks side. Updated 2 migration tests to cleo.db. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…test for shared handle (E6-L2) - establishLegacyBrainSchema restores foreign_keys pragma to pre-drop state (was leaving it OFF, breaking the T10314 idempotent-pragma contract) - memory-schema reset test asserts the new shared-handle contract: reset clears the brain singleton (new drizzle wrapper) but keeps the shared dual-scope cleo.db handle alive (co-owned by tasks domain) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- project-health.ts: BRAIN_DB -> cleo.db (dbs.brain probe targets the shared consolidated DB); collapse DB_EXPECTED_VERSIONS to single cleo.db floor - scaffold/ensure-dirs.ts ensureBrainDb: idempotency probe via getBrainDbPath (cleo.db) so re-scaffold reports skipped not always-created - scaffold/project-detection.ts checkBrainDb -> cleo.db - scaffold-characterization tests updated to cleo.db (mirrors L1) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
E6-L2 (T11522) — brain domain store rewrite
Routes the BRAIN domain through the dual-scope chokepoint, mirroring the tasks facade (E6-L1, #884).
Acceptance criteria
ensureColumns(~15) removed frommemory-sqlite.tsCREATE TABLE IF NOT EXISTS(~8) removed frommemory-sqlite.tsgetBrainDb()delegates open toopenDualScopeDb('project', cwd)via the$clientfacadedrizzle-brain/20260601000001brain_task_observations,20260601000002transcript/promotion/backfill)pnpm run typecheck(tsc -b) passes@cleocode/coresuite — zero NEW deterministic failures vs baseline (remaining failures are pre-existing@cleocode/worktreenapi env flakes, confirmed on origin/main)Key design — brain same-name collision
Unlike tasks (legacy
tasks≠ consolidatedtasks_tasks, co-exist), the brain tables were already domain-prefixed, so legacy and consolidated share the SAME physical names with INCOMPATIBLE shapes (consolidated = exodus-target ISO-8601 + CHECK constraints; runtime = epoch-ms integers).establishLegacyBrainSchemadrops the consolidated target-shape brain tables and runs the legacydrizzle-brainmigrations to recreate them in the runtime shape (idempotent viabrain_attention.created_atINTEGER-vs-TEXT detection). The consolidated-target cutover stays the exodus's job (T11248 / T11553).Other changes
dual-scope-db.ts: opens withallowExtension: trueso sqlite-vec loads on the shared handlecloseBrainDb/resetBrainDbState: no longer tear down the SHARED dual-scope handle (broke the tasks domain); liveness guard re-derives the brain singleton when the tasks side closed the handlecleo.db(project-healthBRAIN_DB,ensureBrainDb,checkBrainDb)getBrainDbPath→resolveDualScopeDbPath('project')🤖 Generated with Claude Code