Repository navigation
fix(gbrain): stop a path case difference from destroying the source index - #2386
ShahriarLak wants to merge 1 commit into
Conversation
…ndex On Windows, /sync-gbrain fails in every mode with: source registration failed: gbrain sources remove <id> failed: This will permanently delete: 129 pages, 627 chunks, 627 embeddings To proceed, pass --confirm-destructive The destructive-flag demand is the symptom. The cause is in ensureSourceRegistered: gbrain held the source at C:/Users/me/projects/quill while the caller derived C:/Users/me/Projects/Quill, and the two were compared with !==. The same directory, spelled differently, was read as drift, so every run took the remove-then-add path. Passing --confirm-destructive is the wrong fix. It really deletes the source's pages, chunks and embeddings and re-walks from scratch, over a mismatch that was never real. This compares case-folded with separators normalised instead, so the registration is left alone. Two related fixes in the same area: - gstack-gbrain-source-wireup had the same defect. Its multi-machine guard parses `sources list --json` with jq, so where jq isn't installed existing_path is empty, the guard can't fire, and every mismatch falls through to remove-then-add. It now falls back to sed, compares normalised, and on a genuine mismatch warns and continues rather than deleting. Its own comment already says gbrain stores pages by content and local_path is informational, which is the argument for never deleting on a path change. - The brain-sync stage spawned gstack-brain-sync with shell:true on Windows. That means cmd.exe, which cannot run an extensionless bash-shebang script: "is not recognized as an internal or external command", exit 1, every run. It now passes the script to bash. Verified on Windows 11 (gbrain 0.42.52, gstack 1.60.1.0): /sync-gbrain went from failing every run to `3 ok, 0 error, 0 skipped`, with the source synced at 129 pages and no destructive operation attempted.
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
|
Closing — upstream fixed this independently and better.
const real = (p: string): string => {
try { return realpathSync(p) } catch { return p }
}
return real(registered) === real(requested)On Windows Verified on the original repro (Windows 11, gstack 1.61.0.0): a full Thanks for sorting it. Nothing needed here. |
The bug
On Windows,
/sync-gbrainfails on every run, in every mode:The flag demand is the symptom, not the cause. In
ensureSourceRegistered, gbrain held the source atC:/Users/me/projects/quillwhile the caller derivedC:/Users/me/Projects/Quill. Those were compared with!==, so the same directory spelled differently was classified as drift, and every run took the remove-then-add path.Passing
--confirm-destructivewould be worse than the bug. It really deletes the source's pages, chunks and embeddings and re-walks from scratch, over a mismatch that was never real. Anyone hitting this and following the error message's advice loses their index.The fix
lib/gbrain-sources.tscompares paths case-folded with separators normalised. Windows and macOS both default to case-insensitive filesystems, so this is correct there; on Linux a case-distinct pair is possible in principle but gstack never creates one, and re-using an existing index is a much cheaper failure than deleting it.Two related fixes in the same area:
bin/gstack-gbrain-source-wireupcarries the identical defect, plus a second trigger. Its multi-machine guard parsessources list --jsonwithjq, so on a machine without jqexisting_pathcomes back empty, the guard can never fire, and every mismatch falls through to remove-then-add. It now falls back tosed, compares normalised, and on a genuine mismatch warns and continues instead of deleting. Its own comment already states that gbrain stores pages by content andlocal_pathis informational metadata, which is the argument for never deleting on a path change.bin/gstack-gbrain-sync.tsspawnedgstack-brain-syncwithshell: trueon Windows. The existing comment (#1731) notes Windows can't spawn a shebang script without a shell, butshell: truemeanscmd.exe, which can't run an extensionless bash-shebang script either. It reported'...gstack-brain-sync' is not recognized as an internal or external commandand exited 1 on every run. It now passes the script tobash.Verification
Windows 11, gbrain 0.42.52.0, gstack 1.60.1.0.
Before:
1 ok, 2 error, 0 skipped(the two errors above), on every run.After:
No destructive operation attempted, index intact at 129 pages.
Note on the dry-run
Worth flagging separately:
--dry-runpreviews this as an idempotentgbrain sources add ...and gives no hint that a real run would attempt asources removefirst. That made the dry-run actively misleading while diagnosing this. Not addressed here, since it's a reporting change rather than a correctness one.