fix(gateway): set NumberOfFiles limits in macOS launchd plist (#36899) - #36939
Closed
luyao618 wants to merge 1 commit into
Closed
fix(gateway): set NumberOfFiles limits in macOS launchd plist (#36899)#36939luyao618 wants to merge 1 commit into
luyao618 wants to merge 1 commit into
Conversation
…search#36899) The generated LaunchAgent plist did not include SoftResourceLimits or HardResourceLimits entries. Under launchd, gateway processes inherit a default RLIMIT_NOFILE soft limit (typically 256), which the long-running gateway exhausts over time. This surfaces as: OSError: [Errno 24] Too many open files: '/Users/<user>/.hermes/sessions/.sessions_<random>.tmp' during atomic writes of sessions.json (and other paths). Add SoftResourceLimits and HardResourceLimits dicts with NumberOfFiles=65536 to generate_launchd_plist() so newly installed LaunchAgents get a sane fd budget out of the box. Existing gateway installs will pick up the new limits on the next 'hermes gateway install' (plist-current check will detect drift and rewrite). Adds a regression test that asserts both keys + the NumberOfFiles integer are present in the emitted plist.
This was referenced Jun 7, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #36899.
On macOS, gateway installs as a launchd LaunchAgent inherit a default
RLIMIT_NOFILEsoft limit (typically 256). Long-running gateway processes eventually exhaust that budget and crash during atomic writes ofsessions.jsonwith:The generated plist in
hermes_cli/gateway.py::generate_launchd_plist()previously did not set any resource limits, so launchd's default applied.Fix
Embed
SoftResourceLimitsandHardResourceLimitsdicts withNumberOfFiles=65536in the emitted plist. This matches the verified manual workaround in the issue and is well below macOS's hard ceiling, so it lifts the soft limit without requiring any user intervention. The existinglaunchd_plist_is_current()drift check will rewrite stale plists on the nexthermes gateway install --system.Verification
python -m pytest tests/hermes_cli/test_gateway_service.py -k launchd_plist— passes.test_launchd_plist_sets_nofiles_resource_limitsparses the generated plist and asserts both keys +NumberOfFilesintegers are present (verified at 65536 viaplistlib.loads).NumberOfFilesis a documented launchd key (seeman launchd.plist), no regressions.Scope
hermes_cli/gateway.py—generate_launchd_plist()(XML insertion only)tests/hermes_cli/test_gateway_service.py— one focused regression test