Skip to content

Fix MacOS multiprocessing by relaxing sandbox - #1808

Merged
davidhao3300 merged 2 commits into
mainfrom
dev/david.hao/fix-macos-mp
Aug 3, 2025
Merged

davidhao3300 merged 2 commits into
mainfrom
dev/david.hao/fix-macos-mp

Conversation

@davidhao3300

@davidhao3300 davidhao3300 commented Aug 3, 2025 •

Copy link
Copy Markdown
Contributor

The following test script fails in the codex sandbox:

import multiprocessing
from multiprocessing import Lock, Process

def f(lock):
    with lock:
        print("Lock acquired in child process")

if __name__ == '__main__':
    lock = Lock()
    p = Process(target=f, args=(lock,))
    p.start()
    p.join()

with

Traceback (most recent call last):
  File "/Users/david.hao/code/codex/codex-rs/cli/test.py", line 9, in <module>
    lock = Lock()
           ^^^^^^
  File "/Users/david.hao/.local/share/uv/python/cpython-3.12.9-macos-aarch64-none/lib/python3.12/multiprocessing/context.py", line 68, in Lock
    return Lock(ctx=self.get_context())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/david.hao/.local/share/uv/python/cpython-3.12.9-macos-aarch64-none/lib/python3.12/multiprocessing/synchronize.py", line 169, in __init__
    SemLock.__init__(self, SEMAPHORE, 1, 1, ctx=ctx)
  File "/Users/david.hao/.local/share/uv/python/cpython-3.12.9-macos-aarch64-none/lib/python3.12/multiprocessing/synchronize.py", line 57, in __init__
    sl = self._semlock = _multiprocessing.SemLock(
                         ^^^^^^^^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 1] Operation not permitted

After reading, adding this line to the sandbox configs fixes things - MacOS multiprocessing appears to use sem_lock(), which opens an IPC which is considered a disk write even though no file is created. I interrogated ChatGPT about whether it's okay to loosen, and my impression after reading is that it is, although would appreciate a close look

Breadcrumb: You can run cargo run -- debug seatbelt --full-auto <cmd> to test the sandbox

@github-actions

github-actions Bot commented Aug 3, 2025 •

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@davidhao3300

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@davidhao3300
davidhao3300 marked this pull request as ready for review August 3, 2025 06:03
@davidhao3300
davidhao3300 requested a review from bolinfest August 3, 2025 06:03
@davidhao3300

Copy link
Copy Markdown
Contributor Author

recheck

github-actions Bot added a commit that referenced this pull request Aug 3, 2025
@davidhao3300
davidhao3300 enabled auto-merge (squash) August 3, 2025 06:10
@davidhao3300
davidhao3300 disabled auto-merge August 3, 2025 06:10
@davidhao3300
davidhao3300 enabled auto-merge (squash) August 3, 2025 06:11

@nornagon-openai nornagon-openai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems safe. I looked at the docs for this and don’t think this is a significant risk.

@davidhao3300
davidhao3300 merged commit 75eecb6 into main Aug 3, 2025
@davidhao3300
davidhao3300 deleted the dev/david.hao/fix-macos-mp branch August 3, 2025 13:59
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 3, 2025

@bolinfest bolinfest left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This PR needs a test to illustrate/verify what this allows.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants