Skip to content

feat: add /debug/memory endpoints for production memory diagnostics#87

Closed
bolinocroustibat wants to merge 1 commit into
mainfrom
feat/debug-memory-endpoint
Closed

feat: add /debug/memory endpoints for production memory diagnostics#87
bolinocroustibat wants to merge 1 commit into
mainfrom
feat/debug-memory-endpoint

Conversation

@bolinocroustibat
Copy link
Copy Markdown
Collaborator

@bolinocroustibat bolinocroustibat commented Mar 31, 2026

Related to #86

Memory keeps growing in production even after the mcp SDK fix (PR #84). We need visibility into what is allocating memory.

Adds temporary debug endpoints gated behind ENABLE_DEBUG=true env var:

  • GET /debug/memory -- current RSS, tracemalloc top allocations, GC stats, top object types
  • GET /debug/memory/snapshot -- take a tracemalloc baseline
  • GET /debug/memory/diff -- compare current allocations to the baseline, showing what grew

Uses only stdlib (tracemalloc, gc, resource). Returns 404 when ENABLE_DEBUG is not set.

Usage on the VM:

# Take baseline after warmup
curl http://localhost:8000/debug/memory/snapshot

# Wait for traffic, then check what grew
curl http://localhost:8000/debug/memory/diff

# Full memory overview
curl http://localhost:8000/debug/memory

To be removed once the memory issue is identified and fixed.

@bolinocroustibat bolinocroustibat self-assigned this Mar 31, 2026
Temporary debug endpoints gated behind ENABLE_DEBUG=true env var:
- GET /debug/memory -- RSS, tracemalloc top allocations, GC stats, object type counts
- GET /debug/memory/snapshot -- take a tracemalloc baseline
- GET /debug/memory/diff -- compare current allocations to baseline

Uses only stdlib (tracemalloc, gc, resource). Returns 404 when disabled.

Made-with: Cursor
@bolinocroustibat bolinocroustibat force-pushed the feat/debug-memory-endpoint branch from a200698 to ffc111b Compare March 31, 2026 12:31
@bolinocroustibat bolinocroustibat added 1 - High priority Important and urgent perf Latency of tool calls, memory usage, connection throughput bug Something isn't working and removed perf Latency of tool calls, memory usage, connection throughput labels Mar 31, 2026
@bolinocroustibat bolinocroustibat marked this pull request as draft April 1, 2026 16:43
@bolinocroustibat bolinocroustibat added 3 - Low priority Nice-to-have feature New MCP tools, prompts, resource types, or protocol capabilities and removed 1 - High priority Important and urgent bug Something isn't working labels Apr 1, 2026
@bolinocroustibat
Copy link
Copy Markdown
Collaborator Author

Since #86 seems to be solved with fewer profiling/performance calls to Sentry, this PR might not be useful anymore. Let's confirm all is good on production for a few days and than close it without merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3 - Low priority Nice-to-have feature New MCP tools, prompts, resource types, or protocol capabilities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant