Skip to content

fix: sync all registered sources in autopilot cycle instead of single brainDir#1079

Open
samvilian wants to merge 1 commit into
garrytan:masterfrom
samvilian:fix/multi-source-cycle-sync
Open

fix: sync all registered sources in autopilot cycle instead of single brainDir#1079
samvilian wants to merge 1 commit into
garrytan:masterfrom
samvilian:fix/multi-source-cycle-sync

Conversation

@samvilian

Copy link
Copy Markdown

Summary

Fixes #1078

In multi-source brains, runPhaseSync() resolves the source ID by matching brainDir against sources.local_path. When --repo points to a parent directory that doesn't match any source (e.g. /home/ubuntu/brain vs /home/ubuntu/brain/wiki/), sourceId resolves to undefined, causing importFile() to fall back to the schema DEFAULT 'default' for source_id. Since no row with id='default' exists in sources, every INSERT violates pages_source_id_fkey.

Changes

  • src/core/cycle.ts: runPhaseSync() now enumerates all registered sources from the database and syncs each one individually with its correct source_id and local_path
  • Aggregates per-source results into a unified SyncPhaseResult
  • Reports per-source status in details.sourcesSynced for observability
  • Preserves the legacy single-dir fallback when no sources are registered

Before

[cycle.sync] start
[gbrain phase] sync.fullsync.import start strategy=markdown
Warning: skipped wiki/.../file.md: insert or update on table "pages" violates foreign key constraint "pages_source_id_fkey"
  56 files failed
sync_status: blocked_by_failures

After

[cycle.sync] start
[gbrain phase] sync.git_pull start  (logseq)
[gbrain phase] sync.git_pull start  (wiki)
[gbrain phase] sync.git_pull start  (obsidian)
sync_status: completed
sourcesSynced: ["logseq: ok", "wiki: ok", "obsidian: ok", "books: error (not a git repo)"]

Test

Verified locally with 4 registered sources (logseq, wiki, obsidian, books) — all FK constraint errors resolved, sync completes successfully across all git-initialized sources.

In multi-source brains, autopilot/dream passes --repo with a parent
directory that may not match any source's local_path. This causes
resolveSourceForDir() to return undefined, making importFile() fall back
to the schema DEFAULT ('default') for source_id. Since no row with
id='default' exists in the sources table, every INSERT violates the
pages_source_id_fkey foreign key constraint.

Fix: enumerate all registered sources from DB and sync each one
individually with its correct source_id. Preserves the legacy fallback
for brains with no registered sources.

Fixes garrytan#1078
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.

Autopilot/dream sync fails with FK constraint error in multi-source brains

2 participants