Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix xargs failure when os.sysconf is blocked in sandboxed environments#3591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@MichaelRWolf
Copy link

Fixes#3589

This PR fixes a bug wherepre_commit.xargs fails in highly restricted sandboxed environments (like Cursor-IDE's AI-tool sandbox) whenos.sysconf('SC_ARG_MAX') is blocked. This can manifest as import-time failures or runtime failures depending on when the sysconf call occurs.

Changes:

  • Made_max_length parameter lazy-evaluated (defaults toNone, computed at runtime)
  • Addedtry/except OSError in_get_platform_max_length() to handle blocked sysconf calls
  • Falls back to POSIX minimum (4096) when sysconf is unavailable
  • Added comprehensive tests using subprocess approach to verify fix works at both import-time and runtime

Testing:

  • All existing tests pass
  • New tests verify import-time and runtime behavior when sysconf is blocked

MichaelRWolfand others added6 commitsNovember 28, 2025 19:15
- Add subprocess-based test to expose import-time os.sysconf bug- Test runs in fresh subprocess to avoid conftest.py import issues- Test fails with current buggy implementation, will pass after fix
- Add module-level docstring- Extract subprocess script into helper function- Add constant for blocked sysconf error message- Improve test docstring explaining two-phase approach- Add inline comments clarifying test orchestration- Remove TODO comments
- Lazy-evaluate _max_length to avoid import-time os.sysconf call- Handle OSError in _get_platform_max_length() with POSIX fallback- Use consistent calculation pattern in fallback path
- Extract _PRACTICAL_ARG_MAX constant to replace magic number 2^17- Use descriptive variable names: arg_max_base, calculated_length, clamped_length- Extract shared sub-expression for headroom and environment size- Add comments explaining each calculation step
- Add test for xargs without _max_length parameter (lazy evaluation)- Add test for xargs with explicit _max_length parameter- Both tests use subprocess approach to verify actual xargs execution- Tests verify fix works at runtime, not just import time
@asottile
Copy link
Member

I'm not really convinced this is a good idea. there's literally zero reason to block read only access to sysconf. I think cursor should fix their broken setup instead

not to mention if sysconf is blocked I can't imagine what else is blocked and I don't expect pre-commit to get any further

plus I can't accept ai generated patches and it's super clear this was not written by you

@MichaelRWolf
Copy link
Author

Thanks for your swift response. I had hoped for a few days (or weeks), but got a response in a fewminutes. Thanks.

This was my largest attempt at patching such a public repo, so I'd appreciate some assistance to understand what I cold have done differently to propose a change that would have worked for you.

BTW.... I invested time in this patch because I found pre-commit hooks to be so helpful. I was at the point of having to decide whether to drop pre-commit or Cursor. It was tough. I wanted to use them BOTH. I've been involved with open source for decades. I figured I could make a difference here much easier than with OpenAI. ;-}

Since the issue was triggered by a single line in pre-commit, I started there.

It worked. The proposed change allows me to continue using pre-commit in a repo that has code I've been maintaing for about 20+ years -- my personal profile that works across many systems.

I can now ask Cursor to "analyze and commit", and it will create a commit message for staged changes, then commit (including pre-commit hooks).

I was actually doing a happy dance to celebrate this win when I received your comments.

Let me see if I can address each of them...

I'm not really convinced this is a good idea. there's literally zero reason to block read only access to sysconf. I think cursor should fix their broken setup instead

I can't speak to their reasons for blockingsysconf, but my research convinced me that lead me to believe that POSIX_MAX_ARG is a safe default foros.sysconf('SC_ARG_MAX'), both at load-time and also at run-time. Do you agree?

not to mention if sysconf is blocked I can't imagine what else is blocked and I don't expect pre-commit to get any further

I guess I don't understand what this is pointing at. I only researched the problems that arose with os.sysconf(). There was only one
os.sysconf('SC_ARG_MAX')

Once this was overcome, pre-commit got much further. All the way.. It completed beautifully.

plus I can't accept ai generated patches and it's super clear this was not written by you

This PR was my work. Human research. Human review. Human testing. Human experience.

AI was my assistant, not the leader. This was NOT vibe coding.

I started with background research. Then we generated a failing test that would showcase the issue. Only then did I modify the original code.

Generating the code was actually the easy part. I could have done that in significantly less time, but I wanted the test (and the understanding behind it) to give me the confidence that it was a robust change. I'm happy to have had AI to assist me. I'm especially grateful that it pointed out a problem with my testing strategy allowedconftest.py that peventedpytest from even running my tests.

@MichaelRWolf
Copy link
Author

TL;DR; -- I submitted this work because I value what pre-commit does for me. It was my work. Human work. Human experience. Human caring.

It fixed my work-flow blockage. I think it could be helpful to othersj, too.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

os.sysconf() call fails in highly restricted sandboxed environments (e.g., Cursor IDE)

2 participants

@MichaelRWolf@asottile

[8]ページ先頭

©2009-2025 Movatter.jp