Skip to content

Conversation

@code-yeongyu
Copy link
Owner

Summary

Fixes multiple memory leak issues identified in issue #165.

Changes

1. BackgroundManager Task Accumulation (manager.ts)

  • Problem: Completed tasks accumulated in tasks Map forever, causing linear memory growth
  • Solution:
    • Added 5-minute TTL for completed tasks (COMPLETED_TASK_RETENTION_MS)
    • Added max 50 completed tasks limit with FIFO eviction (MAX_COMPLETED_TASKS)
    • Fixed race conditions in async completion paths
    • Added timer.unref() to prevent blocking process exit
    • Clear notifications when tasks are evicted

2. Tool Input Cache (tool-input-cache.ts)

  • Problem: Module-level setInterval never cleared, plus no cache size limit
  • Solution:
    • Moved interval to lazy start on first use (idempotent)
    • Added process.on("exit") cleanup
    • Added max 1000 entries with FIFO eviction (MAX_CACHE_SIZE)
    • Added interval.unref() to prevent blocking process exit

3. Comment Checker (comment-checker/index.ts)

  • Problem: Module-level setInterval never cleared
  • Solution:
    • Moved interval to lazy start in hook factory (idempotent)
    • Added process.on("exit") cleanup
    • Added interval.unref() to prevent blocking process exit

Testing

  • ✅ All existing tests pass (bun test)
  • ✅ TypeScript type checks pass (bun run typecheck)

Oracle Review Summary

Oracle (GPT-5.2) reviewed these changes and confirmed:

  • Fixes address real leak vectors correctly
  • Race conditions are properly handled with status re-checks after async operations
  • Timer unref() prevents keeping process alive just for housekeeping

Closes #165


🤖 Generated with assistance of OhMyOpenCode

- Fixed agent name OmO → Sisyphus
- Added CI PIPELINE section documenting workflow patterns
- Fixed testing documentation (Bun test framework with BDD pattern)
- Added README.zh-cn.md to multi-language docs list
- Added `bun test` command to COMMANDS section
- Added anti-patterns: Over-exploration, Date references
- Updated convention: Test style with BDD comments
- Added script/generate-changelog.ts to structure
- Updated timestamp (2025-12-22) and git commit reference (aad7a72)

🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
…t checker (#165)

- Add TTL-based cleanup for completed tasks in BackgroundManager
- Add cache size limits with FIFO eviction for tool input cache
- Lazy-load setInterval timers to prevent blocking process exit
- Use timer.unref()/interval.unref() to allow graceful shutdown
- Add process exit handlers for proper cleanup

closes #165

🤖 Generated with assistance of [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
@code-yeongyu code-yeongyu merged commit 0801427 into master Dec 22, 2025
5 checks passed
@code-yeongyu code-yeongyu deleted the investigate-memory-leak branch December 22, 2025 02:11
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