Skip to content

fix(sandbox): stop creating an undeletable "nul" file from cmd-style redirects#4257

Merged
esengine merged 1 commit into
main-v2from
fix/4252-nul-redirect
Jun 13, 2026
Merged

fix(sandbox): stop creating an undeletable "nul" file from cmd-style redirects#4257
esengine merged 1 commit into
main-v2from
fix/4252-nul-redirect

Conversation

@esengine

Copy link
Copy Markdown
Owner

Closes #4252

Problem

On Windows, an undeletable file named nul keeps appearing in the workspace root. It can't be removed by Explorer or cmd (reserved device name) — only rm from git bash works — and it breaks builds and git operations.

Root cause

The model frequently appends the Windows cmd idiom 2>nul / >nul to discard output. reasonix runs shell commands under bash or PowerShell, never cmd.exe. Only cmd.exe treats nul as the null device — bash and PowerShell treat it as an ordinary filename, so 2>nul literally creates a file called nul in the cwd (the workspace root).

Reproduced on this box:

$ bash -c "echo hi 2>nul"          # → creates ./nul
PS> echo hi > /dev/null                  # → creates ./nul

Fix

Normalize cmd-style nul redirects (>nul, 2>nul, 1>>NUL, &>nul, …) to the target shell's real null device — /dev/null for bash, $null for PowerShell — in Shell.argv, the single point every shell invocation funnels through. Non-redirect uses of the word (echo nul, grep nul file, cat nul.txt, rm nul) are left untouched (RE2 has no lookahead, so the trailing delimiter is captured and re-emitted).

Validation

  • Unit test TestNormalizeNulRedirect (rewrite cases + negatives) and TestArgvNormalizesNulRedirect.
  • E2E: the rewritten form (echo hi 2>/dev/null / 2>$null) creates no nul file under bash or PowerShell, whereas the original 2>nul did.
  • go test ./internal/sandbox/ + go vet pass.

… device

The model often appends Windows cmd idioms like `2>nul` / `>nul` to discard
output. reasonix runs commands under bash or PowerShell (never cmd.exe), where
`nul` is an ordinary filename, not the null device — so the redirect created an
undeletable file named `nul` (a Windows reserved name) in the workspace root,
which breaks builds and git operations.

Rewrite those redirects to `/dev/null` (bash) / `$null` (PowerShell) in argv,
the single point every shell invocation funnels through. Non-redirect uses of
"nul" (echo nul, grep nul, nul.txt) are left untouched.

Closes #4252
@esengine esengine requested a review from SivanCola as a code owner June 13, 2026 05:47
@github-actions github-actions Bot added the v2 Go rewrite (1.x) — main-v2 branch, active development label Jun 13, 2026
@esengine esengine merged commit d40797b into main-v2 Jun 13, 2026
14 checks passed
@esengine esengine deleted the fix/4252-nul-redirect branch June 13, 2026 05:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: 在工作区生成了nul文件

1 participant