SIGN IN SIGN UP

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

### 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
C
Colin Francis committed
e64c7e31a7e62929d5d2a9048ad7df3315a546cd
Parent: 998d772
Committed by GitHub <noreply@github.com> on 4/28/2026, 11:34:34 PM