project/conat: fix memory leak #8703
Draft
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.
ref: #8702
src/packages/project/conat/open-files.tsline 165 (used for local debugging).Root cause
raw/messages, so keyed updates (like open-files touches) grew unbounded over time.Detailed explanation of the change
raw/messagesarrays because the server deletes old keyed rows without notifying clients.CoreStreamlooks up the previous raw seq for that key and locally deletes that seq withprocessPersistentDelete(..., { noEmit: true }). This removes the stale entry fromraw/messageswhile avoiding extra change events.CoreStreamnow records the last value per key (lastValueByKey) soprevis still available during conflict resolution, even if the old seq is deleted from memory.remotecache for the same reason: if theCoreStreamkventry is evicted,DKVcan still supply a prev value to the merge function.Fix (client-side GC for keyed updates)
processPersistentDelete(..., { noEmit: true }). This keeps the in-memory arrays flat without changing server behavior.lastValueByKeysoprevis still available for merge conflict resolution even after the old seq is removed.remotecache to supplyprevto merge when the CoreStream kv entry has been evicted.Other cleanup
Tests
previs preserved.In a local test setup we see that open-files stats show keyed-KV arrays staying flat instead of growing unbounded. Example log lines: