{"draft":null,"from":144,"to":145,"files":[{"path":"src/engine/state-source.ts","added":11,"removed":2,"diff":"--- a/src/engine/state-source.ts\n+++ b/src/engine/state-source.ts\n@@ -88,6 +88,11 @@\n \t\t\tconst json = JSON.stringify({ value });\n \t\t\tentry = { kind: \"json\", json, bytes: overhead + 2 * json.length };\n \t\t}\n+\t\tthis.#remember(cacheKey, entry);\n+\t\treturn value;\n+\t}\n+\t#remember(cacheKey: string, entry: CachedValue): void {\n+\t\tthis.#drop(cacheKey);\n \t\t// Payload accounting is bounded, not a measurement of actual isolate heap.\n \t\tif (entry.bytes <= this.#maxBytes && this.#maxEntries > 0) {\n \t\t\twhile (this.#bytes + entry.bytes > this.#maxBytes || this.#cache.size >= this.#maxEntries)\n@@ -95,11 +100,15 @@\n \t\t\tthis.#cache.set(cacheKey, entry);\n \t\t\tthis.#bytes += entry.bytes;\n \t\t}\n-\t\treturn value;\n \t}\n \twrite(collection: string, key: string, value: unknown): void {\n-\t\tthis.#drop(JSON.stringify([collection, key]));\n+\t\tconst cacheKey = JSON.stringify([collection, key]);\n+\t\tthis.#drop(cacheKey);\n \t\tthis.#source.write(collection, key, value);\n+\t\t// Allocation counters are immutable scalars. Keep successful writes within\n+\t\t// the existing cache budget instead of immediately reading them back.\n+\t\tif (typeof value === \"number\" && Number.isSafeInteger(value) && !Object.is(value, -0))\n+\t\t\tthis.#remember(cacheKey, { kind: \"scalar\", value, bytes: 2 * cacheKey.length + 176 });\n \t}\n \tremove(collection: string, key: string): void {\n \t\tthis.#drop(JSON.stringify([collection, key]));"}],"unmatched":[]}