whole-bank transfer skips Knowledge Pages and does not regenerate mental-model search state
Bug description
Whole-bank export/import does not preserve the Knowledge Pages tree and does not regenerate the derived search state of restored mental models.
Current main explicitly puts knowledge_pages in _SKIP_TABLES because the generic row restorer cannot satisfy its self-referential parent FK. At the same time, export strips embedding and search_vector from carried mental_models, while import restores those rows without running the target-side mental-model embedding/search-document lifecycle.
The result is a logically incomplete bank after transfer:
- folders/pages, parent relationships,
managed, andsort_orderare lost; - backing mental models may exist but are no longer connected to Knowledge Page nodes;
- restored mental models can have missing embedding and lexical search state;
- a target using another text backend cannot regenerate the backend-specific projection.
Expected behavior
A whole-bank transfer should preserve the complete logical Knowledge Pages tree while treating embeddings, lexical projections, and physical indexes as target-derived state.
Minimal fix boundary
- Add typed Knowledge Page rows to the transfer archive schema; do not pass raw unvalidated dictionaries between phases.
- Restore the bank row and mental models before Knowledge Pages.
- Restore folders in deterministic parent-first/topological order, then pages after both their parent folder and backing mental model exist.
- Preserve IDs, bank isolation,
parent_id,mental_model_id,managed,sort_order, names, and timestamps according to the existing whole-bank transfer contract. - Regenerate restored mental-model embeddings and backend-specific lexical state on the target through the same canonical lifecycle used by normal writes.
- Preserve mental-model history, bank config, directives, and webhooks under their existing options and ordering.
- Keep this separate from #3270, whose root cause is a target-bank
internal_idcollision swallowed byON CONFLICT DO NOTHING. If #3270 is still open, treat it as a prerequisite for same-instance transfer tests rather than duplicating its fix here. - No source-backend physical index or
search_vectorpayload should be trusted or copied.
Acceptance coverage
- Nested folders restore parent-first with zero orphans.
- Pages retain their backing mental-model relationship and bank isolation.
- Page names/content are searchable after import on native and VChord, plus a base-column backend path.
- Mental-model embeddings are regenerated with the target embedding provider; lexical state matches the target text backend.
skip,replace, andnew-idconflict modes preserve referential integrity or fail explicitly.- History/config/directive/webhook behavior remains unchanged.
- A source bank and imported target bank have equal canonical logical data when derived fields and physical indexes are excluded.
Related
- #3270: target-bank creation can fail on a carried
internal_idcollision. - #3268: backend-specific Knowledge Page query failure.