Repository navigation
fix(cooperation): eliminate unresponsive-frame sync failures and session traps on heavy web apps (#766) - #769
Merged
NianJiuZst merged 7 commits intoNov 18, 2026
Conversation
…ion traps on heavy web apps (Tencent#766) Why: On heavy Canvas + CSS-in-JS web applications such as Lark Base / Feishu Bitable (Tencent#766), `bsk cooperate sync`, `bsk sync`, and `bsk evaluate` repeatedly failed with `"A page frame is not responding"` (`frame 0` and/or hidden cross-origin `accounts.larksuite.com/session-tools/refresh` iframes) while screenshots succeeded: 1. `cooperation-capture.ts` `styleFacts()` continued iterating and concatenating every inline CSSOM `rule.cssText` string even after a cross-origin CDN stylesheet had already set `facts.readable = false`, while `dom-primitives.ts` and `cooperation-capture.ts` performed repeated `querySelectorAll("*")`, `closest()`, and unconditional V8->C++ `chrome.dom.openOrClosedShadowRoot` sweeps across thousands of nodes. 2. `CooperationController.command` ignored caller `timeout_ms` on `sync` and `enable` (and `lifecycle.rs` hardcoded `None` on `CooperateAction::Sync`, while daemon `ToolCooperate` and CLI/MCP IPC hardcoded `30s`/`35s` ceilings without snapshot headroom), aborting busy main frames at the fixed 3s per-frame IPC deadline even when `--timeout-ms 20000` was supplied, while `cooperate wait` re-broadcast duplicate `COOPERATION_READ` sweeps on every poll cycle. 3. `hidden-frames.ts` `ownedByHiddenElement` failed closed whenever `owners.length !== siblings.length` (e.g. `<object>`/`<embed>` or un-navigated `<iframe>` placeholders), whenever a visible cross-origin widget iframe coexisted alongside a silent hidden cross-origin iframe, or when an unfocused frame was hidden via `pointer-events: none` or offscreen `position: fixed`. 4. `CooperationController.run` only allowed `navigate`/`reload` escape from `page_load_failed` (and rejected auto-injected `target` `context_id` before probing `unrecoverableNavigationSource`), trapping sessions on `FrameUnresponsiveError` or `frame_unobservable` until `session stop` — and CDP preflight probes in `navigation.ts` waited indefinitely on wedged renderers instead of falling back to browser-process navigation. 5. Unbounded `ensureOverlayInjected` and `tabs.sendMessage` calls to wedged frames (`pushOverlayStateForTab`, hover/record `bypassOverlay`, `resetAgentOverlays`, and `COOPERATION_ARM_FRAME`) hung `navigate` / `session stop` on hovered wedged tabs and risked 5-minute Chromium `kRequestTimeout` MV3 Service Worker evictions. What: - Short-circuit `styleFacts()` in O(sheets) as soon as any stylesheet is cross-origin unreadable, skip `@font-face` and `@keyframes`, extract `data-*` attribute names directly (including `@scope`) without full-sheet `cssText` concatenation, skip `:focus` root queries when no root has `:focus`, cache `[aria-labelledby]`/`[aria-describedby]` IDs per root, and replace quadratic `querySelectorAll("*")` / `closest()` / unconditional `openOrClosedShadowRoot` walks with `TreeWalker` (`FILTER_REJECT` on extension overlays) and WHATWG shadow-host tag checks. - Forward caller `timeout_ms` (up to `25000ms`, with matching daemon transport and CLI/MCP IPC snapshot headroom) and `AbortSignal` across `bsk open`, `bsk sync`, `bsk cooperate sync|enable|wait`, and MCP `bsk_session(open|sync)` into `collectCooperationFrames` with at most one in-flight `COOPERATION_READ` per frame while retiring provably hidden silent child frames after `3000ms`, and retry transient mid-observation document replacements in `--settle`. - Teach `describeFrameOwners` (`includeDeclaredSrc`) and `ownedByHiddenElement` to recognize unfocused `pointer-events: none` and offscreen `position: fixed` frames, accept `owners.length >= siblings.length` when displayed owners all match distinct live siblings, and safely disambiguate cross-origin siblings via exact-before-origin owner `declaredSrc` matching without letting redirected displayed frames claim hidden siblings. - Allow `navigate`, `reload`, `navigate_back`, and `navigate_forward` to leave tabs stuck on `FrameUnresponsiveError` or `frame_unobservable` (including when `ImplicitScopeRegistry` auto-injects a prior `target` `context_id` after a cross-document transition), and bound preflight CDP attachment/readiness probes in `navigation.ts` so wedged renderers fall back cleanly to `chrome.tabs` navigation recovery. - Bound `ensureOverlayInjected`, `pushOverlayStateForTab`, hover/record `bypassOverlay`, `resetAgentOverlays`, and `COOPERATION_ARM_FRAME` calls to `3000ms`, and emit application-level `system.heartbeat` ticks on `chrome.alarms` wakeups without disturbing daemon silence-based liveness reaping. - Add real-Chrome full-stack regression coverage in `settlement.browser.test.ts` and `hidden-frames.browser.test.ts` plus unit tests in `cooperate/settle.rs`, `lifecycle.rs`, and `daemon/ipc.rs`, and update bilingual changelogs and skill interaction references. Fixes Tencent#766
NianJiuZst
force-pushed
the
fix/766-unresponsive-frame-cooperation
branch
from
November 18, 2026 09:13
d780aed to
101db5e
Compare
…escape, and script injection (Tencent#766) Why: Full-stack verification on top of Tencent#769 uncovered five remaining timeout and recovery gaps on genuinely wedged or slow renderers: 1. `settled_sync_with_conditions_using`, `cooperate sync --settle`, and MCP `bsk_session(action="sync", settle=true)` passed a static `timeout_ms` into `cooperate::settle::run`, multiplying `Sync -> Wait -> Sync -> Wait -> Sync` up to `55s–100s` on a wedged page instead of bounding retries to the caller's remaining wall-clock deadline. 2. When a wedged tab had already tripped `CdpReadGate` (e.g. after running `bsk snapshot` / `bsk get-html` per recovery guidance or after a `soft_detached` reattachment timeout), `prepareNavigation` rethrew `CdpReadTimeoutError` instead of falling back to browser-process navigation; additionally, `recoverBrowserNavigation`'s post-commit CDP handoff, entry `refresh` elapsed time on `failedLoadRecovery`, post-timeout `observeTab`, and uncommitted `tab.pendingUrl` on a timed-out wedged navigation could exceed daemon transport grace or block subsequent `navigate` escapes. 3. `CooperationController.command` defaulted `cooperate wait` (without `--timeout-ms`) to a `15000ms` loop deadline while leaving `requestedTimeoutMs` `undefined` (`3000ms` per-frame sweep), and `CooperationController.run` omitted `actionReplyTimeoutMs` / `signal` on `verifyEvidence` and post-action `tool.evaluate` / `tool.upload` refreshes. 4. `injectCooperationAllFrames`, `injectRecordFrameAllFrames`, and `armCommittedFrame` awaited unbounded `chrome.scripting.executeScript(...)` calls when repairing missing-receiver frames on wedged tabs. 5. `cooperation-capture.ts` ran `invisibleAttribute` (`styleFacts()`) before verifying structural `childList` batch eligibility and accepted punctuated `data-*` attribute names outside `DATA_ATTR_RE`, while `settle.rs` matched `"changed during observation"` broadly enough to include `"Control policy changed during observation"`. What: - Add `cooperate::settle::run_bounded` (`settle.rs`) and wire remaining wall-clock `timeout_ms` budgets across `lifecycle.rs`, `cooperate.rs`, and `mcp/tools.rs` so Attempt 1 always runs while subsequent `SETTLING_PAUSES` and `Wait`/`Sync` retries stop once the deadline elapses (preserving the last `Sync` error when an `unavailable` `Wait` exhausts budget), and narrow mid-observation retry matching to `"Document changed during observation"`. - Fall back to `"browser"` navigation on `CdpReadTimeoutError` in `prepareNavigation`, bound `recoverBrowserNavigation` post-commit CDP handoffs (`acquireNavigationExecution`, `Page.enable`, `readMainFrameInfo`, `Page.setLifecycleEventsEnabled`) to remaining `timeoutMs`, deduct entry `refresh` elapsed time on `failedLoadRecovery`, detach `observeTab` on timed-out/failed navigations, and permit `FrameUnresponsiveError` navigation escape even when an uncommitted `tab.pendingUrl` remains set. - Default `rawTimeoutMs` to `15000` for `cooperate wait` when `timeout_ms` is omitted, and forward bounded `actionReplyTimeoutMs` + `signal` into `verifyEvidence` and post-action `tool.evaluate` / `tool.upload` `refresh`. - Introduce `executeScriptBounded(..., 3000)` and apply it across `ensureOverlayInjected`, `injectCooperationAllFrames`, `injectRecordFrameAllFrames`, and `armCommittedFrame`. - Defer `invisibleAttribute` checks in `textChanges` until after non-attribute records qualify with zero unmatched removals, and require `/^data-[-\w]+$/` in `invisibleAttribute`. - Cover bounded settled `bsk sync --timeout-ms` and `CdpReadGate`-tripped wedged `navigate` recovery in real-Chrome `settlement.browser.test.ts`, and sync `CHANGELOG.md`, `CHANGELOG.zh-CN.md`, and `interaction-details.md`.
…dged-early (Tencent#766) Why: In `settlement.browser.test.ts` Part 3, clicking `<a href=".../wedged">` triggered a cross-site process swap (`healthy.test` -> `127.0.0.1`) followed by a fixed 250ms sleep while `/wedged` deferred `for (;;) {}` via an 80ms `setTimeout`. On slower 2-vCPU Linux CI runners, spawning the cross-site renderer took ~200ms so `bsk navigate` arrived after `onCommitted` invalidated the old context yet before `/wedged`'s 80ms timer wedged the main thread. What: - Point `#open-wedged` at `/wedged-early` (synchronous inline `for (;;) {}` with zero responsive window after commit) and await the HTTP server's `/wedged-early` response completion before issuing the recovery `navigate` / `session stop`.
…vigate escape (Tencent#766) Why: Chromium's Browser Process (`NavigationURLLoader`) fetches `/wedged-early` in parallel with spawning a cross-site renderer process (`--site-per-process`), so waiting only on the HTTP response callback still raced `RenderFrameHost` commit on 2-vCPU Linux CI runners (`onBeforeNavigate` had invalidated `state.context` while `webNavigation.getAllFrames` still observed the responsive `/escaped` document). What: - Poll `bsk tab list --scope agent` (passive browser-process read that leaves `ImplicitScopeRegistry` untouched) until `tab.url` commits `/wedged-early` before issuing the recovery `navigate` and `session stop`.
…cape checks (Tencent#766) Why: On 2-vCPU Linux CI runners, navigating to `http://127.0.0.1:<port>/wedged-early` after `http://127.0.0.1:<port>/wedged` had already entered `for (;;) {}` reused the hung `127.0.0.1` `RenderProcessHost`, preventing `CommitNavigation` from ever completing on the subsequent link-click scenarios. What: - Assign distinct site-isolated hostnames (`wedged1.test`..`wedged4.test`) via `--host-resolver-rules` for each wedged navigation step so every scenario commits into a fresh renderer process before wedging.
…nd overlay bounds on wedged frames (Tencent#766) Why: 1. In `recoverBrowserNavigation`, `waitUntil === "networkidle"` (and non-commit same-document recovery) called `readMainFrameInfo`, which swallowed both `CdpReadTimeoutError` (when `CdpReadGate` had not yet settled a departing wedged renderer's pending read) and its internal 1500ms timeout into `{ frameId: null }`, causing `if (!frame.frameId) throw new Error("No main frame after navigation")` to abort recovery with `cdp_failed` instead of succeeding once the gate reopened or reporting `reached: "timeout"` at deadline. 2. On navigation escapes with a tight `timeout_ms` (`< 6000ms`, e.g. `--timeout 3s`), `CooperationController.run` spent the full 3000ms `DEFAULT_FRAME_REPLY_MS` on entry `refresh` and then clamped `req.params.timeout_ms` to `1ms`, starving `prepareNavigation` + `recoverBrowserNavigation` while also overwriting the caller's original `timeout_ms` in recovery timeout diagnostics. 3. On tabs hosting a wedged hidden cross-origin child OOPIF (such as Lark Base's `session-tools/refresh`), `bsk record start` and `bsk record stop` still hung on unbounded `RECORD_FRAME_START` `tabs.sendMessage`, unbounded `waitForDocumentSettled` CDP `Page.createIsolatedWorld` / `Runtime.evaluate` probes, and `RecordFrameCoordinator.stop` waiting for proven-hidden child frames, while `VideoManager.cleanup` (`VIDEO_OVERLAY` with `recording_id: null`) and `defaultSendToTab` (`CAPTURE_SUPPRESS` / `captureFullTabPng` fallback) lacked bounds on wedged tabs. What: - Query `Page.getFrameTree` directly within `recoverBrowserNavigation`'s `withinDeadline`, retrying briefly on `CdpReadTimeoutError` across cross-document commits and returning `false` (`reached: "timeout"`) when the deadline expires. - Proportion precondition-free navigation entry `refresh` to `Math.max(200, Math.floor(timeout_ms / 2))` when `timeout_ms < 6000` and preserve the caller's original `timeout_ms` via `withReportedTimeoutMs` / `readReportedTimeoutMs`. - Bound `RecordFrameCoordinator.#startFrame` (`3000ms`), recording `sendToTab`, `waitForDocumentSettled` CDP probes (`SETTLE_MAX_MS`), `VIDEO_OVERLAY` teardown, `CAPTURE_SUPPRESS` `defaultSendToTab` (with balancing `end`), and `captureFullTabPng` `Page.captureScreenshot` fallback (`10500ms`), and tolerate proven-hidden non-root child frames in `RecordFrameCoordinator.stop`. - Extend real-Chrome E2E `settlement.browser.test.ts`, `navigation-recovery.test.ts`, and bilingual `CHANGELOG` entries.
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.
Summary
Fixes #766.
Eliminates
"A page frame is not responding"(cooperation_sync_required) synchronization/action failures, multiplied retry timeouts, session traps, recording/video/overlay hangs, and MV3 Service Worker liveness disconnects on heavy Canvas + CSS-in-JS web applications such as Lark Base / Feishu Bitable as well as genuinely wedged renderers.Root Causes (Why)
styleFacts()& DOM walk overhead incooperation-capture.ts/dom-primitives.ts:<link rel="stylesheet">markedfacts.readable = false,styleFacts()continued iterating and concatenating every inline CSS-in-JSrule.cssTextstring across hundreds/thousands of rules,textChangesraninvisibleAttribute(styleFacts()) before checking whether structuralchildListrecords already disqualified the batch, andcontrols,observeShadowSubtree,hasAddedSubframeElement, andisExtensionOverlayNodeexecuted repeatedquerySelectorAll("*"),closest(), and unconditional V8→C++chrome.dom.openOrClosedShadowRootcalls on every element.timeout_ms, missing transport/IPC headroom, and multipliedsettleretry budgets:CooperationController.commandignoredparams.timeout_msonsyncandenable(and left default15000mscooperate waitsweeps at3000msper frame),CooperationController.runomittedactionReplyTimeoutMs+signalonverifyEvidenceand post-actiontool.evaluate/tool.uploadrefreshes,lifecycle.rshardcodedtimeout_ms: NoneonCooperateAction::Sync, daemontool_dispatch_transport_timeout(30s) + CLI/MCP IPC (35s) lacked snapshot headroom, andcooperate::settle::runrepeated statictimeout_msacrossSync -> Wait -> Sync -> Wait -> Sync(burning up to55s–100son a wedged page instead of bounding retries to remaining wall-clock budget).hidden-frames.tsownedByHiddenElement:ownedByHiddenElementrequired exactowners.length === siblings.length(failing closed whenever<object>/<embed>or un-navigated<iframe>placeholders existed), failed whenever a visible cross-origin widget iframe coexisted alongside a silent hidden cross-origin iframe (such asaccounts.larksuite.com/session-tools/refresh), and did not treat unfocusedpointer-events: noneor offscreenposition: fixediframes as hidden.navigate/reloadagainst unresponsive orCdpReadGate-tripped tabs:CooperationController.runonly permittednavigate/reloadescape onpage_load_failed(rejecting auto-injectedtargetcontext_idfromImplicitScopeRegistryand blocking subsequent escapes when a timed-out wedged navigation lefttab.pendingUrlset),prepareNavigationrethrewCdpReadTimeoutErrorwhenCdpReadGatewas already tripped instead of falling back to"browser",recoverBrowserNavigationpost-commit CDP handoffs (Page.enable,Page.getFrameTreeonnetworkidle/ same-document recovery) and short-timeout_ms(< 6000ms) entryrefresh/ post-timeoutobserveTabcould starve recovery or exceed daemon transport grace.tabs.sendMessagecalls to wedged frames:chrome.scripting.executeScript(ensureOverlayInjected,injectCooperationAllFrames,injectRecordFrameAllFrames,armCommittedFrame),tabs.sendMessage(pushOverlayStateForTab, hover/recordbypassOverlay,RECORD_FRAME_START/ recordingsendToTab,CAPTURE_SUPPRESS/VIDEO_OVERLAYcleanup,resetAgentOverlays,COOPERATION_ARM_FRAME), andwaitForDocumentSettledCDP probes hungnavigate,record,video,screenshot, orsession stopon wedged tabs/subframes and risked 5-minute MV3 Service WorkerkRequestTimeoutevictions.Key Changes (What)
apps/extension/src/content/cooperation-capture.ts&dom-primitives.ts:styleFacts()in@font-faceand@keyframesrules, deferinvisibleAttributechecks until after structuralchildListfiltering, and collectdata-*attribute names directly (/^data-[-\w]+$/, including@scope) without full-sheetcssTextconcatenation.:focusroot selector queries when no root has:focus, cache[aria-labelledby]/[aria-describedby]IDs per root, combine shadow-root + subframe discovery on added subtrees, gateopenOrClosedShadowRootbehind WHATWG shadow-host tag checks, and replacequerySelectorAll("*")walks withTreeWalker(FILTER_REJECTon extension overlays).apps/extension/src/cooperation/browser-bridge.ts,controller.ts,crates/bsk-cli/src/daemon/tool_pipeline.rs,cli/cooperate.rs,cli/lifecycle.rs,cli/mcp/tools.rs, &cooperate/settle.rs:timeout_ms(up to25000ms, including default15000mscooperate waitand post-actionevaluate/upload+verifyEvidencerefreshes, with matching daemon transport and CLI/MCP IPC snapshot headroom) andAbortSignalacrossbsk open,bsk sync,bsk cooperate sync|enable|wait, and MCPbsk_session(open|sync)intocollectCooperationFrames, keeping a single in-flightCOOPERATION_READper frame while retiring silent hidden child frames once3000mshas elapsed and their parent frame has answered."Document changed during observation",effect_state: "none") and boundsettleretries viacooperate::settle::run_boundedso Attempt 1 always runs and subsequent pauses/retries respect remaining wall-clocktimeout_ms.apps/extension/src/cooperation/hidden-frames.ts:pointer-events: noneand completely offscreenposition: fixedframes ashidden: true, allowowners.length >= siblings.lengthwhen every displayed owner matches a distinct other sibling, and safely disambiguate cross-origin siblings via exact-before-origin ownerdeclaredSrcmatching without allowing redirected displayed frames to claim hidden siblings.apps/extension/src/cooperation/controller.ts&apps/extension/src/tools/navigation.ts:navigate,reload,navigate_back, andnavigate_forward(without preconditions or human hold/activity, including whenImplicitScopeRegistryauto-injects a priortargetcontext_idor when an uncommittedtab.pendingUrlremains set on aFrameUnresponsiveErrortab) to leave tabs stuck onFrameUnresponsiveErrororframe_unobservable, fall back to"browser"navigation onCdpReadTimeoutErrorinprepareNavigation, proportion precondition-free entryrefreshwhentimeout_ms < 6000while preserving originalreportedTimeoutMs, detachobserveTabon timed-out/failed navigations, and bound post-commit CDP handoffs (includingPage.getFrameTreeretries past transientCdpReadGateblocks onnetworkidle) inrecoverBrowserNavigationto remainingtimeoutMs.apps/extension/src/entrypoints/background.ts,lib/heartbeat.ts,lib/keepalive.ts,lib/runtime-content-scripts.ts,lib/capture-suppress-bridge.ts,lib/recording/frame-coordinator.ts,lib/recording/document-settle.ts,cooperation/browser-bridge.ts,tools/dispatcher.ts,tools/observation.ts,tools/record.ts, &tools/tabs.ts:executeScriptBounded(ensureOverlayInjected,injectCooperationAllFrames,injectRecordFrameAllFrames,armCommittedFrame),pushOverlayStateForTab, hover/recordbypassOverlay,RECORD_FRAME_START/ recordingsendToTab/waitForDocumentSettled(plus proven-hidden child-frame tolerance inRecordFrameCoordinator.stop),CAPTURE_SUPPRESS/VIDEO_OVERLAYcleanup /captureFullTabPngfallback,resetAgentOverlays, andCOOPERATION_ARM_FRAME, and emit application-levelsystem.heartbeatticks onchrome.alarmswakeups without disturbing daemon silence-based liveness reaping.CHANGELOG.md,CHANGELOG.zh-CN.md, andcrates/bsk-cli/skill/references/interaction-details.md.Verification
apps/extension/src/cooperation/settlement.browser.test.tsexercising realbskCLI +bsk daemon+ MV3 extension + multi-process Chrome (--site-per-process):<link rel="stylesheet">, large inline CSSOM/DOM, visible cross-origin widget OOPIF,<object>placeholder, and spinning hidden cross-originaccounts.test/session-tools/refreshOOPIF (cooperate sync --timeout-ms 15000,bsk sync,evaluate --unverified,click,read,screenshot,ledger status, andbsk record start+bsk record stopagainst an already-wedged hidden cross-originaccounts-rec.test/session-tools/refreshOOPIF).for (;;) {}) renderer: settledbsk sync --timeout-ms 7000stays bounded to a single attempt (< 12s,effect_state: "none", unfrozen ledger), trippingCdpReadGateviabsk snapshot(phase: "blocked") still falls back cleanly to browser navigation with bounded post-commit timeout (after 6000ms) on a synchronously wedged destination, andbsk navigate --wait-until networkidle --timeout 3sescapes to a healthy page and resumessync+evaluatein the same session.ImplicitScopeRegistryauto-injectedcontext_idremain active:bsk navigateandbsk session stopboth complete cleanly without hanging.hidden-frames.browser.test.tsto verify that a displayed cross-origin iframe that redirected to a third origin and hung is never falsely classified as hidden when a hidden iframe shares its initialdeclaredSrcorigin.settlement.browser.test.ts,hidden-frames.browser.test.ts,cooperation-capture.browser.test.ts,navigation-history.browser.test.ts,navigation-same-document.browser.test.ts,navigation-wait.browser.test.ts,runtime-injection.browser.test.ts,video/capture.browser.test.ts, andBSK_COOP_FRAMES_ONLY=1 evals/browser/cases/regression/cooperation/run.mjs.pnpm lint,pnpm protocol:check,pnpm --filter @browser-skill/extension compile,pnpm ext:test(190 suites / 4,102 tests),i18n,vom,dsh-plugin+check-dsh-package.mjs,eval:browser:check,check-skill-bundles.mjs,check-crate-skill.mjs,scripts/*.test.mjs,check-changelog-sync.py.cargo fmt --all -- --check,cargo clippy --workspace --all-targets --locked -- -D warnings,cargo test --workspace --locked.