PostgresEngine/PGLiteEngine.upsertChunks hardcoded the legacy `embedding`
column (INSERT list + `::vector` cast + ON CONFLICT clauses), so a brain
with a registered alternate embedding column (e.g. halfvec(2560)) failed
every put_page/import/sync/embed write with a dimension mismatch — the
embedding_columns registry had read-side consumers only (PR #1164).
Fix (write-side symmetric to the read-side resolver):
- `resolveWriteColumn(cfg)` + `resolveWriteColumnForEngine(engine)` in
search/embedding-column.ts: user-declared registry entry whose provider
matches the current embedding model wins; no match => undefined (legacy
column). Builtins are never consulted so the multimodal builtin can't
capture text writes.
- `upsertChunks` accepts a caller-resolved `embeddingColumn` descriptor in
BOTH engines; the target column + cast (`::vector` / `::halfvec(N)`)
and the v0.40.3.0 D24 ON CONFLICT race-fix CASE arms follow the column.
- Stale scans follow the write column: `countStaleChunks`,
`listStaleChunks` (both cursor arms), and the shared
buildStaleChunkWhere accept the descriptor — without this, an
alt-column brain re-selects (and re-pays for) already-embedded chunks
forever.
- Boundary threading: runEmbedCore (embedPage/embedAll/embedAllStale),
embedStaleForSource + the embed-backfill handler, importFromContent /
importCodeFile / withImportTransaction, and the contextual-retrieval
re-embed transaction all resolve once and pass the descriptor.
- `preflightDimMismatch` skips the legacy-column dim comparison when a
non-default write column resolved (it would otherwise hard-block embed
runs on alt-column brains).
Tests: resolveWriteColumn unit coverage; PGLite e2e for the write target,
D24 preserve-on-reupsert, stale-scan contrast, and an `embed --stale
--dry-run` convergence integration; Postgres e2e twins (DATABASE_URL-gated).
Takeover of PR #1263 rebased onto current master (D24 ON CONFLICT
semantics, batchRetry wrapper, signature-stale + embed-backfill paths).
Fixes#1262
Co-authored-by: DmitryBMsk <DmitryBMsk@users.noreply.github.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>