Skip to content

fix(cooperation,cdp,daemon): stop false coverage-changed freezes across SPA routes and subframe churn - #762

Merged
NianJiuZst merged 1 commit into
Tencent:mainfrom
NianJiuZst:fix/page-coverage-changed
Nov 18, 2026
Merged

NianJiuZst merged 1 commit into
Tencent:mainfrom
NianJiuZst:fix/page-coverage-changed

Conversation

@NianJiuZst

Copy link
Copy Markdown
Collaborator

Summary

Fixes the high-frequency false-positive failure reported by users on modern SPA applications and sites with dynamic child <iframe>s:

{
  "code": "permission_denied",
  "message": "Page interaction coverage changed; wait and synchronize",
  "exit_code": 1,
  "data": {
    "effect_state": "unknown",
    "phase": "control",
    "reason": "control_context_invalid"
  }
}

which also froze the tab's IntentWal ledger (effect_state: "unknown") and cascaded across subsequent commands.

Root Causes

  1. Same-document SPA URL updates and same-process child-iframe DOM.documentUpdated events were treated as root document destruction (ChromiumCdp + cooperation-capture.ts)

    • ChromiumCdp routed root Page.navigatedWithinDocument (history.pushState, history.replaceState, #hash) and parameterless DOM.documentUpdated (emitted by Chromium on { tabId } whenever any same-process child <iframe> mounts or navigates once DOM is enabled) to onDocumentChanged -> cooperation.invalidate(tabId), setting state.unavailable = true while the main document and its collector remained live.
    • doAttach after soft_detached populated attachingEntry.frames without restoring entry.frameDiscovery.rootFrameId.
    • cooperation-capture.ts rotated state.document on every root location.href update, causing mid-action prepareFrames refreshes to misclassify ?query / #hash updates as cross-document replacements (mainDocumentChanged = true).
  2. Multi-step actions self-locked across their own navigation / submission side effects

    • Actions whose native input initiated form submission (onBeforeNavigate, e.g. auto-submitting OTP/search fills) or instant-commit navigation (Cannot find context / Execution context was destroyed after Input.insertText had already notified the page) failed during Step 3 verification or scroll-to visibility measurement instead of returning their completed receipt.
  3. Concurrent subframe lifecycle races poisoned in-flight actions and target contexts

    • scheduleObserveTab could run collectCooperationFrames ahead of armCommittedFrame on child onCommitted events; COOPERATION_ARM rejected newly mounted child frames whose lease was not yet initialized; collectCooperationFrames skipped its single replacement pass when a sibling failed frame was a proven-hidden unobservable subframe (e.g. display: none + sandbox="" srcdoc); and non-owner refresh failures (observeTab, status, wait, passive read --context) mutated state.unavailable / state.context during state.working.
  4. Handler-diagnosed errors and daemon implicit target contexts after failed navigations

    • Post-invoke interruption() checks overwrote explicit navigate / reload errors and structured result.data.reason errors (download_capture_failed, fill_target_changed) with control_context_invalid.
    • ImplicitScopeRegistry continued auto-injecting revoked target context_ids after navigations or effect_state: "unknown" errors, preventing context-free navigate / reload / navigate_back recovery off Chrome page_load_failed interstitial error pages.

Changes

  • Extension (chromium-cdp.ts, background.ts, cooperation-capture.ts, types.ts, controller.ts):
    • Added onRouteChanged -> cooperation.invalidateRoute(tabId, url) and top-frame FrameState.url, keeping target-policy DOM contexts valid across same-pathname query/fragment updates (?q=..., ?view=..., #section, including bsk plan batches and post-mouseReleased SPA handlers) while revoking stale contexts and refs on pathname / #/... hash-router transitions (deferring invalidation until finally when triggered by an in-flight action so the triggering receipt settles cleanly with effect_state: "none" for subsequent un-synced actions).
    • Restored entry.frameDiscovery.rootFrameId on soft_detached reattach and removed DOM.documentUpdated from firing onDocumentChanged.
    • Allowed post-input Runtime.callFunctionOn on bound objectIds (boundObjectCompletion) to finish across onBeforeNavigate, and completed handleFill Step 3 when Input.insertText (finalValueAlreadyNotified) already delivered input before cross-document navigation tore down the old V8 context.
    • Sequenced scheduleObserveTab behind per-tab pendingArms, initialized collection leases on non-clear COOPERATION_ARM, allowed collectCooperationFrames replacement passes past proven-hidden failed subframes, isolated state.working / target contexts from non-owner refresh errors, preserved handler-diagnosed errors, and enabled navigate / reload / navigate_back / navigate_forward bootstrap recovery off page_load_failed root error pages.
  • Daemon (scopes.rs, tool_pipeline.rs):
    • Added clear_implicit_tab_context in reconcile_completed_tool_rpc so full-page navigations and context-revoking errors clear stale implicit target contexts while retaining c<N> / o<N> ring alias expansion.
  • Docs & Bilingual Changelog:
    • Updated docs/dynamic-reading.md, CHANGELOG.md, and CHANGELOG.zh-CN.md.

Verification

  • pnpm --filter @browser-skill/extension compile & pnpm --filter @browser-skill/extension test (190 suites, 4,076 tests)
  • cargo test -p bsk --lib daemon:: & cargo test -p bsk --test integration plan_cli
  • Real-Chrome .browser.test.ts suites (settlement.browser.test.ts including new end-to-end SPA/subframe/OTP/failed-navigation regression test, cooperation-capture.browser.test.ts, navigation-same-document.browser.test.ts, hidden-frames.browser.test.ts)
  • pnpm eval:browser:dynamic-read (59 CLI/MCP/plan commands across target & strict) & BSK_COOP_TARGET_ONLY=1 node evals/browser/cases/regression/cooperation/run.mjs
  • pnpm lint, pnpm protocol:check, node scripts/check-skill-bundles.mjs, cargo fmt --all -- --check, cargo clippy -p bsk --lib --bins -- -D warnings

…ss SPA routes and subframe churn

Why:
- Users on modern SPA apps and commercial sites with child iframes frequently hit
  `permission_denied: Page interaction coverage changed; wait and synchronize`
  (`reason: control_context_invalid`, `effect_state: unknown`), which also froze
  the tab's `IntentWal` ledger until a manual sync/reconcile.
- Interacting root causes across CDP, content capture, cooperation controller,
  interaction handlers, and daemon scope caching produced this failure mode:
  1. `ChromiumCdp` routed root `Page.navigatedWithinDocument` (`pushState`,
     `replaceState`, `#hash`) and parameterless `DOM.documentUpdated` (emitted on
     `{ tabId }` whenever any same-process child `<iframe>` mounts or navigates
     once `DOM` is active) to `onDocumentChanged` -> `cooperation.invalidate`,
     setting `state.unavailable = true` on a live document, while `doAttach`
     after `soft_detached` did not restore `entry.frameDiscovery.rootFrameId`.
  2. `cooperation-capture.ts` rotated `state.document` on every root
     `location.href` change, causing mid-action `prepareFrames` refreshes to
     misclassify same-document `?query` / `#hash` updates as cross-document
     replacements (`mainDocumentChanged = true`).
  3. Multi-step actions (`fill` Step 3, main/child-frame `scroll-to` visibility
     projection) that initiated their own form submission / `onBeforeNavigate`
     (or instant-commit navigation after `Input.insertText` had already fired
     `input`) aborted before returning their completed receipt.
  4. Background `observeTab` raced `armCommittedFrame` on child `onCommitted`,
     `COOPERATION_ARM` / `COOPERATION_RESUME` did not initialize leases on newly
     mounted child frames, `collectCooperationFrames` blocked its replacement
     pass when a sibling unobservable subframe was proven hidden, and non-owner
     `refresh` failures mutated `state.unavailable` / `state.context` during
     `state.working`.
  5. Handler-diagnosed errors (`Page.navigate` network rejections,
     `download_capture_failed`, `fill_target_changed`) were overwritten by the
     post-invoke `interruption()` check.
  6. `ImplicitScopeRegistry` kept auto-injecting revoked `target` `context_id`s
     after navigations or `effect_state: unknown` errors, while recovery off
     Chrome `page_load_failed` interstitials rejected `target` auto-injected
     contexts after a broken-link click.

What:
- Add `ChromiumCdpOptions.onRouteChanged` + `CooperationController.invalidateRoute`
  and `FrameState.url` on top frames, keeping `target` DOM contexts valid across
  same-pathname query/fragment updates (while consuming strict baselines for
  untargeted actions) and revoking stale contexts/refs on pathname or `#/...`
  hash-router transitions after action settlement (`effect_state: none`); restore
  `rootFrameId`, reconcile soft-detached child frames across same-document route
  updates and post-dialog checks, and stop firing `onDocumentChanged` on
  `DOM.documentUpdated`.
- Allow post-input `Runtime.callFunctionOn` (bound `objectId`) and `DOM.getBoxModel`
  visibility measurement to finish across `onBeforeNavigate`, and complete
  `handleFill` Step 3 when `Input.insertText` already notified the page before
  cross-document navigation tore down the old V8 context.
- Sequence `scheduleObserveTab` behind `armCommittedFrame`, initialize leases on
  newly mounted child frames across `COOPERATION_ARM` and `COOPERATION_RESUME`,
  allow `collectCooperationFrames` replacement passes past proven-hidden failed
  subframes, and isolate `state.working` / `target` contexts from non-owner
  `refresh` failures.
- Preserve handler-diagnosed navigation and `result.data.reason` errors, track
  `implicit_ctx_usable` in `ImplicitScopeRegistry` so `clear_implicit_tab_context`
  revokes auto-injection without dropping `last_vom` or `c<N>`/`o<N>` aliases for
  `unchanged`/`delta` hydration, and enable `navigate`/`reload`/`navigate_back`/
  `navigate_forward` recovery off `page_load_failed` root error pages.
- Add real-Chrome E2E coverage in `settlement.browser.test.ts` exercising all
  scenarios end-to-end across CLI, MCP, daemon `IntentWal`/`scopes`, and Chrome.
@NianJiuZst
NianJiuZst force-pushed the fix/page-coverage-changed branch from 23edba1 to 8df7721 Compare November 17, 2026 13:04
@NianJiuZst
NianJiuZst merged commit c030903 into Tencent:main Nov 18, 2026
12 checks passed
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