mirror of
https://github.com/morluto/rea.git
synced 2026-11-29 01:46:39 +00:00
* fix(views): bound the evidence-json serialization cache Paging a retained record with the evidence-json view cached its whole chunked serialization in a WeakMap for as long as the parent stayed retained, even for a one-unit page. Nothing counted those copies, so paging many large retained records could exhaust server memory despite successful retention admission. The cache now keeps whole serializations least recently used first, within 16 Mi code units in total. A record that does not fit, and a mutable inline parent, is paged by one streaming pass over jsonParts that keeps only the parts around the requested window, so memory stays bounded by the page. Both paths return identical text and coverage. The limit inventory now links to the agent result budget section instead of repeating its delivery contract. * fix(views): hold cached evidence-json records weakly and test the cache bounds Review on #14588: the module-wide Map kept cached Evidence alive after its ledger released it, and the cache limits were untested. EvidenceJsonSerializationCache now owns the cache. Records are keys of a WeakMap, least-recently-used order is a Set of entries that reach their record only through a WeakRef, and a FinalizationRegistry returns a collected record's code units. The cache therefore never extends a record's lifetime, and its total stays within the configured code units. projectEvidenceJsonView takes the cache, defaulting to the shared one, so tests can size it. New cases cover a retained record that overflows the cache during its scan (pages before and after the overflow match, nothing is cached, and the scan keeps only the window's parts) and LRU eviction across three records. * fix(views): use Budget.chargeEvicting and unregister evicted FinalizationRegistry entries