fix(sync-gbrain): fall through to filesystem walk when source has 0 code pages#1575
fix(sync-gbrain): fall through to filesystem walk when source has 0 code pages#1575kkroo wants to merge 1 commit into
Conversation
…ode pages
`/sync-gbrain --full` was a silent no-op on sources that had never been
initially synced. The orchestrator's --full path routed to
`gbrain reindex-code`, which only re-chunks existing `type='code'`
pages — it does NOT walk the filesystem (see reindex-code.ts docstring:
"Explicit backfill for v0.19.0 → v0.21.0 brains... walk every page
where type='code'"). For a source with zero code pages, reindex-code
exits 0 with `codePages: 0` and the orchestrator reports success
despite indexing nothing.
Side-by-side proof on the same source ID:
gbrain sync --strategy code --source <id> --dry-run -> 14,799 files
gbrain reindex-code --source <id> --dry-run -> 0 code page(s)
Fix: probe the source's existing code page count via
`reindex-code --dry-run --json` before deciding the subcommand. If
zero pages (or probe fails), fall through to `sync --strategy code`
which does the filesystem walk via `performFullSync`. Preserves the
v0.21.0 backfill semantics for sources that already have code pages.
Repro:
1. Fresh source: `gbrain sources add my-repo --path ~/my-repo --federated`
2. `/sync-gbrain --full` (or invoke orchestrator directly)
3. Before this fix: completes in ~10s, page_count=0
4. After this fix: walks the filesystem as expected
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Blocking correctness issue: this adds a direct Current |
|
Hit this same bug today on a fresh source after a PGLite re-init — One alternative worth weighing: instead of probing Trade-off:
PoC at Either approach fixes the bug. Genuine taste call on whether |
Summary
/sync-gbrain --fullis currently a silent no-op for sources that have never been initially synced. The orchestrator atbin/gstack-gbrain-sync.ts:404-407routes--fulltogbrain reindex-code, but reindex-code only re-chunks existing `type='code'` pages — it does NOT walk the filesystem.For a fresh source (zero code pages),
reindex-codeexits 0 with `codePages: 0` and the orchestrator reports success despite indexing nothing.Repro
Side-by-side dry-run on the same source ID proves the discrepancy:
This bug bit hard on a real fresh install of a 14,799-file Go monorepo — appeared to complete in ~10 seconds with no errors, but nothing got indexed. Confusing because everything else looked successful.
Fix
Probe the source's existing code-page count via `reindex-code --dry-run --json` before deciding the subcommand. If zero pages (or probe fails for any reason), fall through to `sync --strategy code` which does the filesystem walk via `performFullSync`.
Preserves the v0.21.0 reindex-code backfill semantics for sources that already have code pages.
Diff shape
Test plan
🤖 Generated with Claude Code