Repository navigation
fix(mcp): drain a synthesized navigation before the tool replies - #745
Merged
SGavrl merged 1 commit intoAug 31, 2026
Merged
Conversation
A submit click runs the page's form glue and leaves the navigation as pending state. It becomes a request only when a driving layer converts it. The CDP path converts it, in Input.dispatchMouseEvent and after Runtime.evaluate, which is why the same click POSTs over CDP and does nothing over MCP. The transport's own pump cannot cover this. It is armed after every dispatch, but it sits in a biased select behind read_line, so a client that sends its next tool call immediately, which an agent does, wins that race every time. The reply is also written before any pump turn could run, so browser_click answered "Clicked" while nothing had left the process, and location.href already reported the destination, telling the agent the submit had happened. Add settle_synthetic_navigation and call it from every tool that can synthesize a click, a keypress, or run a script, so the invariant holds for the surface rather than for one tool. It is a no-op when nothing is pending. Fixes h4ckf0r0day#618.
This was referenced Aug 29, 2026
Contributor
Author
|
Obstacle course, for the CONTRIBUTING pre-PR item I could not tick from a unit test. Companion repo at the ref your CI pins (
No delta. The single failure is the same stage on both, and it fails on untouched So it is a property of this host rather than of the change, and I have not chased it further since it is outside the diff. It is deterministic rather than flaky here: re-running just that stage with Everything else in this PR is unchanged. |
3 tasks done
SGavrl
approved these changes
Aug 31, 2026
markjacksoncerberus
added a commit
to markjacksoncerberus/obscura
that referenced
this pull request
Sep 11, 2026
…ng): the reflected verdict — A PAGE THAT TOOK FIVE SECONDS WAS NOT SLOWED DOWN, IT WAS EXECUTED (a 5s watchdog terminated the V8 isolate and never cancelled the termination, so every later script, handler and CDP evaluate died with it), and then the browser learned to keep the promise `img.alt` makes — Quests h4ckf0r0day#731–h4ckf0r0day#752 (reflection suite 10,065 scoreable → 56,591/56,660; 0 regressions over 392 ritual rows) The region was chosen by measuring, and the measurement was the finding. A 26-file sample of the platform's biggest files came back 40,500/42,147 — the campaign is in good health — with three rows reading `testharness did not load` whose denominators were 10,202, 8,922 and 8,271. 27,395 subtests were not failing. They were invisible. h4ckf0r0day#731 ⭐⭐⭐ V8 termination is STICKY. `terminate_execution()` does not unwind a script, it puts the isolate into a state where every later entry into JS bails out until `cancel_terminate_execution()` clears it — and that call was never made, so the `<reset>` script meant to recover was itself terminated on arrival. The watchdog did not kill a script; it killed the page, and from a driver's side that is a browser that silently stopped answering. h4ckf0r0day#732 The budget had both halves backwards: no timeout at all under 10 kB (a fifty-byte `while(1){}` hung the engine forever) and five seconds above it (the heaviest real pages need 10-25s, measured). Now every script is guarded at 60s, `OBSCURA_SCRIPT_TIMEOUT_MS` overrides, `0` disables. That one fix was +28,036 subtests before a line of reflection was written. h4ckf0r0day#733-h4ckf0r0day#744 Then the suite could be read: 183 reflected members across 33 interfaces were simply absent — `a.ping`, `q.cite`, `td.colSpan`, `th.scope`, `img.srcset`, `track.kind`, the whole `<frame>`/`<marquee>` family. Rebuilt keyed by INTERFACE, because `Element.prototype` cannot express that `a.type` is a DOMString while `input.type` is a 22-keyword enum, or that `value` is a DOMString on `<data>` and a double on `<meter>`. The clamped types clamp in the GETTER only; `progress.max = 0` is ignored; `<meter>`'s six numbers are a system; and `nonce` writes an internal slot and touches the attribute only when connected, because the attack it defends against is a page that can be made to READ it. h4ckf0r0day#745-h4ckf0r0day#752, five more root causes from re-reading the same sample: - `'zIndex' in el.style` was FALSE. A trap answers `get` but not `in`, so `'gridTemplateAreas' in body.style` reported we support nothing. - The browser gave TWO answers to "do you support this?" — `CSS.supports()`'s validator chain and the property registry were different lists. Underneath: a CSS-wide keyword is valid in EVERY declaration, and a dozen branches forgot. - `font-family: simple default` is a font called "simple default" — the CSS-wide exclusion belongs to the `<family-name>`, not to each `<custom-ident>` in it. - An unknown media query is not a broken one. MQ4 has three truth values; collapsing `<general-enclosed>` to `not all` made `@media not (future-thing)` come out TRUE. - `<img width=200>` was 200 of nothing — the dimension attributes never reached the cascade, so on the old web this browser exists for, every image, cell and frame laid out at `auto`. - The URL parser said no and four APIs did not listen (`xhr.open`, `sendBeacon`, `location.href`, and `window.location =`, which was replacing the Location object with a string).⚠️ The ritual caught THREE regressions in my own work, which is why it exists: the computed-style proxy's `if (prop in target)` delegation began answering from the INLINE declaration once every property had an IDL attribute; a condvar wait with NO predicate check lost the `notify_one()` of a script that finished before its watchdog was scheduled, so `join()` froze the ENGINE THREAD for the whole budget (a hung browser, not a hung script, with nothing in the log); and a generated table must not assume a reflector is ONLY a reflector — `iframe.src` navigates the frame. Keeping the existing setters costs 69 subtests, and a browser that scores 56,660 and cannot load an iframe is not a better browser. Results: reflection suite 10,065 scoreable → 56,591/56,660 · dimension-attributes 952 → 1720/1720 · CSS-supports-CSSStyleDeclaration 869 → 1495/1495 · url/failure 604 → 1174/1175 · test_font_family_parsing 1768 → 2217/2232 · idlharness?include=HTML 2299 → 2773 · three dead files worth +5,245 more. Zero regressions: 392 ritual rows, 55,689 → 55,707, two rows moved — one an improvement (scroll-behavior-main-frame-root 1/40 → 40/40) and one the documented flaky img file, re-proven solo at 205/228/228 on the pre-arc binary and 207/228/205 on the final one. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01EiXpEBV3Kfpy9zWXHqAhRU
whyparv
pushed a commit
to whyparv/obscura
that referenced
this pull request
Nov 17, 2026
…pending-navigation fix(mcp): drain a synthesized navigation before the tool replies
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.
Fixes #618.
What changed
settle_synthetic_navigation()onBrowserState: consume the pending navigation, and if one landed, clear the ref table (it names elements in a document that is gone) and give the new document one event-loop slice, so a tool that reads the URL or the text next sees the landed page rather than an empty one. It is a no-op when nothing is pending.It is called from
browser_click,browser_fill,browser_type,browser_press_keyandbrowser_evaluate, not frombrowser_clickalone. The invariant @yinnho describes is the useful thing here: every tool that can synthesize a click, a keypress, or run a script drains pending navigation before it replies.browser_evaluaterunninglocation.href = ...orform.submit(), and an Enter throughbrowser_press_key, land in the same pending state, so fixing only the reported tool would leave the same bug one call to the left. Those five tools becomeasync; two existing tests that called them directly gained.await.@yinnho's framing in the issue is right and holds here exactly: pumping is not draining. A submit click runs the page's own form glue and leaves the navigation as pending state. It becomes a request only when a driving layer converts it. The CDP path converts it, in two places:
crates/obscura-cdp/src/domains/input.rs:227after a dispatched mouse event, andcrates/obscura-cdp/src/domains/runtime.rs:32afterRuntime.evaluate. MCP had no equivalent, which is the whole of your Path A versus Path B.Why the existing pump does not already cover it
BrowserState::advance_active_page_tasksalready pumps and drains, and it is armed after every dispatch. It still never gets a turn here, for two independent reasons:The select is
biasedwithread_linefirst, so a client that already has its next tool call queued, which an agent always does, wins that race every time. And the response is written before the loop comes back around at all, so even an unbiased select would reply first.That is also where the misleading part of the report comes from.
location.hrefreports the destination because the pending navigation has already updated the page's URL state. The agent is told the submit happened while no request has left the process, which is worse than an outright failure.Validation
New test
click_on_a_submit_button_issues_the_request_before_replying, built on your repro page: a recording server serving the form,browser_fillon#q,browser_clickon#go. The assertion is at the wire, not onlocation.href, because the URL was the thing that lied.Red with the drain removed from
tool_click, green with it:Full four-configuration sequence from CONTRIBUTING, in a
rust:latestcontainer so the result matches CI rather than my Windows host:cargo build --release -p obscura-cli --bins --features rendercargo nextest run --release --features render --no-fail-fastcargo build --release -p obscura-cli --bins --no-default-featurescargo nextest run --release -p obscura --no-fail-fastcargo nextest run --release --workspace --exclude obscura --exclude obscura-render --no-default-features --no-fail-fastcargo check --release -p obscura-render --no-default-featuresRendering
Not applicable. No layout, paint, screenshot, screencast or PDF code is touched.
browser_screenshotandbrowser_pdfare not among the five tools changed.Performance
The added work is one
process_pending_navigation()per call to those five tools, which returns immediately when nothing is pending, so the cost on the common path is a check. When a navigation is pending the tool now waits for one event-loop slice before replying, which is work the client was going to pay for on its next call anyway, moved to where it is correct. The other MCP tools are untouched.Relationship to the other issues on this
#640's framing, that the transport never pumps the page task queue, is not what breaks this: the pump exists and is armed. It loses a race and, more fundamentally, runs after the reply. So this fix is orthogonal to any pump change and does not close #640.
I have not touched
location.hrefreporting a destination for a navigation that has not been converted. After this change the two agree for these tools, but the underlying "URL state moves before the request" behaviour is still reachable from anywhere that does not drain, and it deserves its own issue rather than a rider here.Checklist