Repository navigation
/sync-gbrain code stage fails on existing sources (gbrain ≥0.42 --confirm-destructive guard); use reindex-code in place #1985
Description
Summary
/sync-gbrain's code stage fails for any already-registered source on gbrain >= 0.42. Both --full and --code-only (and plain incremental) error with a destructive-delete guard. The orchestrator (gstack-gbrain-sync.ts) refreshes a code source by removing and re-adding it, but gbrain 0.42 now gates gbrain sources remove behind --confirm-destructive. The orchestrator doesn't pass that flag, so the remove is refused and the whole code stage errors.
The source is not deleted (the guard blocks the remove), and the memory + brain-sync stages still succeed — but the code index never gets refreshed through the orchestrator. The only working refresh path is calling gbrain reindex-code directly.
Environment
- gstack: 1.57.10.0
- gbrain: 0.42.40.0
- Engine: PGLite (local-stdio MCP), single-machine macOS (darwin)
- Source already registered (created by a prior
/setup-gbrain/--fullrun)
Repro
/setup-gbrain→ local PGLite, repo policyread-write(registers sourcegstack-code-<repo>with N pages). This first run works because the source doesn't exist yet (register = pure add).- Make any change (or none) and run
/sync-gbrain --fullor/sync-gbrain --code-onlyagain. - Code stage errors; memory + brain-sync still pass.
Actual output
gstack-gbrain-sync (full):
ERR code source registration failed: gbrain sources remove gstack-code-autoleadai-6b2cc40d failed:
⚠️ This will permanently delete: 768 pages, 6,786 chunks, 6,786 embeddings
To proceed, pass --confirm-destructive (or use soft-delete: gbrain sources archive gstack-code-autoleadai-6b2cc40d).
To preview without side effects: --dry-run
(1.9s)
OK memory gbrain import: 3 imported, 112 unchanged, 0 failed (3.7s)
OK brain-sync curated artifacts pushed (2.1s)
SKIP dream call-graph state unknown (doctor unavailable)
3 ok, 1 error, 0 skipped
Identical ERR code for --code-only.
Root cause
The orchestrator's code stage re-registers an existing source via gbrain sources remove <id> + gbrain sources add, instead of refreshing in place. gbrain >= 0.42 added a --confirm-destructive guard on sources remove (it would drop all pages/chunks/embeddings). The orchestrator predates that guard and doesn't pass the flag, so re-registration of any existing source fails.
This is distinct from #1734 (autopilot destructive auto-recovery) — here it's the orchestrator's own remove+add registration path tripping gbrain's new safety guard, on a non-autopilot manual sync.
Impact
/sync-gbrain --full and --code-only can no longer refresh the code index for a repo that was already indexed once. Users on gbrain 0.42+ get a confusing "permanently delete" error on a routine re-sync. The index is safe (remove is blocked), but the documented refresh verb is broken.
Workaround (confirmed working)
Refresh in place, no remove:
gbrain reindex-code --source <id> --yes
For memory + artifacts only: /sync-gbrain --no-code (those stages are unaffected).
Suggested fix
In gstack-gbrain-sync.ts's code stage, for an existing source skip the remove+add and refresh in place with gbrain reindex-code --source <id> --yes (already the path --full advertises). Only sources add for a genuinely new source. If a true re-register is ever needed, prefer gbrain sources archive or pass --confirm-destructive explicitly with a clear log line — never an implicit destructive remove on a routine sync.
Activity
jbetala7 commentedon Jun 17, 2026
Opened #2031 to fix this:
ensureSourceRegistered()'s drift re-register path issuedgbrain sources remove <id> --yeswithout--confirm-destructive, which gbrain >= 0.42 refuses — surfacing assource registration failedand aborting the code stage. The fix passes--confirm-destructive(matching the orchestrator's ownsafeSourcesRemove()), with a regression test that fails on main with the exactTo proceed, pass --confirm-destructiveerror.v1.61.0.0 fix wave: guards failing open / silent failures (9 fixes, 4…