Skip to content

dream synthesize writes synthesized pages to 'default' source, ignoring the resolved brain source #1586

@chengdalong26

Description

@chengdalong26

Summary

gbrain dream --phase synthesize --dir <brain-dir> writes the synthesized
reflection/idea pages to the default source, even when <brain-dir> is a
registered source (its .gbrain-source dotfile names the source id). Result:
persistent multi_source_drift warnings in doctor, and the named source's
last_sync never advances ("stale" forever).

Root cause

In src/core/cycle/synthesize.ts, collectChildPutPageSlugs() (~L870)
hardcodes source_id: 'default' for all subagent-written pages. The comment at
L849-854 acknowledges this is a known gap:

Subagent put_page tool schema doesn't expose source_id (subagents are scoped
to a single source); default to 'default' for the current dream-cycle product
behavior. Threading the source_id through reverseWriteRefs guarantees getPage
targets the correct (source, slug) row...

So the brain_put_page write path never honors the resolved source from the
6-tier resolveSourceId chain (--source / GBRAIN_SOURCE / .gbrain-source
/ path-match / brain-default / 'default').

Impact

  • doctormulti_source_drift: pages live at default but their intended
    source is the named brain source.
  • doctorsync_freshness: the named source is flagged stale forever,
    because dream writes land in default and never advance the source's sync.
  • Workaround forces operators to git commit && gbrain sync --source <id> to
    re-home the pages, which leaves duplicate copies (one in default, one in the
    named source). Search dedupes by slug so retrieval is unaffected, but
    page_count / chunk_count inflate.

Repro

  1. gbrain sources add mybrain --path ~/mybrain (so ~/mybrain/.gbrain-source
    = mybrain)
  2. gbrain dream --phase synthesize --dir ~/mybrain
  3. gbrain doctormulti_source_drift lists the new reflection/idea pages as
    intended=mybrain but present at default.

Suggested fix

Thread the resolved sourceId into the subagent put_page write path and through
collectChildPutPageSlugs / reverseWriteRefs, so synthesized pages are
attributed to the correct source at write time instead of the hardcoded
'default'.

Env

gbrain 0.35.8.0, postgres engine, multi-source setup (multiple federated
sources).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions