perf(sessions,think): memoise the auto-compaction estimate and drop per-turn config re-reads (#2226)
* perf(sessions): memoise the active path token total for auto-compaction The auto-compaction threshold check ran a sized path walk after every insert, so a turn's cost grew with the transcript. The core now keeps the active path's total in memory: a tail append extends it, an update of a counted row shifts it by the delta, and any write that changes the path or its overlays (branch append, delete, clear, compaction, import) drops it so the next read re-derives it from one walk. Also: a fresh-id append probes existence by key instead of reading the row's content, and Think skips the per-request think_config writes for lastClientTools and lastBody when the serialized value is unchanged. * perf(think): read the skills fingerprint from think_config once per object * fix(sessions): bound the token memo at the path cap and drop it on a rolled-back cutover The memoised path total kept every row's estimate past MAX_PATH_DEPTH, while the uncached walk only sees the newest window; the memo now tracks its depth and is dropped once a tail append would exceed the cap. The sync write aperture gains abandon(), which forgets the tail and token caches; Think and AIChat call it when the cutover transaction throws after the message write, so a rolled-back row is not counted.
M
Matt committed
d5d250e8593edbebb286c0f97a05c224bd23d054
Parent: 8c8f86d
Committed by GitHub <noreply@github.com>
on 9/9/2026, 4:11:14 PM