[PR #494] [MERGED] feat(quickjs): implement delete session in after agent hook to clean up completed repl sessions #508

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

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/deepagentsjs/pull/494
Author: @colifran
Created: 4/28/2026
Status: Merged
Merged: 4/28/2026
Merged by: @colifran

Base: mainHead: colifran/repl-memory-management


📝 Commits (3)

  • 1ff2b96 implement delete session in after agent hook
  • 97a01dd add changeset, fix spelling error
  • 1e9714c remove unnecessary assertion

📊 Changes

6 files changed (+92 additions, -2 deletions)

View changed files

.changeset/some-beds-serve.md (+5 -0)
📝 libs/providers/quickjs/src/middleware.int.test.ts (+0 -2)
📝 libs/providers/quickjs/src/middleware.test.ts (+59 -0)
📝 libs/providers/quickjs/src/middleware.ts (+5 -0)
📝 libs/providers/quickjs/src/session.test.ts (+13 -0)
📝 libs/providers/quickjs/src/session.ts (+10 -0)

📄 Description

Summary

ReplSession uses a static map to preserve QuickJS WASM runtime state across js_eval calls within a run. Previously sessions were never cleaned up, causing unbounded memory growth as each thread_id accumulated a live WASM runtime for the lifetime of the process.

  • Added ReplSession.deleteSession(key) to dispose of the QuickJS runtime and removes the entry from the session map
  • Added an afterAgent hook in createQuickJSMiddleware that calls deleteSession for the current thread's session key at the end of each agent run

Sessions still persist across all js_eval calls within a single run. The map remains for correct concurrent thread isolation. Without it, simultaneous runs from different threads would share a runtime.

Tests

Unit tests covering the following scenarios:

  • ReplSession.deleteSession disposes and removes an existing session
  • ReplSession.deleteSession is a no-op for a key that does not exist
  • afterAgent disposes the session for the finished thread
  • afterAgent on a thread with no session does not throw
  • afterAgent only removes the session for the finished thread, leaving other active threads intact

🔄 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/494 **Author:** [@colifran](https://github.com/colifran) **Created:** 4/28/2026 **Status:** ✅ Merged **Merged:** 4/28/2026 **Merged by:** [@colifran](https://github.com/colifran) **Base:** `main` ← **Head:** `colifran/repl-memory-management` --- ### 📝 Commits (3) - [`1ff2b96`](https://github.com/langchain-ai/deepagentsjs/commit/1ff2b960ef71af6be128b36797344e79d9279868) implement delete session in after agent hook - [`97a01dd`](https://github.com/langchain-ai/deepagentsjs/commit/97a01dd78d68478551267cc800d8028ec3e77838) add changeset, fix spelling error - [`1e9714c`](https://github.com/langchain-ai/deepagentsjs/commit/1e9714c62efe0f1852a8e12cf2d206eab6387c7a) remove unnecessary assertion ### 📊 Changes **6 files changed** (+92 additions, -2 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/some-beds-serve.md` (+5 -0) 📝 `libs/providers/quickjs/src/middleware.int.test.ts` (+0 -2) 📝 `libs/providers/quickjs/src/middleware.test.ts` (+59 -0) 📝 `libs/providers/quickjs/src/middleware.ts` (+5 -0) 📝 `libs/providers/quickjs/src/session.test.ts` (+13 -0) 📝 `libs/providers/quickjs/src/session.ts` (+10 -0) </details> ### 📄 Description ### Summary ReplSession uses a static map to preserve QuickJS WASM runtime state across js_eval calls within a run. Previously sessions were never cleaned up, causing unbounded memory growth as each thread_id accumulated a live WASM runtime for the lifetime of the process. - Added ReplSession.deleteSession(key) to dispose of the QuickJS runtime and removes the entry from the session map - Added an afterAgent hook in createQuickJSMiddleware that calls deleteSession for the current thread's session key at the end of each agent run Sessions still persist across all js_eval calls within a single run. The map remains for correct concurrent thread isolation. Without it, simultaneous runs from different threads would share a runtime. ### Tests Unit tests covering the following scenarios: - ReplSession.deleteSession disposes and removes an existing session - ReplSession.deleteSession is a no-op for a key that does not exist - afterAgent disposes the session for the finished thread - afterAgent on a thread with no session does not throw - afterAgent only removes the session for the finished thread, leaving other active threads intact --- <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:23:30 -04:00
yindo closed this issue 2026-06-05 17:23:30 -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#508