Summary
gbrain sync --source <id> updates source bookkeeping for the requested source, but the import/write path can still write pages/chunks/tags under the default source.
Repro / observed behavior
From an OpenClaw Support KB install:
gbrain sync --repo ~/.gbrain/sources/openclaw-support-kb --source openclaw-support-kb
gbrain sources list --json
Observed before patch:
default had ~636 pages
openclaw-support-kb existed but had 0 pages
- search worked only because data had accidentally landed in
default
Root cause
sync --source carried sourceId into sync state/bookkeeping, but performFullSync() called runImport() without that source id. Then runImport() / importFile() / engine CRUD defaulted page writes and slug lookups to the default source.
The same source-blind slug path affected page lookup, tag reconciliation, chunk upserts/deletes, and version creation during import.
Expected behavior
Named-source sync/import should write and reconcile content under the requested sources.id, while calls that omit sourceId preserve the current default-source behavior.
Patch direction
Thread optional sourceId through:
sync.ts → runImport() / importFile()
import.ts → importFile()
import-file.ts → getPage, putPage, tags, chunks, versions
- PGLite/Postgres engine page/chunk/tag/version CRUD
Default behavior should remain source_id='default' when no source id is provided.
Validation target
bun run typecheck
- source-scoped sync of a multi-file repo lands pages under the named source
gbrain search ... --source <id> returns expected hits
Summary
gbrain sync --source <id>updates source bookkeeping for the requested source, but the import/write path can still write pages/chunks/tags under the default source.Repro / observed behavior
From an OpenClaw Support KB install:
gbrain sync --repo ~/.gbrain/sources/openclaw-support-kb --source openclaw-support-kb gbrain sources list --jsonObserved before patch:
defaulthad ~636 pagesopenclaw-support-kbexisted but had 0 pagesdefaultRoot cause
sync --sourcecarriedsourceIdinto sync state/bookkeeping, butperformFullSync()calledrunImport()without that source id. ThenrunImport()/importFile()/ engine CRUD defaulted page writes and slug lookups to the default source.The same source-blind slug path affected page lookup, tag reconciliation, chunk upserts/deletes, and version creation during import.
Expected behavior
Named-source sync/import should write and reconcile content under the requested
sources.id, while calls that omitsourceIdpreserve the current default-source behavior.Patch direction
Thread optional
sourceIdthrough:sync.ts→runImport()/importFile()import.ts→importFile()import-file.ts→getPage,putPage, tags, chunks, versionsDefault behavior should remain
source_id='default'when no source id is provided.Validation target
bun run typecheckgbrain search ... --source <id>returns expected hits