Skip to content

refactor(T11522): route memory-sqlite.ts brain domain through openDualScopeDb (E6-L2)#899

Merged
kryptobaseddev merged 7 commits into
mainfrom
task/T11522-e6-memory
Jun 1, 2026
Merged

refactor(T11522): route memory-sqlite.ts brain domain through openDualScopeDb (E6-L2)#899
kryptobaseddev merged 7 commits into
mainfrom
task/T11522-e6-memory

Conversation

@kryptobaseddev
Copy link
Copy Markdown
Owner

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

  1. ✅ ALL ensureColumns (~15) removed from memory-sqlite.ts
  2. ✅ ALL raw CREATE TABLE IF NOT EXISTS (~8) removed from memory-sqlite.ts
  3. getBrainDb() delegates open to openDualScopeDb('project', cwd) via the $client facade
  4. ✅ Post-hoc DDL → Drizzle forward migrations (drizzle-brain/20260601000001 brain_task_observations, 20260601000002 transcript/promotion/backfill)
  5. pnpm run typecheck (tsc -b) passes
  6. ✅ Full @cleocode/core suite — zero NEW deterministic failures vs baseline (remaining failures are pre-existing @cleocode/worktree napi env flakes, confirmed on origin/main)

Key design — brain same-name collision

Unlike tasks (legacy tasks ≠ consolidated tasks_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). establishLegacyBrainSchema drops the consolidated target-shape brain tables and runs the legacy drizzle-brain migrations to recreate them in the runtime shape (idempotent via brain_attention.created_at INTEGER-vs-TEXT detection). The consolidated-target cutover stays the exodus's job (T11248 / T11553).

Other changes

  • dual-scope-db.ts: opens with allowExtension: true so sqlite-vec loads on the shared handle
  • closeBrainDb/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 handle
  • Health/scaffold probes retargeted to cleo.db (project-health BRAIN_DB, ensureBrainDb, checkBrainDb)
  • getBrainDbPathresolveDualScopeDbPath('project')

🤖 Generated with Claude Code

kryptobaseddev and others added 7 commits June 1, 2026 00:47
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant