Skip to content

Studio: fix compressed pages, router paths and early empty reads in the browser panel - #13532

Merged
danielhanchen merged 9 commits into
unslothai:mainfrom
oobabooga:fix/studio-browser-panel-core
Oct 13, 2026
Merged

danielhanchen merged 9 commits into
unslothai:mainfrom
oobabooga:fix/studio-browser-panel-core

Conversation

@oobabooga

@oobabooga oobabooga commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Live testing the web browser panel with a loaded model turned up four problems:

  • python.org shows binary garbage, in the panel and to the model.
  • Hugging Face's "Filter by name" changes the address to huggingface.co/srcdoc?search=..., and Reload drops the filter.
  • A page that draws its content after load reads as "(nothing readable here)" right after browser_navigate.
  • Submitting a form with an empty password field asks "Let Unsloth sign in on selenium.dev?".

Root causes

  • Compressed responses are never decoded. _fetch_url_raw sends no Accept-Encoding, which per RFC 9110 12.5.3 means any content coding is acceptable, and reads the body as is. python.org's Fastly cache serves gzip regardless, even to Accept-Encoding: identity; which pages are affected changes with the cache state. The panel, web_fetch and image search share this fetcher.
  • The page runs at about:srcdoc with an opaque origin. location.pathname is "srcdoc", and an about:srcdoc document can only change its fragment (HTML: can have its URL rewritten). HF builds its URL from the pathname, hence /srcdoc?....
  • The agent reads a new page as soon as the tab stops loading. observeLoaded snapshots immediately, and settle() only checks that the DOM is quiet, which it is while a request is in flight.
  • gateElement treats any form with a password input as a sign-in, filled or not.

Fix

  • Decoding (core/inference/tools.py). _ContentDecoder undoes gzip and deflate (zlib-wrapped or raw) as the body streams. Decoded output counts against the caller's existing byte limits, compressed input is capped too, and a truncated or invalid stream is an error rather than garbage. The fetcher now sends Accept-Encoding: gzip, deflate, and any other coding returns a clear error.
  • Router paths (routes/browser.py, store.ts). The pushState/replaceState wrappers map a URL built from "srcdoc" to the page's real path, and when the page has no <base> of its own, the shell's <base> follows the router so relative links and requests resolve as in a browser. Reload loads the router's same-site address.
  • Waiting for content (routes/browser_network.py, agent/executor.ts, agent/page-wait.ts). The shell wraps the page's fetch and XMLHttpRequest only to count its requests, until their bodies are read. Each action records the time just before it goes out, and the wait covers every request started since then. After a navigation the read waits for those requests and 350 ms of DOM quiet, at most 3 s (1 s for a DOM that never rests), and notes it if requests were still open. A router rewriting the address during that wait is still the same page. settle() after an action waits the same way. Plain browser_snapshot and browser_find do not wait.
  • Wording (agent/gate.ts). The prompt says "Sign in" only when a password field holds a value; otherwise "Submit this form on {host}?". Approval is still required either way.

Behavior that stays as on main:

  • Reads of a loaded page cost what they cost on main, including pages with a ticking clock or a stalled image.
  • The page's requests go out exactly as before; the wrapper only counts them.
  • The desktop app's native webview is untouched.

Intentional limits:

  • A router that updates the address a moment after its content (HF does) can leave the previous address in the tool result. The content is current, and the address bar catches up.
  • A page that opens a long poll while loading takes the full 3 s on navigation, with the note.
  • Brotli and zstd are refused with an error rather than decoded.

Screenshots

Before is main, after is this change, each a separate Studio driven through the same steps in Chromium.

python.org/about/ opened by hand (served gzip-encoded)

1-gzip-page

The model clicks Submit on a form whose Password field is empty: the approval no longer calls it a sign-in

3-empty-password-prompt

Testing

Live A/B in Studio, main against this branch, separate backends, Qwen3-VL-8B-Instruct UD-Q4_K_XL loaded on each, driven through the UI with Playwright Chromium. Delays were applied identically on both sides with Playwright routing.

Case Main This PR
python.org/about/, model asked for title and heading Garbage snapshot, invented title ("About Python") "About Python™ | Python.org"
_fetch_page_text on the same URL "(binary content, 8648 bytes; not readable as text)" The page as Markdown
HF "Filter by name", typed by hand Address /srcdoc?sort=trending&search=... Address /models?sort=trending&search=Qwen3-VL-8B-Instruct
Then Reload /models, filter gone Filter kept, matching models listed
Selenium index, GitHub API delayed 1.5 s Empty at every read (2 of 2 runs); model says the link is absent 235 links in the navigation read in 4 of 5 runs; in the other, GitHub's response was still open at the 3 s cap and the read said so
Selenium web form, password empty "sign in on selenium.dev?" "submit this form on selenium.dev?"; Allow submits

Agent read latency, from the first command the page receives to the tool result:

Page Main This PR
example.com: navigate, then 3 reads 1 to 8 ms each 375 ms for the navigation, 2 to 3 ms for the reads
epochconverter.com (DOM changes every second) 2 to 6 ms 515 ms for the navigation, 4 to 10 ms for the reads
  • test_web_fetch_content_encoding.py (new): codings and variants, the request header, bombs, truncation, zlib output held back at the end of a raw deflate stream, and coded error pages.
  • test_browser_routes.py: the shell's request counting, srcdoc mapping and routed <base>.
  • browser-network.test.ts (new) runs the shipped shell script; browser-agent-page-wait.test.ts (new) runs the wait on a fake clock, including a request a click starts synchronously and one still open at the deadline; browser-agent-executor.test.ts (new) reads a page at the address its router moved to while it filled in. Gate and reload cases were added to existing tests.
  • Backend fetch and browser suites: 1,711 passed. Frontend: tsc -b clean; npm test runs 11,787 tests and the 12 failures also fail on main.

Not tested: the desktop app, Firefox and WebKit, and signed-in sites.

Staging screenshots

python.org/about/ opened in the browser panel by a browser_navigate action, merge base (left) against this branch (right), each a separate Studio built from its tree:

python.org served gzip: bytes before, the page after

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 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-13T10:35:16.244269Z 3926199 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.

@mahiatlinux mahiatlinux self-assigned this Oct 13, 2026
@oobabooga

Copy link
Copy Markdown
Member Author

Reached Codex review convergence at oobabooga#364.

@danielhanchen danielhanchen self-assigned this Oct 13, 2026
The browser pointer and script tools (unslothai#13505) use AgentAnswer.pending as a
boolean for a script still running; a numeric pending here would merge into
the same type.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@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: c981474445

ℹ️ 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 (nativeWebHistory || entry.kind !== "web" || entry.method === "POST") return null;
if (!tab.displayUrl || tab.displayUrl === entry.url) return null;
try {
if (new URL(tab.displayUrl).origin !== new URL(entry.url).origin) return null;

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 Preserve routed URLs after cross-origin redirects

When the requested entry redirects to a different origin (for example example.com to www.example.com) and the final page then uses pushState for a filter or route, entry.url remains the pre-redirect address while displayUrl is the final routed address. This comparison rejects that legitimate route, so Reload refetches the original entry and drops the router state; the safety check needs to use the loaded page's final origin, which is also the origin against which frame URL messages are validated.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not changing here: after a cross-origin redirect Reload refetches the requested entry, as it does on main, so nothing is lost relative to today. Allowing it safely needs the loaded page's origin kept on the tab, which is a separate change.

Comment on lines +16539 to +16540
if coding not in ("", "identity", *_DECODED_CODINGS):
return f"Failed to fetch URL: unsupported Content-Encoding {coding[:40]!r}.", "", ""

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 Decode every supported Content-Encoding layer

A response can validly apply multiple content codings and report them as an ordered list, such as Content-Encoding: deflate, gzip; both layers are advertised and individually supported here, but the whole header string fails this membership check and the fetch is rejected. Parse the coding list and decode its supported layers in reverse application order so standards-compliant stacked responses do not fail as an unsupported encoding.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not changing: stacked codings are not served by real sites in practice; such a response now gets a clear unsupported-encoding error instead of the undecoded bytes it got before.

…fused send

Reload at the router's address now swaps the entry in place instead of
truncating the pages ahead, and a second send() the browser refuses no longer
ends the count of the request still in flight.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

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

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@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: d224fbb373

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

}
window.fetch = (input, init) => {
const done = track();
return nativeFetch(input, init).finally(done);

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 Keep fetches pending across deferred body reads

When an action handler receives fetch headers but defers consuming the Response (for example, it queues .json() on a short timer), this removes the only in-flight marker before the body wrapper creates another one. On an otherwise quiet page, settle can run its first poll during that gap, see zero requests and an old DOM quiet time, and snapshot before the response is parsed and rendered. Preserve a pending handoff from the original fetch until body consumption starts or the response is otherwise discarded.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not changing: pages read a response's body in the same promise chain that resolves the fetch, which is the case this counts. Holding the count until a body is read would keep every fetch whose body is never read (beacons, fire-and-forget calls) open, so every action on such a page would wait the full 3 s.

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 13, 2026
# Conflicts:
#	studio/frontend/src/features/browser/agent/executor.ts
#	studio/frontend/src/features/browser/agent/page-agent.ts
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@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: 3926199a44

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

catch { original.call(this, state, title); }
if (next) {
pageUrl = next;
routedBase?.setAttribute("href", pageUrl);

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 Reject cross-origin router bases before applying them

On a proxied page with no declared <base>, a cross-origin pushState/replaceState leaves next truthy even though shellPath(next) gives the native history call undefined; this line therefore retargets the injected base to the forbidden origin. The real API would reject such a URL, and useFrameMessages also rejects the cross-origin URL report, so the visible address remains on the original site while later relative links and resources resolve against another site; validate the origin before mutating the routed base.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not changing: a cross-origin pushState is refused by every browser with a SecurityError, so legitimate pages never make one; the shell's handling of such a call is unchanged from main apart from the base following the router.

Comment on lines +16252 to +16253
wrapped = data[0] & 0x0F == 8 and (data[0] << 8 | data[1]) % 31 == 0
self.inflater = zlib.decompressobj(15 if wrapped else -15)

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 Retry ambiguous deflate streams as raw

When a server uses raw deflate and the payload's first two bytes happen to satisfy the zlib header checksum (for example, a valid raw stored stream beginning 78 9c 00 63 ff), this heuristic opens a zlib-wrapped inflater and returns a compressed-response error even though wbits=-15 decodes it. Since this branch explicitly supports raw deflate from nonconforming servers, retry raw mode when the initial wrapped decode fails before producing output rather than relying solely on this ambiguous two-byte sniff.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not changing: it needs a server sending non-standard raw deflate whose first block also passes the zlib header checksum (a non-final stored block). zlib-wrapped deflate, which RFC 9110 specifies, and gzip are unaffected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants