Repository navigation
Studio: stop the Windows Terminal from creating nul files through Git Bash - #17010
Conversation
Codex Review Summary: ✅ CompletedThis 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 Summary: ❌ FailedThis 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 |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e2a595853e
ℹ️ 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".
| _NUL_REDIRECT_RE = re.compile( | ||
| r"(?<![-=<>])((?:[0-9]+|&)?(?:>>?|>\||>&)|<)([ \t]*)nul(?=[\s;&|()<>]|$)", re.IGNORECASE | ||
| ) | ||
| _HEREDOC_RE = re.compile(r"<<(-?)[ \t]*(['\"]?)([^\s'\"<>;&|()]+)\2") |
There was a problem hiding this comment.
Preserve heredocs with whitespace in quoted delimiters
On Windows Git Bash, a valid heredoc such as cat <<'END BAT' > run.bat is not recognized because the delimiter pattern excludes whitespace even inside quotes. The scanner then processes the heredoc body as executable shell text and changes embedded dir 2>nul to dir 2>/dev/null, corrupting the generated batch file. Recognize the complete quote-removed heredoc delimiter before scanning its body; quoted delimiters containing spaces must receive the same preservation as <<'EOF'.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: a heredoc delimiter with a space in it is not something models write; EOF style delimiters, quoted or not, are covered.
| m = _NUL_REDIRECT_RE.match(command, i) | ||
| if m: | ||
| out.append(f"{m.group(1)}{m.group(2)}/dev/null") |
There was a problem hiding this comment.
Exclude conditional comparison operators from redirect rewriting
On Windows Git Bash, this match also rewrites < and > inside Bash [[ ... ]] conditions, where they are string-comparison operators rather than redirects. For example, [[ abc < nul ]] && echo yes || echo no previously prints yes, but the rewritten comparison against /dev/null prints no. This silently changes control flow in otherwise valid commands. Track conditional-expression context and only replace actual redirection targets.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: a string comparison against the bare word nul inside [[ ]] is not something a real Terminal session sends, while 2>nul is. Tracking [[ ]] context would add parsing for a case nobody hits.
|
Codex Review: Didn't find any major issues. Chef's kiss. 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 review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 77c5f2a8c7
ℹ️ 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".
| if c in "'\"": | ||
| j = command.find(c, i + 1) | ||
| i = n if j < 0 else j + 1 |
There was a problem hiding this comment.
Honor escaped quotes when locating substitution boundaries
On Windows Git Bash, an escaped double quote inside a double-quoted command substitution makes command.find() mistake that escaped quote for the closing quote. The resulting substitution boundary can extend into subsequent literal text, which is then incorrectly rewritten as shell syntax. For example, echo "$(printf '%s' "a\"b") literal >nul text" prints a"b literal >/dev/null text after rewriting instead of the original a"b literal >nul text. Unlike the previously fixed missing rewrite inside $(), this corrupts text outside the substitution. Scan quoted spans with escape handling so recursive rewriting stays within the executable substitution.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: it needs an escaped quote inside a nested quoted string inside $( ) followed by a literal >nul in the outer string, which real Terminal commands do not contain. The common forms are covered.
…ain (#17040) ## Summary Two tests have been red on main since this morning's merges. Every PR based on main now inherits them: #17010, which changes only the Windows bash tool, fails both. Both reproduce on main locally: ``` (Python 3.13, a-f) studio/backend/tests/test_custom_provider_api_type.py::test_base_url_query_survives_native_provider_calls At index 0 diff: ('/v1/models/claude-sonnet-4-5', 'tenant=a') != ('/v1/messages', 'tenant=a') Repo tests (CPU, studio) tests/studio/test_model_picker_contracts.py::test_batch_sizes_reach_an_api_load_through_the_server_mirror assert 'strip_batch = "n_batch" in kwargs,' in '...openai_auto_switch_settings.py...' ``` In both cases the product change is correct and the test is out of date. - **#16951 and #16953.** #16951 (keep the base URL query string on provider calls) added a test that lists every request the three native providers make. #16953 merged four minutes later. It looks up the model's output cap with `GET /v1/models/<model>` before a Messages API stream that sets no `max_tokens`, so that provider now makes one more request. That request goes through `_append_provider_path`, so it keeps `?tenant=a`, which is the invariant #16951 cares about. The test simply predates it. Each PR was green on its own. - **#16927.** It moved the llama.cpp flag stripping into `strip_args_shadowed_by(args, fields)`, so the line now reads `strip_batch = "n_batch" in fields,` and is called with the same kwargs. What gets stripped is unchanged. The contract test grepped for the old source line. ## Change Tests only: - `test_base_url_query_survives_native_provider_calls` expects the output-cap lookup first, with its query string kept. It also empties `_anthropic_output_caps` first, so the lookup happens whatever ran earlier in the worker. That cache is module-global, and with an entry already cached the request list would change with test order. - `test_batch_sizes_reach_an_api_load_through_the_server_mirror` stops grepping that line. It calls the real `model_override_load_kwargs`, imported the same way as the lookup-ladder helper already in that file: - a stored `-b` is dropped when the override has `n_batch`; - a stored `-ub` is dropped when the override has `n_ubatch`; - both stay when neither field is set. ## Testing | | main | this branch | |---|---|---| | `test_custom_provider_api_type.py` + `test_anthropic_default_max_tokens.py` | 1 failed | 29 passed, in either file order | | `tests/studio/test_model_picker_contracts.py` | 1 failed | 203 passed | | the batch test with `strip_batch = False` planted in `strip_args_shadowed_by` | | fails |
…tores window (#17055) ## Summary Since #16755 merged, every `Frontend CI` run fails on both `Frontend build + bundle sanity` and `Frontend unit tests (Windows)`, with the same file. On PRs this includes #17010 and the cosmos3, images and voice PRs, and the main push runs are red too: ``` # Error: Test "without Web Locks a session with no mark does not take a later sign-in for a peer's rotation" at tests/auth-refresh-transient.test.ts:453:1 generated asynchronous activity after the test ended. This activity created the error "TypeError: Cannot read properties of undefined (reading 'location')" and would have caused the test to fail, but instead triggered an unhandledRejection event. not ok 140 - tests/auth-refresh-transient.test.ts ``` The product code is correct; the test does not wait for it. In the new test, `authFetch` returns the 401, and the rejected-refresh path then sends the tab to `/login` through `window.location` on a later turn. The test ends right after the returned response. The fixture's `t.after` then restores the real `globalThis.window`, which is `undefined` under Node, so the deferred redirect throws. The sibling tests that take a 401 already `await f.settle()` before they finish. This one does not. The failure depends on the Node version. CI pins Node 22 (`22.23.4`), which fails the file every time. Node 24 does not, which is why the PR was green where it was written. ## Change `studio/frontend/tests/auth-refresh-transient.test.ts`, tests only: - The fixture's `t.after` drains five turns before it restores `window`, `fetch`, `setTimeout`, `clearTimeout` and `Date.now`. That is the same drain as `f.settle()`. Deferred work from any test in the file now runs against the fixture's window, not after it is gone. - The new test settles and asserts what the rejected path does, `location.href == "/login"`. It also keeps its existing checks: the other sign-in's tokens stay and nothing is cleared. ## Testing | | Node 22.23.4 (CI) | Node 24.22.1 | |---|---|---| | main | file fails (`# pass 23`, `# fail 1`, the error above) | 23 pass | | this branch | 23 pass | 23 pass | | this branch, fixture drain alone (new assertion removed) | 23 pass | |
…helper (#17442) ## Summary `Source lint` fails on main since #17256, and on every PR based on it (seen on #17429 and #17435): ``` duplicate definitions (1): studio/backend/core/inference/tools.py:9806: _substitution_end is defined twice (def at line 6738, def here) ``` These are not two copies of one function. They are two different helpers that ended up with the same name: | | Added by | Returns for `$( ... )` | Unterminated | Quotes inside | |---|---|---|---|---| | line 6738 | #17256 (heredoc screening), used by `_quote_end` | one past the `)` | `-1` | `_quote_end`, which handles `\"` and nested `$(` | | line 9806 | #17010 (Windows `2>nul` rewrite), used by `_bash_nul_to_dev_null` | the index of the `)` | `len(command)` | naive `find` of the same quote | The later definition wins at module scope. So since #17256 merged, its `_quote_end` has been running #17010's helper rather than the one written for it, while #17010's nul rewrite keeps its own. The lint is right, and both PRs are correct on their own. The fix is to give #17256's helper its own name. The practical effect is small but real: the two disagree on some quoting. For example, `"( )'$("`")"` reads as unterminated with the intended helper and as closed with the shadowing one, which changes how the Terminal heredoc screen splits that command. ## Change - The helper at line 6738 is renamed `_quoted_substitution_end`, and its one caller in `_quote_end` uses it. That is the function #17256 wrote and tested. - #17010's `_substitution_end` and the nul rewrite are untouched. - `test_the_heredoc_quote_scanner_keeps_its_own_substitution_helper` in `studio/backend/tests/test_permission_mode.py` pins both contracts: - `_quoted_substitution_end` returns one past the `)` and `-1` when unterminated; - `_quote_end` closes `"$(echo "a)")"` at its last quote and keeps the case above unterminated; - `_substitution_end` keeps the nul rewrite's own return values. It fails on main, where the name is shadowed. ## Testing - `scripts/lint_duplicate_definitions.py` on `tools.py`: flags main, clean here - `studio/backend/tests/test_permission_mode.py` and `test_windows_bash_nul_redirect.py`: 2637 passed, 1 skipped. The new test fails on main. - `tests/test_lint_duplicate_definitions.py`: 12 passed
Fixes #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>nulor>nul 2>&1to hide output. In cmd that is the NUL device, but in Git Bash it creates a real file namednulin 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. #13037 stopped such a file from breaking the MXC workdir scan (#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:
grep '2>nul' run.bat,git commit -m "... >nul"), escaped\>nul, comments.batwritten throughcat <<EOFkeeps its2>nulnul.txt,null),->nul/=>nul, here-stringsnulas 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 runsecho hidden > nulthrough the real Terminal on Git Bash and checks nonulentry is left behind.