Raise macOS RLIMIT_NOFILE so GUI-spawned agents inherit more than 256 - #12289
Raise macOS RLIMIT_NOFILE so GUI-spawned agents inherit more than 256#12289sanshengai wants to merge 1 commit into
Conversation
macOS GUI apps inherit launchd's soft maxfiles of 256. cmux login shells and coding agents inherit that ceiling, so Codex hits EMFILE while scanning SKILL.md files and misreports them as invalid. Raise the soft limit at CmuxMain.main() before worker re-exec or child spawn. Never lower an existing limit or change the hard limit.
|
@sanshengai is attempting to deploy a commit to the Manaflow Team on Vercel. A member of the Team first needs to authorize it. |
|
@codex review |
|
To use Codex here, create a Codex account and connect to github. |
@sanshengai cubic can't start this review because your workspace has reached its free monthly review limit. cubic has reviewed 339,945 of the 320,000 allowed lines of code this month. Reviews resume on 1 October 2026 (in 20 days). Paid plans include much higher monthly review limits. Upgrade now to resume reviews. To help optimise your usage, you can tune cubic to get the most out of your usage limits:
|
|
I have read the CLA Document v2.2 and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
|
To use Codex here, create a Codex account and connect to github. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe change adds macOS file descriptor limit management. It calculates capped targets, tries preferred and fallback limits, tests the calculation behavior, and invokes the limit update before application startup and child process creation. ChangesFile descriptor limit initialization
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant CmuxMain
participant FileDescriptorLimit
participant Kernel as RLIMIT_NOFILE
participant ChildProcesses
CmuxMain->>FileDescriptorLimit: raiseSoftLimitIfNeeded()
FileDescriptorLimit->>Kernel: read current limits
FileDescriptorLimit->>Kernel: try preferred or fallback soft limit
Kernel-->>FileDescriptorLimit: apply result
CmuxMain->>ChildProcesses: start workers and child processes
ChildProcesses->>Kernel: inherit raised soft limit
Merge Risk: ⚪ Minimal · up to The limit initialization preserves existing and hard limits, applies before child creation, and no actionable merge-blocking risk remains. Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 error, 1 warning)
✅ Passed checks (23 passed)
Full details: Cmux No Ambient Global StateExplanation The PR adds a caseless public enum used as a static-only namespace in Resolution Replace
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
|
Summary
RLIMIT_NOFILEsoft limit atCmuxMain.main(), before worker re-exec or any child spawn, so login shells and coding agents inherit more than launchd's default 256.launchctl limit maxfilessoft=256. Ghostty's/usr/bin/login -flp …does not raise it. Codex then fans out skill-file reads (up to 8×64 concurrent opens) and fails withEMFILE(Too many open files (os error 24)), which it surfaces asSkipped loading N skill(s) due to invalid SKILL.md fileseven when the files are fine.setrlimitfailure. If Darwin rejects 65536 (OPEN_MAXis 10240 on some versions), it falls back to 10240 then 8192.Testing
swift buildofPackages/macOS/CmuxFoundationsucceeds with the newFileDescriptorLimittype (Swift 6 / macOS 14).proposedSoftLimit(raise 256, clamp to hard, never lower, ignore unlimited).swift testcould not run under Command Line Tools-only (TestingMacrosplugin missing); please runswift test --filter FileDescriptorLimitTestswith Xcode 26..appin this environment (needs the Ghostty submodule / Xcode 26). Logic matches a live diagnosis on cmux 0.64.22:launchctl limit maxfileswas256 unlimited, the cmux process sat at ~167 open files, and a Codex session started from that tree skipped 18 validSKILL.mdfiles withos error 24.python3 -c 'import resource; print(resource.getrlimit(resource.RLIMIT_NOFILE))'should show a soft limit well above 256.Demo Video
Not a UI change.
Checklist
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Low Risk
Process-startup resource limit bump with conservative guards; no auth or data-path changes, and failures are ignored.
Overview
Raises the macOS
RLIMIT_NOFILEsoft limit at the very start ofCmuxMain.main(), before worker re-exec or any child spawn, so login shells and coding agents inherit more than launchd’s default 256 open files.Adds
FileDescriptorLimitin CmuxFoundation: best-effortsetrlimittoward 65,536, with 10,240 / 8,192 fallbacks if Darwin rejects the preferred value; it never lowers an existing soft limit, never changes the hard limit, and ignores failures. Unit tests coverproposedSoftLimit(raise from 256, clamp to hard, no lowering, unlimited soft).Reviewed by Cursor Bugbot for commit 4c97503. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by cubic
Raises the macOS
RLIMIT_NOFILEsoft limit at process startup so GUI-spawned agents inherit more than launchd's default 256, preventingEMFILEerrors that made coding agents skip validSKILL.mdfiles.FileDescriptorLimit.raiseSoftLimitIfNeeded()inCmuxFoundation, called fromCmuxMain.main()before worker re-exec or child spawn.setrlimitfailure.proposedSoftLimit.Written for commit 4c97503. Summary will update on new commits.
Summary by CodeRabbit
New Features
Tests