Skip to content

fix(cache): store database in per-schema-version directory#433

Merged
wan9chi merged 9 commits into
mainfrom
fix-cache-per-version-dir
Jun 9, 2026
Merged

fix(cache): store database in per-schema-version directory#433
wan9chi merged 9 commits into
mainfrom
fix-cache-per-version-dir

Conversation

@fengmk2

@fengmk2 fengmk2 commented Jun 9, 2026

Copy link
Copy Markdown
Member

The task cache was one shared cache.db keyed only by an in-DB user_version. An older vp build opening a database written by a newer build aborted with Unrecognized database version, so switching between branches that pin different Vite+ versions broke the cache.

Store the cache in a per-schema-version subdirectory (e.g. node_modules/.vite/task-cache/v13/) so incompatible builds use separate databases and stay warm across branch switches. An unrecognized database is now rebuilt instead of aborting, and a one-time sweep removes the legacy top-level cache files.

Closes voidzero-dev/vite-plus#1785


Note

Medium Risk
Changes where and how the SQLite task cache is created and cleaned, which affects all cached runs; behavior is simpler but users may retain orphaned legacy top-level cache files until they run cache clean.

Overview
Fixes branch switches between Vite+ versions that previously aborted with Unrecognized database version when an older build opened a newer cache.db.

The task cache now lives under a schema-version subdirectory (e.g. node_modules/.vite/task-cache/v13/). Session init writes only there; cache clean removes the whole task-cache tree (all versions plus any legacy top-level files). Opening the DB drops in-DB user_version migration and version-mismatch errors in favor of CREATE TABLE IF NOT EXISTS in that versioned folder, so each pinned version keeps an isolated warm cache and stale top-level cache.db files are never opened.

Test support: vtt list-dir --recursive finds archives under nested version dirs; new unit and e2e coverage covers version isolation and ignored legacy cache paths.

Reviewed by Cursor Bugbot for commit 1a1937f. Configure here.

fengmk2 added 4 commits June 9, 2026 14:16
The task cache was one shared cache.db keyed only by an in-DB user_version. An older vp build opening a database written by a newer build aborted with "Unrecognized database version", so switching between branches that pin different Vite+ versions broke the cache.

Store the cache in a per-schema-version subdirectory (e.g. task-cache/v13/) so incompatible builds use separate databases and stay warm across branch switches. An unrecognized database is now rebuilt instead of aborting, and a one-time sweep removes the legacy top-level cache files.

Closes voidzero-dev/vite-plus#1785
Use an exhaustive match for the database schema-version check instead of a loop with stacked ifs, and inline the version-set statement into the create arm.

Run the one-time legacy-layout cleanup lazily on first cache open rather than on every session startup, so commands that never touch the cache don't pay for it.

No behavior change.
Plants a pre-versioned top-level cache.db and an orphaned .tar.zst, then asserts the first run sweeps them and recreates the cache under the per-version subdirectory, with the second run hitting the migrated cache.
Assert on extension-filtered listings (the cache db left the top level and reappears nested) instead of snapshotting the literal v13 directory, so the test survives a CACHE_SCHEMA_VERSION bump.
@fengmk2

fengmk2 commented Jun 9, 2026

Copy link
Copy Markdown
Member Author

@cursor review

@fengmk2

fengmk2 commented Jun 9, 2026

Copy link
Copy Markdown
Member Author

@codex review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 30f24a6. Configure here.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@fengmk2 fengmk2 marked this pull request as ready for review June 9, 2026 08:23
@fengmk2 fengmk2 requested a review from wan9chi June 9, 2026 08:23
@fengmk2 fengmk2 self-assigned this Jun 9, 2026
fengmk2 added 2 commits June 9, 2026 16:57
The per-version cache directory already isolates incompatible schemas, so the in-database user_version is redundant: remove the PRAGMA query, the match/reset loop, and the legacy-layout sweep. load_from_path now just ensures the tables exist (CREATE TABLE IF NOT EXISTS).

A cache left by another version is harmlessly ignored (it lives in a directory this build never opens) and reclaimable via vp cache clean, which still wipes the whole task-cache base. Replace the migration e2e fixture with one asserting the leftover is ignored.
Fold the WAL pragma and the two CREATE TABLE IF NOT EXISTS statements into one execute_batch, so opening the cache is one SQLite call instead of three. On an existing database the IF NOT EXISTS creates are near-free no-ops; load_from_path runs once per process (OnceCell).
@fengmk2

fengmk2 commented Jun 9, 2026

Copy link
Copy Markdown
Member Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 1a1937f. Configure here.

wan9chi and others added 2 commits June 9, 2026 23:52
The name collided with execute/mod.rs's `cache_base_path`, which means the
workspace root that cached relative paths anchor to. This field is the parent
of all `vN` version dirs, so `cache_root` is clearer and pairs with the
versioned sibling `cache_path` (cache_root.join("v13")).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
It is only referenced within the module (by cache_schema_dir_name), so the
`pub` was unnecessary.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

wan9chi commented Jun 9, 2026

Copy link
Copy Markdown
Member

wan9chi commented Jun 9, 2026

Copy link
Copy Markdown
Member

Merge activity

  • Jun 9, 4:00 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jun 9, 4:00 PM UTC: @wan9chi merged this pull request with Graphite.

@wan9chi wan9chi merged commit 7ed8c9d into main Jun 9, 2026
18 checks passed
@wan9chi wan9chi deleted the fix-cache-per-version-dir branch June 9, 2026 16:00
wan9chi added a commit that referenced this pull request Jun 9, 2026
## Why

`crates/vite_task` had two unrelated fields both named `cache_base_path`, which was a trap for anyone reading across the cache code:

- In [`session/mod.rs`](crates/vite_task/src/session/mod.rs), it meant the **cache directory** — the parent of all `vN` schema-version subdirs.
- In [`execute/mod.rs`](crates/vite_task/src/session/execute/mod.rs), it meant the **workspace root** — the directory that relative paths stored in cache entries (inputs, outputs, archives) are resolved against. It is literally set to `self.workspace_path`.

Same name, opposite halves of the cache machinery (where the cache lives vs. what cached paths point at).

## What

This PR renames the `execute` one to `workspace_root`, naming it for the value it actually holds and disambiguating it from the cache directory. The doc comment is updated to spell out the role. All 10 references (the `ExecutionContext` field and the `execute_spawn` parameter it feeds) are renamed.

The `session` field was renamed to `cache_root` in the parent PR (#433), so after both PRs the two concepts read clearly:

| Field | Where | Meaning |
| --- | --- | --- |
| `cache_root` | session | parent of all `vN` cache dirs |
| `cache_path` | session | this build's versioned dir (`…/v13`) |
| `workspace_root` | execute | dir that cached relative paths anchor to |
| `cache_dir` | execute | where cache files (db, archives) are stored |

Pure rename + doc tidy; no behavior change. `cargo check -p vite_task` passes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
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.

Failed to initialize cache: Unrecognized database version: 13 error

2 participants