(fix) bound per-session kernel-state and nudge-dedup caches with LRU eviction - #121
Open
ranxianglei wants to merge 1 commit into
Open
(fix) bound per-session kernel-state and nudge-dedup caches with LRU eviction#121ranxianglei wants to merge 1 commit into
ranxianglei wants to merge 1 commit into
Conversation
This was referenced Sep 6, 2026
Contributor
Author
|
我来协助看一下这个问题,请分析并回复处理结果。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #113.
Problem
Two per-session caches grow without bound for the lifetime of the engine process:
AcpStateStore.states(src/state.ts) — one full acp-kernelCompressionStateper session id, including every block summary;delete()had zero callers.lastNudgeTurn(src/index.ts) — one entry per session id that ever received a nudge.A long-lived server handling many sessions leaks memory proportional to total historical session count × per-session state size. (
compressCallIdsToHideis intentionally left alone: it is bounded by in-flight compress calls and self-cleans on tool/result arrival.)Cause
Plain
Maps with only insert paths; nothing evicts idle sessions.Fix
src/lru.ts:LruMap<K,V>(extendsMap, API-compatible drop-in) +DEFAULT_SESSION_CACHE_LIMIT = 512. Recency refreshes on both get and set; over-cap inserts evict the coldest entry.AcpStateStore.statesis now an LRU map capped at 512 sessions (constructor takes an optional limit for tests).lastNudgeTurnis now an LRU map with the same cap. Worst case after eviction of a cold session: one extra non-emergency nudge when it returns (per-turn dedup restarts) — bounded and self-healing.stateForalready rehydrates from the durable log (the same path a restart uses), and rehydration is deterministic — bN ids are recorded in the durable event or synthesised in ledger order, and message refs are re-derived from the append-only full-log array (allLogMessagesincludes shadowed originals), so numbering reproduces exactly.blocks/nextBlockIdbut notnextRunId, so the first compression after a restart (or eviction) reused run idr1colliding with a rehydrated block. Rehydration now continues run ids after the rehydrated max (nextRunIdAfter).tokenSnapshot, nudge cadence state, stats counters — all self-heal on the session's next turn; documented on the field.Verification
Map.seton an existing key does not move it to MRU position — fixed by delete+re-insert).npm run typecheckclean;npm test213 pass / 0 fail (208 baseline + 5 new);npm run buildclean (dist committed per AGENTS.md §4).Built against main @ 6348af8 (v0.2.20).