Skip to content

fix(schema): kg_entities.attributes + vec dim guard + ESM __dirname + user_version - #18

Merged
totobusnello merged 1 commit into
mainfrom
fix/lane3-schema-runtime
Jun 16, 2026
Merged

totobusnello merged 1 commit into
mainfrom
fix/lane3-schema-runtime

Conversation

@totobusnello

Copy link
Copy Markdown
Owner

Verified pre-launch schema/runtime fixes (review swarm lane 3).

  • P0 kg_entities was created without an attributes column → kg-extract/kg-build crashed (no column named attributes, via index.ts INSERT) on every clean install. Added the column to the CREATE + idempotent ALTER for existing DBs. Confirmed via PRAGMA table_info(kg_entities).
  • P1 vec dim mismatch: switching embedding provider (e.g. 3072→1536) on an existing DB silently crashed inserts. Added a pre-create dim check that throws an actionable error.
  • P1 embed.ts used __dirname (undefined in ESM) as the sqlite-vec fallback → ReferenceError if the optional dep was missing. Now uses fileURLToPath(import.meta.url).
  • P1 PRAGMA user_version was never set (stayed 0) → pragma-alignment test failed, op-audit recorded 0. Now set to SCHEMA_VERSION at end of ensureSchema.

Build clean; ingest+search smoke passed.

[P0] kg_entities: add attributes TEXT to CREATE TABLE + idempotent ALTER
 after the CREATE block so existing DBs created pre-fix also get the column.
 Without this, `kg-extract`/`kg-build` crashed "no column named attributes"
 on every fresh install because migrateToV7 ran before ensureGraphTables.

[P1] ensureVecTable: detect embedding dim mismatch before IF NOT EXISTS.
 If vec_chunks already exists with a different dim, throw a clear actionable
 error instead of a cryptic vec0 crash on the first INSERT after a provider
 switch (e.g. Gemini 3072d → OpenAI 1536d).

[P1] embed.ts: fix __dirname ReferenceError in ESM fallback path.
 import.meta.dirname is undefined on Node 20 LTS; fallback was __dirname
 which is NOT defined in ESM. Replaced with dirname(fileURLToPath(import.meta.url))
 and added the required node:path/node:url imports.

[P1] db.ts ensureSchema: set PRAGMA user_version = SCHEMA_VERSION after
 migrations so pragma-alignment tests pass and op-audit records correct value.

Build: tsc clean (exit 0). Smoke: ingest + stats OK, kg_entities schema
confirmed (id,name,entity_type,attributes,...), user_version=18.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@totobusnello
totobusnello merged commit 8dc2259 into main Jun 16, 2026
1 check passed
@totobusnello
totobusnello deleted the fix/lane3-schema-runtime branch June 16, 2026 19:43
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