Repository navigation
fix(browser): back/forward return once their commit's DevTools events are applied - #696
Conversation
… are applied dev-464 showed that an agent's next command after back/forward could fail [browser.document_changed]: the command returned before the history commit's DevTools events were applied, each of which bumps the tab's generation, so the next command was authorized against the old one (#640's quick wake made it frequent; #675 reverted it, and back/forward now wait the 1.2 s grace again). A trace of every navigation event (4 configurations x 20 runs) showed that each new document brings exactly its address, the main frame's Runtime.executionContextsCleared and, unless the engine runs extensions, its Page.frameNavigated, and no other bump; every failure had one of these after the return. back/forward now record the frame tracker's counts of those two events and return when the address has moved and both (with extensions, the first) have been applied and the tab is not loading. LOAD_SETTLE_GRACE stays the bound and the fallback (same-document or same-address entries). back/forward with no entry that way return at once, as official does.
…ext; no spin past the grace READER-12 should-fixes on #696: (a) clearing removes the main frame's execution context and an evaluate before the new one exists fails document_changed; with extensions the context came up to 8 ms after the clearing in 30 of 67 navigating runs (none after the navigation without, 0 of 68): back/forward now also wait for it, in both. (b) ExecPhase::next_wake: once the grace has passed, a wait still loading wakes at its deadline (the load's own messages wake the poll) instead of at a past instant every poll.
|
PR test build retired — merged into |
…tory change has landed (#706) * fix(browser): back/forward never end their wait early, before the history change has landed A back/forward wait ended at the load's end when a poll happened to see the page loading, which can be before the history change's DevTools events land; each bumps the tab's generation, so the agent's next command failed [browser.document_changed]. Measured on the published dev-469: 1 in 30. The wait now always runs to LOAD_SETTLE_GRACE (1.2 s) for back/forward, as 9 in 10 already did; next_wake wakes at the grace for them even after a load. Old since #287 (20 Nov). #696 is the real fix. * fix(browser): a back/forward still loading past the grace waits for its load, not a 10 ms poll READER-12b F1 on #706: with history set, next_wake stayed at the (past) grace, so a back/forward still loading after 1.2 s was polled every 10 ms until its load ended. Past the grace it now wakes at its deadline; the load's own messages wake the poll, as #696 does.
…commit # Conflicts: # apps/desktop/src/surfaces/browser/rpc/exec/mod.rs # apps/desktop/src/surfaces/browser/rpc/exec/nav.rs
|
Merged dev 5054ee4 (dev-471) in at 98c1426. Conflicts with #706 (same lines in exec/nav.rs and exec/mod.rs) resolved to this PR's version: #706's 'history: bool' gives way to 'history_from', which never ends a back/forward at a load it happened to see either. One addition so that holds with no frame tracker yet: start_history now always makes a HistoryFrom (counts from zero), so such a wait runs to the grace instead of taking the old saw_loading path. Next: READER-12b's follow-ups (F1 no-entry and click-made pushState; F2 extensions_active vs the engine; F3 no-entry waits for !loading), then the full gate. |
…it for a main-frame navigation the engine is known to send READER-12b's #696 follow-ups. F1/F3: the engine refreshes can_go_back/forward only when loading changes, so a click-made same-document entry could look absent and the no-entry shortcut would skip it; the shortcut is gone: with no entry the back does nothing and the wait ends at the grace, as before #696 (measured: no-entry 1,291 ms median on dev-469 and on #706). F2: whether to wait for the main frame's Page.frameNavigated no longer rests only on the app's view of extensions: a tab whose main-frame navigations have reached the app before waits for this one too.
…its cases as a table ORCHESTRATOR / READER-12b should-fix on #696: the condition that decides when a back/forward has landed moves out of step_wait_load into exec/settle.rs, tested as a table: cross-document commit + load end; same-document (pushState / hash) ends at the grace; no entry ends at the grace; an iframe navigation does not end it; a load seen that is not the history move does not end it (#706's guarantee); tab closed resolves; the deadline resolves at 15 s. The comment on a tab with no frame tracker yet now says what happens.
… depends on std only rune-desktop has no tests (AGENTS.md; guardrails Rule 8 failed #696 on 80da0ff for the #[test] / #[cfg(test)] lines). The table moves outside the repo (operation-detox harness\browser\settle-table.rs, which includes settle.rs by path). settle.rs now holds HistoryFrom and takes the wait's elapsed time and deadline as Durations, so it builds with std alone.
…n (re-land #640) (#732) #640 gave the engine's messages their own quiet waker, so each DevTools round trip of an agent's browser command no longer waits for the window's next frame. #675 reverted it because back/forward then ended before their history commit was applied. That early end was in the settle logic, fixed since by #706 and #696 (back/forward now wait for the commit's own DevTools events), so the faster wake comes back unchanged. This reverts commit b76cc0a.
back/forwardnow return once the history commit's own DevTools events have been applied, instead of after the fixed 1.2 s wait that #675 restored. The aim is correct first and fast second:dev-464returned too early, and the agent's next command failed.The measured order
Before designing this, a trace build (#676, scratch) logged every navigation event in order: the tab updates, the main frame's
Runtime.*andPage.*events, and every generation bump with its cause. It ran in four configurations (no extension; uBlock Origin Lite; a page with a cross-origin frame; both), with 20 runs each ofback,forwardandreload, and #640's quick wake on:back: next command failedforwardreloadWhat each new document brings: every one moved the tab's generation exactly 3 times without extensions:
sync_tabs);Runtime.executionContextsCleared;Page.frameNavigated.With extensions it moved twice, because the engine keeps
Page.*events to itself (cdp_ledger).Why the next command failed: every failure had one of these bumps after
back/forwardreturned.want 25 now 26in the trace.Why
reloadnever failed: its wait ends on the load, 34–92 ms in, after its last bump (15–21 ms).The change
rpc/frames.rs: the frame tracker counts the main frame'sRuntime.executionContextsCleared(top-level session) andPage.frameNavigated(no parent, top-level session).exec/nav.rs:back/forwardrecord the address and both counts when they start. They return when the address has moved and the count of cleared contexts has gone up. Without extensions, the count of main-frame navigations must also have gone up. The tab must not be loading.LOAD_SETTLE_GRACE(1.2 s) stays the upper bound. It is also the fallback for an entry that sends none of these, such as a same-document or same-address entry.can_go_back/can_go_forwardare not consulted: the engine refreshes them only when loading changes, so a click-made same-document entry could look absent (READER-12b F1).browser-paneextensions_active(): whether the running engine was started with--extension. Only then arePage.*events dropped.exec/mod.rsnext_wake: a back/forward wait wakes at the grace until its commit is applied.ENGINE_REVISIONstays 9, and no wire message changes.Proof (in the comments, before merge)
back→forward,back→snapshot,back→evaluate,forward→snapshot, in all four configurations, 20 runs per cell, 0 first-try failures required. The publisheddev-469is the before column.unloadhandler,Cache-Control: no-store);backwith no entry;backtwice without waiting;document_changed).back/forwardmedians and worst cases per configuration, before and after, as windows.tools\smoke.ps1.