Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
Let a slow guard reading finish for the retried click
Claude9f6bc2ce6fe3
diff --git a/docs/architecture.md b/docs/architecture.mdindex 3b4e78c06..c6dd93c18 100644--- a/docs/architecture.md+++ b/docs/architecture.md@@ -1144,7 +1144,12 @@ to the page with each guard check and chat observation; texts the checkconsulted unread come back, are read (the decision model first, the activemodel within four seconds) and the check runs again, up to three times whileit reaches texts nobody has read (a send control's name first, the recipient-rows behind it next). The page monitor's capture reports only that texts were+rows behind it next). The check waits four seconds, but a slower active model+is not cut off: its read goes on in the background for the run (charged and+traced to it, cancelled when the run stops or ends, given up after 20 seconds),+and the retried click joins it instead of asking again. Only the latest check's+reads are carried over; a check about other texts cancels them. An in-browser+model, whose requests cannot be cancelled, is still cut off at four seconds. The page monitor's capture reports only that texts wereconsulted unread; page feedback then asks for them, reads them and capturesagain, so the conversation that owns a footer action is decided with thereadings. While the active model decides on such a page, the decision modeldiff --git a/package.json b/package.jsonindex 2f6cd2723..bb48bd8c3 100644--- a/package.json+++ b/package.json@@ -64,7 +64,7 @@"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/publication-prefetch.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/guard-advisory-writes.mjs test/trusted-field-preparation.mjs test/draftjs-text.mjs test/codemirror-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/clarify-timeout-policy.mjs test/guard-ask-cards.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/page-feedback-unbindable-target.mjs test/guard-advisory-actions.mjs test/rich-text-preflight-page-change.mjs test/keyboard-receiver-frame.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-scroll-churn.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/incomplete-completion-recovery.mjs test/guard-advisory-completion.mjs test/guard-policy.mjs test/lean-mode.mjs test/prompt-unverified-pages.mjs test/prompt-missing-values.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/sidepanel-permission-gate-ui.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/x-compose-trusted-typing.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-reply-route-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/mastodon-delete-after-correction-mv3.mjs && 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/x-compose-dialog-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: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/guard-reading-carry-over.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/guard-advisory-writes.mjs test/trusted-field-preparation.mjs test/draftjs-text.mjs test/codemirror-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/clarify-timeout-policy.mjs test/guard-ask-cards.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/page-feedback-unbindable-target.mjs test/guard-advisory-actions.mjs test/rich-text-preflight-page-change.mjs test/keyboard-receiver-frame.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-scroll-churn.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/incomplete-completion-recovery.mjs test/guard-advisory-completion.mjs test/guard-policy.mjs test/lean-mode.mjs test/prompt-unverified-pages.mjs test/prompt-missing-values.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/sidepanel-permission-gate-ui.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/x-compose-trusted-typing.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-reply-route-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/mastodon-delete-after-correction-mv3.mjs && 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/x-compose-dialog-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/guard-advisory-writes.mjs test/draftjs-text.mjs test/codemirror-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/page-feedback-unbindable-target.mjs test/guard-advisory-actions.mjs test/rich-text-preflight-page-change.mjs test/keyboard-receiver-frame.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/x-compose-trusted-typing.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-scroll-churn.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-native-button-route.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/page-feedback-held-time.mjs test/page-monitor-held-observation.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",@@ -98,7 +98,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/guard-policy.mjs 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/guard-advisory-writes.mjs test/trusted-field-preparation.mjs test/draftjs-text.mjs test/codemirror-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/clarify-timeout-policy.mjs test/guard-ask-cards.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/page-feedback-unbindable-target.mjs test/guard-advisory-actions.mjs test/rich-text-preflight-page-change.mjs test/keyboard-receiver-frame.mjs test/ask-response-scope.mjs test/auto-mode.mjs test/model-picker-icon.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/incomplete-completion-recovery.mjs test/guard-advisory-completion.mjs test/lean-mode.mjs test/prompt-unverified-pages.mjs test/prompt-missing-values.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 test/improver-providers.mjs test/improver-providers-agent.mjs test/improver-guards-ledger.mjs test/improver-guards-tools.mjs test/improver-clarify.mjs test/improver-clarify-scheduler.mjs test/improver-misc.mjs test/improver-forms.mjs test/improver-forms-strict-secrets.mjs test/improver-content-press-keys-hint.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/guard-reading-carry-over.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/guard-advisory-writes.mjs test/trusted-field-preparation.mjs test/draftjs-text.mjs test/codemirror-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/clarify-timeout-policy.mjs test/guard-ask-cards.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/page-feedback-unbindable-target.mjs test/guard-advisory-actions.mjs test/rich-text-preflight-page-change.mjs test/keyboard-receiver-frame.mjs test/ask-response-scope.mjs test/auto-mode.mjs test/model-picker-icon.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/incomplete-completion-recovery.mjs test/guard-advisory-completion.mjs test/lean-mode.mjs test/prompt-unverified-pages.mjs test/prompt-missing-values.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 test/improver-providers.mjs test/improver-providers-agent.mjs test/improver-guards-ledger.mjs test/improver-guards-tools.mjs test/improver-clarify.mjs test/improver-clarify-scheduler.mjs test/improver-misc.mjs test/improver-forms.mjs test/improver-forms-strict-secrets.mjs test/improver-content-press-keys-hint.mjs && npm run test:plan-notifications","test:shard:browser-a": "node --test test/captcha-draft-content.mjs test/captcha-challenge-surfaces.mjs && 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/sidepanel-permission-gate-ui.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/x-compose-trusted-typing.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-scroll-churn.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-native-button-route.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/improver-content-account-chrome.mjs test/improver-content-recipient.mjs test/improver-content-truncated-replacement.mjs test/improver-forms-probe.mjs test/improver-misc-trace-browser.mjs test/page-feedback-held-time.mjs test/page-monitor-held-observation.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/upload-release-binding-mv3.mjs --selector-recovery && node test/quality/upload-release-binding-mv3.mjs --sequential-assets && 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/agent.js b/src/chrome/src/agent/agent.jsindex 802cc670c..be48ed8c4 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -298,6 +298,9 @@ const COMPLETION_READING_TIMEOUT_MS = 6_000;// language, after a click in a run that has to prove a submission; the active// model gets this long when the decision model is not sure.const CONTROL_READING_TIMEOUT_MS = 4_000;+// A messaging guard's reading that outlasts its click's wait goes on in the+// background at most this long, so that the retried click can use it.+const CONTROL_READING_LATE_TIMEOUT_MS = 20_000;// A dialog title or a wall text no model answered reads as nothing to stop// for; it is asked again only after this long, so page reads and actions do// not each wait for it.@@ -29323,8 +29326,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// Reads, in any language, the texts of a messaging page its checks consulted// unread ([{ kind, text }]): the decision model first, the active model- // within four seconds. A text no model could read stays unread, and each- // check keeps taking it the cautious way. True when any of them was read.+ // within four seconds (_readGuardPageTexts). A text no model could read in+ // time stays unread, and each check keeps taking it the cautious way. True+ // when any of them was read.async _readUnreadPageTexts(tabId, texts = []) {const byKind = new Map();for (const item of (Array.isArray(texts) ? texts : []).slice(0, 64)) {@@ -29333,15 +29337,17 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dif (!byKind.has(kind)) byKind.set(kind, new Set());byKind.get(kind).add(text);}+ this._cancelOtherGuardPageTextReads(tabId, new Set([...byKind]+ .flatMap(([kind, list]) => [...list].slice(0, 48).map(text => kind + '\u0000' + text))));let read = false;for (const [kind, list] of byKind) {const pending = [...list].slice(0, 48);- // Texts a background prefetch is reading now are joined first, so+ // Texts a background read has in flight are joined first, so// _readPageTexts asks only what is still unread (and still makes a// held reading one of the most recent the page gets).await this._joinBackgroundPageTextReads(kind, pending);try {- await this._readPageTexts(tabId, kind, pending, {}, { maxChars: 400, mainTimeoutMs: CONTROL_READING_TIMEOUT_MS });+ await this._readGuardPageTexts(tabId, kind, pending);} catch (error) {if (this._checkAbort(tabId)) throw error;}@@ -29350,14 +29356,73 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dreturn read;}- // Waits for the reads of these texts that a background publication- // prefetch has in flight (_socialPublicationPrefetchReadings), so a click- // joins them instead of asking a model the same question again. The wait- // is capped: a read that does not settle in time is read again here.+ // The guard's click waits four seconds for its readings, but a slower model+ // is not cut off there. Its read goes on in the background for the run+ // (charged and traced to it, cancelled when the run stops or ends, given up+ // after CONTROL_READING_LATE_TIMEOUT_MS), and the click's retry joins it+ // (_joinBackgroundPageTextReads) instead of asking the same question again+ // and timing out the same way. Only the latest check's reads are carried+ // over: a check about other texts cancels them+ // (_cancelOtherGuardPageTextReads). An in-browser model, whose requests+ // cannot be cancelled, is still asked in the foreground and cut off at four+ // seconds.+ async _readGuardPageTexts(tabId, kind, texts) {+ const inFlight = this._guardPageTextReads ||= new Map();+ const ask = texts.filter(text => !inFlight.has(kind + '\u0000' + text));+ const unread = ask.filter(text => this._pageTextReading(kind, text) === null);+ // Held readings are still passed on, to keep them among the most recent.+ if (!unread.length || !this._socialPublicationBackgroundProvider(this._activeProvider(tabId))) {+ await this._readPageTexts(tabId, kind, ask, {}, { maxChars: 400, mainTimeoutMs: CONTROL_READING_TIMEOUT_MS });+ return;+ }+ const runSignal = this._runAbortSignal(tabId);+ const binding = { signal: runSignal, costState: this.currentCostState.get(tabId) || null,+ runId: this.currentRunId.get(tabId) || null,+ current: () => !this._checkAbort(tabId) && this._runAbortSignal(tabId) === runSignal && !runSignal?.aborted };+ const abort = this._socialPublicationBackgroundAbort(binding, tabId);+ const background = this._socialPublicationBackgroundCall(tabId, null, binding, abort);+ const keys = unread.map(text => kind + '\u0000' + text);+ const tabReads = (this._guardPageTextReadsByTab ||= new Map()).get(tabId)+ || this._guardPageTextReadsByTab.set(tabId, new Set()).get(tabId);+ const entry = { abort, keys };+ tabReads.add(entry);+ const work = this._readPageTexts(tabId, kind, ask, {},+ { maxChars: 400, mainTimeoutMs: CONTROL_READING_LATE_TIMEOUT_MS, background }).catch(() => null);+ const settled = this._trackSocialPublicationBackgroundRun(tabId,+ this._socialPublicationBackgroundSettle(abort, work, null).finally(() => {+ for (const key of keys) if (inFlight.get(key) === settled) inFlight.delete(key);+ tabReads.delete(entry);+ if (!tabReads.size && this._guardPageTextReadsByTab.get(tabId) === tabReads) this._guardPageTextReadsByTab.delete(tabId);+ }));+ for (const key of keys) inFlight.set(key, settled);+ let timer = null;+ await Promise.race([settled, new Promise(resolve => { timer = setTimeout(resolve, CONTROL_READING_TIMEOUT_MS); })]);+ clearTimeout(timer);+ // A Stop while waiting ends the check, as a foreground read would.+ this._throwIfAborted(this._runAbortSignal(tabId));+ }++ // A guard check about other texts than an earlier check's reads still in+ // flight cancels them: the model moved on to another control.+ _cancelOtherGuardPageTextReads(tabId, requestedKeys) {+ for (const entry of this._guardPageTextReadsByTab?.get(tabId) || []) {+ if (entry.keys.some(key => requestedKeys.has(key)) || entry.abort.controller.signal.aborted) continue;+ const reason = new Error('A later guard check reads other texts.');+ reason.name = 'AbortError';+ entry.abort.controller.abort(reason);+ }+ }++ // Waits for the reads of these texts already in flight: a background+ // publication prefetch's (_socialPublicationPrefetchReadings) or the+ // guard's own that outlasted an earlier click (_readGuardPageTexts). A+ // click joins them instead of asking a model the same question again. The+ // wait is capped: a prefetch read that does not settle in time is read again+ // here, while a guard read still going is not asked twice.async _joinBackgroundPageTextReads(kind, texts) {- const reading = this._socialPublicationPrefetchReading;- if (!reading?.size) return;- const pending = [...new Set(texts.map(text => reading.get(kind + '\u0000' + text)).filter(Boolean))];+ const pending = [...new Set([this._socialPublicationPrefetchReading, this._guardPageTextReads]+ .flatMap(reading => (reading?.size ? texts.map(text => reading.get(kind + '\u0000' + text)) : []))+ .filter(Boolean))];if (!pending.length) return;let timer = null;await Promise.race([Promise.allSettled(pending),diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 9de3e6c03..241956fd9 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -225,6 +225,9 @@ const COMPLETION_READING_TIMEOUT_MS = 6_000;// language, after a click in a run that has to prove a submission; the active// model gets this long when the decision model is not sure.const CONTROL_READING_TIMEOUT_MS = 4_000;+// A messaging guard's reading that outlasts its click's wait goes on in the+// background at most this long, so that the retried click can use it.+const CONTROL_READING_LATE_TIMEOUT_MS = 20_000;// A dialog title or a wall text no model answered reads as nothing to stop// for; it is asked again only after this long, so page reads and actions do// not each wait for it.@@ -26317,8 +26320,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// Reads, in any language, the texts of a messaging page its checks consulted// unread ([{ kind, text }]): the decision model first, the active model- // within four seconds. A text no model could read stays unread, and each- // check keeps taking it the cautious way. True when any of them was read.+ // within four seconds (_readGuardPageTexts). A text no model could read in+ // time stays unread, and each check keeps taking it the cautious way. True+ // when any of them was read.async _readUnreadPageTexts(tabId, texts = []) {const byKind = new Map();for (const item of (Array.isArray(texts) ? texts : []).slice(0, 64)) {@@ -26327,15 +26331,17 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dif (!byKind.has(kind)) byKind.set(kind, new Set());byKind.get(kind).add(text);}+ this._cancelOtherGuardPageTextReads(tabId, new Set([...byKind]+ .flatMap(([kind, list]) => [...list].slice(0, 48).map(text => kind + '\u0000' + text))));let read = false;for (const [kind, list] of byKind) {const pending = [...list].slice(0, 48);- // Texts a background prefetch is reading now are joined first, so+ // Texts a background read has in flight are joined first, so// _readPageTexts asks only what is still unread (and still makes a// held reading one of the most recent the page gets).await this._joinBackgroundPageTextReads(kind, pending);try {- await this._readPageTexts(tabId, kind, pending, {}, { maxChars: 400, mainTimeoutMs: CONTROL_READING_TIMEOUT_MS });+ await this._readGuardPageTexts(tabId, kind, pending);} catch (error) {if (this._checkAbort(tabId)) throw error;}@@ -26344,14 +26350,73 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dreturn read;}- // Waits for the reads of these texts that a background publication- // prefetch has in flight (_socialPublicationPrefetchReadings), so a click- // joins them instead of asking a model the same question again. The wait- // is capped: a read that does not settle in time is read again here.+ // The guard's click waits four seconds for its readings, but a slower model+ // is not cut off there. Its read goes on in the background for the run+ // (charged and traced to it, cancelled when the run stops or ends, given up+ // after CONTROL_READING_LATE_TIMEOUT_MS), and the click's retry joins it+ // (_joinBackgroundPageTextReads) instead of asking the same question again+ // and timing out the same way. Only the latest check's reads are carried+ // over: a check about other texts cancels them+ // (_cancelOtherGuardPageTextReads). An in-browser model, whose requests+ // cannot be cancelled, is still asked in the foreground and cut off at four+ // seconds.+ async _readGuardPageTexts(tabId, kind, texts) {+ const inFlight = this._guardPageTextReads ||= new Map();+ const ask = texts.filter(text => !inFlight.has(kind + '\u0000' + text));+ const unread = ask.filter(text => this._pageTextReading(kind, text) === null);+ // Held readings are still passed on, to keep them among the most recent.+ if (!unread.length || !this._socialPublicationBackgroundProvider(this._activeProvider(tabId))) {+ await this._readPageTexts(tabId, kind, ask, {}, { maxChars: 400, mainTimeoutMs: CONTROL_READING_TIMEOUT_MS });+ return;+ }+ const runSignal = this._runAbortSignal(tabId);+ const binding = { signal: runSignal, costState: this.currentCostState.get(tabId) || null,+ runId: this.currentRunId.get(tabId) || null,+ current: () => !this._checkAbort(tabId) && this._runAbortSignal(tabId) === runSignal && !runSignal?.aborted };+ const abort = this._socialPublicationBackgroundAbort(binding, tabId);+ const background = this._socialPublicationBackgroundCall(tabId, null, binding, abort);+ const keys = unread.map(text => kind + '\u0000' + text);+ const tabReads = (this._guardPageTextReadsByTab ||= new Map()).get(tabId)+ || this._guardPageTextReadsByTab.set(tabId, new Set()).get(tabId);+ const entry = { abort, keys };+ tabReads.add(entry);+ const work = this._readPageTexts(tabId, kind, ask, {},+ { maxChars: 400, mainTimeoutMs: CONTROL_READING_LATE_TIMEOUT_MS, background }).catch(() => null);+ const settled = this._trackSocialPublicationBackgroundRun(tabId,+ this._socialPublicationBackgroundSettle(abort, work, null).finally(() => {+ for (const key of keys) if (inFlight.get(key) === settled) inFlight.delete(key);+ tabReads.delete(entry);+ if (!tabReads.size && this._guardPageTextReadsByTab.get(tabId) === tabReads) this._guardPageTextReadsByTab.delete(tabId);+ }));+ for (const key of keys) inFlight.set(key, settled);+ let timer = null;+ await Promise.race([settled, new Promise(resolve => { timer = setTimeout(resolve, CONTROL_READING_TIMEOUT_MS); })]);+ clearTimeout(timer);+ // A Stop while waiting ends the check, as a foreground read would.+ this._throwIfAborted(this._runAbortSignal(tabId));+ }++ // A guard check about other texts than an earlier check's reads still in+ // flight cancels them: the model moved on to another control.+ _cancelOtherGuardPageTextReads(tabId, requestedKeys) {+ for (const entry of this._guardPageTextReadsByTab?.get(tabId) || []) {+ if (entry.keys.some(key => requestedKeys.has(key)) || entry.abort.controller.signal.aborted) continue;+ const reason = new Error('A later guard check reads other texts.');+ reason.name = 'AbortError';+ entry.abort.controller.abort(reason);+ }+ }++ // Waits for the reads of these texts already in flight: a background+ // publication prefetch's (_socialPublicationPrefetchReadings) or the+ // guard's own that outlasted an earlier click (_readGuardPageTexts). A+ // click joins them instead of asking a model the same question again. The+ // wait is capped: a prefetch read that does not settle in time is read again+ // here, while a guard read still going is not asked twice.async _joinBackgroundPageTextReads(kind, texts) {- const reading = this._socialPublicationPrefetchReading;- if (!reading?.size) return;- const pending = [...new Set(texts.map(text => reading.get(kind + '\u0000' + text)).filter(Boolean))];+ const pending = [...new Set([this._socialPublicationPrefetchReading, this._guardPageTextReads]+ .flatMap(reading => (reading?.size ? texts.map(text => reading.get(kind + '\u0000' + text)) : []))+ .filter(Boolean))];if (!pending.length) return;let timer = null;await Promise.race([Promise.allSettled(pending),diff --git a/test/guard-reading-carry-over.mjs b/test/guard-reading-carry-over.mjsnew file mode 100644index 000000000..d63b65477--- /dev/null+++ b/test/guard-reading-carry-over.mjs@@ -0,0 +1,193 @@+// The messaging guard reads a control's name before a click it cannot prove+// harmless, and the click waits four seconds for that reading. A slower model+// is not cut off there: its read goes on in the background for the run, and+// the retried click uses its answer instead of asking again and timing out the+// same way (QA A6, D6, W: Telegram, Gmail and WhatsApp clicks blocked with+// "could not read in time what this control does" while a local model needed+// about five seconds per reading).+import assert from 'node:assert/strict';+import { mock, test } from 'node:test';++const area = { get: async () => ({}), set: async () => {}, remove: async () => {} };+globalThis.chrome = globalThis.browser = {+ storage: { local: area, session: area },+ runtime: { getURL: path => `extension://owned/${path}`, sendMessage: async () => ({}) },+ tabs: { get: async id => ({ id, url: 'https://web.telegram.org/k/' }), sendMessage: async () => ({}) },+ scripting: { executeScript: async () => [{ result: null }] },+};++const flush = async (rounds = 6) => {+ for (let i = 0; i < rounds; i += 1) await new Promise(resolve => setImmediate(resolve));+};++function deferred() {+ let resolve;+ const promise = new Promise(done => { resolve = done; });+ return { promise, resolve };+}++for (const build of ['chrome', 'firefox']) {+ const { Agent } = await import(`../src/${build}/src/agent/agent.js`);++ // A Telegram chat list's "More" button: the page cannot tell yet whether it+ // sends anything, so the guard asks what its name means.+ function fixture({ provider = { name: 'local-openai-proxy', chat: async () => ({}) } } = {}) {+ const agent = new Agent({ getActive: () => provider });+ const tab = 7, asked = [], answers = [];+ agent._activeProvider = () => provider;+ agent._semanticDecisions = async (_tab, kind, { items = [] } = {}, options = {}) => {+ const answer = deferred();+ asked.push({ kind, texts: items.map(item => item.text), options });+ answers.push(answer);+ return answer.promise.then(choice => items.map(() => (choice+ ? { choice, evidence: '', source: 'main_model' } : { choice: null, evidence: '', source: 'unavailable' })));+ };+ const names = { ref_more: 'More', ref_search: 'Search' };+ agent._messageRecipientContentProbe = async (_tab, params) => {+ const name = names[params.args?.ref_id];+ return params.__wbPageReadings?.message_control?.[name]+ ? { success: true, conclusive: true, messageSend: false, nonMessagingTarget: true, identityCandidates: [] }+ : { success: true, conclusive: false, messageSend: null, composerAvailable: false,+ reasonCode: 'message_control_unread', pageTextsNeeded: [{ kind: 'message_control', text: name }] };+ };+ return { agent, tab, asked, answers };+ }++ test(`${build}: a reading that misses the click's wait is used by the retried click`, async () => {+ mock.timers.enable({ apis: ['setTimeout'] });+ try {+ const f = fixture();+ const first = f.agent._messageRecipientGuardProbe(f.tab, { tool: 'click_ax', args: { ref_id: 'ref_more' } });+ await flush();+ assert.equal(f.asked.length, 1);+ assert.equal(f.asked[0].options.mainTimeoutMs, 20_000, 'The model gets longer than the click waits');+ assert.equal(typeof f.asked[0].options.background?.current, 'function', 'The read is the run\'s background read');+ mock.timers.tick(4_000);+ await flush();+ const blocked = await first;+ assert.equal(blocked.reasonCode, 'message_control_unread', 'The click itself still waits only four seconds');+ // The model answers a second later; the retried click finds the reading.+ f.answers[0].resolve('conversation_tool');+ await flush();+ const retried = await f.agent._messageRecipientGuardProbe(f.tab, { tool: 'click_ax', args: { ref_id: 'ref_more' } });+ assert.equal(retried.conclusive, true, JSON.stringify(retried));+ assert.equal(retried.messageSend, false);+ assert.equal(f.asked.length, 1, 'The name is not asked about twice');+ } finally {+ mock.timers.reset();+ }+ });++ test(`${build}: a click retried while the reading is still going joins it`, async () => {+ mock.timers.enable({ apis: ['setTimeout'] });+ try {+ const f = fixture();+ const first = f.agent._messageRecipientGuardProbe(f.tab, { tool: 'click_ax', args: { ref_id: 'ref_more' } });+ await flush();+ mock.timers.tick(4_000);+ await flush();+ assert.equal((await first).reasonCode, 'message_control_unread');+ const retry = f.agent._messageRecipientGuardProbe(f.tab, { tool: 'click_ax', args: { ref_id: 'ref_more' } });+ await flush();+ assert.equal(f.asked.length, 1, 'The retry waits for the read in flight instead of asking again');+ f.answers[0].resolve('conversation_tool');+ await flush();+ const retried = await retry;+ assert.equal(retried.conclusive, true, JSON.stringify(retried));+ assert.equal(f.asked.length, 1);+ } finally {+ mock.timers.reset();+ }+ });++ test(`${build}: a reading that arrives in time still lets the first click through`, async () => {+ const f = fixture();+ const first = f.agent._messageRecipientGuardProbe(f.tab, { tool: 'click_ax', args: { ref_id: 'ref_more' } });+ await flush();+ f.answers[0].resolve('conversation_tool');+ const result = await first;+ assert.equal(result.conclusive, true, JSON.stringify(result));+ assert.equal(f.asked.length, 1);+ });++ test(`${build}: Stop cancels a guard reading that outlasted its click`, async () => {+ mock.timers.enable({ apis: ['setTimeout'] });+ try {+ const f = fixture();+ const controller = new AbortController();+ f.agent._runAbortSignal = () => controller.signal;+ f.agent._checkAbort = () => controller.signal.aborted;+ const first = f.agent._messageRecipientGuardProbe(f.tab, { tool: 'click_ax', args: { ref_id: 'ref_more' } });+ await flush();+ mock.timers.tick(4_000);+ await flush();+ await first;+ const signal = f.asked[0].options.background.signal;+ assert.equal(signal.aborted, false);+ controller.abort();+ assert.equal(signal.aborted, true, 'The background read stops with the run');+ // A late answer of a stopped run is not kept.+ f.answers[0].resolve('conversation_tool');+ await flush();+ assert.equal(f.agent._pageTextReading('message_control', 'More'), null);+ } finally {+ mock.timers.reset();+ }+ });++ test(`${build}: the end of the run cancels a guard reading still going`, async () => {+ mock.timers.enable({ apis: ['setTimeout'] });+ try {+ const f = fixture();+ const first = f.agent._messageRecipientGuardProbe(f.tab, { tool: 'click_ax', args: { ref_id: 'ref_more' } });+ await flush();+ mock.timers.tick(4_000);+ await flush();+ await first;+ f.agent._cancelSocialPublicationBackground(f.tab);+ assert.equal(f.asked[0].options.background.signal.aborted, true);+ await flush();+ assert.equal(f.agent._guardPageTextReads.size, 0, 'Nothing is left to join');+ } finally {+ mock.timers.reset();+ }+ });++ test(`${build}: a check about another control cancels the earlier control's reading`, async () => {+ // QA D6: after a blocked click the model tried other parts of the row.+ // Only the latest check's reading is carried over, so earlier ones do+ // not keep the model busy.+ mock.timers.enable({ apis: ['setTimeout'] });+ try {+ const f = fixture();+ const first = f.agent._messageRecipientGuardProbe(f.tab, { tool: 'click_ax', args: { ref_id: 'ref_more' } });+ await flush();+ mock.timers.tick(4_000);+ await flush();+ await first;+ const other = f.agent._messageRecipientGuardProbe(f.tab, { tool: 'click_ax', args: { ref_id: 'ref_search' } });+ await flush();+ assert.equal(f.asked[0].options.background.signal.aborted, true, 'The reading of "More" was cancelled');+ assert.deepEqual(f.asked.map(item => item.texts), [['More'], ['Search']]);+ assert.equal(f.asked[1].options.background.signal.aborted, false);+ f.answers[1].resolve('conversation_tool');+ assert.equal((await other).conclusive, true);+ f.answers[0].resolve('conversation_tool');+ await flush();+ assert.equal(f.agent._pageTextReading('message_control', 'More'), null, 'A cancelled reading is not kept');+ } finally {+ mock.timers.reset();+ }+ });++ test(`${build}: an in-browser model is still asked in the foreground and cut off at four seconds`, async () => {+ const f = fixture({ provider: { name: 'webgpu', chat: async () => ({}) } });+ const first = f.agent._messageRecipientGuardProbe(f.tab, { tool: 'click_ax', args: { ref_id: 'ref_more' } });+ await flush();+ assert.equal(f.asked.length, 1);+ assert.equal(f.asked[0].options.mainTimeoutMs, 4_000);+ assert.equal(f.asked[0].options.background, undefined);+ f.answers[0].resolve(null);+ assert.equal((await first).reasonCode, 'message_control_unread');+ });+}