Skip to content

fix(browser): the policy guard loads the last allowed page instead of going back - #160

Merged
william-monroy merged 1 commit into
mainfrom
fix/browser-policy-guard-hang
Nov 23, 2026
Merged

william-monroy merged 1 commit into
mainfrom
fix/browser-policy-guard-hang

Conversation

@william-monroy

@william-monroy william-monroy commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

policy-chrome.test.ts failed now and then on Ubuntu with MCP 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 with page.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 own browser_navigate_back waits for commit for this reason). Two effects:

  1. The 60 s hang. browser_navigate to /redirect runs page.goto(..., { waitUntil: "domcontentloaded" }) with the 60 s navigation timeout. The redirect lands on 127.0.0.1/landed, which commits; the guard's goBack brings back the allowed page from the cache before /landed fires DOMContentLoaded, so the goto waits 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 full pw:api logs:

    06:10:41.622 navigating to "http://localhost:41927/redirect", waiting until "domcontentloaded"
    06:10:41.652 "commit" event fired / navigated to "http://127.0.0.1:41927/landed"
    06:10:41.653 page.goBack started, waiting for navigation until "domcontentloaded"
    06:10:41.677 "commit" event fired / navigated to "http://localhost:41927/"   <- restored, no DOMContentLoaded follows
    06:11:11.654 page.goBack failed
    06:11:41.623 browserBackend.callTool failed                                  <- the navigate, 60.0 s later
    

    It only happens when the tab has no take-back in flight. In the test the blocked link click came first, and its goBack usually stayed pending (same reason) and swallowed the redirect's take-back. On Ubuntu that goBack sometimes fails within milliseconds and the guard falls back to a fresh goto; 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).

  2. 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. That goBack then 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 stale goBack.

Not a CI-only action timeout: none of the four failures shows Timeout 5000ms exceeded, and the hung call is a navigation.

Fix

NavigationGuard.revert loads the last allowed page again with goto instead of going back in history, waits only for commit, 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 to about:blank and the popup close stay as they were.

Test

policy-chrome.test.ts, still one Chrome launch: the /landed page 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 out after 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. afterEach closes the held connection before closing the server.

Loops:

  • CI diagnostic, Ubuntu, node 22/24/26, the instrumented copy looping beside the browser suite (old test order): old guard 336 runs, 5 navigations at 60.0 s, 29 at 10 s, and the refused click at 15.7 s in 290; fixed guard 240 runs, 0 failures, slowest navigation 1.8 s, slowest click 1.2 s.
  • macOS, 6 CPU burners and browser-tools.test.ts looping 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 check passes locally.

@william-monroy
william-monroy force-pushed the fix/browser-policy-guard-hang branch from ee4aa9b to d49fbd5 Compare November 23, 2026 06:36
@william-monroy william-monroy changed the title fix(browser): policy guard never leaves a tool call waiting on a taken-back navigation fix(browser): the policy guard loads the last allowed page instead of going back Nov 23, 2026
@william-monroy
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
william-monroy force-pushed the fix/browser-policy-guard-hang branch from d49fbd5 to d58b717 Compare November 23, 2026 06:37
@william-monroy
william-monroy merged commit 2c8541c into main Nov 23, 2026
14 checks passed
@william-monroy
william-monroy deleted the fix/browser-policy-guard-hang branch November 23, 2026 06:52
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.

1 participant