Skip to content

fix(browser): make engine ledger sole frame authority and auto-attach owner - #350

Merged
Hona merged 2 commits into
devfrom
ws9/pr1c-frame-authority
Nov 21, 2026
Merged

Hona merged 2 commits into
devfrom
ws9/pr1c-frame-authority

Conversation

@Hona

@Hona Hona commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Makes the browser engine's EngineCdpLedger (apps/browser-engine/src/frame_authority.rs, cdp_ledger.rs) the sole authority over frame tracking, child-target auto-attach, and extension-frame isolation at parity with official OpenCode (origin/dev b9a60d9d078d87bfb90f039e431090508f88ac02), closing all four findings + four rev-2 gaps from notes/review-rd274.md.

Key Changes

  • Single engine-side authority (apps/browser-engine/src/frame_authority.rs, cdp_ledger.rs, engine/extensions.rs, prompts.rs):
    • EngineCdpLedger absorbs prompts.cdp_ext_frames, tracks frames (parent, session, url: Option<String>, origin, extension), web_sessions, extension_targets, extension_contexts, contexts, and verified objects (DOM.resolveNode -> Runtime.callFunctionOn / Runtime.releaseObject).
    • access(frame_id) implements official's cycle-bounded ancestor walk (policy.ts:279-293), treating frames with no URL yet as Unavailable and omitting file:// (#303).
    • classify_surface distinguishes Clean | Subframes | WholeTab (browser.is_none() -> WholeTab): raw HostMsg::CdpCall stays refused on !Clean AND refuses raw DOM.*/Accessibility.* while extensions are active; HostMsg::TypedCdpCall refuses WholeTab, keeps a 3-line refusal of Input.* on !Clean until PR 2 (input_guard.rs) lands, refuses HeapProfiler.*/Profiler.*/Tracing.* while extensions are active (recorded difference), and leaves screenshots unmasked on Subframes (official parity).
    • Enforces pre- and post-reply frame_access + session ownership across all ref/node calls (DOM.resolveNode, DOM.describeNode, DOM.getBoxModel, DOM.getContentQuads, DOM.scrollIntoViewIfNeeded, DOM.focus, DOM.querySelector*, Accessibility.getFullAXTree, Accessibility.getPartialAXTree, Runtime.callFunctionOn), requires frameId on Accessibility.getFullAXTree, refuses excluded frames on DOM.getFrameOwner, and rejects forged/released objectIds.
    • Drops extension console/exception/log/network events via official's page_context + extension_origin + extension_stack rules (diagnostics.ts:103-134) without ext_exec_contexts caps or regex redaction.
  • Engine-owned waitForDebuggerOnStart auto-attach lifecycle (frame_authority.rs, cdp_ledger.rs, engine.rs):
    • Arms every tab at creation (Target.setAutoAttach { autoAttach: true, waitForDebuggerOnStart: true, flatten: true, filter: [iframe, worker, {exclude:true}] }, Page.enable, Runtime.enable, Page.getFrameTree with retry-on-commit if initial fetch fails).
    • Resumes paused targets from the engine's outbox immediately after the same do_message_loop_work turn (avoiding CEF's ObserverListReentrancyPolicy while requiring zero app round trips): workers resume and detach (child-targets.ts:22-29); extension iframes (and web OOPIFs that commit/redirect to extension origins) stay attached in extension_targets with nested Target.setAutoAttach + Page.getFrameTree and diagnostics disabled (chromium.ts:617-625, 1146-1157), never forwarded to the app.
    • Holds back announcing newly attached OOPIFs whose pre-commit targetInfo.url is empty until a clean non-extension URL commits; replays only announced clean web OOPIFs on root Page.enable (Dispatch::ReplayWebTargets) and replays contexts on Runtime.enable (Dispatch::ReEnable).
    • Stays armed across app disconnect/reconnect; disarms only on tab close (_cdp_reg drop) or Unprepared (never triggered by worker replies or "no session"/"target closed" races; re-arms automatically on next main-frame commit).
    • Refuses Target.setAutoAttach, Target.attachToTarget, Target.detachFromTarget, Target.setDiscoverTargets, and Runtime.runIfWaitingForDebugger on TypedCdpCall.
  • Policy & desktop routing cache (crates/browser-policy/src/cdp.rs, crates/browser-pane/src/{protocol,machine,client,find,installer}.rs, apps/desktop/src/surfaces/browser/rpc/{session,mod,frames,exec/*}.rs):
    • Adds check_no_pierce for DOM.getDocument/DOM.describeNode in browser-policy.
    • Adds #[serde(default)] Ready.frame_authority and #[serde(default)] HostMsg::TypedCdpCall.frame_id, and bumps ENGINE_REVISION from 2 to 3 in crates/browser-pane/src/installer.rs:17 because https://anoma.ly/release/opencode-rune/browser-engine/stable.json now serves 156.0.26-2 (dev was 2).
    • Routes exec/* calls through TypedCdpCall when engine_agent_tools() is true, passes frame_id on ref calls, always sends explicit frameId on Accessibility.getFullAXTree, skips app-side Target.setAutoAttach/detachFromTarget when engine_frame_authority() is true, and purges subtrees in TabFrameState on URL-free Rune.frameExcluded notices.
  • Merged dev 5157d6b77 (#319 Guard 1b, #286 cookies, #328 downloads, #329 debug-only overrides): Preserves Guard 1b (refuse_reply/blocked_url) uniformly on all replies, flattened OOPIFs, and announced events; moves flush_outbox into engine/picks.rs.

Verification

  • Live CEF 156 proof (proof/ws9/pr1c-frame-authority-proof.json, OPENCODE_RUNE_OTEL=0, real MV3 extension, re-run after dev 5157d6b77 merge): 22/22 PASS + 5/5 #319/#286 compat probes PASS (Ready.cookies, ProfileCookiesList, Guard 1b typed_cdp_call refusal + controlled_permission_refused notice):
    • Nested top -> extension iframe -> cross-origin web iframe: both ran (never stalled), both emitted URL-free Rune.frameExcluded, neither forwarded or present in Page.getFrameTree, both refused on Accessibility.getFullAXTree and DOM.getFrameOwner.
    • Late-attach tab with clean web OOPIF + extension iframe -> nested web iframe: Page.enable replayed ONLY the clean web OOPIF with its real URL; tree & contexts clean.
    • Socket killed on armed tab: new cross-origin iframe and dedicated worker both ran.
    • Tight 150-iteration add+remove iframe/worker race: tab stayed armed (not Unprepared), final iframe ran, typed AX + tree succeeded.
    • Verified DOM.resolveNode -> Runtime.callFunctionOn -> Runtime.releaseObject passed; forged/post-release objectId, excluded-frame DOM.getBoxModel, auto-attach methods, profiling, Input.* on !Clean, raw DOM.*, and pierce: true all refused.
  • scripts/guardrails.ps1: 5/5 passed (frame_authority.rs 763/800, cdp_ledger.rs 576/800, engine.rs 1,429/1,500, client.rs 1,432/1,500).
  • OPENCODE_RUNE_EMBED_PLUGINS=1 cargo.ps1 check --workspace: 0 warnings.
  • cargo.ps1 check --manifest-path apps/browser-engine/Cargo.toml --bins: 0 warnings.
  • scripts/web.ps1 -Check: 0 warnings.

@Hona
Hona merged commit 9aac3ea into dev Nov 21, 2026
6 checks passed
@Hona
Hona deleted the ws9/pr1c-frame-authority branch November 21, 2026 03:41
@github-actions

github-actions Bot commented Nov 21, 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.

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