Repository navigation
Studio: fix compressed pages, router paths and early empty reads in the browser panel - #13532
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. |
|
Reached Codex review convergence at oobabooga#364. |
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.
|
@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: 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; |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
| if coding not in ("", "identity", *_DECODED_CODINGS): | ||
| return f"Failed to fetch URL: unsupported Content-Encoding {coding[:40]!r}.", "", "" |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
|
@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: 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); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
# Conflicts: # studio/frontend/src/features/browser/agent/executor.ts # studio/frontend/src/features/browser/agent/page-agent.ts
|
@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: 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); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
| wrapped = data[0] & 0x0F == 8 and (data[0] << 8 | data[1]) % 31 == 0 | ||
| self.inflater = zlib.decompressobj(15 if wrapped else -15) |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
Live testing the web browser panel with a loaded model turned up four problems:
huggingface.co/srcdoc?search=..., and Reload drops the filter.browser_navigate.Root causes
_fetch_url_rawsends noAccept-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 toAccept-Encoding: identity; which pages are affected changes with the cache state. The panel,web_fetchand image search share this fetcher.about:srcdocwith an opaque origin.location.pathnameis"srcdoc", and anabout:srcdocdocument can only change its fragment (HTML: can have its URL rewritten). HF builds its URL from the pathname, hence/srcdoc?....observeLoadedsnapshots immediately, andsettle()only checks that the DOM is quiet, which it is while a request is in flight.gateElementtreats any form with a password input as a sign-in, filled or not.Fix
core/inference/tools.py)._ContentDecoderundoesgzipanddeflate(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 sendsAccept-Encoding: gzip, deflate, and any other coding returns a clear error.routes/browser.py,store.ts). ThepushState/replaceStatewrappers 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.routes/browser_network.py,agent/executor.ts,agent/page-wait.ts). The shell wraps the page'sfetchandXMLHttpRequestonly 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. Plainbrowser_snapshotandbrowser_finddo not wait.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:
Intentional limits:
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)
The model clicks Submit on a form whose Password field is empty: the approval no longer calls it a sign-in
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.
_fetch_page_texton the same URL/srcdoc?sort=trending&search=.../models?sort=trending&search=Qwen3-VL-8B-Instruct/models, filter goneAgent read latency, from the first command the page receives to the tool result:
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,srcdocmapping 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.tsc -bclean;npm testruns 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: