Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 135 to 136

Compare

+39 −11 in 2 places
Lines 14–32 at 136 (were 14–26 at 135)
1414}
1515
1616/**
17− * Operation-local read cache with fixed payload and entry limits. Serialized
18− * values preserve the storage copy contract. Discard it after an outer host
17+ * Operation-local read cache with fixed payload and entry limits. Private numeric
18+ * pages, immutable scalars and serialized objects preserve the copy contract. Discard it after an outer host
1919 * rollback or any mutation made through another storage instance.
2020 */
21+type CachedValue = { bytes: number } & (
22+ | { kind: "scalar"; value: string | number | boolean | null | undefined }
23+ | { kind: "numbers"; value: readonly number[] }
24+ | { kind: "json"; json: string }
25+);
2127export class CachedStateStorage implements GraphStateStorage {
2228 readonly #source: GraphStateStorage;
23− readonly #cache = new Map<string, { json: string; bytes: number }>();
29+ readonly #cache = new Map<string, CachedValue>();
2430 readonly #maxBytes: number;
2531 readonly #maxEntries: number;
2632 #bytes = 0;
Lines 60–99 at 136 (were 54–71 at 135)
5460 if (hit) {
5561 this.#cache.delete(cacheKey);
5662 this.#cache.set(cacheKey, hit);
63+ if (hit.kind === "scalar") return hit.value;
64+ if (hit.kind === "numbers") return hit.value.slice();
5765 return (JSON.parse(hit.json) as { value?: unknown }).value;
5866 }
5967 const value = this.#source.read(collection, key);
60− const json = JSON.stringify({ value });
61− // Charge two bytes per UTF-16 unit and a conservative fixed entry cost.
62− // This bounds retained payload; it is not an isolate heap measurement.
63− const bytes = 2 * (json.length + cacheKey.length) + 128;
64− if (bytes <= this.#maxBytes && this.#maxEntries > 0) {
65− while (this.#bytes + bytes > this.#maxBytes || this.#cache.size >= this.#maxEntries)
68+ const overhead = 2 * cacheKey.length + 160;
69+ let entry: CachedValue;
70+ if (
71+ value === undefined ||
72+ value === null ||
73+ typeof value === "string" ||
74+ typeof value === "boolean" ||
75+ (typeof value === "number" && Number.isFinite(value))
76+ ) {
77+ entry = { kind: "scalar", value, bytes: overhead + (typeof value === "string" ? 2 * value.length : 16) };
78+ } else if (
79+ Array.isArray(value) &&
80+ value.length <= 256 &&
81+ Object.keys(value).length === value.length &&
82+ value.every(Number.isSafeInteger)
83+ ) {
84+ // Store one private, bounded numeric page. Public reads still receive a
85+ // fresh copy; neither the source result nor a reader can mutate the cache.
86+ entry = { kind: "numbers", value: value.slice(), bytes: overhead + 32 + value.length * 8 };
87+ } else {
88+ const json = JSON.stringify({ value });
89+ entry = { kind: "json", json, bytes: overhead + 2 * json.length };
90+ }
91+ // Payload accounting is bounded, not a measurement of actual isolate heap.
92+ if (entry.bytes <= this.#maxBytes && this.#maxEntries > 0) {
93+ while (this.#bytes + entry.bytes > this.#maxBytes || this.#cache.size >= this.#maxEntries)
6694 this.#drop(this.#cache.keys().next().value!);
67− this.#cache.set(cacheKey, { json, bytes });
68− this.#bytes += bytes;
95+ this.#cache.set(cacheKey, entry);
96+ this.#bytes += entry.bytes;
6997 }
7098 return value;
7199 }
MCP
compare on this site's /mcp
CLI
abso diff 135 136 src/engine/state-source.ts --json
JSON
/christopher/abso-core/compare/135..136?file=src%2Fengine%2Fstate-source.ts&format=json