feat(schema): add v3 cache invalidation - #233
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (3)
Summary by CodeRabbit
WalkthroughThe change upgrades archive, home, and WIKG manifest schemas from version 2 to version 3. Archive upgrades rebuild chapter FTS artifacts, remove obsolete index settings, and create refreshed database overlays. Home upgrades remove derived state. Search-index access now invalidates incompatible caches, reports them as missing on reads, and recreates them on writes. Tests cover upgrades, cache concurrency, archive overlays, and isolated runtime state. Sequence Diagram(s)sequenceDiagram
participant SchemaUpgrade
participant Archive
participant DirectoryDocument
participant FTSArtifacts
SchemaUpgrade->>Archive: extract archive database
Archive->>DirectoryDocument: open extracted document
DirectoryDocument->>FTSArtifacts: refresh chapter artifacts
DirectoryDocument->>DirectoryDocument: remove archive_index_settings
SchemaUpgrade->>Archive: add database.db overlay
sequenceDiagram
participant SearchIndexClient
participant openSearchIndexDatabase
participant SQLiteCache
participant IndexFile
SearchIndexClient->>openSearchIndexDatabase: open index.db
openSearchIndexDatabase->>SQLiteCache: inspect search_index_state.version
SQLiteCache-->>openSearchIndexDatabase: return missing or incompatible version
openSearchIndexDatabase->>IndexFile: delete incompatible cache
openSearchIndexDatabase-->>SearchIndexClient: report missing or initialize cache
Possibly related PRs
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches✨ Simplify code
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (3)
test/core/storage/schema-upgrade/index.test.ts (2)
89-135: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueGood coverage. One addition would strengthen it.
The test proves the FTS artifact is created and
archive_index_settingsis dropped. Add an assertion that the mutation token is preserved, becausewriteWikgArchiveWithOverlaysruns withpreserveMutationToken: trueand the newdatabase.dboverlay changes archive content.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/core/storage/schema-upgrade/index.test.ts` around lines 89 - 135, Extend the test around upgradeWikiGraphArchiveSchema to assert that the archive’s mutation token remains unchanged after the v2-to-v3 upgrade. Capture the token before upgrading and compare it with the token read afterward, preserving coverage for writeWikgArchiveWithOverlays configured with preserveMutationToken: true.
1207-1213: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueInclude all production document paths.
WIKG_ARCHIVE_PATTERNSalso permitscover/data.binandcover/info.json, butisTestArchiveDocumentPathomits them. ReuseisWikgArchivePathor add these paths to keep the fixture complete.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/core/storage/schema-upgrade/index.test.ts` around lines 1207 - 1213, Update isTestArchiveDocumentPath to recognize every production archive path allowed by WIKG_ARCHIVE_PATTERNS, including cover/data.bin and cover/info.json. Prefer reusing isWikgArchivePath if it provides the same validation; otherwise extend the existing predicate while preserving its current database, TOC, source, and summary path handling.packages/core/src/storage/schema-upgrade/index.ts (1)
256-264: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUse
DATABASE_ENTRY_PATHfor the archive database path.The constant is defined in
packages/core/src/storage/wikg/wikg-coordinator/constants.ts. Use it for bothdatabasePathandentryPath.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/core/src/storage/schema-upgrade/index.ts` around lines 256 - 264, Update the database archive path construction and returned entry metadata in the surrounding schema-upgrade logic to use the existing DATABASE_ENTRY_PATH constant for both the join filename and entryPath value, replacing the duplicated literal "database.db".
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/core/src/document/directory/search-index.ts`:
- Around line 28-42: Serialize the search-index lifecycle in the surrounding
search-index operation using a per-document lock that covers compatibility
validation, cache deletion, initialization, and the database operation. Ensure
readonly callers cannot delete a cache while a writer is rebuilding it, while
preserving existing readonly error behavior. Add a concurrent read/write
regression test covering simultaneous incompatible-cache handling.
In `@packages/core/src/runtime/common/wiki-graph/dir.ts`:
- Line 11: Remove the process-wide testingStateDirectoryPathOverride fallback
and update the related directory-path resolution and cleanup logic to use only
the caller’s AsyncLocalStorage context. Ensure overlapping test scopes cannot
read or restore a shared latest path; if context-local access is unavailable,
use the existing API-boundary serialization mechanism instead.
---
Nitpick comments:
In `@packages/core/src/storage/schema-upgrade/index.ts`:
- Around line 256-264: Update the database archive path construction and
returned entry metadata in the surrounding schema-upgrade logic to use the
existing DATABASE_ENTRY_PATH constant for both the join filename and entryPath
value, replacing the duplicated literal "database.db".
In `@test/core/storage/schema-upgrade/index.test.ts`:
- Around line 89-135: Extend the test around upgradeWikiGraphArchiveSchema to
assert that the archive’s mutation token remains unchanged after the v2-to-v3
upgrade. Capture the token before upgrading and compare it with the token read
afterward, preserving coverage for writeWikgArchiveWithOverlays configured with
preserveMutationToken: true.
- Around line 1207-1213: Update isTestArchiveDocumentPath to recognize every
production archive path allowed by WIKG_ARCHIVE_PATTERNS, including
cover/data.bin and cover/info.json. Prefer reusing isWikgArchivePath if it
provides the same validation; otherwise extend the existing predicate while
preserving its current database, TOC, source, and summary path handling.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 801f832e-8ade-4a0e-8f71-f27720f24840
📒 Files selected for processing (15)
docs/schema-upgrade.mdpackages/cli/src/commands/archive-command/index.test.tspackages/core/src/document/directory/search-index.test.tspackages/core/src/document/directory/search-index.tspackages/core/src/document/home-schema-upgrade.tspackages/core/src/document/schema.tspackages/core/src/retrieval/search-index/search/errors.tspackages/core/src/runtime/common/wiki-graph/dir.tspackages/core/src/storage/schema-upgrade/index.tspackages/core/src/storage/wikg/archive/manifest.tstest/core/library/query.test.tstest/core/retrieval/query/archive-view/index.test.tstest/core/storage/schema-upgrade/index.test.tstest/core/storage/wikg/archive.test.tstest/core/storage/wikg/wiki-graph-archive-file.test.ts
💤 Files with no reviewable changes (1)
- packages/core/src/document/schema.ts
Summary
Verification