Repository navigation
Studio: stop a Git Bash nul file from blocking every Windows MXC tool call - #13037
Conversation
…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.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
|
@codex security review |
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
… 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.
Fixes #12473.
Problem
On Windows, a Git Bash command such as
echo hi > nulleaves a real file namednulin the session workdir. The MXC workdir scan inos_sandbox._host_channel_hazardlooks at each entry with a plainos.lstat. A plain Win32 path ending innul(orcon,com1,lpt1on Windows 10) resolves to the device, not the file, so the scan sees a character device and raises: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 anulfile is judged as the regular file it is. Reported paths keep the caller's spelling.nulis walked the same way, and the cached-verdict witness (directory_signature) uses the same spelling.os.path.ismountis no longer asked on Windows.ntpath.ismountrunsabspath, which mapsC:\work\nulto\\.\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.os.name == "nt"gates the new path, so the existing tests that stand insys.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:nul,NUL,con,com1,lpt1,nul.txtanswers 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().nulis walked and its witness changes when its contents do.nulfile and anulhard-linked from outside the workdir are still refused.nulfile and anuldirectory created through\\?\, a hard link out of that directory, and a real Git Bashecho hi > nul(found withtools._windows_bash()).windows-latestrunner (Python 3.12, Git 2.55)WorkdirUnsafeError: the session workdir contains a device or IPC node: C:\Users\runneradmin\...\nultest_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.pyThe Windows runs used the same test file on both sides; the Git Bash test runs a real
echo hi > nulthrough 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).