Repository navigation
Unsloth Studio: let browser_navigate open files the model wrote in its tool workspace - #18062
Conversation
A model that writes page.html with python and then calls browser_navigate with page.html, ./page.html or file:///.../page.html got a host lookup or scheme error. A path inside this chat's tool workspace now opens as a file tab in the browser panel (the same sandboxed preview a chat-made page gets); a path outside it is refused with what to do instead.
…r a reopened file's own bytes
…nly listed suffixes
…ay to the status badge
…p the drive in Windows file URLs [skip ci]
|
@codex review |
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: 1150a443b6
ℹ️ 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".
| with open(full, "rb") as handle: | ||
| data = handle.read(_MAX_WORKSPACE_FILE_BYTES + 1) |
There was a problem hiding this comment.
Open workspace files through race-safe file descriptors
A concurrent workspace writer can replace the checked file or a parent directory with a symlink after the containment checks but before this open. The server then reads the target and sends it in open_file.data, exposing server-readable files outside the chat workspace. Replacing draw.html with an outside-file symlink between getsize and open reproduces the leak. Open relative to a held workspace directory descriptor with no-follow semantics and validate the opened descriptor, as view_image already does.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in db56c81: the read now walks from a held workspace descriptor with O_NOFOLLOW and checks the opened inode against the resolved path, as view_image does; tests swap the file and a parent for links after the checks.
… in after the checks
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! 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". |
…ad (#18315) ## Translate: keep the stable gutter without a :has() over the chat thread The long-thread composer gate, `tests/studio/playwright_long_thread_gate.py`, fails on `main` since #18293. It fails on every PR that runs it, for example #18062 and #18108, across `Frontend build + bundle sanity`, `Frontend unit tests (Windows)` and `Composer`: ``` FAIL: :has() matching costs 6.7 ms per keystroke at 200 turns, budget 5.0 ms (1.3x over) studio/frontend/src/index.css:5473 (exact text match) main:has(.translate-page) ``` ### Cause #18293 added this rule so a classic scrollbar does not narrow the Translate panes: ```css main:has(.translate-page) { scrollbar-gutter: stable; } ``` The `<main>` it matches is the layout's scroll container, and on the chat page that element holds the whole thread. An unanchored `:has()` there makes Chromium re-walk every descendant on each keystroke. The gate measures exactly that cost, and it grows with the chat. ### Fix The intent is unchanged: while Translate is open, its layout `<main>` keeps a stable gutter. Only the way that element is selected changes. - `translate-page.tsx`: a layout effect marks the layout `<main>` that holds `.translate-page` with `data-translate-page` while the page is mounted, and removes it on unmount. The page's own root is also a `<main>`, so the effect starts from its parent. - `index.css`: `main:has(.translate-page)` becomes `main[data-translate-page]`. An attribute selector costs nothing per keystroke, and the Translate page renders the same. ### Verification **Long-thread gate, run locally on the same host:** | | `:has()` at 40 turns | `:has()` at 200 turns | Selector matching growth | Gate | |---|---|---|---|---| | `main` | 0.76 ms/key | 3.86 ms/key | 2.11x for 5x the turns (limit 2.0x) | FAIL | | this PR | 0.06 ms/key | 0.09 ms/key | 0.38 to 0.45 ms/key | PASS | **Other checks:** - `tests/translate-page.test.ts`: 27 passed. - `npm run typecheck`: no errors. ### Screenshots Translate page at 1366x768, before (`main`) and after (this PR). Each side was built from its own isolated Studio install. Both render the same page, and on both the layout `<main>` reports `scrollbar-gutter: stable`. The page width is 1076 px on both sides. 
The problem
Ask Unsloth Studio to "make a single html file that draws something on a canvas and show it to me in the browser", and the model writes
mandelbrot.htmlwith python or terminal, then callsbrowser_navigatewithmandelbrot.html,./x.htmlorfile:///.../x.html. Every one of those fails before the panel sees it: a bare name is read as a host ("Failed to resolve host"), afile://URL is refused ("only http/https URLs are allowed", web_access_policy.py#L128-L129), and./x.htmlgives "invalid hostname or port". The tool works fine on real http(s) URLs. It had no way to show a file the model just made.Serving the workspace on a loopback URL wouldn't fix it: the panel refuses every loopback origin the user didn't type into the tab's address bar (executor.ts navigateTo, L1066-L1076), so the error would only move from the backend to the panel.
The fix
browser_navigaterecognizes a workspace file by syntax alone: a barepage.html, a relative or absolute path, afile://URL (includingfile:///C:/...on Windows), or a folder path such asout/page.html. A bare name the workspace has but that reads like a site (run.py,notes.md) is answered with "open it as ./run.py", so the approval check and the open always agree. It resolves the path in the same per-chat workspace python and terminal run in (_get_workdir(session_id)) and sends the panel anopen_fileaction carrying the bytes (2 MB cap).browser_snapshot,browser_read_fileandbrowser_edit_filework on it. Reopening the same path refreshes that tab.example.com/page.html,localhost:3000/x.htmlandexample.pyare still sites.Approval
Opening a workspace file hands its bytes to the model, so it now asks like any other sensitive read: in Ask and Auto (the default) the call stops on the usual approval card; Off and Full Access do not ask, as for every other tool there. Web addresses are unchanged. The read is race-safe: it walks from a held workspace directory without following links and checks the opened file is the one that was approved, as
view_imagedoes, so a file or folder swapped for a link after the checks is refused. Probing a name never creates a sandbox for a chat that only browses.Tests
studio/backend/tests/test_browser_agent.py: workspace names, paths and file URLs open; outside paths,..,~, symlinks out and missing files are refused with guidance; sites with file-like paths stay sites; a malformedfile://[is refused, not raised; the action carries this chat's file; status badge. 90 passed.studio/frontend/tests/browser-agent-files.test.ts:open_fileopens a file tab and reads its preview; a reopen (same length too) shows the new bytes; an off-screen chat is refused before any tab opens. 13 passed.test_opening_a_workspace_file_asks_wherever_a_sensitive_read_asks: 4 permission modes x 11 targets;test_the_approval_check_and_the_open_agree_on_every_target; race tests swap the file and a parent for links after the checks.Staging: browser agent tests pass on ubuntu-latest, windows-latest and macos-15.
Before/after in Studio
A scripted OpenAI-compatible model, added as a Custom connection, calls
browser_navigate {"url": "draw.html"}on a file seeded in the chat's workspace; permission mode Auto. Before, the call runs unasked and its result isFailed to resolve host(the scripted model's closing line is fixed text on both sides). After, it stops on an approval card; after Allow the browser panel opens the page.Before/after on AMD NPU models
Running on the AMD DevLab Strix Halo runner; results and screenshots will be added here.
Not covered
The real panel in Unsloth Desktop (native views) wasn't driven.