Problem
On macOS, the default launchctl limit maxfiles soft limit is 256. Hermes gateway processes with multiple profiles + MCP servers routinely exceed this:
trade-paper gateway: 286 fds (198 IPv4, 50 REG, 20 PIPE)
When the limit is hit, any file operation fails with:
OSError: [Errno 24] Too many open files: '.sessions_*.tmp'
This crashes session saves, kanban dispatches, and any tool that opens files.
Root cause
- Each MCP server subprocess (playwright, sequential-thinking, memory, brave-search) maintains persistent pipes/sockets
- Multiple profiles each run their own gateway with independent MCP connections
- Hermes never closes idle MCP connections or monitors fd usage
- No startup warning when
ulimit -n is near capacity
Workaround
Manually add SoftResourceLimits → NumberOfFiles: 4096 to each gateway launchd plist.
Suggested fixes
- Startup detection: Check
resource.getrlimit(resource.RLIMIT_NOFILE) at gateway start, warn if soft limit < 1024
- MCP lazy init: Don't connect all MCP servers at startup — connect on first tool call
- Idle MCP timeout: Close MCP connections idle for N minutes, reconnect on demand
- Periodic fd check: Log warning in gateway loop if fd count exceeds 80% of soft limit
Environment
- macOS 26.5 (Apple Silicon)
- Hermes 3 profiles (default, research, trade-paper)
- 6 MCP servers configured
- Python 3.x, launchd-managed gateways
Problem
On macOS, the default
launchctl limit maxfilessoft limit is 256. Hermes gateway processes with multiple profiles + MCP servers routinely exceed this:When the limit is hit, any file operation fails with:
This crashes session saves, kanban dispatches, and any tool that opens files.
Root cause
ulimit -nis near capacityWorkaround
Manually add
SoftResourceLimits→NumberOfFiles: 4096to each gateway launchd plist.Suggested fixes
resource.getrlimit(resource.RLIMIT_NOFILE)at gateway start, warn if soft limit < 1024Environment