| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
prune() sets time.compacted but leaves the full output string and attachments in the part. Since toModelMessages already replaces compacted output with '[Old tool result content cleared]', the stored data is never used after compaction but still gets loaded from disk into memory on every prompt loop iteration. Clear both fields when pruning so they are not reloaded on subsequent iterations, reducing memory pressure in long sessions.
|
The following comment was made by an LLM, it may be inaccurate: I found potentially related PRs: ⚠️ Potential Duplicates:
Recommendation: Check PR #7049 first, as it appears to be directly addressing the same bug fix. It may have already been merged or closed, making PR #14693 potentially redundant. |
Sorry, something went wrong.
|
Closing in favor of #7049, which addresses the same root cause (compacted tool outputs and attachments not being cleared during pruning) and includes tests. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Issue for this PR
Closes #5700, #3013
Related: #9385, #9151, #7046, #5363, #13796, #12255, #10248, #9156, #9140, #10913
Type of change
What does this PR do?
SessionCompaction.prune() marks old tool outputs as compacted by setting part.state.time.compacted = Date.now(), but it never clears the actual output string or attachments array from the part. Since toModelMessages already replaces compacted output with "[Old tool result content cleared]" (message-v2.ts:620), the stored data is dead weight after compaction.
The problem is that every prompt loop iteration reloads all parts from storage into memory. In a long session with many tool calls (file reads, grep results, bash output), these compacted-but-still-full parts accumulate significant data that gets loaded into RAM repeatedly for no reason.
This clears both output and attachments on the part when pruning, so subsequent reloads don't bring dead data back into memory.
How did you verify your code works?
I monitored RSS memory of the bun process over multiple long sessions using /proc/<pid>/status and /proc/<pid>/smaps. Before the fix, a session would climb to 14-22GB RSS over the course of extended use. After the fix, memory growth is noticeably slower because compacted parts no longer contribute to the reload size.
Also verified that toModelMessages already guards compacted parts at message-v2.ts:620-621 — it checks part.state.time.compacted and substitutes "[Old tool result content cleared]" regardless of what's in output, so clearing the field has no functional impact on the messages sent to the API.
Checklist