Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork910
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
- 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
for more information, seehttps://pre-commit.ci
asottile commentedNov 29, 2025
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 commentedNov 29, 2025
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 can't speak to their reasons for blocking
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 Once this was overcome, pre-commit got much further. All the way.. It completed beautifully.
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 allowed |
MichaelRWolf commentedNov 29, 2025
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. |
Fixes#3589
This PR fixes a bug where
pre_commit.xargsfails 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:
_max_lengthparameter lazy-evaluated (defaults toNone, computed at runtime)try/except OSErrorin_get_platform_max_length()to handle blocked sysconf callsTesting: