Skip to content

fix(gbrain): make --full do a full code walk, not a delta one - #2406

Closed
ShahriarLak wants to merge 1 commit into
garrytan:mainfrom
ShahriarLak:fix/gbrain-full-walk
Closed

fix(gbrain): make --full do a full code walk, not a delta one#2406
ShahriarLak wants to merge 1 commit into
garrytan:mainfrom
ShahriarLak:fix/gbrain-full-walk

Conversation

@ShahriarLak

Copy link
Copy Markdown
Contributor

/sync-gbrain --full does not do a full walk. runCodeImport() walks with a bare gbrain sync --strategy code --source X — right strategy, but an incremental walk. It only revisits files changed since the source's checkpoint, so a file missed at the original import is never revisited and stays out of the index indefinitely.

The reindex-code pass below cannot rescue it: it re-chunks pages that already exist and never walks the filesystem. That is the same property the comment directly above the call already relies on when explaining why the walk must run first — that fix made a fresh source get pages at all, but left --full unable to discover a file the first walk skipped. This PR is the missing half.

Why it is expensive

The failure is silent. Nothing errors, nothing warns, and the verdict block still reports OK while gbrain search and gbrain code-def answer out of a partial index. It presents as "gbrain is weak at code questions" rather than "the index is incomplete", so it survives indefinitely.

Measured

Two local code sources, before and after, counting exported functions resolvable via gbrain code-def:

source before after
A 61/201 (30%) 180/201 (89%) — 79 files had no page at all
B whole source files missing 93%

Both had been serving search from a partial index for weeks.

Reproduce on your own brain

gbrain sync --source <id> --strategy code --full --dry-run

Compare N file(s) would be imported against that source's page_count. To check one file: gbrain get <file-slug> returning page_not_found means it was never imported.

Worth knowing while testing: the default strategy is markdown and --strategy is per-invocation, never persisted on the source — drop the flag and the same command reports strategy=markdown and a handful of files.

Scope

Two lines of behaviour change, gated on args.mode === "full", so incremental runs are untouched and stay fast. --yes because this is spawned non-interactively and a full walk otherwise prompts to confirm import cost. The failure summary now echoes the real argv instead of a hardcoded string that could disagree with what ran.

Verified: file parses under bun build; an incremental --dry-run confirms the walk does not gain --full; a --full run performs the discovery pass and imports the previously-missing files.

🤖 Generated with Claude Code

`runCodeImport()` walked with a bare `gbrain sync --strategy code --source X`.
The strategy is right, but that walk is incremental: it only revisits files
changed since the source's checkpoint. A file missed at the ORIGINAL import is
therefore never revisited and stays out of the index indefinitely.

The reindex-code pass below cannot rescue it. It re-chunks pages that already
exist and never walks the filesystem — the same property the comment directly
above already relies on when explaining why the walk has to run first. That fix
landed one flag short: it made a fresh source get pages at all, but left
`--full` unable to discover a file the first walk skipped.

Net effect: `/sync-gbrain --full` did not perform a full walk, and re-running it
never re-detected the gap.

The failure is silent, which is what makes it expensive. Nothing errors, nothing
warns, and the verdict block still reports OK while `gbrain search` and
`gbrain code-def` answer out of a partial index. It reads as "gbrain is weak at
code questions" rather than "the index is incomplete".

Measured on two local code sources before and after this change, counting
exported functions resolvable via `gbrain code-def`: one went from 61/201 (30%)
to 180/201 (89%), importing 79 files that had no page at all; the other had
whole source files missing entirely and reached 93%. Both had been serving
search from a partial index for weeks.

Scoped to `--full` so incremental runs stay fast. `--yes` because this spawns
non-interactively and a full walk otherwise prompts to confirm import cost.

Anyone can check their own brain without applying this:

    gbrain sync --source <id> --strategy code --full --dry-run

and compare "N file(s) would be imported" against that source's page_count.
Worth knowing while doing so: the default strategy is markdown and --strategy
is per-invocation, never persisted on the source, so dropping the flag reports
strategy=markdown and a handful of files.
@trunk-io

trunk-io Bot commented Jul 31, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

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

@garrytan

Copy link
Copy Markdown
Owner

Thank you — this was absorbed on main (credited in the v1.6x CHANGELOG entries; roster in PR #2604). Closing.

@garrytan garrytan closed this Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants