[PR #250] [MERGED] fix(deepagents): fix OOM in conversation history offloading #297

Closed
opened 2026-06-05 17:22:34 -04:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/deepagentsjs/pull/250
Author: @christian-bromann
Created: 2/23/2026
Status: Merged
Merged: 2/24/2026
Merged by: @christian-bromann

Base: mainHead: cb/performance-improvements


📝 Commits (4)

  • c9f3d52 fix(deepagents): fix OOM in conversation history offloading (#XXX)
  • 806ff20 Fix OOM issue in conversation history offloading
  • d942d16 improved behavior for empty files
  • d69428f format

📊 Changes

4 files changed (+398 additions, -81 deletions)

View changed files

.changeset/khaki-emus-melt.md (+5 -0)
📝 libs/deepagents/src/backends/sandbox.test.ts (+257 -39)
📝 libs/deepagents/src/backends/sandbox.ts (+86 -16)
📝 libs/deepagents/src/middleware/summarization.ts (+50 -26)

📄 Description

The summarization middleware used edit() to append to the conversation history file, which downloaded the file twice and performed a full string search-and-replace — causing ~6x peak memory relative to file size. Replace with direct byte concatenation via uploadFiles(), reducing peak memory to ~2x.

Also harden BaseSandbox.edit() with memory and performance improvements:

  • Count occurrences via indexOf loop instead of split() to avoid allocating intermediate arrays
  • Use replaceAll() instead of split().join()
  • Reuse found index for single-replace to skip redundant search
  • Release raw Uint8Array early for GC
  • Guard against empty oldString (infinite loop)
  • Short-circuit when oldString === newString

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langchain-ai/deepagentsjs/pull/250 **Author:** [@christian-bromann](https://github.com/christian-bromann) **Created:** 2/23/2026 **Status:** ✅ Merged **Merged:** 2/24/2026 **Merged by:** [@christian-bromann](https://github.com/christian-bromann) **Base:** `main` ← **Head:** `cb/performance-improvements` --- ### 📝 Commits (4) - [`c9f3d52`](https://github.com/langchain-ai/deepagentsjs/commit/c9f3d525aa4a755b18a5ff1e69d2f67fbde5e30e) fix(deepagents): fix OOM in conversation history offloading (#XXX) - [`806ff20`](https://github.com/langchain-ai/deepagentsjs/commit/806ff20b8c38d7b85f6ce1226ee47fb568035489) Fix OOM issue in conversation history offloading - [`d942d16`](https://github.com/langchain-ai/deepagentsjs/commit/d942d1641ab87724210b62d1089d653e58ef7e11) improved behavior for empty files - [`d69428f`](https://github.com/langchain-ai/deepagentsjs/commit/d69428fb68938f11299f54c6d9535104850b3488) format ### 📊 Changes **4 files changed** (+398 additions, -81 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/khaki-emus-melt.md` (+5 -0) 📝 `libs/deepagents/src/backends/sandbox.test.ts` (+257 -39) 📝 `libs/deepagents/src/backends/sandbox.ts` (+86 -16) 📝 `libs/deepagents/src/middleware/summarization.ts` (+50 -26) </details> ### 📄 Description The summarization middleware used edit() to append to the conversation history file, which downloaded the file twice and performed a full string search-and-replace — causing ~6x peak memory relative to file size. Replace with direct byte concatenation via uploadFiles(), reducing peak memory to ~2x. Also harden BaseSandbox.edit() with memory and performance improvements: - Count occurrences via indexOf loop instead of split() to avoid allocating intermediate arrays - Use replaceAll() instead of split().join() - Reuse found index for single-replace to skip redundant search - Release raw Uint8Array early for GC - Guard against empty oldString (infinite loop) - Short-circuit when oldString === newString --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-06-05 17:22:34 -04:00
yindo closed this issue 2026-06-05 17:22:34 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/deepagentsjs#297