fix(preview): keep snapshots slim unless the agent asks - #7302

Open
gbarros-dev wants to merge 13 commits into
pingdotgg:mainfrom
gbarros-dev:fix/preview-slim-snapshot
Open

fix(preview): keep snapshots slim unless the agent asks#7302
gbarros-dev wants to merge 13 commits into
pingdotgg:mainfrom
gbarros-dev:fix/preview-slim-snapshot

Conversation

@gbarros-dev

@gbarros-devgbarros-dev commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

preview_snapshot dumped the accessibility tree, console, and network on every inspect. preview_wait_for also matched sidebar chrome, so agents thought a page was ready when only a nav label matched.

Snapshots default to URL, main-landmark text, visible controls, and a PNG. AX, console, and network load only when include asks. Wait searches main by default and requires a visible locator.

Split out of closed#7127.

Tests: vp test run packages/contracts/src/preview.test.ts

Implemented with Grok 4.6 through Grok CLI.


Note

Medium Risk
Changes default MCP/desktop snapshot shape and debugger domain wiring; agents or integrations that assumed always-on diagnostics may break until they pass include.

Overview
Preview automation snapshots are slim by default.preview_snapshot and desktop IPC now accept optional include (ax, console, network); without it callers get URL, main-landmark visible text, interactive elements, action timeline, and PNG only. CDP accessibility, log, and network domains are enabled on demand per control session instead of on every attach.

preview_wait_for is scoped to real page content. Text and locator matching default to the main landmark (plus modal/overlay roots); optional scope: "document" searches the full page. Locator waits require visibility and skip dialog trigger slots.

Snapshot harvesting adds stable element ids, pointer-cursor table/layout nodes, and CDP screenshot fallback when capturePage fails. accessibilityTree is optional in the contract.

Breaking for consumers: anything expecting full AX/console/network on every snapshot must pass include.

Reviewed by Cursor Bugbot for commit 3755a33. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Make preview snapshots slim by default and scope preview_wait_for to main landmark

  • Snapshots now require explicit include values (ax, console, network) to return diagnostic data. Default snapshots omit the accessibility tree and return empty console and network arrays.
  • preview_wait_for defaults to the main landmark scope. It searches overlay roots, traverses shadow DOM, and ignores invisible elements unless scope is set to document.
  • Adds a CDP Page.captureScreenshot fallback to captureAutomationSnapshot when Electron's capturePage fails.
  • Refactors withControlSession in Manager.ts to resolve WebContents internally and re-check session validity before executing callbacks.
  • Behavioral Change: existing preview_wait_for calls relying on matches outside the main landmark or within invisible nodes will fail unless scope: "document" is passed.

Macroscope summarized 3755a33.

@coderabbitai

coderabbitaiBot commented Aug 17, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8834cb66-be84-4273-a921-43d3e4b089ce

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actionsgithub-actionsBot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Aug 17, 2026
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated

@macroscopeappmacroscopeappBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Effect service conventions review: two findings on the desktop preview snapshot path. Details inline.

Posted via Macroscope — Effect Service Conventions

Comment threadapps/desktop/src/preview/Manager.ts
Comment threadapps/desktop/src/preview/Manager.ts Outdated
@macroscopeapp

macroscopeappBot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This PR changes the default preview snapshot payload and wait_for matching behavior across the MCP, web, IPC, and desktop automation layers, rather than only adding an opt-in path. It also includes unresolved control-session lifecycle and stale-webview risks that require human assessment.

Not approved because:

  • 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity

Adjust the Minimum Blocking Severity for this repo — including turning it Off — in Settings. You can add or adjust custom eligibility rules. Learn more.

@gbarros-dev
gbarros-devforce-pushed the fix/preview-slim-snapshot branch from 47b1e15 to 88686c5CompareAugust 17, 2026 08:36
Comment threadapps/desktop/src/preview/Manager.ts
Comment threadapps/desktop/src/preview/Manager.ts Outdated
@gbarros-dev
gbarros-devforce-pushed the fix/preview-slim-snapshot branch from 149b56c to 3501c4dCompareSeptember 3, 2026 09:34
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts
Comment threadapps/desktop/src/preview/Manager.ts
preview_snapshot dumped the accessibility tree, console, and network on
every inspect. preview_wait_for also matched sidebar chrome, so agents
thought a page was ready when only a nav label matched.
Snapshots default to URL, main-landmark text, visible controls, and a
PNG. AX, console, and network load only when include asks. Wait searches
main by default and requires a visible locator.
Pointer-cursor div/td controls were never selected. An empty <main>
fell back to body text, leaking sidebar chrome. A failed capturePage
plus an empty CDP screenshot became a 0x0 image.
Snapshots now select those controls, keep empty main text empty, and
surface a typed capture failure. Tests cover the slim default, include
ax, wait scope, and the failed-screenshot path.
The new snapshot tests spread makeTestPreviewWebContents(), which is
typed as never. CI typecheck rejected that. The mocks are now a local
webview object.
Snapshots treated every div/td/tr with computed cursor:pointer as
clickable. Cursor inherits, so nested layout nodes filled the 200-cap
and hid real controls. Only the outermost pointer container is kept.
Skipping any layout node whose parent had cursor:pointer dropped whole
clickable areas when the pointer sat on li, section, label, or table.
Only a harvested ancestor (div/td/tr) now suppresses descendants.
Comment threadapps/desktop/src/preview/Manager.ts
@gbarros-dev
gbarros-devforce-pushed the fix/preview-slim-snapshot branch from 87f7dcc to a23b4f5CompareSeptember 3, 2026 10:14
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
const epoch = (yield* Ref.get(controlEpochRef)).get(tabId) ?? 0;
const control = yield* ensureControlSession(wc);
const execute = Effect.fn("PreviewManager.executeControlAction")(function* () {
const requestedWc = yield* requireWebContents(tabId);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Mediumpreview/Manager.ts:1421

Automation requests that fail in requireWebContents or ensureControlSession leave a permanent running entry in actionTimeline, so later snapshots report an action that never completes. withControlSession records the event before those calls, but installs Effect.onExit(finalize) only around execute; install finalization around the entire operation (or otherwise finalize these early failures) so the entry becomes failed/interrupted.

🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/desktop/src/preview/Manager.ts around line 1421:
Automation requests that fail in `requireWebContents` or `ensureControlSession` leave a permanent `running` entry in `actionTimeline`, so later snapshots report an action that never completes. `withControlSession` records the event before those calls, but installs `Effect.onExit(finalize)` only around `execute`; install finalization around the entire operation (or otherwise finalize these early failures) so the entry becomes `failed`/`interrupted`.

@cursorcursorBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3755a33. Configure here.

if (tabs.has(tabId)) yield* update(tabId, { controller: "none" });
});
return yield* control.semaphore.withPermit(execute().pipe(Effect.onExit(finalize)));
return yield* control.semaphore.withPermit(execute(activeWc).pipe(Effect.onExit(finalize)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale webview used after re-ensure

Medium Severity

withControlSession re-reads the tab after the first ensureControlSession, then can await a second ensure and still pass the pre-await activeWc into execute. A swap (or the detach-before-publish window of the first swap) leaves click, type, and snapshot talking to a guest the tab no longer owns.

Fix in CursorFix in Web

Triggered by learned rule: PreviewManager: re-read tab state from tabsRef after mutations, don't use stale snapshots

Reviewed by Cursor Bugbot for commit 3755a33. Configure here.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L100-499 changed lines (additions + deletions).vouch:trustedPR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@gbarros-dev
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

fix(preview): keep snapshots slim unless the agent asks - #7302

Open
gbarros-dev wants to merge 13 commits into
pingdotgg:mainfrom
gbarros-dev:fix/preview-slim-snapshot
Open

fix(preview): keep snapshots slim unless the agent asks#7302
gbarros-dev wants to merge 13 commits into
pingdotgg:mainfrom
gbarros-dev:fix/preview-slim-snapshot

Conversation

@gbarros-dev

@gbarros-devgbarros-dev commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

preview_snapshot dumped the accessibility tree, console, and network on every inspect. preview_wait_for also matched sidebar chrome, so agents thought a page was ready when only a nav label matched.

Snapshots default to URL, main-landmark text, visible controls, and a PNG. AX, console, and network load only when include asks. Wait searches main by default and requires a visible locator.

Split out of closed#7127.

Tests: vp test run packages/contracts/src/preview.test.ts

Implemented with Grok 4.6 through Grok CLI.


Note

Medium Risk
Changes default MCP/desktop snapshot shape and debugger domain wiring; agents or integrations that assumed always-on diagnostics may break until they pass include.

Overview
Preview automation snapshots are slim by default.preview_snapshot and desktop IPC now accept optional include (ax, console, network); without it callers get URL, main-landmark visible text, interactive elements, action timeline, and PNG only. CDP accessibility, log, and network domains are enabled on demand per control session instead of on every attach.

preview_wait_for is scoped to real page content. Text and locator matching default to the main landmark (plus modal/overlay roots); optional scope: "document" searches the full page. Locator waits require visibility and skip dialog trigger slots.

Snapshot harvesting adds stable element ids, pointer-cursor table/layout nodes, and CDP screenshot fallback when capturePage fails. accessibilityTree is optional in the contract.

Breaking for consumers: anything expecting full AX/console/network on every snapshot must pass include.

Reviewed by Cursor Bugbot for commit 3755a33. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Make preview snapshots slim by default and scope preview_wait_for to main landmark

  • Snapshots now require explicit include values (ax, console, network) to return diagnostic data. Default snapshots omit the accessibility tree and return empty console and network arrays.
  • preview_wait_for defaults to the main landmark scope. It searches overlay roots, traverses shadow DOM, and ignores invisible elements unless scope is set to document.
  • Adds a CDP Page.captureScreenshot fallback to captureAutomationSnapshot when Electron's capturePage fails.
  • Refactors withControlSession in Manager.ts to resolve WebContents internally and re-check session validity before executing callbacks.
  • Behavioral Change: existing preview_wait_for calls relying on matches outside the main landmark or within invisible nodes will fail unless scope: "document" is passed.

Macroscope summarized 3755a33.

@coderabbitai

coderabbitaiBot commented Aug 17, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8834cb66-be84-4273-a921-43d3e4b089ce

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actionsgithub-actionsBot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Aug 17, 2026
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated

@macroscopeappmacroscopeappBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Effect service conventions review: two findings on the desktop preview snapshot path. Details inline.

Posted via Macroscope — Effect Service Conventions

Comment threadapps/desktop/src/preview/Manager.ts
Comment threadapps/desktop/src/preview/Manager.ts Outdated
@macroscopeapp

macroscopeappBot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This PR changes the default preview snapshot payload and wait_for matching behavior across the MCP, web, IPC, and desktop automation layers, rather than only adding an opt-in path. It also includes unresolved control-session lifecycle and stale-webview risks that require human assessment.

Not approved because:

  • 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity

Adjust the Minimum Blocking Severity for this repo — including turning it Off — in Settings. You can add or adjust custom eligibility rules. Learn more.

@gbarros-dev
gbarros-devforce-pushed the fix/preview-slim-snapshot branch from 47b1e15 to 88686c5CompareAugust 17, 2026 08:36
Comment threadapps/desktop/src/preview/Manager.ts
Comment threadapps/desktop/src/preview/Manager.ts Outdated
@gbarros-dev
gbarros-devforce-pushed the fix/preview-slim-snapshot branch from 149b56c to 3501c4dCompareSeptember 3, 2026 09:34
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts
Comment threadapps/desktop/src/preview/Manager.ts
preview_snapshot dumped the accessibility tree, console, and network on
every inspect. preview_wait_for also matched sidebar chrome, so agents
thought a page was ready when only a nav label matched.
Snapshots default to URL, main-landmark text, visible controls, and a
PNG. AX, console, and network load only when include asks. Wait searches
main by default and requires a visible locator.
Pointer-cursor div/td controls were never selected. An empty <main>
fell back to body text, leaking sidebar chrome. A failed capturePage
plus an empty CDP screenshot became a 0x0 image.
Snapshots now select those controls, keep empty main text empty, and
surface a typed capture failure. Tests cover the slim default, include
ax, wait scope, and the failed-screenshot path.
The new snapshot tests spread makeTestPreviewWebContents(), which is
typed as never. CI typecheck rejected that. The mocks are now a local
webview object.
Snapshots treated every div/td/tr with computed cursor:pointer as
clickable. Cursor inherits, so nested layout nodes filled the 200-cap
and hid real controls. Only the outermost pointer container is kept.
Skipping any layout node whose parent had cursor:pointer dropped whole
clickable areas when the pointer sat on li, section, label, or table.
Only a harvested ancestor (div/td/tr) now suppresses descendants.
Comment threadapps/desktop/src/preview/Manager.ts
@gbarros-dev
gbarros-devforce-pushed the fix/preview-slim-snapshot branch from 87f7dcc to a23b4f5CompareSeptember 3, 2026 10:14
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
const epoch = (yield* Ref.get(controlEpochRef)).get(tabId) ?? 0;
const control = yield* ensureControlSession(wc);
const execute = Effect.fn("PreviewManager.executeControlAction")(function* () {
const requestedWc = yield* requireWebContents(tabId);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Mediumpreview/Manager.ts:1421

Automation requests that fail in requireWebContents or ensureControlSession leave a permanent running entry in actionTimeline, so later snapshots report an action that never completes. withControlSession records the event before those calls, but installs Effect.onExit(finalize) only around execute; install finalization around the entire operation (or otherwise finalize these early failures) so the entry becomes failed/interrupted.

🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/desktop/src/preview/Manager.ts around line 1421:
Automation requests that fail in `requireWebContents` or `ensureControlSession` leave a permanent `running` entry in `actionTimeline`, so later snapshots report an action that never completes. `withControlSession` records the event before those calls, but installs `Effect.onExit(finalize)` only around `execute`; install finalization around the entire operation (or otherwise finalize these early failures) so the entry becomes `failed`/`interrupted`.

@cursorcursorBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3755a33. Configure here.

if (tabs.has(tabId)) yield* update(tabId, { controller: "none" });
});
return yield* control.semaphore.withPermit(execute().pipe(Effect.onExit(finalize)));
return yield* control.semaphore.withPermit(execute(activeWc).pipe(Effect.onExit(finalize)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale webview used after re-ensure

Medium Severity

withControlSession re-reads the tab after the first ensureControlSession, then can await a second ensure and still pass the pre-await activeWc into execute. A swap (or the detach-before-publish window of the first swap) leaves click, type, and snapshot talking to a guest the tab no longer owns.

Fix in CursorFix in Web

Triggered by learned rule: PreviewManager: re-read tab state from tabsRef after mutations, don't use stale snapshots

Reviewed by Cursor Bugbot for commit 3755a33. Configure here.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L100-499 changed lines (additions + deletions).vouch:trustedPR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@gbarros-dev
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

fix(preview): keep snapshots slim unless the agent asks - #7302

Open
gbarros-dev wants to merge 13 commits into
pingdotgg:mainfrom
gbarros-dev:fix/preview-slim-snapshot
Open

fix(preview): keep snapshots slim unless the agent asks#7302
gbarros-dev wants to merge 13 commits into
pingdotgg:mainfrom
gbarros-dev:fix/preview-slim-snapshot

Conversation

@gbarros-dev

@gbarros-devgbarros-dev commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

preview_snapshot dumped the accessibility tree, console, and network on every inspect. preview_wait_for also matched sidebar chrome, so agents thought a page was ready when only a nav label matched.

Snapshots default to URL, main-landmark text, visible controls, and a PNG. AX, console, and network load only when include asks. Wait searches main by default and requires a visible locator.

Split out of closed#7127.

Tests: vp test run packages/contracts/src/preview.test.ts

Implemented with Grok 4.6 through Grok CLI.


Note

Medium Risk
Changes default MCP/desktop snapshot shape and debugger domain wiring; agents or integrations that assumed always-on diagnostics may break until they pass include.

Overview
Preview automation snapshots are slim by default.preview_snapshot and desktop IPC now accept optional include (ax, console, network); without it callers get URL, main-landmark visible text, interactive elements, action timeline, and PNG only. CDP accessibility, log, and network domains are enabled on demand per control session instead of on every attach.

preview_wait_for is scoped to real page content. Text and locator matching default to the main landmark (plus modal/overlay roots); optional scope: "document" searches the full page. Locator waits require visibility and skip dialog trigger slots.

Snapshot harvesting adds stable element ids, pointer-cursor table/layout nodes, and CDP screenshot fallback when capturePage fails. accessibilityTree is optional in the contract.

Breaking for consumers: anything expecting full AX/console/network on every snapshot must pass include.

Reviewed by Cursor Bugbot for commit 3755a33. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Make preview snapshots slim by default and scope preview_wait_for to main landmark

  • Snapshots now require explicit include values (ax, console, network) to return diagnostic data. Default snapshots omit the accessibility tree and return empty console and network arrays.
  • preview_wait_for defaults to the main landmark scope. It searches overlay roots, traverses shadow DOM, and ignores invisible elements unless scope is set to document.
  • Adds a CDP Page.captureScreenshot fallback to captureAutomationSnapshot when Electron's capturePage fails.
  • Refactors withControlSession in Manager.ts to resolve WebContents internally and re-check session validity before executing callbacks.
  • Behavioral Change: existing preview_wait_for calls relying on matches outside the main landmark or within invisible nodes will fail unless scope: "document" is passed.

Macroscope summarized 3755a33.

@coderabbitai

coderabbitaiBot commented Aug 17, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8834cb66-be84-4273-a921-43d3e4b089ce

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actionsgithub-actionsBot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Aug 17, 2026
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated

@macroscopeappmacroscopeappBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Effect service conventions review: two findings on the desktop preview snapshot path. Details inline.

Posted via Macroscope — Effect Service Conventions

Comment threadapps/desktop/src/preview/Manager.ts
Comment threadapps/desktop/src/preview/Manager.ts Outdated
@macroscopeapp

macroscopeappBot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This PR changes the default preview snapshot payload and wait_for matching behavior across the MCP, web, IPC, and desktop automation layers, rather than only adding an opt-in path. It also includes unresolved control-session lifecycle and stale-webview risks that require human assessment.

Not approved because:

  • 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity

Adjust the Minimum Blocking Severity for this repo — including turning it Off — in Settings. You can add or adjust custom eligibility rules. Learn more.

@gbarros-dev
gbarros-devforce-pushed the fix/preview-slim-snapshot branch from 47b1e15 to 88686c5CompareAugust 17, 2026 08:36
Comment threadapps/desktop/src/preview/Manager.ts
Comment threadapps/desktop/src/preview/Manager.ts Outdated
@gbarros-dev
gbarros-devforce-pushed the fix/preview-slim-snapshot branch from 149b56c to 3501c4dCompareSeptember 3, 2026 09:34
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts
Comment threadapps/desktop/src/preview/Manager.ts
preview_snapshot dumped the accessibility tree, console, and network on
every inspect. preview_wait_for also matched sidebar chrome, so agents
thought a page was ready when only a nav label matched.
Snapshots default to URL, main-landmark text, visible controls, and a
PNG. AX, console, and network load only when include asks. Wait searches
main by default and requires a visible locator.
Pointer-cursor div/td controls were never selected. An empty <main>
fell back to body text, leaking sidebar chrome. A failed capturePage
plus an empty CDP screenshot became a 0x0 image.
Snapshots now select those controls, keep empty main text empty, and
surface a typed capture failure. Tests cover the slim default, include
ax, wait scope, and the failed-screenshot path.
The new snapshot tests spread makeTestPreviewWebContents(), which is
typed as never. CI typecheck rejected that. The mocks are now a local
webview object.
Snapshots treated every div/td/tr with computed cursor:pointer as
clickable. Cursor inherits, so nested layout nodes filled the 200-cap
and hid real controls. Only the outermost pointer container is kept.
Skipping any layout node whose parent had cursor:pointer dropped whole
clickable areas when the pointer sat on li, section, label, or table.
Only a harvested ancestor (div/td/tr) now suppresses descendants.
Comment threadapps/desktop/src/preview/Manager.ts
@gbarros-dev
gbarros-devforce-pushed the fix/preview-slim-snapshot branch from 87f7dcc to a23b4f5CompareSeptember 3, 2026 10:14
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
const epoch = (yield* Ref.get(controlEpochRef)).get(tabId) ?? 0;
const control = yield* ensureControlSession(wc);
const execute = Effect.fn("PreviewManager.executeControlAction")(function* () {
const requestedWc = yield* requireWebContents(tabId);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Mediumpreview/Manager.ts:1421

Automation requests that fail in requireWebContents or ensureControlSession leave a permanent running entry in actionTimeline, so later snapshots report an action that never completes. withControlSession records the event before those calls, but installs Effect.onExit(finalize) only around execute; install finalization around the entire operation (or otherwise finalize these early failures) so the entry becomes failed/interrupted.

🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/desktop/src/preview/Manager.ts around line 1421:
Automation requests that fail in `requireWebContents` or `ensureControlSession` leave a permanent `running` entry in `actionTimeline`, so later snapshots report an action that never completes. `withControlSession` records the event before those calls, but installs `Effect.onExit(finalize)` only around `execute`; install finalization around the entire operation (or otherwise finalize these early failures) so the entry becomes `failed`/`interrupted`.

@cursorcursorBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3755a33. Configure here.

if (tabs.has(tabId)) yield* update(tabId, { controller: "none" });
});
return yield* control.semaphore.withPermit(execute().pipe(Effect.onExit(finalize)));
return yield* control.semaphore.withPermit(execute(activeWc).pipe(Effect.onExit(finalize)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale webview used after re-ensure

Medium Severity

withControlSession re-reads the tab after the first ensureControlSession, then can await a second ensure and still pass the pre-await activeWc into execute. A swap (or the detach-before-publish window of the first swap) leaves click, type, and snapshot talking to a guest the tab no longer owns.

Fix in CursorFix in Web

Triggered by learned rule: PreviewManager: re-read tab state from tabsRef after mutations, don't use stale snapshots

Reviewed by Cursor Bugbot for commit 3755a33. Configure here.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L100-499 changed lines (additions + deletions).vouch:trustedPR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@gbarros-dev
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

fix(preview): keep snapshots slim unless the agent asks - #7302

Open
gbarros-dev wants to merge 13 commits into
pingdotgg:mainfrom
gbarros-dev:fix/preview-slim-snapshot
Open

fix(preview): keep snapshots slim unless the agent asks#7302
gbarros-dev wants to merge 13 commits into
pingdotgg:mainfrom
gbarros-dev:fix/preview-slim-snapshot

Conversation

@gbarros-dev

@gbarros-devgbarros-dev commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

preview_snapshot dumped the accessibility tree, console, and network on every inspect. preview_wait_for also matched sidebar chrome, so agents thought a page was ready when only a nav label matched.

Snapshots default to URL, main-landmark text, visible controls, and a PNG. AX, console, and network load only when include asks. Wait searches main by default and requires a visible locator.

Split out of closed#7127.

Tests: vp test run packages/contracts/src/preview.test.ts

Implemented with Grok 4.6 through Grok CLI.


Note

Medium Risk
Changes default MCP/desktop snapshot shape and debugger domain wiring; agents or integrations that assumed always-on diagnostics may break until they pass include.

Overview
Preview automation snapshots are slim by default.preview_snapshot and desktop IPC now accept optional include (ax, console, network); without it callers get URL, main-landmark visible text, interactive elements, action timeline, and PNG only. CDP accessibility, log, and network domains are enabled on demand per control session instead of on every attach.

preview_wait_for is scoped to real page content. Text and locator matching default to the main landmark (plus modal/overlay roots); optional scope: "document" searches the full page. Locator waits require visibility and skip dialog trigger slots.

Snapshot harvesting adds stable element ids, pointer-cursor table/layout nodes, and CDP screenshot fallback when capturePage fails. accessibilityTree is optional in the contract.

Breaking for consumers: anything expecting full AX/console/network on every snapshot must pass include.

Reviewed by Cursor Bugbot for commit 3755a33. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Make preview snapshots slim by default and scope preview_wait_for to main landmark

  • Snapshots now require explicit include values (ax, console, network) to return diagnostic data. Default snapshots omit the accessibility tree and return empty console and network arrays.
  • preview_wait_for defaults to the main landmark scope. It searches overlay roots, traverses shadow DOM, and ignores invisible elements unless scope is set to document.
  • Adds a CDP Page.captureScreenshot fallback to captureAutomationSnapshot when Electron's capturePage fails.
  • Refactors withControlSession in Manager.ts to resolve WebContents internally and re-check session validity before executing callbacks.
  • Behavioral Change: existing preview_wait_for calls relying on matches outside the main landmark or within invisible nodes will fail unless scope: "document" is passed.

Macroscope summarized 3755a33.

@coderabbitai

coderabbitaiBot commented Aug 17, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8834cb66-be84-4273-a921-43d3e4b089ce

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actionsgithub-actionsBot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Aug 17, 2026
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated

@macroscopeappmacroscopeappBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Effect service conventions review: two findings on the desktop preview snapshot path. Details inline.

Posted via Macroscope — Effect Service Conventions

Comment threadapps/desktop/src/preview/Manager.ts
Comment threadapps/desktop/src/preview/Manager.ts Outdated
@macroscopeapp

macroscopeappBot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This PR changes the default preview snapshot payload and wait_for matching behavior across the MCP, web, IPC, and desktop automation layers, rather than only adding an opt-in path. It also includes unresolved control-session lifecycle and stale-webview risks that require human assessment.

Not approved because:

  • 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity

Adjust the Minimum Blocking Severity for this repo — including turning it Off — in Settings. You can add or adjust custom eligibility rules. Learn more.

@gbarros-dev
gbarros-devforce-pushed the fix/preview-slim-snapshot branch from 47b1e15 to 88686c5CompareAugust 17, 2026 08:36
Comment threadapps/desktop/src/preview/Manager.ts
Comment threadapps/desktop/src/preview/Manager.ts Outdated
@gbarros-dev
gbarros-devforce-pushed the fix/preview-slim-snapshot branch from 149b56c to 3501c4dCompareSeptember 3, 2026 09:34
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts
Comment threadapps/desktop/src/preview/Manager.ts
preview_snapshot dumped the accessibility tree, console, and network on
every inspect. preview_wait_for also matched sidebar chrome, so agents
thought a page was ready when only a nav label matched.
Snapshots default to URL, main-landmark text, visible controls, and a
PNG. AX, console, and network load only when include asks. Wait searches
main by default and requires a visible locator.
Pointer-cursor div/td controls were never selected. An empty <main>
fell back to body text, leaking sidebar chrome. A failed capturePage
plus an empty CDP screenshot became a 0x0 image.
Snapshots now select those controls, keep empty main text empty, and
surface a typed capture failure. Tests cover the slim default, include
ax, wait scope, and the failed-screenshot path.
The new snapshot tests spread makeTestPreviewWebContents(), which is
typed as never. CI typecheck rejected that. The mocks are now a local
webview object.
Snapshots treated every div/td/tr with computed cursor:pointer as
clickable. Cursor inherits, so nested layout nodes filled the 200-cap
and hid real controls. Only the outermost pointer container is kept.
Skipping any layout node whose parent had cursor:pointer dropped whole
clickable areas when the pointer sat on li, section, label, or table.
Only a harvested ancestor (div/td/tr) now suppresses descendants.
Comment threadapps/desktop/src/preview/Manager.ts
@gbarros-dev
gbarros-devforce-pushed the fix/preview-slim-snapshot branch from 87f7dcc to a23b4f5CompareSeptember 3, 2026 10:14
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
const epoch = (yield* Ref.get(controlEpochRef)).get(tabId) ?? 0;
const control = yield* ensureControlSession(wc);
const execute = Effect.fn("PreviewManager.executeControlAction")(function* () {
const requestedWc = yield* requireWebContents(tabId);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Mediumpreview/Manager.ts:1421

Automation requests that fail in requireWebContents or ensureControlSession leave a permanent running entry in actionTimeline, so later snapshots report an action that never completes. withControlSession records the event before those calls, but installs Effect.onExit(finalize) only around execute; install finalization around the entire operation (or otherwise finalize these early failures) so the entry becomes failed/interrupted.

🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/desktop/src/preview/Manager.ts around line 1421:
Automation requests that fail in `requireWebContents` or `ensureControlSession` leave a permanent `running` entry in `actionTimeline`, so later snapshots report an action that never completes. `withControlSession` records the event before those calls, but installs `Effect.onExit(finalize)` only around `execute`; install finalization around the entire operation (or otherwise finalize these early failures) so the entry becomes `failed`/`interrupted`.

@cursorcursorBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3755a33. Configure here.

if (tabs.has(tabId)) yield* update(tabId, { controller: "none" });
});
return yield* control.semaphore.withPermit(execute().pipe(Effect.onExit(finalize)));
return yield* control.semaphore.withPermit(execute(activeWc).pipe(Effect.onExit(finalize)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale webview used after re-ensure

Medium Severity

withControlSession re-reads the tab after the first ensureControlSession, then can await a second ensure and still pass the pre-await activeWc into execute. A swap (or the detach-before-publish window of the first swap) leaves click, type, and snapshot talking to a guest the tab no longer owns.

Fix in CursorFix in Web

Triggered by learned rule: PreviewManager: re-read tab state from tabsRef after mutations, don't use stale snapshots

Reviewed by Cursor Bugbot for commit 3755a33. Configure here.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L100-499 changed lines (additions + deletions).vouch:trustedPR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@gbarros-dev
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

fix(preview): keep snapshots slim unless the agent asks - #7302

Open
gbarros-dev wants to merge 13 commits into
pingdotgg:mainfrom
gbarros-dev:fix/preview-slim-snapshot
Open

fix(preview): keep snapshots slim unless the agent asks#7302
gbarros-dev wants to merge 13 commits into
pingdotgg:mainfrom
gbarros-dev:fix/preview-slim-snapshot

Conversation

@gbarros-dev

@gbarros-devgbarros-dev commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

preview_snapshot dumped the accessibility tree, console, and network on every inspect. preview_wait_for also matched sidebar chrome, so agents thought a page was ready when only a nav label matched.

Snapshots default to URL, main-landmark text, visible controls, and a PNG. AX, console, and network load only when include asks. Wait searches main by default and requires a visible locator.

Split out of closed#7127.

Tests: vp test run packages/contracts/src/preview.test.ts

Implemented with Grok 4.6 through Grok CLI.


Note

Medium Risk
Changes default MCP/desktop snapshot shape and debugger domain wiring; agents or integrations that assumed always-on diagnostics may break until they pass include.

Overview
Preview automation snapshots are slim by default.preview_snapshot and desktop IPC now accept optional include (ax, console, network); without it callers get URL, main-landmark visible text, interactive elements, action timeline, and PNG only. CDP accessibility, log, and network domains are enabled on demand per control session instead of on every attach.

preview_wait_for is scoped to real page content. Text and locator matching default to the main landmark (plus modal/overlay roots); optional scope: "document" searches the full page. Locator waits require visibility and skip dialog trigger slots.

Snapshot harvesting adds stable element ids, pointer-cursor table/layout nodes, and CDP screenshot fallback when capturePage fails. accessibilityTree is optional in the contract.

Breaking for consumers: anything expecting full AX/console/network on every snapshot must pass include.

Reviewed by Cursor Bugbot for commit 3755a33. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Make preview snapshots slim by default and scope preview_wait_for to main landmark

  • Snapshots now require explicit include values (ax, console, network) to return diagnostic data. Default snapshots omit the accessibility tree and return empty console and network arrays.
  • preview_wait_for defaults to the main landmark scope. It searches overlay roots, traverses shadow DOM, and ignores invisible elements unless scope is set to document.
  • Adds a CDP Page.captureScreenshot fallback to captureAutomationSnapshot when Electron's capturePage fails.
  • Refactors withControlSession in Manager.ts to resolve WebContents internally and re-check session validity before executing callbacks.
  • Behavioral Change: existing preview_wait_for calls relying on matches outside the main landmark or within invisible nodes will fail unless scope: "document" is passed.

Macroscope summarized 3755a33.

@coderabbitai

coderabbitaiBot commented Aug 17, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8834cb66-be84-4273-a921-43d3e4b089ce

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actionsgithub-actionsBot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Aug 17, 2026
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated

@macroscopeappmacroscopeappBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Effect service conventions review: two findings on the desktop preview snapshot path. Details inline.

Posted via Macroscope — Effect Service Conventions

Comment threadapps/desktop/src/preview/Manager.ts
Comment threadapps/desktop/src/preview/Manager.ts Outdated
@macroscopeapp

macroscopeappBot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This PR changes the default preview snapshot payload and wait_for matching behavior across the MCP, web, IPC, and desktop automation layers, rather than only adding an opt-in path. It also includes unresolved control-session lifecycle and stale-webview risks that require human assessment.

Not approved because:

  • 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity

Adjust the Minimum Blocking Severity for this repo — including turning it Off — in Settings. You can add or adjust custom eligibility rules. Learn more.

@gbarros-dev
gbarros-devforce-pushed the fix/preview-slim-snapshot branch from 47b1e15 to 88686c5CompareAugust 17, 2026 08:36
Comment threadapps/desktop/src/preview/Manager.ts
Comment threadapps/desktop/src/preview/Manager.ts Outdated
@gbarros-dev
gbarros-devforce-pushed the fix/preview-slim-snapshot branch from 149b56c to 3501c4dCompareSeptember 3, 2026 09:34
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts
Comment threadapps/desktop/src/preview/Manager.ts
preview_snapshot dumped the accessibility tree, console, and network on
every inspect. preview_wait_for also matched sidebar chrome, so agents
thought a page was ready when only a nav label matched.
Snapshots default to URL, main-landmark text, visible controls, and a
PNG. AX, console, and network load only when include asks. Wait searches
main by default and requires a visible locator.
Pointer-cursor div/td controls were never selected. An empty <main>
fell back to body text, leaking sidebar chrome. A failed capturePage
plus an empty CDP screenshot became a 0x0 image.
Snapshots now select those controls, keep empty main text empty, and
surface a typed capture failure. Tests cover the slim default, include
ax, wait scope, and the failed-screenshot path.
The new snapshot tests spread makeTestPreviewWebContents(), which is
typed as never. CI typecheck rejected that. The mocks are now a local
webview object.
Snapshots treated every div/td/tr with computed cursor:pointer as
clickable. Cursor inherits, so nested layout nodes filled the 200-cap
and hid real controls. Only the outermost pointer container is kept.
Skipping any layout node whose parent had cursor:pointer dropped whole
clickable areas when the pointer sat on li, section, label, or table.
Only a harvested ancestor (div/td/tr) now suppresses descendants.
Comment threadapps/desktop/src/preview/Manager.ts
@gbarros-dev
gbarros-devforce-pushed the fix/preview-slim-snapshot branch from 87f7dcc to a23b4f5CompareSeptember 3, 2026 10:14
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
const epoch = (yield* Ref.get(controlEpochRef)).get(tabId) ?? 0;
const control = yield* ensureControlSession(wc);
const execute = Effect.fn("PreviewManager.executeControlAction")(function* () {
const requestedWc = yield* requireWebContents(tabId);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Mediumpreview/Manager.ts:1421

Automation requests that fail in requireWebContents or ensureControlSession leave a permanent running entry in actionTimeline, so later snapshots report an action that never completes. withControlSession records the event before those calls, but installs Effect.onExit(finalize) only around execute; install finalization around the entire operation (or otherwise finalize these early failures) so the entry becomes failed/interrupted.

🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/desktop/src/preview/Manager.ts around line 1421:
Automation requests that fail in `requireWebContents` or `ensureControlSession` leave a permanent `running` entry in `actionTimeline`, so later snapshots report an action that never completes. `withControlSession` records the event before those calls, but installs `Effect.onExit(finalize)` only around `execute`; install finalization around the entire operation (or otherwise finalize these early failures) so the entry becomes `failed`/`interrupted`.

@cursorcursorBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3755a33. Configure here.

if (tabs.has(tabId)) yield* update(tabId, { controller: "none" });
});
return yield* control.semaphore.withPermit(execute().pipe(Effect.onExit(finalize)));
return yield* control.semaphore.withPermit(execute(activeWc).pipe(Effect.onExit(finalize)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale webview used after re-ensure

Medium Severity

withControlSession re-reads the tab after the first ensureControlSession, then can await a second ensure and still pass the pre-await activeWc into execute. A swap (or the detach-before-publish window of the first swap) leaves click, type, and snapshot talking to a guest the tab no longer owns.

Fix in CursorFix in Web

Triggered by learned rule: PreviewManager: re-read tab state from tabsRef after mutations, don't use stale snapshots

Reviewed by Cursor Bugbot for commit 3755a33. Configure here.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L100-499 changed lines (additions + deletions).vouch:trustedPR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@gbarros-dev
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

fix(preview): keep snapshots slim unless the agent asks - #7302

Open
gbarros-dev wants to merge 13 commits into
pingdotgg:mainfrom
gbarros-dev:fix/preview-slim-snapshot
Open

fix(preview): keep snapshots slim unless the agent asks#7302
gbarros-dev wants to merge 13 commits into
pingdotgg:mainfrom
gbarros-dev:fix/preview-slim-snapshot

Conversation

@gbarros-dev

@gbarros-devgbarros-dev commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

preview_snapshot dumped the accessibility tree, console, and network on every inspect. preview_wait_for also matched sidebar chrome, so agents thought a page was ready when only a nav label matched.

Snapshots default to URL, main-landmark text, visible controls, and a PNG. AX, console, and network load only when include asks. Wait searches main by default and requires a visible locator.

Split out of closed#7127.

Tests: vp test run packages/contracts/src/preview.test.ts

Implemented with Grok 4.6 through Grok CLI.


Note

Medium Risk
Changes default MCP/desktop snapshot shape and debugger domain wiring; agents or integrations that assumed always-on diagnostics may break until they pass include.

Overview
Preview automation snapshots are slim by default.preview_snapshot and desktop IPC now accept optional include (ax, console, network); without it callers get URL, main-landmark visible text, interactive elements, action timeline, and PNG only. CDP accessibility, log, and network domains are enabled on demand per control session instead of on every attach.

preview_wait_for is scoped to real page content. Text and locator matching default to the main landmark (plus modal/overlay roots); optional scope: "document" searches the full page. Locator waits require visibility and skip dialog trigger slots.

Snapshot harvesting adds stable element ids, pointer-cursor table/layout nodes, and CDP screenshot fallback when capturePage fails. accessibilityTree is optional in the contract.

Breaking for consumers: anything expecting full AX/console/network on every snapshot must pass include.

Reviewed by Cursor Bugbot for commit 3755a33. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Make preview snapshots slim by default and scope preview_wait_for to main landmark

  • Snapshots now require explicit include values (ax, console, network) to return diagnostic data. Default snapshots omit the accessibility tree and return empty console and network arrays.
  • preview_wait_for defaults to the main landmark scope. It searches overlay roots, traverses shadow DOM, and ignores invisible elements unless scope is set to document.
  • Adds a CDP Page.captureScreenshot fallback to captureAutomationSnapshot when Electron's capturePage fails.
  • Refactors withControlSession in Manager.ts to resolve WebContents internally and re-check session validity before executing callbacks.
  • Behavioral Change: existing preview_wait_for calls relying on matches outside the main landmark or within invisible nodes will fail unless scope: "document" is passed.

Macroscope summarized 3755a33.

@coderabbitai

coderabbitaiBot commented Aug 17, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8834cb66-be84-4273-a921-43d3e4b089ce

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actionsgithub-actionsBot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Aug 17, 2026
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated

@macroscopeappmacroscopeappBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Effect service conventions review: two findings on the desktop preview snapshot path. Details inline.

Posted via Macroscope — Effect Service Conventions

Comment threadapps/desktop/src/preview/Manager.ts
Comment threadapps/desktop/src/preview/Manager.ts Outdated
@macroscopeapp

macroscopeappBot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This PR changes the default preview snapshot payload and wait_for matching behavior across the MCP, web, IPC, and desktop automation layers, rather than only adding an opt-in path. It also includes unresolved control-session lifecycle and stale-webview risks that require human assessment.

Not approved because:

  • 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity

Adjust the Minimum Blocking Severity for this repo — including turning it Off — in Settings. You can add or adjust custom eligibility rules. Learn more.

@gbarros-dev
gbarros-devforce-pushed the fix/preview-slim-snapshot branch from 47b1e15 to 88686c5CompareAugust 17, 2026 08:36
Comment threadapps/desktop/src/preview/Manager.ts
Comment threadapps/desktop/src/preview/Manager.ts Outdated
@gbarros-dev
gbarros-devforce-pushed the fix/preview-slim-snapshot branch from 149b56c to 3501c4dCompareSeptember 3, 2026 09:34
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts
Comment threadapps/desktop/src/preview/Manager.ts
preview_snapshot dumped the accessibility tree, console, and network on
every inspect. preview_wait_for also matched sidebar chrome, so agents
thought a page was ready when only a nav label matched.
Snapshots default to URL, main-landmark text, visible controls, and a
PNG. AX, console, and network load only when include asks. Wait searches
main by default and requires a visible locator.
Pointer-cursor div/td controls were never selected. An empty <main>
fell back to body text, leaking sidebar chrome. A failed capturePage
plus an empty CDP screenshot became a 0x0 image.
Snapshots now select those controls, keep empty main text empty, and
surface a typed capture failure. Tests cover the slim default, include
ax, wait scope, and the failed-screenshot path.
The new snapshot tests spread makeTestPreviewWebContents(), which is
typed as never. CI typecheck rejected that. The mocks are now a local
webview object.
Snapshots treated every div/td/tr with computed cursor:pointer as
clickable. Cursor inherits, so nested layout nodes filled the 200-cap
and hid real controls. Only the outermost pointer container is kept.
Skipping any layout node whose parent had cursor:pointer dropped whole
clickable areas when the pointer sat on li, section, label, or table.
Only a harvested ancestor (div/td/tr) now suppresses descendants.
Comment threadapps/desktop/src/preview/Manager.ts
@gbarros-dev
gbarros-devforce-pushed the fix/preview-slim-snapshot branch from 87f7dcc to a23b4f5CompareSeptember 3, 2026 10:14
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
const epoch = (yield* Ref.get(controlEpochRef)).get(tabId) ?? 0;
const control = yield* ensureControlSession(wc);
const execute = Effect.fn("PreviewManager.executeControlAction")(function* () {
const requestedWc = yield* requireWebContents(tabId);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Mediumpreview/Manager.ts:1421

Automation requests that fail in requireWebContents or ensureControlSession leave a permanent running entry in actionTimeline, so later snapshots report an action that never completes. withControlSession records the event before those calls, but installs Effect.onExit(finalize) only around execute; install finalization around the entire operation (or otherwise finalize these early failures) so the entry becomes failed/interrupted.

🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/desktop/src/preview/Manager.ts around line 1421:
Automation requests that fail in `requireWebContents` or `ensureControlSession` leave a permanent `running` entry in `actionTimeline`, so later snapshots report an action that never completes. `withControlSession` records the event before those calls, but installs `Effect.onExit(finalize)` only around `execute`; install finalization around the entire operation (or otherwise finalize these early failures) so the entry becomes `failed`/`interrupted`.

@cursorcursorBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3755a33. Configure here.

if (tabs.has(tabId)) yield* update(tabId, { controller: "none" });
});
return yield* control.semaphore.withPermit(execute().pipe(Effect.onExit(finalize)));
return yield* control.semaphore.withPermit(execute(activeWc).pipe(Effect.onExit(finalize)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale webview used after re-ensure

Medium Severity

withControlSession re-reads the tab after the first ensureControlSession, then can await a second ensure and still pass the pre-await activeWc into execute. A swap (or the detach-before-publish window of the first swap) leaves click, type, and snapshot talking to a guest the tab no longer owns.

Fix in CursorFix in Web

Triggered by learned rule: PreviewManager: re-read tab state from tabsRef after mutations, don't use stale snapshots

Reviewed by Cursor Bugbot for commit 3755a33. Configure here.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L100-499 changed lines (additions + deletions).vouch:trustedPR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@gbarros-dev
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

fix(preview): keep snapshots slim unless the agent asks - #7302

Open
gbarros-dev wants to merge 13 commits into
pingdotgg:mainfrom
gbarros-dev:fix/preview-slim-snapshot
Open

fix(preview): keep snapshots slim unless the agent asks#7302
gbarros-dev wants to merge 13 commits into
pingdotgg:mainfrom
gbarros-dev:fix/preview-slim-snapshot

Conversation

@gbarros-dev

@gbarros-devgbarros-dev commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

preview_snapshot dumped the accessibility tree, console, and network on every inspect. preview_wait_for also matched sidebar chrome, so agents thought a page was ready when only a nav label matched.

Snapshots default to URL, main-landmark text, visible controls, and a PNG. AX, console, and network load only when include asks. Wait searches main by default and requires a visible locator.

Split out of closed#7127.

Tests: vp test run packages/contracts/src/preview.test.ts

Implemented with Grok 4.6 through Grok CLI.


Note

Medium Risk
Changes default MCP/desktop snapshot shape and debugger domain wiring; agents or integrations that assumed always-on diagnostics may break until they pass include.

Overview
Preview automation snapshots are slim by default.preview_snapshot and desktop IPC now accept optional include (ax, console, network); without it callers get URL, main-landmark visible text, interactive elements, action timeline, and PNG only. CDP accessibility, log, and network domains are enabled on demand per control session instead of on every attach.

preview_wait_for is scoped to real page content. Text and locator matching default to the main landmark (plus modal/overlay roots); optional scope: "document" searches the full page. Locator waits require visibility and skip dialog trigger slots.

Snapshot harvesting adds stable element ids, pointer-cursor table/layout nodes, and CDP screenshot fallback when capturePage fails. accessibilityTree is optional in the contract.

Breaking for consumers: anything expecting full AX/console/network on every snapshot must pass include.

Reviewed by Cursor Bugbot for commit 3755a33. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Make preview snapshots slim by default and scope preview_wait_for to main landmark

  • Snapshots now require explicit include values (ax, console, network) to return diagnostic data. Default snapshots omit the accessibility tree and return empty console and network arrays.
  • preview_wait_for defaults to the main landmark scope. It searches overlay roots, traverses shadow DOM, and ignores invisible elements unless scope is set to document.
  • Adds a CDP Page.captureScreenshot fallback to captureAutomationSnapshot when Electron's capturePage fails.
  • Refactors withControlSession in Manager.ts to resolve WebContents internally and re-check session validity before executing callbacks.
  • Behavioral Change: existing preview_wait_for calls relying on matches outside the main landmark or within invisible nodes will fail unless scope: "document" is passed.

Macroscope summarized 3755a33.

@coderabbitai

coderabbitaiBot commented Aug 17, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8834cb66-be84-4273-a921-43d3e4b089ce

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actionsgithub-actionsBot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Aug 17, 2026
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated

@macroscopeappmacroscopeappBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Effect service conventions review: two findings on the desktop preview snapshot path. Details inline.

Posted via Macroscope — Effect Service Conventions

Comment threadapps/desktop/src/preview/Manager.ts
Comment threadapps/desktop/src/preview/Manager.ts Outdated
@macroscopeapp

macroscopeappBot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This PR changes the default preview snapshot payload and wait_for matching behavior across the MCP, web, IPC, and desktop automation layers, rather than only adding an opt-in path. It also includes unresolved control-session lifecycle and stale-webview risks that require human assessment.

Not approved because:

  • 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity

Adjust the Minimum Blocking Severity for this repo — including turning it Off — in Settings. You can add or adjust custom eligibility rules. Learn more.

@gbarros-dev
gbarros-devforce-pushed the fix/preview-slim-snapshot branch from 47b1e15 to 88686c5CompareAugust 17, 2026 08:36
Comment threadapps/desktop/src/preview/Manager.ts
Comment threadapps/desktop/src/preview/Manager.ts Outdated
@gbarros-dev
gbarros-devforce-pushed the fix/preview-slim-snapshot branch from 149b56c to 3501c4dCompareSeptember 3, 2026 09:34
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts
Comment threadapps/desktop/src/preview/Manager.ts
preview_snapshot dumped the accessibility tree, console, and network on
every inspect. preview_wait_for also matched sidebar chrome, so agents
thought a page was ready when only a nav label matched.
Snapshots default to URL, main-landmark text, visible controls, and a
PNG. AX, console, and network load only when include asks. Wait searches
main by default and requires a visible locator.
Pointer-cursor div/td controls were never selected. An empty <main>
fell back to body text, leaking sidebar chrome. A failed capturePage
plus an empty CDP screenshot became a 0x0 image.
Snapshots now select those controls, keep empty main text empty, and
surface a typed capture failure. Tests cover the slim default, include
ax, wait scope, and the failed-screenshot path.
The new snapshot tests spread makeTestPreviewWebContents(), which is
typed as never. CI typecheck rejected that. The mocks are now a local
webview object.
Snapshots treated every div/td/tr with computed cursor:pointer as
clickable. Cursor inherits, so nested layout nodes filled the 200-cap
and hid real controls. Only the outermost pointer container is kept.
Skipping any layout node whose parent had cursor:pointer dropped whole
clickable areas when the pointer sat on li, section, label, or table.
Only a harvested ancestor (div/td/tr) now suppresses descendants.
Comment threadapps/desktop/src/preview/Manager.ts
@gbarros-dev
gbarros-devforce-pushed the fix/preview-slim-snapshot branch from 87f7dcc to a23b4f5CompareSeptember 3, 2026 10:14
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
const epoch = (yield* Ref.get(controlEpochRef)).get(tabId) ?? 0;
const control = yield* ensureControlSession(wc);
const execute = Effect.fn("PreviewManager.executeControlAction")(function* () {
const requestedWc = yield* requireWebContents(tabId);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Mediumpreview/Manager.ts:1421

Automation requests that fail in requireWebContents or ensureControlSession leave a permanent running entry in actionTimeline, so later snapshots report an action that never completes. withControlSession records the event before those calls, but installs Effect.onExit(finalize) only around execute; install finalization around the entire operation (or otherwise finalize these early failures) so the entry becomes failed/interrupted.

🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/desktop/src/preview/Manager.ts around line 1421:
Automation requests that fail in `requireWebContents` or `ensureControlSession` leave a permanent `running` entry in `actionTimeline`, so later snapshots report an action that never completes. `withControlSession` records the event before those calls, but installs `Effect.onExit(finalize)` only around `execute`; install finalization around the entire operation (or otherwise finalize these early failures) so the entry becomes `failed`/`interrupted`.

@cursorcursorBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3755a33. Configure here.

if (tabs.has(tabId)) yield* update(tabId, { controller: "none" });
});
return yield* control.semaphore.withPermit(execute().pipe(Effect.onExit(finalize)));
return yield* control.semaphore.withPermit(execute(activeWc).pipe(Effect.onExit(finalize)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale webview used after re-ensure

Medium Severity

withControlSession re-reads the tab after the first ensureControlSession, then can await a second ensure and still pass the pre-await activeWc into execute. A swap (or the detach-before-publish window of the first swap) leaves click, type, and snapshot talking to a guest the tab no longer owns.

Fix in CursorFix in Web

Triggered by learned rule: PreviewManager: re-read tab state from tabsRef after mutations, don't use stale snapshots

Reviewed by Cursor Bugbot for commit 3755a33. Configure here.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L100-499 changed lines (additions + deletions).vouch:trustedPR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@gbarros-dev
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

fix(preview): keep snapshots slim unless the agent asks - #7302

Open
gbarros-dev wants to merge 13 commits into
pingdotgg:mainfrom
gbarros-dev:fix/preview-slim-snapshot
Open

fix(preview): keep snapshots slim unless the agent asks#7302
gbarros-dev wants to merge 13 commits into
pingdotgg:mainfrom
gbarros-dev:fix/preview-slim-snapshot

Conversation

@gbarros-dev

@gbarros-devgbarros-dev commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

preview_snapshot dumped the accessibility tree, console, and network on every inspect. preview_wait_for also matched sidebar chrome, so agents thought a page was ready when only a nav label matched.

Snapshots default to URL, main-landmark text, visible controls, and a PNG. AX, console, and network load only when include asks. Wait searches main by default and requires a visible locator.

Split out of closed#7127.

Tests: vp test run packages/contracts/src/preview.test.ts

Implemented with Grok 4.6 through Grok CLI.


Note

Medium Risk
Changes default MCP/desktop snapshot shape and debugger domain wiring; agents or integrations that assumed always-on diagnostics may break until they pass include.

Overview
Preview automation snapshots are slim by default.preview_snapshot and desktop IPC now accept optional include (ax, console, network); without it callers get URL, main-landmark visible text, interactive elements, action timeline, and PNG only. CDP accessibility, log, and network domains are enabled on demand per control session instead of on every attach.

preview_wait_for is scoped to real page content. Text and locator matching default to the main landmark (plus modal/overlay roots); optional scope: "document" searches the full page. Locator waits require visibility and skip dialog trigger slots.

Snapshot harvesting adds stable element ids, pointer-cursor table/layout nodes, and CDP screenshot fallback when capturePage fails. accessibilityTree is optional in the contract.

Breaking for consumers: anything expecting full AX/console/network on every snapshot must pass include.

Reviewed by Cursor Bugbot for commit 3755a33. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Make preview snapshots slim by default and scope preview_wait_for to main landmark

  • Snapshots now require explicit include values (ax, console, network) to return diagnostic data. Default snapshots omit the accessibility tree and return empty console and network arrays.
  • preview_wait_for defaults to the main landmark scope. It searches overlay roots, traverses shadow DOM, and ignores invisible elements unless scope is set to document.
  • Adds a CDP Page.captureScreenshot fallback to captureAutomationSnapshot when Electron's capturePage fails.
  • Refactors withControlSession in Manager.ts to resolve WebContents internally and re-check session validity before executing callbacks.
  • Behavioral Change: existing preview_wait_for calls relying on matches outside the main landmark or within invisible nodes will fail unless scope: "document" is passed.

Macroscope summarized 3755a33.

@coderabbitai

coderabbitaiBot commented Aug 17, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8834cb66-be84-4273-a921-43d3e4b089ce

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actionsgithub-actionsBot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Aug 17, 2026
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated

@macroscopeappmacroscopeappBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Effect service conventions review: two findings on the desktop preview snapshot path. Details inline.

Posted via Macroscope — Effect Service Conventions

Comment threadapps/desktop/src/preview/Manager.ts
Comment threadapps/desktop/src/preview/Manager.ts Outdated
@macroscopeapp

macroscopeappBot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This PR changes the default preview snapshot payload and wait_for matching behavior across the MCP, web, IPC, and desktop automation layers, rather than only adding an opt-in path. It also includes unresolved control-session lifecycle and stale-webview risks that require human assessment.

Not approved because:

  • 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity

Adjust the Minimum Blocking Severity for this repo — including turning it Off — in Settings. You can add or adjust custom eligibility rules. Learn more.

@gbarros-dev
gbarros-devforce-pushed the fix/preview-slim-snapshot branch from 47b1e15 to 88686c5CompareAugust 17, 2026 08:36
Comment threadapps/desktop/src/preview/Manager.ts
Comment threadapps/desktop/src/preview/Manager.ts Outdated
@gbarros-dev
gbarros-devforce-pushed the fix/preview-slim-snapshot branch from 149b56c to 3501c4dCompareSeptember 3, 2026 09:34
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts
Comment threadapps/desktop/src/preview/Manager.ts
preview_snapshot dumped the accessibility tree, console, and network on
every inspect. preview_wait_for also matched sidebar chrome, so agents
thought a page was ready when only a nav label matched.
Snapshots default to URL, main-landmark text, visible controls, and a
PNG. AX, console, and network load only when include asks. Wait searches
main by default and requires a visible locator.
Pointer-cursor div/td controls were never selected. An empty <main>
fell back to body text, leaking sidebar chrome. A failed capturePage
plus an empty CDP screenshot became a 0x0 image.
Snapshots now select those controls, keep empty main text empty, and
surface a typed capture failure. Tests cover the slim default, include
ax, wait scope, and the failed-screenshot path.
The new snapshot tests spread makeTestPreviewWebContents(), which is
typed as never. CI typecheck rejected that. The mocks are now a local
webview object.
Snapshots treated every div/td/tr with computed cursor:pointer as
clickable. Cursor inherits, so nested layout nodes filled the 200-cap
and hid real controls. Only the outermost pointer container is kept.
Skipping any layout node whose parent had cursor:pointer dropped whole
clickable areas when the pointer sat on li, section, label, or table.
Only a harvested ancestor (div/td/tr) now suppresses descendants.
Comment threadapps/desktop/src/preview/Manager.ts
@gbarros-dev
gbarros-devforce-pushed the fix/preview-slim-snapshot branch from 87f7dcc to a23b4f5CompareSeptember 3, 2026 10:14
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
Comment threadapps/desktop/src/preview/Manager.ts Outdated
const epoch = (yield* Ref.get(controlEpochRef)).get(tabId) ?? 0;
const control = yield* ensureControlSession(wc);
const execute = Effect.fn("PreviewManager.executeControlAction")(function* () {
const requestedWc = yield* requireWebContents(tabId);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Mediumpreview/Manager.ts:1421

Automation requests that fail in requireWebContents or ensureControlSession leave a permanent running entry in actionTimeline, so later snapshots report an action that never completes. withControlSession records the event before those calls, but installs Effect.onExit(finalize) only around execute; install finalization around the entire operation (or otherwise finalize these early failures) so the entry becomes failed/interrupted.

🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/desktop/src/preview/Manager.ts around line 1421:
Automation requests that fail in `requireWebContents` or `ensureControlSession` leave a permanent `running` entry in `actionTimeline`, so later snapshots report an action that never completes. `withControlSession` records the event before those calls, but installs `Effect.onExit(finalize)` only around `execute`; install finalization around the entire operation (or otherwise finalize these early failures) so the entry becomes `failed`/`interrupted`.

@cursorcursorBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3755a33. Configure here.

if (tabs.has(tabId)) yield* update(tabId, { controller: "none" });
});
return yield* control.semaphore.withPermit(execute().pipe(Effect.onExit(finalize)));
return yield* control.semaphore.withPermit(execute(activeWc).pipe(Effect.onExit(finalize)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale webview used after re-ensure

Medium Severity

withControlSession re-reads the tab after the first ensureControlSession, then can await a second ensure and still pass the pre-await activeWc into execute. A swap (or the detach-before-publish window of the first swap) leaves click, type, and snapshot talking to a guest the tab no longer owns.

Fix in CursorFix in Web

Triggered by learned rule: PreviewManager: re-read tab state from tabsRef after mutations, don't use stale snapshots

Reviewed by Cursor Bugbot for commit 3755a33. Configure here.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L100-499 changed lines (additions + deletions).vouch:trustedPR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@gbarros-dev