#5499·gbrain

sweep --once fails every pass on a managed Postgres brain served by serve --http

Author: andreineacsuCreated Sep 25, 2026Updated Sep 30, 2026

Environment: gbrain 0.57.0.0 (467ff67), macOS, bun 1.3.14, Postgres 17, installed via clone + bun link, managed persistence and shared skills activated, serve --http via mcp expose.

Expected

INSTALL_FOR_AGENTS.md:286-289:

Stdio gbrain serve runs bounded startup/idle sweeps; gbrain serve --http does not self-sweep. For HTTP, arrange explicit host-side gbrain sweep --once or extraction; use authorized add_link calls for edges needed immediately.

So on an HTTP-served brain, a host cron running gbrain sweep --once is the documented way to get fence reconcile, link/timeline extraction and corpus ingest.

Observed

GBRAIN_HOOKS=0 gbrain sweep --once --json, run from ~ while serve --http is live. It exits 1 on every run:

json
{
  "corpusIngested": 0,
  "factsReconciled": 0,
  "linksExtracted": 0,
  "linksRemoved": 0,
  "timelineExtracted": 0,
  "skipped": [
    { "reason": "facts_fence_error", "count": 1 },
    { "reason": "links_timeline_error", "count": 1 },
    { "reason": "already_ingested", "count": 31 },
    { "reason": "corpus_file_error", "count": 20 }
  ],
  "durationMs": 377
}

stderr (corpus lines collapsed, file names replaced with <file>):

[sweep] facts-fence pass failed: legacy fact-fence reconciliation cannot mutate a managed brain through the legacy writer.
[sweep] links/timeline pass failed: writer_coordinator_required: canonical writer must use the persistence coordinator
[sweep] corpus ingest failed for <file>.txt: The canonical fact writer is busy; extraction has not started.   (x20)

A smaller point: the --json report carries only reason codes. The underlying error text goes to stderr only, so a host job that keeps just the JSON cannot tell a managed-mode refusal from any other failure.

Code-level cause

  1. Pass 1, facts fence reconcile. src/core/sweep.ts:187 calls runExtractFacts, which starts with assertUnmanagedCanonicalWriter(engine, 'legacy fact-fence reconciliation') (src/core/cycle/extract-facts.ts:362). That function (src/core/persistence/maintenance.ts:11-15) throws writer_coordinator_required whenever persistence_brain.enabled is true. Caught at src/core/sweep.ts:200-201 as facts_fence_error.
  2. Pass 2, link/timeline extraction. runLinksTimelinePass writes through engine.addLinksBatch (src/core/sweep.ts:449) and engine.addTimelineEntriesBatch (src/core/sweep.ts:452) without a gbrain.write_sources binding. The managed_writer_guard trigger (src/schema.sql:1883-1885, attached at :1895) raises writer_coordinator_required: canonical writer must use the persistence coordinator. Caught at src/core/sweep.ts:219-220 as links_timeline_error. This is the same write path as the extract --stale refusal in #5280.
  3. Pass 3, corpus ingest. Per file, fact extraction goes through src/core/persistence/facts-maintenance.ts:152-156: the binding's owner is this host, acquireWorktree(binding) returns null, and it throws writer_lock_unavailable ("The canonical fact writer is busy"). My reading, not verified: the running serve --http holds the worktree lock as owner, so a separate CLI process can never take it while the serve is up. Every file then counts as corpus_file_error (src/core/sweep.ts:816).

isTotalFailure (src/commands/sweep.ts:58-66) then sees all three pass errors, prints a total-failure line and sets exit 1.

Serve delegation does not help here. maybeDelegateSweepToServe only delegates when a live serve holds a PGLite data dir (src/commands/sweep-delegate.ts:102-103, probeLivePgliteHolder). On Postgres it falls through to the local run above, and I found no idle sweep in the --http lane.

Consequence

On a managed brain served by serve --http, there is no documented way to run the sweep passes: serve --http does not self-sweep, and sweep --once, the documented host-side substitute, is refused in every pass. Pages written by remote put_page keep their links and timeline unextracted, fact fences stay unreconciled, and transcript corpus files stay unprocessed until something else picks them up.

Question

Should the sweep passes route through the persistence coordinator on a managed brain (or be delegated to the owner serve over IPC, as on PGLite)? If sweep --once is not meant to be supported on managed brains, could INSTALL_FOR_AGENTS.md name the supported alternative for HTTP-served managed brains?

Related: #5280 (managed-mode refusals of extract --stale, same write path as pass 2).