Duplicate check
| Item |
Relation |
| #16 (open) |
Not duplicate — rebuild /compare diff page UI |
| No open issue |
Cache invalidation after disk writes |
Summary
listExtractions(), getExtraction(), and getProductDir() memoize results for 30 seconds. invalidateExtractionCache() exists and its docstring says to call it after writing extraction.json, but nothing in the repo calls it. After batch completion, spotfix accept, or sync extract, pages and APIs can return stale or missing extraction data until the TTL expires.
Steps to reproduce
-
Open a product page that loads via getExtraction("r770").
-
Write a new extraction.json (batch worker, spotfix accept, or extract-one).
-
Reload the product page within 30 seconds.
-
Observe: old extraction values or missing slug in portfolio index until cache TTL elapses.
-
Confirm no callers:
rg 'invalidateExtractionCache' --type ts
# only the definition in lib/extractions.ts
Expected behavior
Any code path that writes extraction.json calls invalidateExtractionCache() so subsequent reads reflect disk state immediately.
Actual behavior
Cache persists for TTL_MS = 30_000 regardless of writes.
Root cause
/** Force a refresh on the next call — invoke after writing an extraction.json. */
export function invalidateExtractionCache(): void {
_listCache = null;
_slugIndex = null;
}
Writers that should invalidate but do not:
worker/handlers/anthropic-batch.ts → writeExtractionJson()
lib/pipeline/spotfix.ts → atomicWriteJson(extractionPath, ...)
scripts/extract-one.ts → writeExtractionJson()
Suggested fix
- Call
invalidateExtractionCache() inside writeExtractionJson() (central fix), or at each write site.
- Add unit test: write invalidates cache; next
getExtraction() sees new data.
PR scope
~10–20 lines + one cache test.
Duplicate check
/comparediff page UISummary
listExtractions(),getExtraction(), andgetProductDir()memoize results for 30 seconds.invalidateExtractionCache()exists and its docstring says to call it after writingextraction.json, but nothing in the repo calls it. After batch completion, spotfix accept, or sync extract, pages and APIs can return stale or missing extraction data until the TTL expires.Steps to reproduce
Open a product page that loads via
getExtraction("r770").Write a new
extraction.json(batch worker, spotfix accept, orextract-one).Reload the product page within 30 seconds.
Observe: old extraction values or missing slug in portfolio index until cache TTL elapses.
Confirm no callers:
Expected behavior
Any code path that writes
extraction.jsoncallsinvalidateExtractionCache()so subsequent reads reflect disk state immediately.Actual behavior
Cache persists for
TTL_MS = 30_000regardless of writes.Root cause
Writers that should invalidate but do not:
worker/handlers/anthropic-batch.ts→writeExtractionJson()lib/pipeline/spotfix.ts→atomicWriteJson(extractionPath, ...)scripts/extract-one.ts→writeExtractionJson()Suggested fix
invalidateExtractionCache()insidewriteExtractionJson()(central fix), or at each write site.getExtraction()sees new data.PR scope
~10–20 lines + one cache test.