fix(datasets): apply validator to cached text before serving it - #80
Conversation
Co-Authored-By: Abhinav Pola <abhinav.pola@openrouter.ai>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
Original prompt from Abhinav
|
TL;DR
fetchCachedTextFilenow runsrequest.validateon cache hits too, so a malformed cached envelope is refetched and overwritten instead of poisoning every run.What changed?
src/datasets/cached-file.ts: cache hit is only returned whenrequest.validate?.(cached.text) === undefined; otherwise fall through to download → validate → write (existing path).src/datasets/cached-file.test.ts: regression test seeding an HTML body under the cache key and asserting one origin request plus the envelope being replaced.Why?
Follow-up to #79, which added validation before cache writes. Entries written before that (or by any other writer) still bypassed the validator on read, so a pinned cache with an HTML/rate-limit body would fail every benchmark run without ever refetching. Flagged by Devin Review on openrouter-web#41251.
How to test
Expected: 19 pass, including "refetches and overwrites a cached entry the validator rejects".
Reviewer focus
validateare unchanged (undefined?.(…) === undefined).Checklist
Link to Devin session: https://openrouter.devinenterprise.com/sessions/949ffdf48c7843febc66e0c2d8dc8486
Open in Devin Desktop: https://openrouter.devinenterprise.com/desktop/session/949ffdf48c7843febc66e0c2d8dc8486?variant=devin
Requested by: @abhinav-pola