fix(registry): recognize migrated SQLite workspaces — closes #35#89
Merged
Conversation
## Problem _registry_exists(workspace) in scripts/codelens.py only checked for .codelens/backend.json or .codelens/frontend.json. A workspace that had run migrate (JSON to SQLite) and then deleted the JSON files was always treated as having no registry — triggering init + scan on every subsequent command and discarding the migrated SQLite data. This was compounded by a second bug: cmd_migrate early-returned whenever codelens.db existed (even if empty), because scan now creates that file via store_scan_result (issue #31). So migrate silently no-op'd and never actually copied JSON into SQLite. ## Fix Three coupled changes, all gated on a new db_is_populated(db_path) helper in scripts/persistent_registry.py: 1. codelens._registry_exists — path 1 (JSON check) is unchanged; new path 2 returns True when codelens.db exists AND the symbols table has at least 1 row. Empty/corrupt dbs still return False so auto-setup runs (constraint: db kosong/corrupt tidak salah dianggap registry valid). 2. commands.migrate.cmd_migrate — only skips re-migration when the db is actually populated (was: os.path.exists). Without this, the empty db shell created by store_scan_result blocked the real JSON-to-SQLite migration. 3. registry.load_frontend_registry / load_backend_registry — added SQLite fallback. When JSON is missing, load from the analysis_cache rows written by PersistentRegistry.store_frontend_registry / store_backend_registry during migrate. Makes the migrated workspace actually usable (padahal data lengkap sudah ada di codelens.db). The helper is shared between (1) and (2) — no dead code, no duplication. ## Backward compatibility - JSON-only workspaces (no migrate) still work — path 1 returns True before any SQLite check, so pre-migration behavior is unchanged. - Empty/corrupt SQLite dbs are NOT treated as valid — auto-setup still runs, so users aren't stuck with a broken registry. - migrate still skips when the db is genuinely populated (the old 'already exists' behavior, just with a stricter condition). ## Files changed - scripts/codelens.py — _registry_exists: add SQLite path - scripts/persistent_registry.py — add db_is_populated() helper - scripts/commands/migrate.py — use db_is_populated for skip check - scripts/registry.py — SQLite fallback in load_*_registry - tests/test_cli.py — 5 new regression tests - tests/test_persistent_registry.py — update test_migrate_already_exists Closes #35
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
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.



Fix
Closes #35
Problem
_registry_exists(workspace)inscripts/codelens.pyonly checked for.codelens/backend.jsonor.codelens/frontend.json. A workspace that had runmigrate(JSON → SQLite) and then deleted the JSON files was always treated as having no registry — triggeringinit + scanon every subsequent command and discarding the migrated SQLite data.This was compounded by a second bug:
cmd_migrateearly-returned whenevercodelens.dbexisted (even if empty), becausescannow creates that file viastore_scan_result(issue #31). Somigratesilently no-op'd and never actually copied JSON → SQLite.What changed
Three coupled changes, all gated on a new
db_is_populated(db_path)helper inscripts/persistent_registry.py:codelens._registry_exists— path 1 (JSON check) is unchanged; new path 2 returnsTruewhencodelens.dbexists AND thesymbolstable has ≥1 row. Empty/corrupt dbs still returnFalseso auto-setup runs (constraint: db kosong/corrupt tidak salah dianggap registry valid).commands.migrate.cmd_migrate— only skips re-migration when the db is actually populated (was:os.path.exists). Without this, the empty db shell created bystore_scan_resultblocked the real JSON→SQLite migration.registry.load_frontend_registry/load_backend_registry— added SQLite fallback. When JSON is missing, load from theanalysis_cacherows written byPersistentRegistry.store_{frontend,backend}_registryduringmigrate. Makes the migrated workspace actually usable (padahal data lengkap sudah ada di codelens.db).The helper is shared between (1) and (2) — no dead code, no duplication.
Backward compatibility
Truebefore any SQLite check, so pre-migration behavior is unchanged.migratestill skips when the db is genuinely populated (the old "already exists" behavior, just with a stricter condition).Files changed
scripts/codelens.py_registry_exists: add SQLite path 2 (populated db check)scripts/persistent_registry.pydb_is_populated(db_path)helperscripts/commands/migrate.pycmd_migrate: usedb_is_populatedfor skip checkscripts/registry.pyload_{frontend,backend}_registry: SQLite fallback when JSON missingtests/test_cli.pytests/test_persistent_registry.pytest_migrate_already_existsto populate db firstManual repro (issue #35)
Before fix:
queryprinted[CodeLens] No registry found. Auto-running init + scan...and re-scanned from scratch.After fix:
Test run
New regression tests in
tests/test_cli.py::TestRegistryExistsSqlite:test_registry_exists_after_migrate_with_json_deleted— the exact issue [BUG-07] _registry_exists() ignores SQLite — spurious auto-setup aftermigrate#35 repro: migrate → delete JSON →_registry_exists()returnsTruetest_registry_exists_false_for_empty_db— empty db (0 symbols) returnsFalse(constraint: db kosong tidak valid)test_registry_exists_false_for_corrupt_db— corrupt db file returnsFalse(constraint: db corrupt tidak valid)test_registry_exists_true_for_json_only_workspace— JSON-only workspace (no migrate) still returnsTrue(backward compat)test_query_uses_sqlite_fallback_after_json_deleted— end-to-end: query returns real data from SQLite after JSON deletionNote on pre-existing test failures
The full suite (
python3 -m pytest tests/) has pre-existing failures intest_architecture.py,test_graph_model.py,test_compact_format.py,test_hybrid_type_resolver.py, andtest_integration.py::TestAllCommandsJSON::test_no_args_command_json[scan](OOM/rc=137). These failures exist onmainwithout my changes (verified viagit stash+ re-run) and are unrelated to issue #35. All tests touching the changed code pass.