Bug Fixes
Fixed SDK Agent Memory Leak (#499)
Fixed a critical memory leak where Claude SDK child processes were never terminated after sessions completed. Over extended usage, this caused hundreds of orphaned processes consuming 40GB+ of RAM.
Root Cause:
- When the SDK agent generator completed naturally (no more messages to process), the
AbortControllerwas never aborted - Child processes spawned by the Agent SDK remained running indefinitely
- Sessions stayed in memory (by design for future events) but underlying processes were never cleaned up
Fix:
- Added proper cleanup to SessionRoutes finally block
- Now calls
abortController.abort()when generator completes with no pending work - Creates new
AbortControllerwhen crash recovery restarts generators - Ensures cleanup happens even if recovery logic fails
Impact:
- Prevents orphaned
claudeprocesses from accumulating - Eliminates multi-gigabyte memory leaks during normal usage
- Maintains crash recovery functionality with proper resource cleanup
Thanks to @yonnock for the detailed bug report and investigation in #499!