Skip to content

Studio: stop a Git Bash nul file from blocking every Windows MXC tool call - #13037

Merged
danielhanchen merged 6 commits into
mainfrom
fix-windows-reserved-name-workdir-scan
Oct 8, 2026
Merged

danielhanchen merged 6 commits into
mainfrom
fix-windows-reserved-name-workdir-scan

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Fixes #12473.

Problem

On Windows, a Git Bash command such as echo hi > nul leaves a real file named nul in the session workdir. The MXC workdir scan in os_sandbox._host_channel_hazard looks at each entry with a plain os.lstat. A plain Win32 path ending in nul (or con, com1, lpt1 on Windows 10) resolves to the device, not the file, so the scan sees a character device and raises:

Windows MXC policy construction failed: the session workdir contains a device or IPC node: ...\nul

Every later Terminal and Python call in that chat then fails the same way. Deleting the file in Explorer helps only until the next > nul.

Fix

On Windows only, the scan now lists and stats the workdir through its \\?\ extended path. That spelling skips Win32 name parsing and reaches the file on disk, so a nul file is judged as the regular file it is. Reported paths keep the caller's spelling.

  • A directory named nul is walked the same way, and the cached-verdict witness (directory_signature) uses the same spelling.
  • os.path.ismount is no longer asked on Windows. ntpath.ismount runs abspath, which maps C:\work\nul to \\.\nul, and reports that as a mount. A Windows mounted folder is always a reparse point, and the scan already refuses those one check earlier, so no coverage is lost.
  • Linux and macOS are unchanged (os.name == "nt" gates the new path, so the existing tests that stand in sys.platform = "win32" over a POSIX tmp dir keep their behaviour).

Real hazards are judged exactly as before: reparse points, outside hard links (the \\?\ stat carries the real link count), FIFOs and sockets are still refused.

Tests

studio/backend/tests/test_sandbox_windows_reserved_names.py:

  • Simulated Windows stat on Linux: a plain stat of nul, NUL, con, com1, lpt1, nul.txt answers for a character device, the \\?\ spelling answers for the file. On main these fail with the exact message from the issue; with this PR the scan returns ().
  • A directory named nul is walked and its witness changes when its contents do.
  • A FIFO next to a nul file and a nul hard-linked from outside the workdir are still refused.
  • Windows-only: a nul file and a nul directory created through \\?\, a hard link out of that directory, and a real Git Bash echo hi > nul (found with tools._windows_bash()).
Suite main this PR
Windows-only tests on a real windows-latest runner (Python 3.12, Git 2.55) 3 failed: WorkdirUnsafeError: the session workdir contains a device or IPC node: C:\Users\runneradmin\...\nul 3 passed
Simulated reserved-name tests (Linux) 8 failed (the issue's error) all passed
New test file on ubuntu-latest / macos-15 n/a 15 passed, 3 Windows-only skipped
test_sandbox_linux.py, test_mxc_*.py, test_sandbox_macos.py, test_tool_sandbox_wiring.py, test_sandbox_tools.py, test_windows_bash_shell.py, test_sandbox_files_and_storage_roots.py 1 failed same 1 failed, rest passed
Studio journeys (auth, settings, crawl, inference settings) and backend upstream CI pass no regression

The Windows runs used the same test file on both sides; the Git Bash test runs a real echo hi > nul through Studio's own Git Bash. The one failure on both sides in the Linux suites (test_an_interrupted_delete_is_finished_when_studio_starts) is pre-existing and unrelated.

Scan time on Linux over a 20,000 file tree is unchanged (main 67.2 to 72.8 ms median, this PR 64.5 to 68.2 ms, 3 interleaved rounds of 15).

…channel scan

On Windows a plain stat of ...\work\nul answers for the NUL device, so the
workdir scan refused every later MXC tool call with 'contains a device or IPC
node'. Stat each entry through its \\?\ path, which reaches the file on disk,
and skip ntpath.ismount, which reads a directory named nul as the \\.\nul
device root (Windows mounted folders are reparse points, refused already).

Fixes #12473
Review follow-ups: list and stat through one spelling so a directory named nul
is walked as the entry stat judged; anchor a drive-relative path at that
drive's own directory; recognise //?/ after normalising; name hazards by the
caller's spelling; native Windows tests for a nul directory and a hard link
out of it.
@danielhanchen danielhanchen self-assigned this Oct 8, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-08T10:50:59.686792Z b65fe64 Manual request
🔒 Security Review ✅ Completed 2026-10-08T10:51:18.635592Z b65fe64 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-08T10:14:04.998600Z 67d7842 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

danielhanchen added a commit to Imagineer99/unsloth that referenced this pull request Oct 8, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: b65fe641b4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: b65fe641b4

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@danielhanchen
danielhanchen merged commit a13d3a5 into main Oct 8, 2026
@danielhanchen
danielhanchen deleted the fix-windows-reserved-name-workdir-scan branch October 8, 2026 11:59
emaxlele pushed a commit to emaxlele/unsloth_LM_Studio that referenced this pull request Nov 9, 2026
… Bash (unslothai#17010)

Fixes unslothai#16991

## Problem

On Windows the Terminal tool runs Git Bash when Git for Windows is
installed. Models on Windows still write the cmd habit `2>nul` or `>nul
2>&1` to hide output. In cmd that is the NUL device, but in Git Bash it
creates a real file named `nul` in the current directory. Windows
reserves that name, so Explorer cannot delete it and users need an admin
console with a `\\?\` path to get rid of it. unslothai#13037 stopped such a file
from breaking the MXC workdir scan (unslothai#12473), but the file is still
created in the user's folder on every such command.

## Fix

Before a Windows Git Bash Terminal command runs, an unquoted redirect
whose target is the bare word `nul` (any case) is rewritten to
`/dev/null`: `2>nul`, `>nul`, `>>nul`, `&>nul`, `>&nul`, `>|nul`,
`<nul`. Output is discarded exactly as the model intended and no file is
created.

Left alone:
- quoted text (`grep '2>nul' run.bat`, `git commit -m "... >nul"`),
escaped `\>nul`, comments
- heredoc bodies, so a `.bat` written through `cat <<EOF` keeps its
`2>nul`
- other names (`nul.txt`, `null`), `->nul` / `=>nul`, here-strings
- Linux, macOS and the Windows cmd Terminal (cmd already treats `nul` as
the device)

The tool descriptions and system prompt are unchanged.

## Tests

`studio/backend/tests/test_windows_bash_nul_redirect.py`: rewrite and
no-rewrite cases, real bash running a rewritten command leaves an empty
directory with the expected output, the rewrite only applies to the
Windows bash profile, and a Windows-only test runs `echo hidden > nul`
through the real Terminal on Git Bash and checks no `nul` entry is left
behind.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sandbox nul file breaks tools

1 participant