#5777·gbrain

Managed brain: sync records source_changed for a page whose own coordinated write is not committed yet, and the failure never clears

Author: howardparkCreated Sep 30, 2026Updated Sep 30, 2026

What happened?

On a managed Postgres brain (worktree bound, gbrain serve --http plus autopilot), autopilot's periodic sync sometimes stops with blocked_by_failures:

source_changed [pinned_git_worktree_conflict]: The pinned Git content conflicts with working-tree bytes; sync did not overwrite them.

for a page nobody edited outside the coordinator. gbrain doctor then carries

sync_failures: 1 unresolved sync failure(s). source=default path=<page>.md code=source_changed: Newer working-tree bytes and the current page disagree with this pinned Git import. request=<uuid> run=<uuid> target=<sha>

until someone runs gbrain sync --no-pull --retry-failed by hand; later successful sync runs do not clear it. On a brain where agents write pages over MCP (put_page, add_timeline_entry) every few minutes this happened three times in one day. First seen on v0.60.11.0, still there on v0.60.12.0.

Cause

A coordinated page write reaches the database and the working-tree file first; its Git effect (commit, push) lands a little later. A sync run enumerated in that window pins the previous HEAD. When that HEAD already holds an earlier commit of the same page that the last sync has not imported yet (two writes to one page between two sync runs), the file is in the run's diff, and prepareManagedSyncMutation (src/core/persistence/sync-prepare.ts) sees

  • working-tree bytes that differ from the pinned content (p.rawHash !== sha256(p.content)), and
  • a current page that differs from the pinned content (!sameCanonicalImport(base, parsedInput)),

and throws source_changed. But the newer working-tree bytes are the current page's own publication. The database already holds them, so there is nothing to import and nothing to protect, and the commit that carries them imports as a no-op on the next run.

What did you expect?

The entry is skipped as a no-op when the working-tree bytes are the current page, the run completes, and no failure is recorded. Working-tree bytes that are neither the pinned commit nor the page should keep failing as they do now.

Steps to reproduce (deterministic, no timing needed)

  1. Managed brain with a source bound to a Git worktree that holds notes/example.md with content A. gbrain sync --no-pull: the page holds A.
  2. Commit a different content B for notes/example.md.
  3. Put content A back into the working-tree file, uncommitted. Now page = A, working tree = A, HEAD = B, which is the state between a coordinated write and its queued commit.
  4. gbrain sync --no-pull: blocked_by_failures, write_error: source_changed, reason: pinned_git_worktree_conflict, although the page and the working tree agree.

Environment

  • gbrain version: 0.60.12.0 (first seen on 0.60.11.0)
  • OS: Ubuntu 26.04
  • Bun version: 1.4.2
  • Database: self-hosted Postgres 17, managed persistence enabled

gbrain doctor --json output (the relevant check)

json
{"name":"sync_failures","status":"warn","message":"1 unresolved sync failure(s). source=default path=<page>.md code=source_changed: Newer working-tree bytes and the current page disagree with this pinned Git import. request=<uuid> run=<uuid> target=<sha> Fix the cause, then run gbrain sync --no-pull --retry-failed with the same source and options."}

A fix with a regression test follows as a PR.