Skip to content

Studio: ask before risky calls when a chat folder is too large to check - #13914

Merged
danielhanchen merged 8 commits into
unslothai:mainfrom
NilayYadav:sandbox-required-large-workdir
Oct 18, 2026
Merged

danielhanchen merged 8 commits into
unslothai:mainfrom
NilayYadav:sandbox-required-large-workdir

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

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 ... use auto" for the rest of the chat, and the permission menu has no auto.

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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 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-18T12:03:09.424364Z 95a38a9 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[bot]

This comment was marked as resolved.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

1 similar comment
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@NilayYadav NilayYadav left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 with Execution 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 a cleaned answer.
  • PR 4995151: the first call returns Execution 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 with requested_mode: auto, effective_mode: os_isolated (macos-seatbelt), limitation workdir_scan_incomplete.

PR 13914 before/after

  • Unchanged on both sides: print(6*7) in the large chat runs without asking (auto, os_isolated); a fresh chat runs the same rmtree without 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 required again.
  • Tests: the new test fails on main and passes here (main: 1 failed, 245 passed; PR: 246 passed). With 4995151, test_permission_mode_degrade.py plus test_sandbox_linux.py show 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).

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

danielhanchen added a commit that referenced this pull request Oct 15, 2026
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.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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."

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 NilayYadav left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in unsloth-tmp no 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.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 15, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

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".

@NilayYadav NilayYadav left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before/after on the final head a56bf54

Run automatically, Sandbox High, Qwen3-1.7B GGUF, macOS 26 arm64, Chromium 1440x900. Main is 5e55110.

PR 13914 before/after at a56bf54

  1. First shutil.rmtree("build") in a chat with 60,000 files: main fails with "Start a new chat, or use auto"; the PR refuses once with "so this call needs the user's approval. Call the tool again to ask for it."
  2. Same call again: main fails again, no approval card, and the model invents a cleaned answer; the PR shows Allow / Always allow / Deny, and after Allow it runs with requested_mode: auto, effective_mode: os_isolated.
  3. After node_modules is removed, one more risky call asks, then rmtree("out") runs without asking and prints cleaned out (requested_mode: required, os_isolated).
  4. Studio-managed project folder: a second chat in the same project asks straight away for rmtree("dist"); after cleanup rmtree("tmpdir") runs without asking and prints cleaned 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.

@danielhanchen danielhanchen added codex-converged# edge case# security# Moves a security boundary: sandbox, allowlist, permission or network guard labels Oct 16, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 95a38a99b2

ℹ️ 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".

@unslothai unslothai deleted a comment from NilayYadav Oct 18, 2026
@unslothai unslothai deleted a comment from NilayYadav Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex-converged# edge case# security# Moves a security boundary: sandbox, allowlist, permission or network guard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants