← Back to Pull requests

Cap process_max_fds at kern.maxfilesperproc on Darwin #134

Closed
unknown closed this pull request without merging on Nov 17, 2026 13:20 UTC
View on GitHub
unknown unknown commented on Nov 15, 2026 10:06 UTC
Author

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_fds reports getrlimit(RLIMIT_NOFILE).rlim_cur as is. The kernel never lets a process open more than kern.maxfilesperproc descriptors, so when the soft limit is higher the metric overstates the real ceiling. For example, with kern.maxfilesperproc = 61440, a soft limit of 1048576 is reported as 1048576 and ulimit -n unlimited (RLIM_INFINITY) is reported as 9.223372036854776e+18, while open() starts failing with EMFILE at fd 61440 in both cases (and getdtablesize() returns 61440). Measured on macOS 26.6 (arm64). This makes process_open_fds / process_max_fds ratios 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.maxfilesperproc cap. For comparison, Prometheus client_golang's Darwin process collector reports the raw getrlimit soft limit, but the Go runtime caps its own soft limit at kern.maxfilesperproc at startup (see adjustFileLimit in Go's src/syscall/rlimit_darwin.go), so in Go processes that value is normally already the enforced one.

Linux is unchanged: there the kernel's setrlimit rejects RLIMIT_NOFILE values above fs.nr_open, so rlim_cur already is the enforced value.

Modifications:

  • Darwin provider: read kern.maxfilesperproc with sysctlbyname and report min(rlim_cur, kern.maxfilesperproc). If the sysctl fails, fall back to rlim_cur as before.

  • Added a test that raises only the soft limit above kern.maxfilesperproc (restoring it afterwards) and checks that maxFileDescriptors matches getdtablesize(), 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.

  • Updated the existing "Max file descriptors reports the soft limit" test to expect the capped value, min(rlim_cur, getdtablesize()). It compared against raw rlim_cur, so it would otherwise fail with this change whenever the soft limit of the shell running the tests is above kern.maxfilesperproc.
  • Result:

    process_max_fds on macOS matches the number of descriptors the process can actually open. Values below kern.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 maxFileDescriptors fails on main (soft limit 1048576) and passes with this change under soft limits of 256, 1048576 and unlimited, and the full swift test run passes (20 tests).

    This change was drafted with Claude Code (claude-opus-5-5); the test results above are from the runs described.

    Diff: 355 lines (+266 / -89) across 4 files Reviewer: kukushechkin Review duration: 3074m
    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
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.5% (MEDIUM) · Higher = larger blast radius
    42.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.8% · Safe to merge
    16.8%