Repository navigation
fix(browser): the policy guard loads the last allowed page instead of going back - #160
Merged
Merged
Conversation
william-monroy
force-pushed
the
fix/browser-policy-guard-hang
branch
from
November 23, 2026 06:36
ee4aa9b to
d49fbd5
Compare
william-monroy
marked this pull request as ready for review
November 23, 2026 06:36
… going back A taken-back navigation went back in history, and Chrome restored the page from its back/forward cache, for which Playwright sees no DOMContentLoaded or load. A browser_navigate whose redirect left the allowed domains could then wait the whole 60 s navigation timeout, the MCP client's own limit, and a refused link click took about 15 s. The guard now loads the last allowed page again, waits for its commit only, and bounds each step by the 5 s cap. The Chrome test keeps the redirect's page from loading and runs that step on a tab with no take-back in flight; against the old guard it fails with the CI error.
william-monroy
force-pushed
the
fix/browser-policy-guard-hang
branch
from
November 23, 2026 06:37
d49fbd5 to
d58b717
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
policy-chrome.test.tsfailed now and then on Ubuntu withMCP error -32001: Request timed out(the MCP SDK client's 60 s limit): runs 45048056092 (#150, node 24), 45063064840 (#152, node 26), and 45116138733 attempts 1 and 2 (#157, node 22). Each time the test took 62 to 66 s. The cause is in the product: the policy guard took a tab back withpage.goBack(), and a tool call could wait 60 s for it.Cause
When a navigation leaves the allowed domains, the guard takes the tab back. It used
goBack({ waitUntil: "domcontentloaded" }). Chrome restores that page from its back/forward cache, and Playwright sees no DOMContentLoaded or load for a restored page (upstream's ownbrowser_navigate_backwaits forcommitfor this reason). Two effects:The 60 s hang.
browser_navigateto/redirectrunspage.goto(..., { waitUntil: "domcontentloaded" })with the 60 s navigation timeout. The redirect lands on127.0.0.1/landed, which commits; the guard'sgoBackbrings back the allowed page from the cache before/landedfires DOMContentLoaded, so thegotowaits for one that never comes, until 60 s, exactly the client's limit. A CI diagnostic run (240 runs of an instrumented copy of the test beside the browser suite, Ubuntu, node 22/24/26) caught it with fullpw:apilogs:It only happens when the tab has no take-back in flight. In the test the blocked link click came first, and its
goBackusually stayed pending (same reason) and swallowed the redirect's take-back. On Ubuntu thatgoBacksometimes fails within milliseconds and the guard falls back to a freshgoto; then the redirect step hits the hang. Counts in that diagnostic run: 5 of 240 navigations took 60.0 s and 23 more took 10 s (the same race, ending on upstream's 5 s load wait), close to the rate on CI (4 failures in about 150 Ubuntu runs of the test since it landed).A refused link click took about 15.7 s, every time (all 336 diagnostic runs on CI and every local run): upstream's click waits up to 10 s for a load that a restored page never fires, then the result waits the guard's 5 s cap for the still-pending
goBack. ThatgoBackthen held the tab for up to 60 s, so a second violation in that tab got no take-back of its own and was left to the stalegoBack.Not a CI-only action timeout: none of the four failures shows
Timeout 5000ms exceeded, and the hung call is a navigation.Fix
NavigationGuard.revertloads the last allowed page again withgotoinstead of going back in history, waits only forcommit, and bounds each step by the existing 5 s cap. A fresh load fires DOMContentLoaded and load, so the navigate and the click return as soon as the tab is back. The fallback toabout:blankand the popup close stay as they were.Test
policy-chrome.test.ts, still one Chrome launch: the/landedpage now never finishes loading (it sends its head and holds the response), and the redirect step runs before the link click, on a tab with no take-back in flight. That reproduces the hang without load: against the old guard the test fails with the CI error (MCP error -32001: Request timed outafter 62 s, 2 of 2 local runs, and 3 of 3 runs of the instrumented copy took 60.0 s for that navigate); with the fix it passes.afterEachcloses the held connection before closing the server.Loops:
browser-tools.test.tslooping alongside: fixed guard 20 of 20 for the instrumented copy (slowest call 1.7 s) and 20 of 20 for the final test. The old guard never hung there with the old test order (30 of 30 passed, click at 15.7 s each time), which is why it looked CI-only.pnpm checkpasses locally.