fix(sqlite-native): keep truncate cache coherent#4637
Conversation
PR Review: fix(sqlite-native): keep truncate cache coherentBoth bugs fixed here are real and the fixes are correct. Fix 1 — off-by-one in cache eviction boundaryThe old formula: let truncate_from_chunk = if size == 0 { 0u32 } else { (size as u32 / kv::CHUNK_SIZE as u32) + 1 };
// kept chunks with: chunk_idx < truncate_from_chunkwas off-by-one on chunk-aligned truncations. Truncating to exactly The new formula uses Fix 2 — stale cache after partial-chunk truncationThe old code wrote the shortened slice to KV via Variable reorderingMoving ConcernsWASM VFS parity (required per CLAUDE.md) The repo requires the native Rust VFS and the WASM TypeScript VFS to match 1:1. The WASM truncate path in Test coverage No tests were added. Suggested cases to cover:
Minor: cache eviction before metadata write The read cache is evicted before the metadata is written. If the metadata write fails, evicted entries are gone from the cache but the KV store is unchanged, forcing unnecessary round-trips on subsequent reads. This is a performance issue on error paths only, not a correctness issue. SummaryThe two correctness fixes are well-reasoned and the math is sound. The main outstanding item is WASM VFS parity, which is a hard requirement per the project's conventions. |
4079bac to
459dd12
Compare
4303e83 to
60882a2
Compare
459dd12 to
d7b2c43
Compare
5f174d0 to
c75356d
Compare
d7b2c43 to
6c17fae
Compare
c75356d to
dfaae41
Compare
6c17fae to
a070720
Compare

Description
Please include a summary of the changes and the related issue. Please also include relevant motivation and context.
Type of change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes.
Checklist: