Repository navigation
Studio: ask before risky calls when a chat folder is too large to check - #13914
Conversation
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 |
1 similar comment
|
@codex review |
NilayYadav
left a comment
There was a problem hiding this comment.
Review + reproduction evidence
Pinned review: 4995151315. One finding, fixed in 4995151315 (Windows still told the model to start a new chat or use auto); one minor limitation noted below.
I reproduced the flow on fresh upstream main and on this branch (macOS 26 arm64 with the Seatbelt sandbox, Qwen3-1.7B GGUF Q4_K_M, Chromium 1440x900): Run automatically, Sandbox High, Tools on; the model fills the chat folder with 60,000 files from the Terminal tool, then runs import shutil; shutil.rmtree("build", ignore_errors=True) with the Python tool.
- main
5e55110: the call fails withExecution error: the session workdir is too large to check for host channels, and `required` cannot promise a boundary it did not verify. Start a new chat, or use `auto` to run with software safeguards.Asking for the same call again fails the same way, with no approval card, and the model then makes up acleanedanswer. - PR
4995151: the first call returnsExecution error: the session workdir is too large to check for host channels, so this call needs the user's approval. Call the tool again to ask for it.The retry shows Allow / Always allow / Deny. After Allow it runs withrequested_mode: auto,effective_mode: os_isolated(macos-seatbelt), limitationworkdir_scan_incomplete.
- Unchanged on both sides:
print(6*7)in the large chat runs without asking (auto,os_isolated); a fresh chat runs the samermtreewithout asking (required,os_isolated). - Recovery: after the folder is emptied, one more risky call asks (the record clears on the next completed scan), then the following one runs without asking under
requiredagain. - Tests: the new test fails on main and passes here (main: 1 failed, 245 passed; PR: 246 passed). With
4995151,test_permission_mode_degrade.pyplustest_sandbox_linux.pyshow 2 tests fixed and no new failures.
Fixed in 4995151315: on Windows the refusal comes from mxc_policy._scan_workdir, which still said "Start a new chat, or use auto". It now gives the same retry instruction, with a test that runs the real scan on a folder over budget.
Known limitation, not changed here: for a project folder the user picked, the record is only cleared by a completed scan, and the Auto launch for that folder skips the scan, so after the folder shrinks Run automatically keeps asking until Studio restarts. It errs on the side of asking; clearing it would mean rescanning large project folders on every launch. Also, an approved call in a picked project folder runs with software safeguards (the existing project-folder path), so "an approved call still runs inside the OS sandbox" holds for chat folders.
Conclusion: the bug is real and this fixes it. The flow above is macOS; Linux goes through the same check and is covered by the tests (run on Linux), and Windows now gives the same retry instruction. Remaining before merge: upstream CI on 4995151 (the earlier run was cancelled before any runner started).
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4995151315
ℹ️ 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".
|
|
||
|
|
||
| def workdir_scan_overran(workdir: str) -> bool: | ||
| return bool(_overran_workdirs) and os.path.realpath(workdir) in _overran_workdirs |
There was a problem hiding this comment.
Avoid resolving workdirs for every streamed delta
Once any workdir has overrun and OS isolation is cached as available, this lookup executes os.path.realpath() on every call. The GGUF structured-tool path evaluates tool_call_may_prompt for each streamed tool-call delta (llama_cpp.py:40008), so a Run automatically Python/Terminal call repeatedly traverses its workdir path while arguments stream; for a selected project on a slow or network filesystem this can stall token streaming, and a wedged path blocks before the scanner's wall-clock worker can help. Cache the canonical key with the workdir entry or otherwise make this hot membership check filesystem-free.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Measured os.path.realpath on the chat folder at about 8.6 us per call; it only runs once some folder has overrun, and only for Python/Terminal in Run automatically. The launch that follows walks that same folder (up to 50,000 entries), so a stalled mount already blocks there before this check could matter. Leaving it as is.
Main (bd06376) is red in Backend CI on five tests, seen on every PR based on it (#13914, #13919). Four come from #13850 and #13806, which are both right; one comes from my own #13909. Each is reproduced locally on main and fixed here. ## From #13850 (token preview) **`test_every_long_lived_spawner_consults_the_shutdown_latch`**: `core/training/token_preview.py` adopts its worker with `adopt_pid` but was in neither the gated nor the not-gated set. It already checks `is_process_shutting_down()` before spawning, so it belongs with the gated spawners, but a gated spawner also has to recheck after adopting: a quit that lands between the check and `adopt_pid` happens after the shutdown sweep took its snapshot, and the worker would outlive it. `_spawn_locked` now rechecks right after adopting, and if the latch is set it stops the new worker and raises `TokenPreviewError("Unsloth is shutting down.")`, the same message `_start_locked` uses. The module goes into the gated set. New test `test_a_quit_that_races_the_spawn_reaps_the_new_worker` drives that race: the latch flips inside `Process.start()`, and the worker must be stopped and the call refused. **`test_the_dataset_format_check_installs_the_decoder`**: `check_format_response` now reads its rows through `load_preview_slice`, which calls `ensure_audio_decoding()` before any tier, so the wiring is intact. The test only read `check_format_response`'s own source. It now checks that `check_format_response` reads through `load_preview_slice`, and that `load_preview_slice` installs the decoder before its first read (`resolve_dataset_path(` / `load_dataset(`), which also pins the ordering the old form never checked. **`test_the_subprocess_tokenizes_and_masks_typed_text`**: the completion-masking half imports unsloth in the worker, as training does, and Backend CI has torch but no `unsloth_zoo` (`Unsloth: Please install unsloth_zoo via pip install unsloth_zoo then retry!`). The test skipped only when torch was missing; it now also skips when `unsloth_zoo` is not importable. The plain tokenization half still runs everywhere. ## From #13806 (drafter training) **`test_owner_training_start_status_cancel_bytes_are_unchanged`**: the training status details gained `"drafter": null`. The test pins the exact status bytes on purpose, so a new field is a deliberate, one-line update to the expected dict. ## From #13909 (mine) **`test_python_children_are_told_to_emit_utf8`**: #13909 made the drafter capability probe decode its child as UTF-8 but set `PYTHONIOENCODING` on its own line, while this guard requires the child env to go through `utf8_child_env()` at the call site. The probe now passes `env = utf8_child_env(env)`, which sets the same variable through the shared helper. ## Verification - `test_audio_dataset_decode.py`, `test_chat_text_encoding.py`, `test_job_accounts.py`, `test_orchestrator_unload_cancel.py`, `test_token_preview.py`, `test_text_io_encoding.py`, `test_drafter_training.py`: 1144 passed. One failure, `test_capability_child_process_runs_for_real`, fails identically on main on this host (it runs the probe in a real child interpreter) and is not failing in CI. - Without `unsloth_zoo` importable: the token preview real-worker test tokenizes, then skips the masking half with its reason. - Sabotage, the post-adopt recheck removed: the spawner-set guard fails (`never rechecks the latch after adopting`) and the new race test fails (`DID NOT RAISE TokenPreviewError`). - Sabotage, `ensure_audio_decoding()` moved after `resolve_dataset_path(` in `load_preview_slice`: the decoder test fails (`the decoder must be installed before the first row is read`). - `tests/test_formatter_fixed_point.py`: passes.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a56bf54f6c
ℹ️ 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".
| "the session workdir is too large to check for host channels, and `required` " | ||
| "cannot promise a boundary it did not verify. Start a new chat, or use `auto`." | ||
| "the session workdir is too large to check for host channels, " | ||
| "so this call needs the user's approval. Call the tool again to ask for it." |
There was a problem hiding this comment.
Allow approved cmd retries to accept an incomplete scan
On Windows hosts where Terminal selects cmd_isolated, an overrun is still unrecoverable for a risky command that only names a relative path (for example del build.log). After the retry is approved, the loop leaves tool_execution_mode at auto, but tools.py:23757-23770 sees no outside host path and rewrites it to required; this branch then raises the same error for the still-oversized workdir. The user is therefore prompted and failed on every retry, so the approved-overrun case needs to permit the incomplete MXC scan without enabling the normal unisolated fallback.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
This is the existing cmd_isolated contract, not something this change introduces: on main the same Terminal call is rewritten to required in every permission mode (Ask and Approve for me included, tools.py around line 23757), so an oversized workdir already refuses it there. Letting an approved required launch accept an unverified scan would weaken that boundary, which is a separate decision for the Windows sandbox. Python on Windows and every Linux/macOS path take the approval route added here. Leaving it out of this PR.
NilayYadav
left a comment
There was a problem hiding this comment.
Follow-up: project folders
Current head: a56bf54. Three more commits since the evidence above:
0f7dd85: a chosen project folder that overran is rescanned before its launch and the flag clears once the scan completes within budget with no hazard. Before this, Run automatically kept asking in that folder until Studio restarted.1767036: that recheck runs at most once a minute per folder (3 launches, 1 walk in the test) and uses the same stale socket sweep as the normal scan, so a dead socket inunsloth-tmpno longer keeps the flag set. 60,000 entries hit the budget in about 0.11 s here.a56bf54: the recheck also runs before the approved host access launch, so an approved absolute path cleanup clears the flag too.
Tests on Linux against the PR base: 4 new or fixed tests pass (test_run_automatically_asks_once_the_chat_folder_is_too_large_to_check, test_windows_asks_the_model_to_retry_when_the_chat_folder_is_too_large, test_a_chosen_project_folder_stops_asking_once_it_is_small_again, test_an_oversized_project_folder_is_rechecked_at_most_once_a_minute), 578 unchanged, no new failures in test_permission_mode_degrade.py, test_sandbox_level.py and test_sandbox_linux.py.
Not changed: Windows Terminal under cmd_isolated still refuses an approved relative path call in an oversized folder. That is the existing cmd_isolated rule (it is rewritten to required in every permission mode on main too) and loosening it is a separate Windows sandbox decision.
|
Codex Review: Didn't find any major issues. 🎉 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". |
NilayYadav
left a comment
There was a problem hiding this comment.
Before/after on the final head a56bf54
Run automatically, Sandbox High, Qwen3-1.7B GGUF, macOS 26 arm64, Chromium 1440x900. Main is 5e55110.
- First
shutil.rmtree("build")in a chat with 60,000 files: main fails with "Start a new chat, or useauto"; the PR refuses once with "so this call needs the user's approval. Call the tool again to ask for it." - Same call again: main fails again, no approval card, and the model invents a
cleanedanswer; the PR shows Allow / Always allow / Deny, and after Allow it runs withrequested_mode: auto,effective_mode: os_isolated. - After
node_modulesis removed, one more risky call asks, thenrmtree("out")runs without asking and printscleaned out(requested_mode: required,os_isolated). - Studio-managed project folder: a second chat in the same project asks straight away for
rmtree("dist"); after cleanuprmtree("tmpdir")runs without asking and printscleaned tmpdir(required,os_isolated).
A user-picked project folder can only be set in the desktop app, so that case is covered by test_a_chosen_project_folder_stops_asking_once_it_is_small_again and test_an_oversized_project_folder_is_rechecked_at_most_once_a_minute.
|
@codex security review |
|
Codex Review: Didn't find any major issues. 🎉 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". |
…box test [skip ci]


With Run automatically and Sandbox High, risky Python and Terminal calls such as
shutil.rmtree("build")run without asking. Once a chat's folder passes 50,000 files (an npm install, a large clone), the sandbox can no longer check it before each launch, so every such call failed with "too large to check for host channels ... useauto" for the rest of the chat, and the permission menu has noauto.Studio now remembers which chat folders were too large to check, and there Run automatically asks first for risky calls, the fallback it already uses when the OS sandbox is not working. An approved call still runs inside the OS sandbox. Nothing runs unasked on an unchecked folder; if the first risky call is the one that finds the folder too large, it is refused once with a message telling the model to call the tool again, and that retry asks.
Other chats, non-risky calls and the other permission modes are unchanged.