Cap process_max_fds at kern.maxfilesperproc on Darwin #134
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 355 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.351
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #134"
general
weight: 0.35
kukushechkin
Report the effective open file descriptor limit on Darwin, which is the RLIMIT_NOFILE soft limit capped at
kern.maxfilesperproc.Motivation:
On Darwin,
process_max_fdsreportsgetrlimit(RLIMIT_NOFILE).rlim_curas is. The kernel never lets a process open more thankern.maxfilesperprocdescriptors, so when the soft limit is higher the metric overstates the real ceiling. For example, withkern.maxfilesperproc= 61440, a soft limit of 1048576 is reported as 1048576 andulimit -n unlimited(RLIM_INFINITY) is reported as 9.223372036854776e+18, whileopen()starts failing with EMFILE at fd 61440 in both cases (andgetdtablesize()returns 61440). Measured on macOS 26.6 (arm64). This makesprocess_open_fds / process_max_fdsratios and alerts useless on such machines.#116 described the soft limit as "the actual ceiling the process will hit"; on Darwin that is only true after applying the
kern.maxfilesperproccap. For comparison, Prometheus client_golang's Darwin process collector reports the rawgetrlimitsoft limit, but the Go runtime caps its own soft limit atkern.maxfilesperprocat startup (seeadjustFileLimitin Go'ssrc/syscall/rlimit_darwin.go), so in Go processes that value is normally already the enforced one.Linux is unchanged: there the kernel's
setrlimitrejects RLIMIT_NOFILE values abovefs.nr_open, sorlim_curalready is the enforced value.Modifications:
kern.maxfilesperprocwithsysctlbynameand reportmin(rlim_cur, kern.maxfilesperproc). If the sysctl fails, fall back torlim_curas before.kern.maxfilesperproc(restoring it afterwards) and checks thatmaxFileDescriptorsmatchesgetdtablesize(), which the kernel computes as the same minimum. It is skipped when the hard limit does not allow such a soft limit, or when the system rejects or clamps it.min(rlim_cur, getdtablesize()). It compared against rawrlim_cur, so it would otherwise fail with this change whenever the soft limit of the shell running the tests is abovekern.maxfilesperproc.Result:
process_max_fdson macOS matches the number of descriptors the process can actually open. Values belowkern.maxfilesperproc(such as the default soft limit of 256) are reported exactly as before.Testing: on macOS 26.6 (arm64, Command Line Tools), with the updated tests
swift test --filter maxFileDescriptorsfails onmain(soft limit 1048576) and passes with this change under soft limits of 256, 1048576 and unlimited, and the fullswift testrun passes (20 tests).This change was drafted with Claude Code (claude-opus-5-5); the test results above are from the runs described.