Skip to content

fix(browser): back/forward never end their wait early, before the history change has landed - #706

Merged
Hona merged 2 commits into
devfrom
browser-tools/history-no-early-end
Nov 22, 2026
Merged

Hona merged 2 commits into
devfrom
browser-tools/history-no-early-end

Conversation

@Hona

@Hona Hona commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

An agent's command right after back/forward can still fail with [browser.document_changed] on the published dev-469, about 1 time in 30. This PR makes a back/forward wait never end early.

Measured

  • On the published dev-469 (app ec0ba232…, published engine 156.0.26-9), with no extension and a page with a cross-origin frame, 10 runs per sequence, every run navigated /app → /page2:

    • back → snapshot: 1 of 10 failed on its first try (the retry succeeded after 23 ms);
    • back → evaluate: 0 of 10;
    • back → wait: 0 of 10.

    File: proof\browser-tools\seq\g696-b469-xframe-backA.json in operation-detox, provenance inside.

  • Two kinds of back in that cell: one returned in 44 ms, the other nine in 1,218–1,229 ms.

Why

The change

  • exec/nav.rs: WaitLoadState gets history: bool, true only in start_history. The settle line uses st.saw_loading && !st.history, so a back/forward always waits until LOAD_SETTLE_GRACE, then until the tab is not loading.
  • exec/mod.rs next_wake: such a wait wakes at the grace even after it saw a load. Without this, a page that is idle after its load would not be polled again until another wake.

Why two files (+17/−3): exec/nav.rs holds the change. exec/mod.rs only keeps such a wait's next wake at the grace; without it, a back that saw its load would next be woken at its 15 s deadline. Past the grace, a back/forward still loading wakes at its deadline instead of every 10 ms (the load's own messages wake the poll; READER-12b F1).

Cost

Every back/forward takes about 1.2 s. Nine in ten already did.

Not in this PR

Proof

In the comments: CI; a kept tools\smoke.ps1 report; the sequence check on this PR's CI build with the published engine 156.0.26-9.

  • Configurations: four (no extension; uBlock Origin Lite; cross-origin frame; both).
  • Sequences: back → snapshot (the snapshot must show the page back landed on), back → evaluate, back → forward, forward → snapshot, 20 runs each, with the address before and after every run.
  • Requirements: 0 first-try failures, and no back/forward returns in under 1.0 s.
  • Also measured: back with no entry to go to, before and after.

Hona added 2 commits November 22, 2026 18:21
…tory 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.
…ts 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.
@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

PR test build retired — merged into dev. Install or auto-update OpenCode (Rune) from https://anoma.ly/release/opencode/desktop-rune/dev/macos-arm64-dmg.

@Hona
Hona merged commit 6bef949 into dev Nov 22, 2026
7 checks passed
@Hona
Hona deleted the browser-tools/history-no-early-end branch November 22, 2026 09:57
Hona added a commit that referenced this pull request Nov 22, 2026
…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.
Hona added a commit that referenced this pull request Nov 22, 2026
…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.
Hona added a commit that referenced this pull request Nov 22, 2026
… are applied (#696)

* fix(browser): back/forward return once their commit's DevTools events 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.

* fix(browser): back/forward also wait for the new document's main context; 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.

* fix(browser): back/forward don't trust the tab's history ends, and wait 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.

* refactor(browser): when a load wait is over is a pure function, with 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.

* fix(browser): the landing condition's tests leave the repo; settle.rs 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.
Hona added a commit that referenced this pull request Nov 22, 2026
…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.
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