fix(cli): register 'reindex' in CLI_ONLY so v0.32.7 sweep is reachable#913
Open
vinsew wants to merge 1 commit into
Open
fix(cli): register 'reindex' in CLI_ONLY so v0.32.7 sweep is reachable#913vinsew wants to merge 1 commit into
vinsew wants to merge 1 commit into
Conversation
`case 'reindex'` lives inside `handleCliOnly` (src/cli.ts:1075), which the
dispatcher only enters when `CLI_ONLY.has(command)` is true at src/cli.ts:90.
The set lists `'reindex-code'` and `'reindex-frontmatter'` but not bare
`'reindex'`, so the markdown re-chunk sweep introduced in v0.32.7 is dead
code: every invocation falls through to `cliOps.get('reindex')` (undefined,
no Operation registered) and exits 1 with "Unknown command: reindex".
Reproduce on unmodified origin/master:
$ gbrain reindex --markdown --dry-run --json
Unknown command: reindex
Run gbrain --help for available commands.
EXIT=1
Fix: add `'reindex',` next to `'reindex-code'` / `'reindex-frontmatter'`.
Test coverage added in `test/reindex.test.ts`:
- Structural: parse the CLI_ONLY line and require it match `/'reindex',/`.
- Runtime: spawn `bun run src/cli.ts reindex --markdown --help` and assert
stderr+stdout does NOT contain "Unknown command: reindex". The
pre-existing `test/reindex.test.ts` cases only call `runReindex(engine, ...)`
directly, bypassing the dispatcher — which is how this regression slipped
past CI in garrytan#898.
Verified locally on a production brain: with the fix in place,
`gbrain reindex --markdown` swept 279 pre-bump pages to chunker_version=2
in 3:28, 0 failures, ~$0.08 in OpenAI embeddings.
Context: PR garrytan#898 (v0.32.7) body marked Codex finding garrytan#3 (reindex not in
CLI_ONLY) as a false positive on the grounds that "CLI_ONLY is the set
that doesn't need an engine; reindex correctly belongs to the engine-backed
dispatch." That premise is incorrect for this codebase — `handleCliOnly`
contains many engine-backed commands (orchestrating engine connect inside
the per-case branch). `case 'reindex'` at src/cli.ts:1075 follows the same
pattern as `case 'orphans'` (1069) and `case 'salience'` (1081), both of
which are in CLI_ONLY.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
gbrain reindex --markdown(introduced in v0.32.7 #898) exits with "Unknown command: reindex" on every invocation. The dispatcher insrc/cli.tsonly reachescase 'reindex'(insidehandleCliOnly) whenCLI_ONLY.has(command)is true at line 90, but the set lists'reindex-code'and'reindex-frontmatter'without bare'reindex'. Adding the missing token wires the case back into the dispatch.Reproduce on unmodified
origin/masterSame input after this patch (
gbrain reindex --markdown --dry-run --json) returns the expected{"pending":N,"would_reindex":N,"dry_run":true,"chunker_version":2}.Byte-level evidence the case is reachable only via CLI_ONLY
src/cli.ts:30—CLI_ONLYset, currently lists'reindex-code','reindex-frontmatter', not'reindex'.src/cli.ts:90—if (CLI_ONLY.has(command)) { await handleCliOnly(...); return; }is the only path intohandleCliOnly.src/cli.ts:96-100— fallthrough iscliOps.get(command)→ undefined for 'reindex' (zeroname: 'reindex'entry insrc/core/operations.ts) →console.error('Unknown command: ${command}'); process.exit(1).src/cli.ts:1075—case 'reindex'lives insideasync function handleCliOnly(line 707). Identical pattern tocase 'orphans'(1069) andcase 'salience'(1081), both of which are registered in CLI_ONLY.Why CI didn't catch this in #898
test/reindex.test.tsexercisesrunReindex(engine, args)directly, bypassing the CLI dispatcher. Two new cases in this PR close that gap:src/cli.ts, locate theCLI_ONLY = new Set(...)line, require it match/'reindex',/.bun run src/cli.ts reindex --markdown --helpin a subprocess and assert stderr+stdout does NOT containUnknown command: reindex.The structural test is the same shape as
test/book-mirror.test.ts's "book-mirror is in CLI_ONLY (does not get 'Unknown command')" guard from PR #564.Context on the #898 review note
#898 body recorded Codex outside-voice finding #3 as a false positive ("CLI_ONLY is the set that doesn't need an engine; reindex correctly belongs to the engine-backed dispatch"). The premise that CLI_ONLY excludes engine-backed commands does not match the current codebase:
handleCliOnlyorchestrates engine connect inside per-case branches for many commands (orphans, salience, anomalies, sources, mounts, dream, etc.). All currently-working engine-backed commands insidehandleCliOnlyare in CLI_ONLY;reindexis the only one that isn't, which is why it's the only one that fails this way.Verified end-to-end
Production brain (Postgres, 279 pages, all
chunker_version=1before fix) with this patch applied:279/279 reindexed, 0 failures, ~3:28, ~$0.08 in OpenAI text-embedding-3-large. CJK sync (
品牌圣经.md) round-trips cleanly through the new chunker on the post-sweep brain.Test plan
bun run typecheck— cleanbun test test/reindex.test.ts— 8 pass / 0 fail (was 6; 2 new cases for CLI_ONLY registration)gbrain reindex --markdown --dry-run→ "Unknown command: reindex", EXIT=1gbrain reindex --markdown --dry-run --json→ valid JSON, EXIT=0🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmithwith what you need.