Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

Fix research delegation blocked by background page updates

Barack Sokullu9bac249069ee
diff --git a/docs/page-feedback-monitor.md b/docs/page-feedback-monitor.md
index f571defb8..ff728dd5e 100644
--- a/docs/page-feedback-monitor.md
+++ b/docs/page-feedback-monitor.md
@@ -369,6 +369,13 @@ Steer or grant authorization. Enter and Alt+Enter retain their existing behavior
private footprint revalidates proceed; legacy AX targets without a footprint
proceed only for DOM changes. Coordinates, scripts and unbound actions stay
fenced. An automatic child-document replacement unbinds only that frame.
+- Research delegation is independent of the source page's DOM. Background updates
+ during inference, refresh or preparation retain the proposed handoff. The handler
+ still validates and consumes a one-use authorization for the exact approved
+ prompt, scoped to its tab and conversation with a five-minute expiry. A suppressed
+ proposal leaves the authorization unused, so a continuation can use it while
+ valid. User intervention, main-frame navigation and top-level viewport changes
+ still require a fresh decision; delegation keeps its state-changing accounting.
- An agent click explains a same-document route update in its own frame within
three seconds when no user activity followed it; full-document navigation
keeps the exact-URL rule.
diff --git a/package.json b/package.json
index 2ca30c996..dc5397492 100644
--- a/package.json
+++ b/package.json
@@ -61,8 +61,8 @@
"benchmark:relevance": "node scripts/benchmark-offline-relevance.mjs --verbose",
"test:social-contract": "node --test test/social-publish-contract.mjs test/publication-quote-markup.mjs",
"test:social-contract:dom": "node test/social-publish-contract-dom.mjs",
- "test:runtime-lifecycle": "node test/bot-memory-dom.mjs && node --test test/agent-lifecycle.mjs test/runtime-startup.mjs test/run-ui-scheduled-lifecycle.mjs test/transport-deadlines.mjs test/cdp-worker-restart.mjs test/bot-memory.mjs test/bot-memory-registries.mjs test/bot-memory-cloud-controller.mjs test/cdp-clear-receipt.mjs test/cdp-field-submit-recovery.mjs test/conversation-persistence.mjs test/history-recovery-state.mjs test/history-recovery-scheduler.mjs test/history-recovery-atomic.mjs test/context-live-tool-group.mjs test/integration-races.mjs test/watch-completion-checkpoint.mjs test/runtime-model-identity.mjs test/provider-message-privacy.mjs test/runtime-task-authority.mjs test/planner-repair-authority.mjs test/runtime-progress-continuation.mjs test/chat-resume-chain.mjs test/chat-resume-completion.mjs test/native-chat-execution-ledger.mjs test/chat-send-dispatch-result.mjs test/chat-reply-dedup-race.mjs test/memcode-lifecycle.mjs test/runtime-peer-review.mjs test/read-continuation-schema.mjs test/completion-submit-acknowledgement.mjs test/completion-live-status.mjs test/completion-iframe-submit.mjs test/form-validation-alert-readings.mjs test/control-effect-readings.mjs test/trusted-retry-readings.mjs test/completion-semantic-commit.mjs test/completion-diagnostics.mjs test/mastodon-publication.mjs test/calculator.mjs test/chat-recovery-protocol.mjs test/chat-pending-reconciliation.mjs test/semantic-page-retry.mjs test/pdf-detection.mjs test/runtime-lifecycle.mjs test/collection-read-progress.mjs test/network-lifecycle.mjs test/text-write-cancellation.mjs test/trusted-field-preparation.mjs test/draftjs-text.mjs test/rich-text-frameworks.mjs test/cdp-managed-text-selection.mjs test/firefox-rich-text-readback.mjs test/contenteditable-beforeinput.mjs test/trusted-field-preparation-ownership.mjs test/typing-preparation-geometry.mjs test/chat-steering.mjs test/lifecycle-steering-restart.mjs test/resource-mutation-guards.mjs test/completion-steering-receipt-authority.mjs test/steering-revision-recovery.mjs test/pending-clarification-hydration.mjs test/permission-steering-wakeup.mjs test/pure-calculation-reply.mjs test/pure-calculation-tools.mjs test/page-feedback.mjs test/page-feedback-progress.mjs test/ask-response-scope.mjs test/ask-completion-churn.mjs test/page-feedback-policy.mjs test/page-feedback-transport-races.mjs test/page-feedback-recovery.mjs test/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/code-scanning-url-recipient.mjs test/apocalypse-comm-parsing.mjs test/apocalypse-scalar-decoding.mjs test/bitgpu-chat-security.mjs test/social-media-url-upgrades.mjs test/downloaded-file-saved-bytes.mjs test/downloaded-file-local-probe.mjs test/formless-verification-recovery.mjs test/file-upload-accept.mjs test/file-upload-accept-agent.mjs test/workflow-route-generic-completion.mjs test/release-publication-completion.mjs test/workflow-implicit-metadata.mjs test/workflow-field-readings.mjs test/workflow-field-anchors.mjs test/user-turn-kind.mjs test/follow-up-task-context.mjs test/completion-current-execution-evidence.mjs test/monitor-intervention-contract.mjs test/monitor-owned-geometry.mjs test/monitor-viewport-remainder.mjs test/monitor-local-attribution.mjs test/monitor-lifecycle-leaks.mjs test/feedback-automatic-churn.mjs test/feedback-navigation-idle.mjs test/feedback-run-boundaries.mjs test/feedback-ask-viewing.mjs test/lifecycle-terminal-done.mjs test/lifecycle-planner-digest.mjs test/lifecycle-vision-fallback.mjs test/guards-control-classification.mjs test/guards-unbound-deletion.mjs test/guards-steering-receipts.mjs && node test/ui-content-lifecycle.mjs && node --test test/native-telegram-chat.mjs test/native-telegram-recipient.mjs test/telegram-native-baseline.mjs test/telegram-native-latest.mjs test/native-chat-pre-enter-draft.mjs test/chat-draft-dispatch-ownership.mjs test/native-telegram-alias-preparation.mjs test/telegram-read-preparation-content.mjs test/queued-composer-ownership.mjs test/onboarding-provider-ready.mjs test/workflow-native-targets.mjs test/native-whatsapp-chat.mjs test/native-chat-context-identity.mjs test/native-whatsapp-contact.mjs test/whatsapp-native-bootstrap.mjs test/whatsapp-drawer-identity.mjs test/whatsapp-read-latest.mjs test/whatsapp-read-preparation.mjs test/whatsapp-chat-completion.mjs test/whatsapp-chat-restart.mjs test/chat-goal-lifecycle.mjs test/chat-completion.mjs test/chat-generic-dispatch.mjs test/completion-live-status-browser.mjs test/native-confirmation-visibility.mjs test/read-continuation-browser.mjs test/iframe-preparation-focus.mjs test/contenteditable-literal.mjs test/native-chat-empty-editor.mjs test/native-chat-trusted-clear.mjs test/chat-steering-ui.mjs test/recipient-confirmation-ui.mjs test/assistant-message-visibility-ui.mjs test/history-recovery.mjs test/history-recovery-ui.mjs test/page-monitor-ui.mjs test/page-monitor-dialog.mjs test/page-monitor-dialog-native.mjs test/page-monitor-inline-post.mjs test/bluesky-composer-context.mjs test/page-monitor-anchored.mjs test/page-monitor-upload-owner.mjs test/page-monitor-upload-release.mjs test/page-monitor-native-controls.mjs test/page-monitor-native-preparation.mjs test/native-preparation-cold.mjs test/page-monitor-navigation.mjs test/page-monitor-main-owner.mjs test/page-monitor-collateral-controls.mjs test/accessibility-tree-scoped-budget.mjs test/ax-reference-origin.mjs test/page-monitor-decorative-hit.mjs test/social-ui-navigation.mjs test/native-resource-deletion-binding.mjs test/native-mastodon-confirmation.mjs test/dropdown-menu-inventory.mjs test/page-monitor-passive-progress.mjs test/page-monitor-feed-items.mjs test/media-download-binding.mjs test/media-download-capture-integration.mjs test/social-media-downloader-reinjection.mjs test/upload-file-local-state-guidance.mjs && node test/message-recipient-upload.mjs && node test/message-recipient-clarify-binding.mjs && node --test test/message-recipient-whatsapp.mjs test/message-control-readings.mjs && node test/quality/integration-mv3.mjs --full-form && node test/quality/literal-calculate-midrun-mv3.mjs && node test/quality/ask-completion-churn-mv3.mjs && node test/quality/ask-person-activity-mv3.mjs && node test/quality/telegram-cold-preparation-mv3.mjs && node test/quality/native-chat-mv3.mjs && node test/quality/native-chat-presubmit-mv3.mjs && node test/quality/cloud-bot-memory-mv3.mjs && node test/quality/whatsapp-contact-matrix.mjs && node test/quality/pdf-detection-mv3.mjs && node test/quality/download-upload-mv3.mjs && node test/quality/upload-release-binding-mv3.mjs && node test/quality/release-review-world-mv3.mjs && node test/quality/downloaded-file-saved-bytes-mv3.mjs && node test/quality/file-upload-accept-mv3.mjs && node test/quality/bulk-resume-mv3.mjs && node test/quality/literal-frame-mv3.mjs && node test/quality/mastodon-publication-mv3.mjs && node test/quality/mastodon-deletion-mv3.mjs && node test/quality/mastodon-delete-confirmation-mv3.mjs && node test/quality/mastodon-delete-confirmation-mv3.mjs --menu-read && node test/quality/mastodon-delete-confirmation-mv3.mjs --vague && node test/quality/unbound-deletion-mv3.mjs && node test/quality/recipient-clarify-mv3.mjs && node test/quality/open-chat-recipients-mv3.mjs && node test/quality/correction-cross-site-mv3.mjs && node test/quality/anchored-action-mv3.mjs && node test/quality/inline-social-composer-mv3.mjs && node test/quality/bluesky-composer-mv3.mjs && node test/quality/dropdown-menu-matrix.mjs && node test/quality/mastodon-deletion-navigation-mv3.mjs && node test/quality/semantic-navigation-matrix.mjs && node test/quality/workflow-replay-mv3.mjs && node test/quality/generative-media-mv3.mjs && node test/quality/cdp-worker-restart-mv3.mjs && node test/quality/steering-worker-restart-mv3.mjs",
- "test:page-feedback": "node --test test/trusted-field-preparation.mjs test/draftjs-text.mjs test/rich-text-frameworks.mjs test/cdp-managed-text-selection.mjs test/firefox-rich-text-readback.mjs test/contenteditable-beforeinput.mjs test/trusted-field-preparation-ownership.mjs test/typing-preparation-geometry.mjs test/pure-calculation-reply.mjs test/pure-calculation-tools.mjs test/page-feedback.mjs test/page-feedback-progress.mjs test/ask-response-scope.mjs test/ask-completion-churn.mjs test/page-feedback-policy.mjs test/page-feedback-transport-races.mjs test/page-feedback-recovery.mjs test/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/page-monitor-ui.mjs test/page-monitor-dialog.mjs test/page-monitor-dialog-native.mjs test/page-monitor-inline-post.mjs test/bluesky-composer-context.mjs test/page-monitor-anchored.mjs test/page-monitor-upload-owner.mjs test/page-monitor-upload-release.mjs test/page-monitor-native-controls.mjs test/page-monitor-passive-progress.mjs test/page-monitor-feed-items.mjs test/media-download-binding.mjs test/media-download-capture-integration.mjs test/monitor-intervention-contract.mjs test/monitor-owned-geometry.mjs test/monitor-viewport-remainder.mjs test/monitor-local-attribution.mjs test/monitor-lifecycle-leaks.mjs test/feedback-automatic-churn.mjs test/feedback-navigation-idle.mjs test/feedback-run-boundaries.mjs test/feedback-ask-viewing.mjs test/delivery-click-ax-response-loss.mjs test/delivery-stop-compound.mjs test/delivery-cdp-input.mjs test/delivery-click-locks.mjs test/delivery-native-button-geometry.mjs test/delivery-hover-transition.mjs test/delivery-dispatch-boundary.mjs && node test/message-recipient-upload.mjs && node test/message-recipient-clarify-binding.mjs && node --test test/message-recipient-whatsapp.mjs",
+ "test:runtime-lifecycle": "node test/bot-memory-dom.mjs && node --test test/agent-lifecycle.mjs test/runtime-startup.mjs test/run-ui-scheduled-lifecycle.mjs test/transport-deadlines.mjs test/cdp-worker-restart.mjs test/bot-memory.mjs test/bot-memory-registries.mjs test/bot-memory-cloud-controller.mjs test/cdp-clear-receipt.mjs test/cdp-field-submit-recovery.mjs test/conversation-persistence.mjs test/history-recovery-state.mjs test/history-recovery-scheduler.mjs test/history-recovery-atomic.mjs test/context-live-tool-group.mjs test/integration-races.mjs test/watch-completion-checkpoint.mjs test/runtime-model-identity.mjs test/provider-message-privacy.mjs test/runtime-task-authority.mjs test/planner-repair-authority.mjs test/runtime-progress-continuation.mjs test/chat-resume-chain.mjs test/chat-resume-completion.mjs test/native-chat-execution-ledger.mjs test/chat-send-dispatch-result.mjs test/chat-reply-dedup-race.mjs test/memcode-lifecycle.mjs test/runtime-peer-review.mjs test/read-continuation-schema.mjs test/completion-submit-acknowledgement.mjs test/completion-live-status.mjs test/completion-iframe-submit.mjs test/form-validation-alert-readings.mjs test/control-effect-readings.mjs test/trusted-retry-readings.mjs test/completion-semantic-commit.mjs test/completion-diagnostics.mjs test/mastodon-publication.mjs test/calculator.mjs test/chat-recovery-protocol.mjs test/chat-pending-reconciliation.mjs test/semantic-page-retry.mjs test/pdf-detection.mjs test/runtime-lifecycle.mjs test/collection-read-progress.mjs test/network-lifecycle.mjs test/text-write-cancellation.mjs test/trusted-field-preparation.mjs test/draftjs-text.mjs test/rich-text-frameworks.mjs test/cdp-managed-text-selection.mjs test/firefox-rich-text-readback.mjs test/contenteditable-beforeinput.mjs test/trusted-field-preparation-ownership.mjs test/typing-preparation-geometry.mjs test/chat-steering.mjs test/lifecycle-steering-restart.mjs test/resource-mutation-guards.mjs test/completion-steering-receipt-authority.mjs test/steering-revision-recovery.mjs test/pending-clarification-hydration.mjs test/permission-steering-wakeup.mjs test/pure-calculation-reply.mjs test/pure-calculation-tools.mjs test/page-feedback.mjs test/page-feedback-progress.mjs test/ask-response-scope.mjs test/ask-completion-churn.mjs test/page-feedback-policy.mjs test/research-escalation-page-feedback.mjs test/page-feedback-transport-races.mjs test/page-feedback-recovery.mjs test/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/code-scanning-url-recipient.mjs test/apocalypse-comm-parsing.mjs test/apocalypse-scalar-decoding.mjs test/bitgpu-chat-security.mjs test/social-media-url-upgrades.mjs test/downloaded-file-saved-bytes.mjs test/downloaded-file-local-probe.mjs test/formless-verification-recovery.mjs test/file-upload-accept.mjs test/file-upload-accept-agent.mjs test/workflow-route-generic-completion.mjs test/release-publication-completion.mjs test/workflow-implicit-metadata.mjs test/workflow-field-readings.mjs test/workflow-field-anchors.mjs test/user-turn-kind.mjs test/follow-up-task-context.mjs test/completion-current-execution-evidence.mjs test/monitor-intervention-contract.mjs test/monitor-owned-geometry.mjs test/monitor-viewport-remainder.mjs test/monitor-local-attribution.mjs test/monitor-lifecycle-leaks.mjs test/feedback-automatic-churn.mjs test/feedback-navigation-idle.mjs test/feedback-run-boundaries.mjs test/feedback-ask-viewing.mjs test/lifecycle-terminal-done.mjs test/lifecycle-planner-digest.mjs test/lifecycle-vision-fallback.mjs test/guards-control-classification.mjs test/guards-unbound-deletion.mjs test/guards-steering-receipts.mjs && node test/ui-content-lifecycle.mjs && node --test test/native-telegram-chat.mjs test/native-telegram-recipient.mjs test/telegram-native-baseline.mjs test/telegram-native-latest.mjs test/native-chat-pre-enter-draft.mjs test/chat-draft-dispatch-ownership.mjs test/native-telegram-alias-preparation.mjs test/telegram-read-preparation-content.mjs test/queued-composer-ownership.mjs test/onboarding-provider-ready.mjs test/workflow-native-targets.mjs test/native-whatsapp-chat.mjs test/native-chat-context-identity.mjs test/native-whatsapp-contact.mjs test/whatsapp-native-bootstrap.mjs test/whatsapp-drawer-identity.mjs test/whatsapp-read-latest.mjs test/whatsapp-read-preparation.mjs test/whatsapp-chat-completion.mjs test/whatsapp-chat-restart.mjs test/chat-goal-lifecycle.mjs test/chat-completion.mjs test/chat-generic-dispatch.mjs test/completion-live-status-browser.mjs test/native-confirmation-visibility.mjs test/read-continuation-browser.mjs test/iframe-preparation-focus.mjs test/contenteditable-literal.mjs test/native-chat-empty-editor.mjs test/native-chat-trusted-clear.mjs test/chat-steering-ui.mjs test/recipient-confirmation-ui.mjs test/assistant-message-visibility-ui.mjs test/history-recovery.mjs test/history-recovery-ui.mjs test/page-monitor-ui.mjs test/page-monitor-dialog.mjs test/page-monitor-dialog-native.mjs test/page-monitor-inline-post.mjs test/bluesky-composer-context.mjs test/page-monitor-anchored.mjs test/page-monitor-upload-owner.mjs test/page-monitor-upload-release.mjs test/page-monitor-native-controls.mjs test/page-monitor-native-preparation.mjs test/native-preparation-cold.mjs test/page-monitor-navigation.mjs test/page-monitor-main-owner.mjs test/page-monitor-collateral-controls.mjs test/accessibility-tree-scoped-budget.mjs test/ax-reference-origin.mjs test/page-monitor-decorative-hit.mjs test/social-ui-navigation.mjs test/native-resource-deletion-binding.mjs test/native-mastodon-confirmation.mjs test/dropdown-menu-inventory.mjs test/page-monitor-passive-progress.mjs test/page-monitor-feed-items.mjs test/media-download-binding.mjs test/media-download-capture-integration.mjs test/social-media-downloader-reinjection.mjs test/upload-file-local-state-guidance.mjs && node test/message-recipient-upload.mjs && node test/message-recipient-clarify-binding.mjs && node --test test/message-recipient-whatsapp.mjs test/message-control-readings.mjs && node test/quality/integration-mv3.mjs --full-form && node test/quality/literal-calculate-midrun-mv3.mjs && node test/quality/ask-completion-churn-mv3.mjs && node test/quality/ask-person-activity-mv3.mjs && node test/quality/telegram-cold-preparation-mv3.mjs && node test/quality/native-chat-mv3.mjs && node test/quality/native-chat-presubmit-mv3.mjs && node test/quality/cloud-bot-memory-mv3.mjs && node test/quality/whatsapp-contact-matrix.mjs && node test/quality/pdf-detection-mv3.mjs && node test/quality/download-upload-mv3.mjs && node test/quality/upload-release-binding-mv3.mjs && node test/quality/release-review-world-mv3.mjs && node test/quality/downloaded-file-saved-bytes-mv3.mjs && node test/quality/file-upload-accept-mv3.mjs && node test/quality/bulk-resume-mv3.mjs && node test/quality/literal-frame-mv3.mjs && node test/quality/mastodon-publication-mv3.mjs && node test/quality/mastodon-deletion-mv3.mjs && node test/quality/mastodon-delete-confirmation-mv3.mjs && node test/quality/mastodon-delete-confirmation-mv3.mjs --menu-read && node test/quality/mastodon-delete-confirmation-mv3.mjs --vague && node test/quality/unbound-deletion-mv3.mjs && node test/quality/recipient-clarify-mv3.mjs && node test/quality/open-chat-recipients-mv3.mjs && node test/quality/correction-cross-site-mv3.mjs && node test/quality/anchored-action-mv3.mjs && node test/quality/inline-social-composer-mv3.mjs && node test/quality/bluesky-composer-mv3.mjs && node test/quality/dropdown-menu-matrix.mjs && node test/quality/mastodon-deletion-navigation-mv3.mjs && node test/quality/semantic-navigation-matrix.mjs && node test/quality/workflow-replay-mv3.mjs && node test/quality/generative-media-mv3.mjs && node test/quality/cdp-worker-restart-mv3.mjs && node test/quality/steering-worker-restart-mv3.mjs",
+ "test:page-feedback": "node --test test/trusted-field-preparation.mjs test/draftjs-text.mjs test/rich-text-frameworks.mjs test/cdp-managed-text-selection.mjs test/firefox-rich-text-readback.mjs test/contenteditable-beforeinput.mjs test/trusted-field-preparation-ownership.mjs test/typing-preparation-geometry.mjs test/pure-calculation-reply.mjs test/pure-calculation-tools.mjs test/page-feedback.mjs test/page-feedback-progress.mjs test/ask-response-scope.mjs test/ask-completion-churn.mjs test/page-feedback-policy.mjs test/research-escalation-page-feedback.mjs test/page-feedback-transport-races.mjs test/page-feedback-recovery.mjs test/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/page-monitor-ui.mjs test/page-monitor-dialog.mjs test/page-monitor-dialog-native.mjs test/page-monitor-inline-post.mjs test/bluesky-composer-context.mjs test/page-monitor-anchored.mjs test/page-monitor-upload-owner.mjs test/page-monitor-upload-release.mjs test/page-monitor-native-controls.mjs test/page-monitor-passive-progress.mjs test/page-monitor-feed-items.mjs test/media-download-binding.mjs test/media-download-capture-integration.mjs test/monitor-intervention-contract.mjs test/monitor-owned-geometry.mjs test/monitor-viewport-remainder.mjs test/monitor-local-attribution.mjs test/monitor-lifecycle-leaks.mjs test/feedback-automatic-churn.mjs test/feedback-navigation-idle.mjs test/feedback-run-boundaries.mjs test/feedback-ask-viewing.mjs test/delivery-click-ax-response-loss.mjs test/delivery-stop-compound.mjs test/delivery-cdp-input.mjs test/delivery-click-locks.mjs test/delivery-native-button-geometry.mjs test/delivery-hover-transition.mjs test/delivery-dispatch-boundary.mjs && node test/message-recipient-upload.mjs && node test/message-recipient-clarify-binding.mjs && node --test test/message-recipient-whatsapp.mjs",
"test:history-recovery": "node --test test/history-recovery.mjs test/history-recovery-ui.mjs test/history-recovery-state.mjs test/history-recovery-scheduler.mjs test/history-recovery-atomic.mjs test/conversation-persistence.mjs",
"test:chat-steering": "node --test test/chat-steering.mjs test/chat-steering-ui.mjs test/recipient-confirmation-ui.mjs test/lifecycle-steering-latency.mjs test/lifecycle-steering-restart.mjs test/lifecycle-run-ui.mjs test/lifecycle-menu-prompts-held.mjs",
"test:rich-text-dom": "node test/ui-content-lifecycle.mjs --dom",
@@ -95,7 +95,7 @@
"test:chat-draft-recovery": "node --test test/native-chat-pre-enter-draft.mjs test/chat-draft-dispatch-ownership.mjs && node test/quality/native-chat-presubmit-mv3.mjs",
"test:upload-owner": "node --test test/page-monitor-upload-owner.mjs test/page-monitor-upload-release.mjs",
"test:shard:quick": "npm run test:cms && npm run test:markdown && npm run test:generative-media && npm run test:systemone && npm run test:systemone:fast && node --test test/browser-dialogs.mjs test/capsolver-cloud-broker.mjs test/captcha-providers.mjs test/captcha-weighted-fallback.mjs test/captcha-hcaptcha-providers.mjs test/captcha-native-providers.mjs test/captcha-runtime-policy.mjs test/captcha-callback-bridge.mjs test/captcha-bridge-registration.mjs test/captcha-aws-recovery.mjs test/captcha-documented-contracts.mjs test/huggingface-signup-recovery.mjs test/trace-full-export.mjs test/feedback-traces.mjs && npm run test:firefox-bidi && npm run test:billing-notice && npm run test:compass-quota && npm run test:provider-limits && npm run test:provider-catalog && npm run test:provider-instances:ui && npm run test:openrouter-capabilities && npm run test:anthropic && npm run test:browser-batch && npm run test:accessibility-tree-benchmark && npm run test:toolbar-guard && npm run test:cloud-bridge-approval && npm run test:discord && npm run test:pdf-read && npm run test:pdf-selection && npm run test:social-contract && npm run test:safesocial && npm run test:build-unpacked && npm run test:attachment-drop && npm run test:workflow-editor && node --test test/profile-sync-stats.mjs && node --test test/memcode-recall.mjs",
- "test:shard:runtime-unit": "node --test test/skill-download-wait.mjs && node --test test/agent-lifecycle.mjs test/runtime-startup.mjs test/run-ui-scheduled-lifecycle.mjs test/transport-deadlines.mjs test/cdp-worker-restart.mjs test/bot-memory.mjs test/bot-memory-click-guard.mjs test/bot-memory-registries.mjs test/bot-memory-cloud-controller.mjs test/cdp-clear-receipt.mjs test/cdp-field-submit-recovery.mjs test/conversation-persistence.mjs test/context-live-tool-group.mjs test/integration-races.mjs test/watch-completion-checkpoint.mjs test/runtime-model-identity.mjs test/provider-message-privacy.mjs test/runtime-task-authority.mjs test/planner-repair-authority.mjs test/runtime-progress-continuation.mjs test/chat-resume-chain.mjs test/chat-resume-completion.mjs test/native-chat-execution-ledger.mjs test/chat-send-dispatch-result.mjs test/chat-reply-dedup-race.mjs test/memcode-lifecycle.mjs test/runtime-peer-review.mjs test/read-continuation-schema.mjs test/completion-submit-acknowledgement.mjs test/completion-live-status.mjs test/completion-iframe-submit.mjs test/form-validation-alert-readings.mjs test/control-effect-readings.mjs test/trusted-retry-readings.mjs test/completion-semantic-commit.mjs test/completion-diagnostics.mjs test/mastodon-publication.mjs test/calculator.mjs test/chat-recovery-protocol.mjs test/chat-pending-reconciliation.mjs test/semantic-page-retry.mjs test/pdf-detection.mjs test/runtime-lifecycle.mjs test/collection-read-progress.mjs test/network-lifecycle.mjs test/text-write-cancellation.mjs test/trusted-field-preparation.mjs test/draftjs-text.mjs test/rich-text-frameworks.mjs test/cdp-managed-text-selection.mjs test/firefox-rich-text-readback.mjs test/contenteditable-beforeinput.mjs test/trusted-field-preparation-ownership.mjs test/typing-preparation-geometry.mjs test/chat-steering.mjs test/resource-mutation-guards.mjs test/completion-steering-receipt-authority.mjs test/steering-revision-recovery.mjs test/pending-clarification-hydration.mjs test/permission-steering-wakeup.mjs test/pure-calculation-reply.mjs test/pure-calculation-tools.mjs test/page-feedback.mjs test/page-feedback-progress.mjs test/ask-response-scope.mjs test/ask-completion-churn.mjs test/page-feedback-policy.mjs test/page-feedback-transport-races.mjs test/page-feedback-recovery.mjs test/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/code-scanning-url-recipient.mjs test/apocalypse-comm-parsing.mjs test/apocalypse-scalar-decoding.mjs test/bitgpu-chat-security.mjs test/social-media-url-upgrades.mjs test/downloaded-file-saved-bytes.mjs test/downloaded-file-local-probe.mjs test/formless-verification-recovery.mjs test/file-upload-accept.mjs test/file-upload-accept-agent.mjs test/workflow-route-generic-completion.mjs test/release-publication-completion.mjs test/workflow-implicit-metadata.mjs test/workflow-field-readings.mjs test/workflow-field-anchors.mjs test/user-turn-kind.mjs test/follow-up-task-context.mjs test/completion-current-execution-evidence.mjs test/video-upload-attachment.mjs test/feedback-automatic-churn.mjs test/feedback-navigation-idle.mjs test/feedback-run-boundaries.mjs test/feedback-ask-viewing.mjs test/lifecycle-terminal-done.mjs test/lifecycle-planner-digest.mjs test/lifecycle-steering-latency.mjs test/lifecycle-steering-restart.mjs test/lifecycle-vision-fallback.mjs test/delivery-click-locks.mjs test/guards-steering-receipts.mjs test/terminal-user-messages.mjs && npm run test:plan-notifications",
+ "test:shard:runtime-unit": "node --test test/skill-download-wait.mjs && node --test test/agent-lifecycle.mjs test/runtime-startup.mjs test/run-ui-scheduled-lifecycle.mjs test/transport-deadlines.mjs test/cdp-worker-restart.mjs test/bot-memory.mjs test/bot-memory-click-guard.mjs test/bot-memory-registries.mjs test/bot-memory-cloud-controller.mjs test/cdp-clear-receipt.mjs test/cdp-field-submit-recovery.mjs test/conversation-persistence.mjs test/context-live-tool-group.mjs test/integration-races.mjs test/watch-completion-checkpoint.mjs test/runtime-model-identity.mjs test/provider-message-privacy.mjs test/runtime-task-authority.mjs test/planner-repair-authority.mjs test/runtime-progress-continuation.mjs test/chat-resume-chain.mjs test/chat-resume-completion.mjs test/native-chat-execution-ledger.mjs test/chat-send-dispatch-result.mjs test/chat-reply-dedup-race.mjs test/memcode-lifecycle.mjs test/runtime-peer-review.mjs test/read-continuation-schema.mjs test/completion-submit-acknowledgement.mjs test/completion-live-status.mjs test/completion-iframe-submit.mjs test/form-validation-alert-readings.mjs test/control-effect-readings.mjs test/trusted-retry-readings.mjs test/completion-semantic-commit.mjs test/completion-diagnostics.mjs test/mastodon-publication.mjs test/calculator.mjs test/chat-recovery-protocol.mjs test/chat-pending-reconciliation.mjs test/semantic-page-retry.mjs test/pdf-detection.mjs test/runtime-lifecycle.mjs test/collection-read-progress.mjs test/network-lifecycle.mjs test/text-write-cancellation.mjs test/trusted-field-preparation.mjs test/draftjs-text.mjs test/rich-text-frameworks.mjs test/cdp-managed-text-selection.mjs test/firefox-rich-text-readback.mjs test/contenteditable-beforeinput.mjs test/trusted-field-preparation-ownership.mjs test/typing-preparation-geometry.mjs test/chat-steering.mjs test/resource-mutation-guards.mjs test/completion-steering-receipt-authority.mjs test/steering-revision-recovery.mjs test/pending-clarification-hydration.mjs test/permission-steering-wakeup.mjs test/pure-calculation-reply.mjs test/pure-calculation-tools.mjs test/page-feedback.mjs test/page-feedback-progress.mjs test/ask-response-scope.mjs test/ask-completion-churn.mjs test/page-feedback-policy.mjs test/research-escalation-page-feedback.mjs test/page-feedback-transport-races.mjs test/page-feedback-recovery.mjs test/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/code-scanning-url-recipient.mjs test/apocalypse-comm-parsing.mjs test/apocalypse-scalar-decoding.mjs test/bitgpu-chat-security.mjs test/social-media-url-upgrades.mjs test/downloaded-file-saved-bytes.mjs test/downloaded-file-local-probe.mjs test/formless-verification-recovery.mjs test/file-upload-accept.mjs test/file-upload-accept-agent.mjs test/workflow-route-generic-completion.mjs test/release-publication-completion.mjs test/workflow-implicit-metadata.mjs test/workflow-field-readings.mjs test/workflow-field-anchors.mjs test/user-turn-kind.mjs test/follow-up-task-context.mjs test/completion-current-execution-evidence.mjs test/video-upload-attachment.mjs test/feedback-automatic-churn.mjs test/feedback-navigation-idle.mjs test/feedback-run-boundaries.mjs test/feedback-ask-viewing.mjs test/lifecycle-terminal-done.mjs test/lifecycle-planner-digest.mjs test/lifecycle-steering-latency.mjs test/lifecycle-steering-restart.mjs test/lifecycle-vision-fallback.mjs test/delivery-click-locks.mjs test/guards-steering-receipts.mjs test/terminal-user-messages.mjs && npm run test:plan-notifications",
"test:shard:browser-a": "node test/bot-memory-dom.mjs && node test/bot-memory-click-dom.mjs && node test/ui-content-lifecycle.mjs && node --test test/native-telegram-chat.mjs test/native-telegram-recipient.mjs test/telegram-native-baseline.mjs test/telegram-native-latest.mjs test/native-chat-pre-enter-draft.mjs test/chat-draft-dispatch-ownership.mjs test/native-telegram-alias-preparation.mjs test/telegram-read-preparation-content.mjs test/queued-composer-ownership.mjs test/onboarding-provider-ready.mjs test/workflow-native-targets.mjs test/native-whatsapp-chat.mjs test/native-chat-context-identity.mjs test/native-whatsapp-contact.mjs test/whatsapp-native-bootstrap.mjs test/whatsapp-drawer-identity.mjs test/whatsapp-read-latest.mjs test/whatsapp-read-preparation.mjs test/whatsapp-chat-completion.mjs test/whatsapp-chat-restart.mjs test/chat-goal-lifecycle.mjs test/chat-completion.mjs test/chat-generic-dispatch.mjs test/completion-live-status-browser.mjs test/native-confirmation-visibility.mjs test/native-button-preparation.mjs test/read-continuation-browser.mjs test/iframe-preparation-focus.mjs test/contenteditable-literal.mjs test/native-chat-empty-editor.mjs test/native-chat-trusted-clear.mjs test/chat-steering-ui.mjs test/recipient-confirmation-ui.mjs test/assistant-message-visibility-ui.mjs test/page-monitor-ui.mjs test/page-monitor-dialog.mjs test/page-monitor-dialog-native.mjs test/page-monitor-inline-post.mjs test/bluesky-composer-context.mjs test/page-monitor-anchored.mjs test/page-monitor-upload-owner.mjs test/page-monitor-upload-release.mjs test/page-monitor-native-controls.mjs test/page-monitor-native-preparation.mjs test/native-preparation-cold.mjs test/page-monitor-navigation.mjs test/page-monitor-main-owner.mjs test/page-monitor-collateral-controls.mjs test/accessibility-tree-scoped-budget.mjs test/ax-reference-origin.mjs test/page-monitor-decorative-hit.mjs test/social-ui-navigation.mjs test/native-resource-deletion-binding.mjs test/native-mastodon-confirmation.mjs test/dropdown-menu-inventory.mjs test/page-monitor-passive-progress.mjs test/page-monitor-feed-items.mjs test/media-download-binding.mjs test/media-download-capture-integration.mjs test/social-media-downloader-reinjection.mjs test/upload-file-local-state-guidance.mjs test/monitor-intervention-contract.mjs test/monitor-owned-geometry.mjs test/monitor-viewport-remainder.mjs test/monitor-local-attribution.mjs test/monitor-lifecycle-leaks.mjs test/lifecycle-run-ui.mjs test/lifecycle-menu-prompts-held.mjs test/delivery-cdp-input.mjs test/delivery-click-ax-response-loss.mjs test/delivery-native-button-geometry.mjs test/delivery-hover-transition.mjs test/delivery-dispatch-boundary.mjs test/delivery-stop-compound.mjs test/guards-control-classification.mjs test/guards-unbound-deletion.mjs test/submit-probe-readings.mjs",
"test:shard:browser-b1": "node test/message-recipient-upload.mjs && node test/message-recipient-clarify-binding.mjs && node --test test/message-recipient-whatsapp.mjs test/message-control-readings.mjs && node test/quality/integration-mv3.mjs --full-form && node test/quality/integration-mv3.mjs --batch && node test/quality/literal-calculate-midrun-mv3.mjs && node test/quality/ask-completion-churn-mv3.mjs && node test/quality/ask-person-activity-mv3.mjs && node test/quality/telegram-cold-preparation-mv3.mjs && node test/quality/native-chat-mv3.mjs && node test/quality/native-chat-presubmit-mv3.mjs && node test/quality/cloud-bot-memory-mv3.mjs",
"test:shard:browser-b2": "node test/quality/whatsapp-contact-matrix.mjs && node test/quality/pdf-detection-mv3.mjs && node test/quality/download-upload-mv3.mjs && node test/quality/upload-release-binding-mv3.mjs && node test/quality/release-review-world-mv3.mjs && node test/quality/downloaded-file-saved-bytes-mv3.mjs && node test/quality/file-upload-accept-mv3.mjs && node test/quality/bulk-resume-mv3.mjs && node test/quality/shared-action-guards-mv3.mjs && node test/quality/video-upload-attachment-mv3.mjs",
diff --git a/src/chrome/src/agent/page-feedback-policy.js b/src/chrome/src/agent/page-feedback-policy.js
index f675b4a40..a1d4b898d 100644
--- a/src/chrome/src/agent/page-feedback-policy.js
+++ b/src/chrome/src/agent/page-feedback-policy.js
@@ -11,6 +11,9 @@ const FRESH_READS = new Set([
const DETACHED_TOOLS = new Set([
'calculate', 'list_downloads', 'read_downloaded_file', 'scratchpad_write', 'progress_read',
'progress_update', 'recall_memcode', 'clarify', 'generate_image', 'schedule_task', 'schedule_resume', 'resize_window',
+ // The handler validates a one-use token and sends its exact approved prompt,
+ // independently of the source page's DOM.
+ 'delegate_research',
]);
const AX_ACTIONS = new Set(['click_ax', 'type_ax', 'set_field', 'set_checked']);
// The arithmetic in a request is found by its structure: the one span the
diff --git a/src/firefox/src/agent/page-feedback-policy.js b/src/firefox/src/agent/page-feedback-policy.js
index f675b4a40..a1d4b898d 100644
--- a/src/firefox/src/agent/page-feedback-policy.js
+++ b/src/firefox/src/agent/page-feedback-policy.js
@@ -11,6 +11,9 @@ const FRESH_READS = new Set([
const DETACHED_TOOLS = new Set([
'calculate', 'list_downloads', 'read_downloaded_file', 'scratchpad_write', 'progress_read',
'progress_update', 'recall_memcode', 'clarify', 'generate_image', 'schedule_task', 'schedule_resume', 'resize_window',
+ // The handler validates a one-use token and sends its exact approved prompt,
+ // independently of the source page's DOM.
+ 'delegate_research',
]);
const AX_ACTIONS = new Set(['click_ax', 'type_ax', 'set_field', 'set_checked']);
// The arithmetic in a request is found by its structure: the one span the
diff --git a/test/page-feedback-policy.mjs b/test/page-feedback-policy.mjs
index 8c2980487..fee22bdde 100644
--- a/test/page-feedback-policy.mjs
+++ b/test/page-feedback-policy.mjs
@@ -102,6 +102,32 @@ for (const build of ['chrome', 'firefox']) {
const keep = (name, args, current = page, events = passive) =>
canRetainPageFeedbackCalls([call(name, args)], { url: 'https://example.com/photo/1', page }, current, events);
+ test(`${build}: research delegation survives source-page churn through the pending decision`, () => {
+ const delegation = call('delegate_research', { authorization_token: 'approved-research', timeout_seconds: 180 });
+ const state = { url: 'https://example.com/photo/1', page };
+ for (const events of [passive,
+ [{ kind: 'dom', source: 'unknown', frameId: 0, target: 'span#counter' }],
+ [{ kind: 'navigation', source: 'unknown', frameId: 23 }],
+ ]) {
+ assert.equal(canRetainPageFeedbackCalls([delegation], state, page, events), true);
+ assert.equal(canRetainPageFeedbackCalls([delegation], state, null, events, { pending: true }), true,
+ 'The approved request does not depend on the source page or a successful tree refresh');
+ }
+ assert.equal(canRetainPageFeedbackCalls([delegation, call('click', { x: 10, y: 20 })], state, page, passive), false,
+ 'Retaining delegation does not retain a stale action in the same batch');
+ });
+
+ test(`${build}: research delegation retains user, navigation and viewport fences`, () => {
+ const args = { authorization_token: 'approved-research' };
+ for (const event of [
+ { kind: 'input', source: 'user', frameId: 0 },
+ { kind: 'click', source: 'user', frameId: 23 },
+ { kind: 'navigation', source: 'unknown', frameId: 0 },
+ { kind: 'resize', source: 'unknown', frameId: 0, target: 'viewport' },
+ ...['base', 'style', 'link'].map(target => ({ kind: 'dom', source: 'page', frameId: 0, target })),
+ ]) assert.equal(keep('delegate_research', args, page, [...passive, event]), false, JSON.stringify(event));
+ });
+
for (const name of ['fetch_url', 'research_url']) {
for (const method of [undefined, 'GET', 'HEAD', 'get', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS']) {
const expected = method == null || ['GET', 'HEAD'].includes(method.toUpperCase())
diff --git a/test/research-escalation-page-feedback.mjs b/test/research-escalation-page-feedback.mjs
new file mode 100644
index 000000000..62f5f3c09
--- /dev/null
+++ b/test/research-escalation-page-feedback.mjs
@@ -0,0 +1,243 @@
+// Real feedback response/dispatch fences and research authorization handler.
+// Browser responses and the external research helper are the only action stubs.
+import assert from 'node:assert/strict';
+import { test } from 'node:test';
+
+const PAGE_URL = 'https://research.example/article';
+const APPROVED_REQUEST = 'Explain how the network token relates to its AI inference business. Use web research and link sources.';
+const PAGE = { success: true, url: PAGE_URL, pageContent: 'main [ref_main]\n heading "Network research" [ref_title]\n text "Article text"' };
+const fixtures = new Map();
+const area = { get: async () => ({}), set: async () => {}, remove: async () => {} };
+let nextTab = 9700;
+const api = {
+ storage: { local: area, session: area },
+ runtime: { getURL: value => `extension://test/${value}`, sendMessage: async () => ({}) },
+ tabs: {
+ get: async id => ({ id, url: fixtures.get(id)?.url || PAGE_URL, title: 'Research' }),
+ sendMessage: async (id, message) => {
+ const fixture = fixtures.get(id);
+ if (message.action === 'page_monitor_capture_model') {
+ return { ready: true, runToken: message.params.runToken, documentToken: 'main-token',
+ snapshotToken: 'research-snapshot', targetCount: 0, focusedTargetAvailable: false,
+ page: structuredClone(PAGE) };
+ }
+ if (message.action === 'get_accessibility_tree') {
+ fixture.reads++;
+ fixture.onRead?.();
+ return structuredClone(PAGE);
+ }
+ if (message.action === 'page_monitor_prepare') {
+ fixture.preparations++;
+ fixture.onPrepare?.();
+ }
+ return { ready: true };
+ },
+ },
+ webNavigation: { getAllFrames: async ({ tabId }) => [{ frameId: 0, parentFrameId: -1,
+ documentId: fixtures.get(tabId)?.documentId || 'main-document', url: fixtures.get(tabId)?.url || PAGE_URL }] },
+ scripting: { executeScript: async () => [{ result: { url: PAGE_URL, contentType: 'text/html' } }] },
+};
+globalThis.chrome = api;
+globalThis.browser = api;
+
+function makeFixture(Agent) {
+ const tab = nextTab++;
+ const provider = { name: 'research feedback fixture', model: 'test', supportsTools: true, supportsVision: false };
+ const agent = new Agent({ getActive: () => provider, getProvider: () => provider, getVisionProvider: async () => null });
+ // Storage is outside this test's response and dispatch boundary.
+ agent._persist = () => {};
+ agent._persistNow = async () => ({ ok: true });
+ agent._pageFeedbackIdleMs = 0;
+ agent.researchEscalationEnabled = true;
+ agent.conversationIds.set(tab, `research-conversation-${tab}`);
+ agent.conversationModes.set(tab, 'ask');
+ const messages = [{ role: 'system', content: 'Research fixture.' }, { role: 'user', content: 'Explain the token and inference business.' }];
+ agent.conversations.set(tab, messages);
+ const fixture = { agent, tab, messages, url: PAGE_URL, documentId: 'main-document', reads: 0,
+ preparations: 0, approvals: 0, helpers: [], emit: null, onRead: null, onPrepare: null };
+ agent._runResearchEscalation = async (sourceTab, authorization, args) => {
+ fixture.helpers.push({ sourceTab, authorization: structuredClone(authorization), args: structuredClone(args) });
+ return { success: true, answer: 'Research answer with sources.', links: ['https://sources.example/research'] };
+ };
+ fixtures.set(tab, fixture);
+ return fixture;
+}
+
+async function start(fixture) {
+ const { agent, tab } = fixture;
+ await agent._claimRunEntry(tab, 'interactive');
+ const from = { tab: { id: tab }, frameId: 0, documentId: fixture.documentId, url: fixture.url };
+ const state = agent.pageMonitorState(from, 'main-token');
+ assert.equal(state.active, true);
+ let seq = 0;
+ fixture.emit = event => {
+ const revision = ++seq;
+ const response = agent.observePageFeedback(from, { ...state, seq: revision, revision,
+ kind: 'dom', source: 'page', target: 'span#counter', ...event });
+ assert.equal(response.accepted, true);
+ };
+}
+
+function cleanup(fixture) {
+ fixture.agent._finishSteeringRun(fixture.tab);
+ fixture.agent._releaseRunEntry(fixture.tab);
+ fixtures.delete(fixture.tab);
+}
+
+async function approve(fixture) {
+ const { agent, tab } = fixture;
+ const result = await agent.executeTool(tab, 'clarify', {
+ question: 'Delegate this research question?', purpose: 'research_escalation',
+ options: ['Continue here', 'Use ChatGPT'], approve_option: 'Use ChatGPT', research_request: APPROVED_REQUEST,
+ }, (type, data) => {
+ if (type !== 'clarify') return;
+ fixture.approvals++;
+ assert.equal(data.requireExplicitAnswer, true);
+ assert.equal(data.researchEscalation.request, APPROVED_REQUEST);
+ queueMicrotask(() => agent.submitClarifyResponse(tab, data.clarifyId, 'Use ChatGPT', 'option'));
+ });
+ assert.equal(result.researchEscalationApproved, true);
+ assert.ok(result.authorization_token);
+ return result.authorization_token;
+}
+
+const proposal = args => ({ id: 'delegate-approved-research', function: {
+ name: 'delegate_research', arguments: JSON.stringify(args),
+} });
+const applyResponse = (fixture, call) => fixture.agent._applyPendingPageFeedback(fixture.tab, fixture.messages, () => {}, {
+ responseToolCalls: [call],
+});
+const capture = fixture => fixture.agent._capturePageFeedbackModelState(fixture.tab, fixture.messages);
+
+for (const build of ['chrome', 'firefox']) {
+ const { Agent } = await import(`../src/${build}/src/agent/agent.js`);
+
+ test(`${build}: approved research dispatches once through DOM churn during inference, refresh and preparation`, async () => {
+ const fixture = makeFixture(Agent), { agent, tab } = fixture;
+ try {
+ await start(fixture);
+ const token = await approve(fixture);
+ await capture(fixture);
+ // These updates arrive after the pre-inference observation, before the
+ // model's delegation proposal reaches its response freshness fence.
+ fixture.emit({}); fixture.emit({});
+ fixture.onRead = () => fixture.emit({});
+ fixture.onPrepare = () => fixture.emit({});
+ const args = { authorization_token: token, research_request: 'A model-added replacement must never be submitted.' };
+ const call = proposal(args);
+ assert.equal(await applyResponse(fixture, call), false, 'The original approved proposal survives counter churn');
+ assert.equal(fixture.helpers.length, 0, 'Retaining a proposal does not submit it or consume authorization');
+ assert.equal(agent._researchEscalationAuthorization(tab, token).ok, true);
+ assert.equal(await agent._refreshPageFeedbackForCall(tab, call), false);
+ const result = await agent.executeTool(tab, 'delegate_research', args);
+ assert.equal(result.success, true);
+ assert.ok(fixture.reads >= 2, 'New counter updates during both response and per-call refresh are exercised');
+ assert.equal(fixture.preparations, 1, 'The real state-changing wrapper prepares the call');
+ assert.equal(fixture.helpers.length, 1);
+ assert.equal(fixture.helpers[0].sourceTab, tab);
+ assert.equal(fixture.helpers[0].authorization.request, APPROVED_REQUEST);
+ assert.equal(fixture.approvals, 1, 'DOM churn does not request fresh consent');
+ assert.equal(agent._researchEscalationAuthorization(tab, token).ok, false);
+
+ const duplicate = await agent.executeTool(tab, 'delegate_research', args);
+ assert.equal(duplicate.denied, true);
+ assert.match(duplicate.error, /already-used research authorization/);
+ assert.equal(fixture.helpers.length, 1, 'Reusing a dispatched token cannot send the prompt again');
+ } finally { cleanup(fixture); }
+ });
+
+ test(`${build}: same-conversation continuation preserves consent while resize requires a new decision`, async () => {
+ const fixture = makeFixture(Agent), { agent, tab } = fixture;
+ const resize = { kind: 'resize', source: 'unknown', target: 'viewport',
+ viewport: { width: 1280, height: 745 }, before: { width: 1280, height: 801 } };
+ try {
+ await start(fixture);
+ const token = await approve(fixture), call = proposal({ authorization_token: token });
+ await capture(fixture);
+ fixture.emit(resize);
+ assert.equal(await applyResponse(fixture, call), true, 'A top-level resize supersedes the first proposal');
+ assert.equal(agent._researchEscalationAuthorization(tab, token).ok, true);
+ const previousRun = agent._pageFeedbackRuns.get(tab).token;
+ agent._releaseRunEntry(tab);
+ await start(fixture);
+ assert.notEqual(agent._pageFeedbackRuns.get(tab).token, previousRun);
+ assert.equal(agent._researchEscalationAuthorization(tab, token).ok, true, 'A new run in the same conversation retains unused consent');
+
+ await capture(fixture);
+ fixture.emit(resize);
+ assert.equal(await agent._refreshPageFeedbackForCall(tab, call), true, 'Continue does not bypass a new resize');
+ assert.equal(fixture.helpers.length, 0);
+ assert.equal(agent._researchEscalationAuthorization(tab, token).ok, true);
+ await agent._applyPendingPageFeedback(tab, fixture.messages);
+ await capture(fixture); // A new decision follows the resize observation.
+ fixture.emit({});
+ fixture.onRead = () => fixture.emit({});
+ fixture.onPrepare = () => fixture.emit({});
+ assert.equal(await applyResponse(fixture, call), false);
+ assert.equal((await agent.executeTool(tab, 'delegate_research', { authorization_token: token })).success, true);
+ assert.equal(fixture.helpers.length, 1);
+ assert.equal(fixture.approvals, 1);
+ assert.equal(fixture.helpers[0].authorization.request, APPROVED_REQUEST);
+ } finally { cleanup(fixture); }
+ });
+
+ for (const intervention of ['user_input', 'viewport', 'navigation', 'steering']) {
+ test(`${build}: ${intervention} during delegation preparation blocks dispatch without consuming consent`, async () => {
+ const fixture = makeFixture(Agent), { agent, tab } = fixture;
+ try {
+ await start(fixture);
+ const token = await approve(fixture);
+ if (intervention === 'steering') agent._beginSteeringRun(tab, () => {}, { detachedRequestId: 'research-steering' });
+ await capture(fixture);
+ fixture.onPrepare = () => {
+ if (intervention === 'user_input') fixture.emit({ kind: 'input', source: 'user', target: 'input#search' });
+ if (intervention === 'viewport') fixture.emit({ kind: 'resize', source: 'unknown', target: 'viewport' });
+ if (intervention === 'navigation') {
+ fixture.url = 'https://research.example/another-article';
+ fixture.documentId = 'replacement-document';
+ agent.observePageNavigation({ tabId: tab, frameId: 0, parentFrameId: -1,
+ documentId: fixture.documentId, url: fixture.url, transitionType: 'link', transitionQualifiers: [] }, 'committed');
+ }
+ if (intervention === 'steering') {
+ assert.equal(agent.steerMessage(tab, 'Continue the research locally.', {
+ requestId: 'research-steering', messageId: 'local-research-correction',
+ }).accepted, true);
+ fixture.emit({});
+ }
+ };
+ const result = await agent.executeTool(tab, 'delegate_research', { authorization_token: token });
+ assert.equal(result.noDispatch, true);
+ assert.equal(result.dispatched, false);
+ assert.equal(fixture.helpers.length, 0);
+ assert.equal(agent._researchEscalationAuthorization(tab, token).ok, true);
+ } finally { cleanup(fixture); }
+ });
+ }
+
+ test(`${build}: DOM retention preserves missing, expired, consumed, scope and feature authorization checks`, async () => {
+ for (const invalid of ['missing', 'unknown', 'expired', 'consumed', 'wrong_tab', 'wrong_conversation', 'disabled']) {
+ const fixture = makeFixture(Agent), { agent, tab } = fixture;
+ try {
+ await start(fixture);
+ const token = await approve(fixture);
+ const args = { authorization_token: token };
+ if (invalid === 'missing') delete args.authorization_token;
+ if (invalid === 'unknown') args.authorization_token = 'research_not-issued';
+ if (invalid === 'expired') agent._researchEscalationAuthorizations.get(token).createdAt = Date.now() - 5 * 60 * 1000 - 1;
+ if (invalid === 'consumed') agent._researchEscalationAuthorization(tab, token, { consume: true });
+ if (invalid === 'wrong_tab') agent._researchEscalationAuthorizations.get(token).tabId = tab + 1;
+ if (invalid === 'wrong_conversation') agent.conversationIds.set(tab, 'another-conversation');
+ if (invalid === 'disabled') agent.researchEscalationEnabled = false;
+ await capture(fixture);
+ fixture.emit({});
+ fixture.onRead = () => fixture.emit({});
+ fixture.onPrepare = () => fixture.emit({});
+ assert.equal(await applyResponse(fixture, proposal(args)), false, `${invalid}: retention only preserves the proposal`);
+ const result = await agent.executeTool(tab, 'delegate_research', args);
+ assert.equal(result.success, false, invalid);
+ assert.equal(result.denied, invalid === 'disabled' ? undefined : true, invalid);
+ assert.equal(fixture.helpers.length, 0, `${invalid}: invalid consent must never open the research helper`);
+ } finally { cleanup(fixture); }
+ }
+ });
+}