Skip to content

fix(cli): init reports an incomplete index instead of 'Already initialized' (#3228) - #3282

Open
LuisAlbertoMK wants to merge 1 commit into
colbymchenry:mainfrom
LuisAlbertoMK:fix/init-partial-index
Open

LuisAlbertoMK wants to merge 1 commit into
colbymchenry:mainfrom
LuisAlbertoMK:fix/init-partial-index

Conversation

@LuisAlbertoMK

Copy link
Copy Markdown

Follow-up to #3223.

When a first index stops partway (OOM, killed mid-index, etc.), the schema can be present while the index is incomplete. \codegraph init\ then printed 'Already initialized in ' with no hint that the index is incomplete, so it read like a working setup that just needed updating.

Now
unInit\ opens the project read-only and checks \getIndexState(). When the state is not 'complete' (e.g. 'indexing', 'partial', 'failed'), it warns that the last run did not finish and tells the user to run \codegraph index\ to rebuild. Otherwise it keeps the previous 'Already initialized' message.

Added a test in cli-install-init.test.ts that seeds index_state='indexing' and asserts the new message (and that 'Already initialized' is not printed).

Tested: tsc --noEmit clean, npm run build, focused cli-install-init suite (5 tests pass).

colbymchenry added a commit that referenced this pull request Nov 18, 2026
… "Already initialized"

A first index that stops partway (killed, out of memory, an error while
resolving references) leaves `.codegraph/codegraph.db` behind, so a second
`codegraph init` took the already-initialized branch, which looked only at
whether the database exists. It printed "Already initialized" and pointed at
`codegraph sync`, which reads like a working setup that just needs an
update, while `codegraph status` on the same project said the last run
never finished.

The already-initialized branch now reads the index state the way `status`
does: read-only, with a rebuild running in another process (a live
rebuild.pid) told apart from a run that died. For a state of `indexing` with
no rebuild running, `partial` or `failed`, it says the index is incomplete,
with the same sentence `status` prints, and drops the sync hint. A complete
index gets the usual answer, and a project another process is rebuilding
gets "Already initialized" plus a note that a rebuild is running. `status`
and `init` share one helper for the wording.

Validation:
- cli-install-init.test.ts: new cases for `indexing`, `partial` and `failed`
  (through `init --yes` and `install --init`), a complete index, and a
  rebuild lock held by a live process versus a dead one. The 4 cases about
  an unfinished index or a rebuild fail on main's source and pass here; all
  5 existing tests in the file are kept and pass (10 passed).
- status-json, status-during-rebuild, status-index-health,
  status-language-coverage and schemaless-db-not-initialized: 56 passed,
  1 skipped, so status prints what it did.
- Real CLI on an excalidraw copy whose first `init` was killed during
  "Resolving refs": v1.6.3 sources print "Already initialized" and the sync
  hint; this branch prints that the index is incomplete and the
  never-finished warning `status` gives, exit 0 on both.

PR #3282 (@LuisAlbertoMK) proposed the same check; this one also tells a
running rebuild from a dead run, and keeps every existing test.

Fixes #3228

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
colbymchenry added a commit that referenced this pull request Nov 18, 2026
… "Already initialized"

A first index that stops partway (killed, out of memory, an error while
resolving references) leaves `.codegraph/codegraph.db` behind, so a second
`codegraph init` took the already-initialized branch, which looked only at
whether the database exists. It printed "Already initialized" and pointed at
`codegraph sync`, which reads like a working setup that just needs an
update, while `codegraph status` on the same project said the last run
never finished.

The already-initialized branch now reads the index state the way `status`
does: read-only, with a rebuild running in another process (a live
rebuild.pid) told apart from a run that died. For a state of `indexing` with
no rebuild running, `partial` or `failed`, it says the index is incomplete,
with the same sentence `status` prints, and drops the sync hint. A complete
index gets the usual answer, and a project another process is rebuilding
gets "Already initialized" plus a note that a rebuild is running. `status`
and `init` share one helper for the wording.

Validation:
- cli-install-init.test.ts: new cases for `indexing`, `partial` and `failed`
  (through `init --yes` and `install --init`), a complete index, and a
  rebuild lock held by a live process versus a dead one. The 4 cases about
  an unfinished index or a rebuild fail on main's source and pass here; all
  5 existing tests in the file are kept and pass (10 passed).
- status-json, status-during-rebuild, status-index-health,
  status-language-coverage and schemaless-db-not-initialized: 56 passed,
  1 skipped, so status prints what it did.
- Real CLI on an excalidraw copy whose first `init` was killed during
  "Resolving refs": v1.6.3 sources print "Already initialized" and the sync
  hint; this branch prints that the index is incomplete and the
  never-finished warning `status` gives, exit 0 on both.

PR #3282 (@LuisAlbertoMK) proposed the same check; this one also tells a
running rebuild from a dead run, and keeps every existing test.

Fixes #3228

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
colbymchenry added a commit that referenced this pull request Nov 18, 2026
… "Already initialized" (#3336)

A first index that stops partway (killed, out of memory, an error while
resolving references) leaves `.codegraph/codegraph.db` behind, so a second
`codegraph init` took the already-initialized branch, which looked only at
whether the database exists. It printed "Already initialized" and pointed at
`codegraph sync`, which reads like a working setup that just needs an
update, while `codegraph status` on the same project said the last run
never finished.

The already-initialized branch now reads the index state the way `status`
does: read-only, with a rebuild running in another process (a live
rebuild.pid) told apart from a run that died. For a state of `indexing` with
no rebuild running, `partial` or `failed`, it says the index is incomplete,
with the same sentence `status` prints, and drops the sync hint. A complete
index gets the usual answer, and a project another process is rebuilding
gets "Already initialized" plus a note that a rebuild is running. `status`
and `init` share one helper for the wording.

Validation:
- cli-install-init.test.ts: new cases for `indexing`, `partial` and `failed`
  (through `init --yes` and `install --init`), a complete index, and a
  rebuild lock held by a live process versus a dead one. The 4 cases about
  an unfinished index or a rebuild fail on main's source and pass here; all
  5 existing tests in the file are kept and pass (10 passed).
- status-json, status-during-rebuild, status-index-health,
  status-language-coverage and schemaless-db-not-initialized: 56 passed,
  1 skipped, so status prints what it did.
- Real CLI on an excalidraw copy whose first `init` was killed during
  "Resolving refs": v1.6.3 sources print "Already initialized" and the sync
  hint; this branch prints that the index is incomplete and the
  never-finished warning `status` gives, exit 0 on both.

PR #3282 (@LuisAlbertoMK) proposed the same check; this one also tells a
running rebuild from a dead run, and keeps every existing test.

Fixes #3228

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant