fix: include DB artifact cache in invalidateAllCaches (#793)

Cherry-picked from #797 — adds clearArtifacts() to gsd-db.ts and wires
it into invalidateAllCaches() so the DB artifact table is cleared
alongside state/path/parse caches.

Co-Authored-By: 0xLeathery (PR #797)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lex Christopherson 2026-03-16 22:32:10 -06:00
parent 5271e51a84
commit 72c86e0792
2 changed files with 18 additions and 1 deletions

View file

@ -12,16 +12,18 @@
import { invalidateStateCache } from './state.js';
import { clearPathCache } from './paths.js';
import { clearParseCache } from './files.js';
import { clearArtifacts } from './gsd-db.js';
/**
* Invalidate all GSD runtime caches in one call.
*
* Call this after file writes, milestone transitions, merge reconciliation,
* or any operation that changes .gsd/ contents on disk. Forgetting to clear
* any single cache causes stale reads (see #431).
* any single cache causes stale reads (see #431, #793).
*/
export function invalidateAllCaches(): void {
invalidateStateCache();
clearPathCache();
clearParseCache();
clearArtifacts();
}

View file

@ -790,6 +790,21 @@ export function upsertRequirement(r: Requirement): void {
/**
* Insert or replace an artifact. Uses the `path` PK for idempotency.
*/
/**
* Delete all rows from the artifacts table.
* The artifacts table is a read cache clearing it forces the next
* deriveState() to fall through to disk reads (native Rust batch parse).
* Safe to call when no database is open (no-op).
*/
export function clearArtifacts(): void {
if (!currentDb) return;
try {
currentDb.exec('DELETE FROM artifacts');
} catch {
// Clearing a cache should never be fatal
}
}
export function insertArtifact(a: {
path: string;
artifact_type: string;