Repository navigation
refactor(browser): keep one document-interception session per tab - #198638
Conversation
Every guarded navigation or action created its own CDP session for document interception and tore it down afterwards, so nothing owned a tab's interception between actions. The tab now owns the session and its frame targets. Each invocation registers a claim with its own policy, handler and failure state, and a paused document goes through the claims present when it arrived. Interception still runs only while a claim exists: the last release disables it and the next claim enables it again, so what is allowed or blocked does not change. Prepares the standing policy for openclaw#198317.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. What this changesThis PR gives each browser tab one document-interception session while keeping navigation policy and failures scoped to individual invocations. Example: Two guarded key presses, "a" then "b", run on the same tab.
Review scores
ProductKind: Refactor · Worth it: Yes Merge readiness⛔ Blocked before merge - 1 item remains Keep open: this PR provides a useful prerequisite for the separate between-actions policy fix. The earlier release-ordering finding is resolved, and no new actionable regression was found; required workflows still need maintainer approval. Priority: P2 Before merge
FindingsNone. Agent review detailsHow this fits togetherThe browser plugin's navigation fence sits between guarded Playwright actions and Chromium document requests, applying invocation policy before continuing or cancelling each request. flowchart TD
A[Guarded browser action] --> B[Invocation claim]
B --> C[Tab document fence]
C --> D[Document policy handlers]
D --> E[CDP session and frame targets]
E --> F[Chromium document requests]
Technical reviewBest possible solution: Keep this as the focused tab-ownership prerequisite and review persistent between-actions policy separately in #198452. Do we have a high-confidence way to reproduce the issue? Current-main source directly establishes invocation-owned sessions; the contributor supplies real-relay counterexamples for the repaired release ordering, while this review executed no target code. Is this the best way to solve the issue? The change reuses the existing fence owner, preserves its callers and policy interface, and adds the lifecycle state needed to share a session without introducing a competing policy implementation. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 6274d9e28a30. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +112, Tests +126. Total +238 across 4 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (3 earlier review cycles)
Reviewed November 14, 2026, 1:21 AM ET / 06:21 UTC (Revision 4). |
…laim The last claim released interception without waiting for the answer, and the next claim dropped a refused Fetch.enable. The extension relay refuses Fetch.enable while its Fetch.disable is unanswered, so back-to-back invocations could run with interception off. Disposal now returns after the release is acknowledged, the next claim starts after that, and a failed enable fails the invocation.
|
ClawSweeper status: applying reviewed decision. I am applying the reviewed decision for this pull request: refactor(browser): keep one document-interception session per tab This is item 1/1 in the current shard. Shard 1/1. This transient lease prevents a newer review from overlapping label, comment, or close mutations. Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
A claim waited for the last release's answer with no bound, so a missing answer hung every later invocation on that tab. The wait now ends at the navigation timeout and fails the claim, which never enables over an unanswered release.
A claim that timed out waiting for the tab's release ran the full cleanup: it stopped a page it never touched, sent the release again and waited a second timeout, and could be kept as a closed claim that refuses every document. It now only drops its claim and fails at the navigation timeout.
|
Real behavior proof for Setup: real Chromium 156 with the bundled extension 2.3.0 loaded unpacked and paired with the Gateway's relay, in a clean macOS VM. The relay and the extension are unmodified. A tap on the relay's client socket in the test records each 1. Delayed release, then reacquire. The second guarded action starts at the moment the first action's The same run on this PR's first commit alone ( 2. Refused On 3. Plain back-to-back key-press actions on one tab, the second making the page navigate to the denied address: blocked in 3 of 3 rounds, no request reached the server. Not shown through the relay: a release that is never answered. The real relay answered every release within about 1 ms or refused, so that case has only a unit test on a mocked transport: the next action fails at the navigation timeout without sending an enable, stopping the page or sending the release again. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
A tab's first claim sent Network.enable and Fetch.enable twice: once when its target was set up with a claim present, and again from the claim. A second invocation joining a claimed tab sent them again too. Each target is now started once per claimed period and every claim awaits that start; a release begins a new period. The dashboard navigation test counts one fence preparation per navigation attempt, which the double enable broke. Its session checks now follow the tab-owned session: one session serves every attempt and is detached, with no listeners left, when the tab closes.
Resolves the conflicts with the merged tab fence (openclaw#198638) in pw-session-navigation-fence.ts and its test. Main holds the fence this branch was stacked on; this branch's side keeps interception on for the tab, starts only document tracking per claim and adds the standing policy. Main's catch on the paused-document handler is kept around both the claimed and the standing path.
…enclaw#198638) * refactor(browser): keep one document-interception session per tab Every guarded navigation or action created its own CDP session for document interception and tore it down afterwards, so nothing owned a tab's interception between actions. The tab now owns the session and its frame targets. Each invocation registers a claim with its own policy, handler and failure state, and a paused document goes through the claims present when it arrived. Interception still runs only while a claim exists: the last release disables it and the next claim enables it again, so what is allowed or blocked does not change. Prepares the standing policy for openclaw#198317. * fix(browser): wait for a tab's interception release before the next claim The last claim released interception without waiting for the answer, and the next claim dropped a refused Fetch.enable. The extension relay refuses Fetch.enable while its Fetch.disable is unanswered, so back-to-back invocations could run with interception off. Disposal now returns after the release is acknowledged, the next claim starts after that, and a failed enable fails the invocation. * fix(browser): fail a claim whose tab release is never answered A claim waited for the last release's answer with no bound, so a missing answer hung every later invocation on that tab. The wait now ends at the navigation timeout and fails the claim, which never enables over an unanswered release. * fix(browser): let a claim that started nothing give up without cleanup A claim that timed out waiting for the tab's release ran the full cleanup: it stopped a page it never touched, sent the release again and waited a second timeout, and could be kept as a closed claim that refuses every document. It now only drops its claim and fails at the navigation timeout. * fix(browser): start a tab's interception once per claimed period A tab's first claim sent Network.enable and Fetch.enable twice: once when its target was set up with a claim present, and again from the claim. A second invocation joining a claimed tab sent them again too. Each target is now started once per claimed period and every claim awaits that start; a release begins a new period. The dashboard navigation test counts one fence preparation per navigation attempt, which the double enable broke. Its session checks now follow the tab-owned session: one session serves every attempt and is detached, with no listeners left, when the tab closes.
Related: #198317
What Problem This Solves
Prepares the fix for #198317. Every guarded browser navigation or action creates its own CDP session for document interception and tears it down afterwards, so nothing owns a tab's interception between actions and a policy for that gap has nowhere to live. This moves ownership to the tab without changing what is allowed or blocked, so the fix (#198452) is a small policy change on top of it.
User Impact
User impact: none intended. Interception still runs only while a guarded navigation or action is in progress, with the same policy decisions, redirect-hop checks, source-page preservation and error precedence.
Three differences worth a reviewer's attention:
Why This Change Was Made
Pageowns the session, its frame targets and the document tracking.installNavigationAuthorityFencekeeps its signature and registers a claim: the invocation's policy, document handler and failure state.main.Fetch.disableandNetwork.disable, and cleanup returns when they are answered, as onmain. The next claim sendsFetch.enableandNetwork.enableonly after that answer, once per target while the tab is claimed; claims that overlap await the same start. It waits for the answer no longer than the navigation timeout, then fails without enabling; having started nothing, it only gives up its claim. A claim whose enable fails fails its invocation. The extension relay refusesFetch.enablewhile itsFetch.disableis unanswered, so sending the two in call order is not enough there.Evidence
Fetch/Networkenable and disable request and its answer. A fixture server at a policy-denied address counts requests.Back-to-back key-press actions on one tab, the second making the page navigate to the denied address: blocked in 3 of 3 rounds, no request reached the server, the tab kept its page.
The second action started at the moment the first action's
Fetch.disablereached the relay (3 of 3 rounds):Fetch.enableis sent after the relay answersFetch.disable, the navigation is blocked and no request reached the server.The same run on this PR's first commit alone (
318c175), which does not wait for the answer: the relay refuses the enable, the action runs with interception off and the denied server receives the document, in 3 of 3 rounds.A refused
Fetch.enable: a second relay session takes the tab's Fetch lease between two actions. The relay refuses the next action'sFetch.enable, the action is rejected with the relay's error before its key press reaches the page, and no request reached the server. Once the lease is released the next action completes. On318c175the refusal is dropped, the key press runs and the denied server receives the document.Not shown through the relay: a release that is never answered. The real relay answered every release within about 1 ms or refused, so that case has only the unit test below.
Fetch.disableanswer withFetch.enablerefused until it arrives; a refused enable failing the invocation; and a release that is never answered, where the next invocation fails at the navigation timeout without sending an enable, stopping the page or sending the release again. Each fails without its part of the change.127.0.0.2, which macOS does not route; they time out there onmainas well.main(10 of 10 runs): a trace shows the test's click inside the nested frame starts no navigation, so the fence has no redirect to see.agent.act.dashboard-ownership.test.ts) checks the tab-owned session: one session serves every navigation attempt and is detached, with no listeners left, when the tab closes. Its per-attempt preparation count is unchanged.Not checked: the full Gateway with a real agent and model (the relay proof drives the browser action functions through the relay), Linux and Windows, and remote-CDP profiles.