Skip to content

fix(exec): ignore OS workqueue threads in pre-fork thread check - #1424

Merged
SequeI merged 1 commit into
nolabs-ai:mainfrom
kipz:kipz/macos-fork-workqueue-threads
Jul 16, 2026
Merged

fix(exec): ignore OS workqueue threads in pre-fork thread check#1424
SequeI merged 1 commit into
nolabs-ai:mainfrom
kipz:kipz/macos-fork-workqueue-threads

Conversation

@kipz

@kipz kipz commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Linked Issue

Closes #1423

Summary

On macOS the Supervised pre-fork thread-count check counted OS-managed libdispatch/GCD workqueue threads that Security.framework spawns for SecTrustSettings* XPC during proxy CA setup. Their count scales with load, so under concurrency the total intermittently exceeded MAX_CRYPTO_THREADS (7) and the fork was refused (Cannot fork: process has 8 threads (max 7 with crypto pool)). Those OS threads are parked and fork-safe (covered by libmalloc's pthread_atfork handlers).

An earlier version of this PR counted only nono's own named threads to exclude the unnamed OS workqueue threads. Review caught two problems with that approach: unnamed threads spawned by nono itself (e.g. via bare std::thread::spawn) would silently bypass the check, and the new mach query leaked a port per thread. Rather than fix both by naming every thread in the codebase, this PR now just raises MAX_CRYPTO_THREADS (7 -> 12) to absorb the observed workqueue variance, keeping the original total-thread-count check unchanged.

Agent Disclosure (if applicable)

This PR was generated by an AI coding agent (Claude) on behalf of the contributor. Files consulted: crates/nono-cli/src/exec_strategy.rs (the Supervised fork-safety check and get_thread_count). No code was adapted from third-party sources. Complies with repository requirements: no unwrap/expect, NonoError used for error propagation, DCO sign-off present.

Test Plan

  • make ci clean: clippy -D warnings -D clippy::unwrap_used, fmt-check, full suite passing.
  • Reproduced on macOS 26.5.2 with a proxy/trust-interception profile at 32-way concurrency: ~4/300 before -> 0/300 after (release build of this branch).

Checklist

  • An issue exists and is linked above
  • All commits are signed-off, using DCO
  • All new code follows the project's coding standards (CLAUDE.md) and is covered by tests
  • Public-facing changes are paired with documentation updates
  • Release note has been added to CHANGELOG.md if needed

Agent Compliance Check (Required for AI/Automated PRs)

  • I am not prohibited from contributing under this policy
  • An issue already exists
  • I disclosed that I am an agent in the issue discussion
  • I described my intent and approach in the issue discussion
  • I reviewed repository coding and security rules for the affected area
  • I provided required attribution for reused or adapted code
  • I did not use forbidden patterns such as unwrap/expect
  • I used NonoError where required
  • I validated and canonicalized all relevant paths
  • This PR matches the approved or disclosed issue scope

@github-actions github-actions Bot added bug Something isn't working nono-cli size/medium labels Jul 16, 2026
@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

PR Review Summary

Size

Metric Value
Lines added +7
Lines removed -4
Total changed 11
Classification Small (< 50 lines)

Affected crates

  • crates/nono-cli — CLI changes. Verify argument parsing, flag documentation, and UX behaviour across supported platforms.

Blast radius — Contained

This PR touches: source code


Updated automatically on each push to this PR.

kipz added a commit to kipz/nono that referenced this pull request Jul 16, 2026
@kipz
kipz marked this pull request as ready for review July 16, 2026 09:29

@nogent-nolabs-ai nogent-nolabs-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nogent code review

2 issues found: 1 high-severity Mach port resource leak on macOS, and 1 medium-severity fork safety bypass.

Automated code + security review. CI already covers clippy, rustfmt, tests, cargo-audit and commit-lint.

Comment thread crates/nono-cli/src/exec_strategy.rs Outdated
Comment thread crates/nono-cli/src/exec_strategy.rs Outdated
Signed-off-by: James Carnegie <me@kipz.org>
@kipz
kipz force-pushed the kipz/macos-fork-workqueue-threads branch from 9169af4 to f877064 Compare July 16, 2026 10:35

@SequeI SequeI left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, this makes sense to me, no big loss in raising the thread limit slightly. Thanks!

@SequeI
SequeI merged commit 099237d into nolabs-ai:main Jul 16, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working nono-cli size/small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Supervised fork intermittently fails on macOS: OS workqueue threads exceed the pre-fork thread budget

2 participants