Skip to content

fix(memory): JobRegistry self-cleanup for completed jobs#1620

Merged
esengine merged 1 commit into
esengine:mainfrom
Bernardxu123:fix/memory-leaks-v2
May 23, 2026
Merged

fix(memory): JobRegistry self-cleanup for completed jobs#1620
esengine merged 1 commit into
esengine:mainfrom
Bernardxu123:fix/memory-leaks-v2

Conversation

@Bernardxu123

Copy link
Copy Markdown
Collaborator

JobRegistry Self-Cleanup

Fixes #1571 (JobRegistry portion)

Problem

Completed jobs accumulate in the JobRegistry Map indefinitely, retaining 64KB output buffers and ChildProcess references. Over a long session, this pins several MB of memory.

Fix

Auto-evict oldest completed jobs when count exceeds MAX_COMPLETED_JOBS (20).

Key decisions per author feedback:

  • MAX_COMPLETED_JOBS = 20 — model doesn't need 50 historical entries
  • No time throttle — gate on count only, O(jobs.size) is trivial at N=20
  • lastCleanupAt initialized to 0 so first call always runs (no dead zone)

Changes

  • src/tools/jobs.ts: Added maybeCleanup() method, called from settleClosed and list()

Testing

  • npm run lint ✅
  • npm run typecheck ✅

- Auto-evict oldest completed jobs when count exceeds MAX_COMPLETED_JOBS (20)
- Cleanup runs on job completion (settleClosed) and list() calls
- No time throttle — gate on count only, O(jobs.size) is trivial at N=20
- Initialize lastCleanupAt to 0 so first call always runs (fixes dead zone)

Fixes esengine#1571 (JobRegistry portion)
@esengine

Copy link
Copy Markdown
Owner

Clean split — narrow diff, both blockers addressed, no time-throttle dead zone since the throttle itself is gone. Merging.

@esengine esengine merged commit 9372b3a into esengine:main May 23, 2026
4 checks passed
@Bernardxu123 Bernardxu123 deleted the fix/memory-leaks-v2 branch May 23, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants