fix(memory): auto-fold AppendOnlyLog when entries exceed 500#1627
fix(memory): auto-fold AppendOnlyLog when entries exceed 500#1627Bernardxu123 wants to merge 1 commit into
Conversation
|
Thanks for splitting this out cleanly — exactly the shape I asked for when closing #1605. The trigger placement (after Drift
The change flips What to do
Main's been moving fast this week — if the rebase takes more than a few hours you may need a second one. Push when ready and I'll merge. The SessionStats rolling-window piece from the original #1605 — same shape, separate PR whenever you're ready. |
Long-running sessions accumulate log entries without limit — each tool result (up to 8K tokens) is stored until explicit /compact. Over hours this causes unbounded memory growth (~2MB/sec during active tasks). Add a log-length check in ContextManager.decideAfterUsage(): when entries exceed MAX_LOG_ENTRIES_FOR_FOLD (500, ≈1MB), trigger the existing fold mechanism. This reuses the proven fold path — no new compression logic, just a length-based trigger alongside the existing token-ratio triggers. The constant is intentionally generous (500 entries) to avoid folding during normal bursty tool-call sequences. Sessions that reach this threshold without hitting the token-ratio fold are exactly the ones that need it: many small calls that individually stay under the ratio but collectively grow the log without bound.
86165eb to
6605bf8
Compare
|
Rebased on latest main — drift cleaned up. Diff now only contains \src/context-manager.ts. |
|
Branch restored and PR reopened. Diff is clean — only \src/context-manager.ts. |
Memory Leak Fix — AppendOnlyLog Fold Trigger
Fixes parts of #1571
Problem
Long-running sessions accumulate log entries without limit — each tool result (up to 8K tokens) is stored until explicit /compact. Over hours this causes unbounded memory growth (~2MB/sec during active tasks).
Fix
Add a log-length check in ContextManager.decideAfterUsage(): when entries exceed MAX_LOG_ENTRIES_FOR_FOLD (500, ≈1MB), trigger the existing fold mechanism.
This reuses the proven fold path — no new compression logic, just a length-based trigger alongside the existing token-ratio triggers. The constant is intentionally generous (500 entries) to avoid folding during normal bursty tool-call sequences. Sessions that reach this threshold without hitting the token-ratio fold are exactly the ones that need it: many small calls that individually stay under the ratio but collectively grow the log without bound.
Changes
Testing
Update
Drift issue fixed — rebased on latest main. Diff now only contains src/context-manager.ts.