Skip to content

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

Side panel: start queued messages when the panel comes back to their tab

Claudeb22ceb863e80
diff --git a/package.json b/package.json
index 898238d6e..4db6e539b 100644
--- a/package.json
+++ b/package.json
@@ -71,7 +71,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-pre-enter-veto.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/action-guard-user-override.mjs test/guard-direct-override.mjs test/guard-override-persistence.mjs test/publication-user-override.mjs test/resource-mutation-clarification.mjs test/publication-override-target.mjs test/completion-steering-receipt-authority.mjs test/steering-revision-recovery.mjs test/pending-clarification-hydration.mjs test/run-ui-hidden-panel.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/input-receiving-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/download-conversation-scope.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/planner-clarify-loop.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/permission-skip-dialog-ui.mjs test/permission-skip-session.mjs test/workflow-native-targets.mjs test/native-whatsapp-chat.mjs test/native-chat-context-identity.mjs test/native-whatsapp-contact.mjs test/whatsapp-chat-selection.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/slash-command-timeline-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 test/upload-file-source-approval.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-pre-enter-veto.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/action-guard-user-override.mjs test/guard-direct-override.mjs test/guard-override-persistence.mjs test/publication-user-override.mjs test/resource-mutation-clarification.mjs test/publication-override-target.mjs test/completion-steering-receipt-authority.mjs test/steering-revision-recovery.mjs test/pending-clarification-hydration.mjs test/run-ui-hidden-panel.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/input-receiving-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/download-conversation-scope.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/planner-clarify-loop.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/queued-composer-landing.mjs test/onboarding-provider-ready.mjs test/sidepanel-permission-gate-ui.mjs test/permission-skip-dialog-ui.mjs test/permission-skip-session.mjs test/workflow-native-targets.mjs test/native-whatsapp-chat.mjs test/native-chat-context-identity.mjs test/native-whatsapp-contact.mjs test/whatsapp-chat-selection.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/slash-command-timeline-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 test/upload-file-source-approval.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/input-receiving-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",
@@ -107,7 +107,7 @@
"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/cookie-banner-host.mjs test/captcha-aws-recovery.mjs test/captcha-documented-contracts.mjs test/huggingface-signup-recovery.mjs test/trace-full-export.mjs test/slash-command-tab-ownership.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:settings-pages: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-pre-enter-veto.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/action-guard-user-override.mjs test/guard-direct-override.mjs test/guard-override-persistence.mjs test/publication-user-override.mjs test/resource-mutation-clarification.mjs test/publication-override-target.mjs test/completion-steering-receipt-authority.mjs test/steering-revision-recovery.mjs test/pending-clarification-hydration.mjs test/run-ui-hidden-panel.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/input-receiving-frame.mjs test/ask-response-scope.mjs test/auto-mode.mjs test/plan-when-needed.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/download-conversation-scope.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/planner-clarify-loop.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/permission-skip-dialog-ui.mjs test/permission-skip-session.mjs test/model-picker-status-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-chat-selection.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/activity-brain-ui.mjs test/recipient-confirmation-ui.mjs test/assistant-message-visibility-ui.mjs test/slash-command-timeline-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/upload-file-source-approval.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/declined-submission-identity.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-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/queued-composer-landing.mjs test/onboarding-provider-ready.mjs test/sidepanel-permission-gate-ui.mjs test/permission-skip-dialog-ui.mjs test/permission-skip-session.mjs test/model-picker-status-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-chat-selection.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/activity-brain-ui.mjs test/recipient-confirmation-ui.mjs test/assistant-message-visibility-ui.mjs test/slash-command-timeline-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/upload-file-source-approval.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/declined-submission-identity.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 && npm run test:quality:resolved-address && 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 && node --test test/iframe-probe-match-index.mjs",
"test:shard:browser-c": "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 && node --test test/viewport-capture-browser.mjs && npm run test:vision-mode",
diff --git a/src/chrome/src/ui/sidepanel.js b/src/chrome/src/ui/sidepanel.js
index 3d0402d6e..7cc23b4a4 100644
--- a/src/chrome/src/ui/sidepanel.js
+++ b/src/chrome/src/ui/sidepanel.js
@@ -3371,6 +3371,11 @@ function queuedComposerSubmissionIsCurrent(item) {
function drainQueuedComposerMessageForCurrentTab() {
if (isProcessing || currentTabId == null || renderedTabId !== currentTabId) return false;
+ // A hidden panel cannot start the run (sendMessage needs the tab on screen),
+ // and moving the message into its composer would strand it there: the
+ // composer is no longer empty when the panel is shown again. Becoming
+ // visible drains it instead (requestVisibleSidePanelStateRefresh).
+ if (document.visibilityState === 'hidden') return false;
if (inputEl.value !== '') return false;
if (steeringRequestsByTab.has(Number(currentTabId))) return false;
const tabId = currentTabId;
@@ -5849,6 +5854,7 @@ async function switchToTab(newTabId) {
// to the already-rendered tab must also invalidate an older pending switch.
const switchGeneration = ++tabSwitchGeneration;
const interruptedTransition = tabSwitchTransitionId != null;
+ let stayedOnRenderedTab = false;
tabSwitchTransitionId = newTabId;
queuedTabSwitchMessages = queuedTabSwitchMessages.filter(msg => msg?.tabId === newTabId);
syncSendButtonState();
@@ -5858,6 +5864,7 @@ async function switchToTab(newTabId) {
historyPopover?.hidePopover();
if (newTabId === currentTabId && renderedTabId === newTabId) {
if (interruptedTransition) await restoreActiveRunState(newTabId);
+ stayedOnRenderedTab = true;
return;
}
let state = null;
@@ -5950,6 +5957,13 @@ async function switchToTab(newTabId) {
tabSwitchTransitionId = null;
if (currentTabId === renderedTabId) drainQueuedAgentUpdatesForTab(currentTabId);
if (visibleStateRefreshPending) requestVisibleSidePanelStateRefresh();
+ // Only a full switch reaches the drain after this block. A run of this
+ // tab may have ended while the panel showed another tab, when its own
+ // drain had to give up; an activation for the tab already rendered (a
+ // second event while switching back, the window regaining focus) is
+ // then the landing that starts the tab's queued messages. A run this
+ // panel still follows drains them itself when it ends.
+ if (stayedOnRenderedTab && !isTabProcessing(newTabId)) void drainQueuedPromptsAfterRunSettles(newTabId);
}
syncSendButtonState();
}
@@ -6022,7 +6036,16 @@ function requestVisibleSidePanelStateRefresh() {
}).catch(() => {});
refreshPromise.then((refreshed) => {
if (!refreshed || refreshPromise !== visibleStateRefreshPromise) return;
- consumePendingContextMenuPrompt().then(() => drainQueuedContextMenuPrompts()).catch(() => {});
+ const refreshedTabId = currentTabId;
+ consumePendingContextMenuPrompt().then(() => {
+ // Queued composer messages come first, as after a run. One whose run
+ // ended while this panel was hidden or showed another tab is still
+ // waiting for its tab to be on screen.
+ if (nextAutomaticQueuedComposerMessage(refreshedTabId) && !isTabProcessing(refreshedTabId)) {
+ return drainQueuedPromptsAfterRunSettles(refreshedTabId);
+ }
+ drainQueuedContextMenuPrompts();
+ }).catch(() => {});
newtabHandoff.consume().catch(() => {});
}).catch(() => {});
return refreshPromise;
@@ -11381,9 +11404,15 @@ function handleAgentUpdateMessage(msg) {
// Fallback queues belong to their source tab even while another tab is visible.
if (msg.type === 'steering_queued') {
if (isConversationClearInProgress(msg.tabId)) return;
- queueUnconsumedSteeringMessages(msg.tabId, msg.data?.messages, {
- held: msg.data?.stopped === true || isTabAbortRequested(msg.tabId),
- });
+ const held = msg.data?.stopped === true || isTabAbortRequested(msg.tabId);
+ queueUnconsumedSteeringMessages(msg.tabId, msg.data?.messages, { held });
+ // A finishing run hands back the corrections it did not apply. This update
+ // can arrive after the run's own end-of-run drain, so it asks for one too;
+ // the drain waits until the background reports the tab idle. Before then,
+ // a run this panel follows drains them itself when it ends.
+ if (!held && sameTabId(currentTabId, msg.tabId) && !isTabProcessing(msg.tabId)) {
+ void drainQueuedPromptsAfterRunSettles(msg.tabId);
+ }
}
// A run stopped outside this panel (page Stop button) also holds its queue.
if (msg.type === 'run_complete' && ['stopped', 'cancelled'].includes(msg.data?.status)) {
diff --git a/src/firefox/src/ui/sidepanel.js b/src/firefox/src/ui/sidepanel.js
index 5adb39288..fa9721472 100644
--- a/src/firefox/src/ui/sidepanel.js
+++ b/src/firefox/src/ui/sidepanel.js
@@ -3623,6 +3623,11 @@ function queuedComposerSubmissionIsCurrent(item) {
function drainQueuedComposerMessageForCurrentTab() {
if (isProcessing || currentTabId == null || renderedTabId !== currentTabId) return false;
+ // A hidden panel cannot start the run (sendMessage needs the tab on screen),
+ // and moving the message into its composer would strand it there: the
+ // composer is no longer empty when the panel is shown again. Becoming
+ // visible drains it instead (requestVisibleSidePanelStateRefresh).
+ if (document.visibilityState === 'hidden') return false;
if (inputEl.value !== '') return false;
if (steeringRequestsByTab.has(Number(currentTabId))) return false;
const tabId = currentTabId;
@@ -5688,6 +5693,7 @@ async function switchToTab(newTabId) {
// to the already-rendered tab must also invalidate an older pending switch.
const switchGeneration = ++tabSwitchGeneration;
const interruptedTransition = tabSwitchTransitionId != null;
+ let stayedOnRenderedTab = false;
tabSwitchTransitionId = newTabId;
queuedTabSwitchMessages = queuedTabSwitchMessages.filter(msg => msg?.tabId === newTabId);
syncSendButtonState();
@@ -5697,6 +5703,7 @@ async function switchToTab(newTabId) {
historyPopover?.hidePopover();
if (newTabId === currentTabId && renderedTabId === newTabId) {
if (interruptedTransition) await restoreActiveRunState(newTabId);
+ stayedOnRenderedTab = true;
return;
}
let state = null;
@@ -5795,6 +5802,13 @@ async function switchToTab(newTabId) {
tabSwitchTransitionId = null;
if (currentTabId === renderedTabId) drainQueuedAgentUpdatesForTab(currentTabId);
if (visibleStateRefreshPending) requestVisibleSidePanelStateRefresh();
+ // Only a full switch reaches the drain after this block. A run of this
+ // tab may have ended while the panel showed another tab, when its own
+ // drain had to give up; an activation for the tab already rendered (a
+ // second event while switching back, the window regaining focus) is
+ // then the landing that starts the tab's queued messages. A run this
+ // panel still follows drains them itself when it ends.
+ if (stayedOnRenderedTab && !isTabProcessing(newTabId)) void drainQueuedPromptsAfterRunSettles(newTabId);
}
syncSendButtonState();
}
@@ -5866,7 +5880,16 @@ function requestVisibleSidePanelStateRefresh() {
}).catch(() => {});
refreshPromise.then((refreshed) => {
if (!refreshed || refreshPromise !== visibleStateRefreshPromise) return;
- consumePendingContextMenuPrompt().then(() => drainQueuedContextMenuPrompts()).catch(() => {});
+ const refreshedTabId = currentTabId;
+ consumePendingContextMenuPrompt().then(() => {
+ // Queued composer messages come first, as after a run. One whose run
+ // ended while this panel was hidden or showed another tab is still
+ // waiting for its tab to be on screen.
+ if (nextAutomaticQueuedComposerMessage(refreshedTabId) && !isTabProcessing(refreshedTabId)) {
+ return drainQueuedPromptsAfterRunSettles(refreshedTabId);
+ }
+ drainQueuedContextMenuPrompts();
+ }).catch(() => {});
newtabHandoff.consume().catch(() => {});
}).catch(() => {});
return refreshPromise;
@@ -10878,9 +10901,15 @@ function handleAgentUpdateMessage(msg) {
// Fallback queues belong to their source tab even while another tab is visible.
if (msg.type === 'steering_queued') {
if (isConversationClearInProgress(msg.tabId)) return;
- queueUnconsumedSteeringMessages(msg.tabId, msg.data?.messages, {
- held: msg.data?.stopped === true || isTabAbortRequested(msg.tabId),
- });
+ const held = msg.data?.stopped === true || isTabAbortRequested(msg.tabId);
+ queueUnconsumedSteeringMessages(msg.tabId, msg.data?.messages, { held });
+ // A finishing run hands back the corrections it did not apply. This update
+ // can arrive after the run's own end-of-run drain, so it asks for one too;
+ // the drain waits until the background reports the tab idle. Before then,
+ // a run this panel follows drains them itself when it ends.
+ if (!held && sameTabId(currentTabId, msg.tabId) && !isTabProcessing(msg.tabId)) {
+ void drainQueuedPromptsAfterRunSettles(msg.tabId);
+ }
}
// A run stopped outside this panel (page Stop button) also holds its queue.
if (msg.type === 'run_complete' && ['stopped', 'cancelled'].includes(msg.data?.status)) {
diff --git a/test/queued-composer-landing.mjs b/test/queued-composer-landing.mjs
new file mode 100644
index 000000000..a4b1e3283
--- /dev/null
+++ b/test/queued-composer-landing.mjs
@@ -0,0 +1,248 @@
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import fs from 'node:fs';
+import vm from 'node:vm';
+
+// A message queued during a run starts when that run ends, but only if the
+// panel shows the run's tab at that moment (drainQueuedPromptsAfterRunSettles
+// needs the tab on screen). When it ended while the panel followed another
+// tab, or was hidden, the message has to start when the panel lands on the
+// tab again: on every activation for it, when the panel becomes visible, and
+// when a finishing run hands corrections back late. The production queue,
+// drain, tab-switch and visibility functions run verbatim; only browser and
+// background boundaries are stubbed.
+
+const settle = (ms = 0) => new Promise(resolve => setTimeout(resolve, ms));
+const RETRY_MS = 20;
+const QUEUED = 'publish 45.0.0 to mozilla amo';
+
+function deferred() {
+ let resolve;
+ const promise = new Promise(done => { resolve = done; });
+ return { promise, resolve };
+}
+
+function extract(source, name) {
+ const start = source.search(new RegExp(`^(?:async )?function ${name}\\(`, 'm'));
+ const end = source.indexOf('\n}', start);
+ assert.ok(start >= 0 && end > start, `Missing production function ${name}`);
+ return source.slice(start, end + 2);
+}
+
+function between(source, from, to) {
+ const start = source.indexOf(from);
+ const end = source.indexOf(to, start + from.length);
+ assert.ok(start >= 0 && end > start, `Missing anchor: ${from}`);
+ return source.slice(start, end);
+}
+
+function panel(build, { currentTabId = 1, renderedTabId = currentTabId, queue = [{ id: 'q1', text: QUEUED }] } = {}) {
+ const source = fs.readFileSync(new URL(`../src/${build}/src/ui/sidepanel.js`, import.meta.url), 'utf8').replace(/\r\n/g, '\n');
+ const sent = [];
+ const background = { running: false, runStateProbes: 0 };
+ const restoreGates = [];
+ const context = vm.createContext({
+ console, Promise, Map, Set, Number, String, Symbol, setTimeout, clearTimeout,
+ sent, background, restoreGates,
+ currentTabId, renderedTabId, isProcessing: false, abortRequested: false,
+ processingTabs: new Set(), abortRequestedTabs: new Set(),
+ tabSwitchGeneration: 0, tabSwitchTransitionId: null, queuedTabSwitchMessages: [],
+ historyRecoveryTabs: new Set(), historyPopover: null, newConversationConfirmationState: null,
+ currentAssistantEl: null, TAB_CHAT_LOAD_FAILED: Symbol('tab-chat-load-failed'),
+ visibleStateRefreshPending: false, visibleStateRefreshInProgress: false,
+ visibleStateRefreshGeneration: 0, visibleStateRefreshPromise: Promise.resolve(),
+ document: { visibilityState: 'visible' },
+ messagesEl: { innerHTML: '', querySelectorAll: () => [] },
+ inputEl: { value: '' },
+ tabInputDrafts: new Map(), permissionSkipCommandContextsByTab: new Map(),
+ steeringRequestsByTab: new Map(), queuedSteeringMessageIds: new Set(),
+ queuedComposerMessagesByTab: new Map(queue.length ? [[1, structuredClone(queue)]] : []),
+ QUEUED_PROMPT_DRAIN_RETRY_MS: RETRY_MS, queuedPromptDrainRetryTimers: new Map(),
+ newtabHandoff: { consume: async () => {} },
+ sendToBackground: async (action) => {
+ if (action === 'agent_run_state') {
+ background.runStateProbes += 1;
+ return { ok: true, running: background.running, starting: false };
+ }
+ return { ok: true };
+ },
+ // The real restore reads the tab's run journal from the background; a
+ // test can hold it open to let another activation arrive meanwhile.
+ restoreActiveRunState: async () => { const gate = restoreGates.shift(); if (gate) await gate.promise; },
+ loadTabChat: async tabId => `chat ${tabId}`,
+ hydrateRestoredChatHistory: async () => {},
+ refreshVisibleSidePanelState: async () => true,
+ waitForTabChatHandoffRetry: async () => {},
+ consumePendingContextMenuPrompt: async () => {},
+ hasQueuedContextMenuPromptForTab: () => false,
+ isConversationClearInProgress: () => false,
+ isPermissionSkipCommandDraft: () => false,
+ isTabProcessing: tabId => context.processingTabs.has(Number(tabId)),
+ isTabAbortRequested: tabId => context.abortRequestedTabs.has(Number(tabId)),
+ // Like the real send, an accepted queued submission leaves the queue and the composer.
+ sendMessage: async (params) => {
+ const item = params.__queuedComposerMessage;
+ sent.push(item ? { tabId: item.tabId, text: item.text } : { text: context.inputEl.value });
+ if (item) context.removeQueuedComposerMessage(item.tabId, item.id);
+ context.inputEl.value = '';
+ delete context.inputEl.queuedComposerSubmission;
+ return true;
+ },
+ t: key => key, addMessage: () => {},
+ });
+ for (const name of [
+ 'syncSendButtonState', 'dismissSelectionAskAction', 'settleNewConversationConfirmation',
+ 'closePermissionSkipDialog', 'hideActivity', 'flushRenderedTabChat', 'flushChatHistorySnapshot',
+ 'resetChatNavigation', 'syncApiMutationsAllowedForCurrentTab', 'restoreComposerModeForCurrentTab',
+ 'syncSelectionScopeUi', 'migrateLegacyEmptyStateFromRestoredChat', 'rebindRestoredMessageControls',
+ 'refreshRenderedStepLabels', 'syncProgressDisplayMode', 'renderAttachmentPreviews',
+ 'renderQueuedComposerMessages', 'restoreLatestChatTurnPosition', 'refreshScheduledJobs',
+ 'refreshRecommendedActions', 'drainQueuedAgentUpdatesForTab', 'drainQueuedContextMenuPrompts',
+ 'renderComposerModePicker', 'autoResizeInput', 'updateSlashCommandAutocomplete',
+ 'resetComposerHistoryNavigation', 'hideSlashCommandAutocomplete',
+ ]) context[name] = () => {};
+ const functions = [
+ 'sameTabId', 'getQueuedComposerMessages', 'setQueuedComposerMessages', 'removeQueuedComposerMessage',
+ 'nextAutomaticQueuedComposerMessage', 'queueUnconsumedSteeringMessages',
+ 'drainQueuedComposerMessageForCurrentTab', 'cancelQueuedPromptDrainRetry', 'scheduleQueuedPromptDrainRetry',
+ 'hasQueuedPromptForTab', 'drainQueuedPromptsAfterRunSettles', 'switchToTab', 'waitForHistoryRecovery',
+ 'researchEscalationSourceTabIdFromState', 'requestVisibleSidePanelStateRefresh',
+ 'syncCurrentTabRunFlags', 'restoreInputDraftForTab', 'captureInputDraftForTab', 'saveInputDraftForTab',
+ ].map(name => extract(source, name)).join('\n');
+ // The top of handleAgentUpdateMessage, which queues handed-back corrections
+ // for their own tab before updates for other tabs are dropped.
+ const steeringUpdate = between(source, ' // Fallback queues belong to their source tab even while another tab is visible.',
+ " // Drop updates that belong to a different tab's run.");
+ vm.runInContext(`${functions}\nfunction onAgentUpdate(msg) {\n${steeringUpdate}\n}`, context);
+ return {
+ context, sent, background, restoreGates,
+ // Copied out of the vm realm so strict deep equality compares plain values.
+ queue: (tabId = 1) => Array.from(context.getQueuedComposerMessages(tabId), item => ({ text: item.text, held: item.held === true })),
+ };
+}
+
+for (const build of ['chrome', 'firefox']) {
+ test(`${build}: a run ending while the panel shows another tab leaves its message queued`, async () => {
+ const h = panel(build, { currentTabId: 2 });
+ await h.context.drainQueuedPromptsAfterRunSettles(1);
+ await settle(RETRY_MS * 3);
+ assert.deepEqual(h.sent, [], 'The panel cannot start a run in a tab it does not show');
+ assert.deepEqual(h.queue(), [{ text: QUEUED, held: false }]);
+ });
+
+ test(`${build}: switching back to the tab starts its queued message`, async () => {
+ const h = panel(build, { currentTabId: 2 });
+ await h.context.switchToTab(1);
+ await settle();
+ assert.deepEqual(h.sent, [{ tabId: 1, text: QUEUED }]);
+ assert.deepEqual(h.queue(), []);
+ });
+
+ test(`${build}: a second activation while switching back still starts it, once`, async () => {
+ const h = panel(build, { currentTabId: 2 });
+ const restore = deferred();
+ h.restoreGates.push(restore);
+ // tabs.onActivated, then windows.onFocusChanged for the same tab while the
+ // first switch is still restoring the tab's run state.
+ const first = h.context.switchToTab(1);
+ await settle();
+ assert.equal(h.context.renderedTabId, 1, 'fixture: the first switch already rendered the tab');
+ const second = h.context.switchToTab(1);
+ await settle();
+ restore.resolve();
+ await Promise.all([first, second]);
+ await settle(RETRY_MS * 3);
+ assert.deepEqual(h.sent, [{ tabId: 1, text: QUEUED }]);
+ assert.deepEqual(h.queue(), []);
+ });
+
+ test(`${build}: an activation for the tab already shown starts its queued message`, async () => {
+ // The panel stayed on the tab (its window lost focus) while the run ended
+ // hidden; the window regaining focus syncs the same tab again.
+ const h = panel(build, { currentTabId: 1 });
+ await h.context.switchToTab(1);
+ await settle();
+ assert.deepEqual(h.sent, [{ tabId: 1, text: QUEUED }]);
+ });
+
+ test(`${build}: a hidden panel keeps the message out of its composer and starts it once visible`, async () => {
+ const h = panel(build, { currentTabId: 1 });
+ h.context.document.visibilityState = 'hidden';
+ await h.context.drainQueuedPromptsAfterRunSettles(1);
+ await settle();
+ assert.deepEqual(h.sent, []);
+ assert.equal(h.context.inputEl.value, '', 'A hidden panel must not strand the message in its composer');
+ assert.deepEqual(h.queue(), [{ text: QUEUED, held: false }]);
+ h.context.document.visibilityState = 'visible';
+ await h.context.requestVisibleSidePanelStateRefresh();
+ await settle();
+ assert.deepEqual(h.sent, [{ tabId: 1, text: QUEUED }]);
+ assert.deepEqual(h.queue(), []);
+ });
+
+ test(`${build}: a correction handed back after the run's own drain starts on its own`, async () => {
+ const h = panel(build, { currentTabId: 1, queue: [] });
+ await h.context.drainQueuedPromptsAfterRunSettles(1); // the run's drain found nothing yet
+ h.context.onAgentUpdate({ tabId: 1, requestId: 'run-1', type: 'steering_queued',
+ data: { messages: [{ id: 'corr-1', text: 'Use the short version' }] } });
+ await settle();
+ assert.deepEqual(h.sent, [{ tabId: 1, text: 'Use the short version' }]);
+ });
+
+ test(`${build}: a correction handed back while its run is finishing waits for it to end`, async () => {
+ const h = panel(build, { currentTabId: 1, queue: [] });
+ h.background.running = true;
+ h.context.onAgentUpdate({ tabId: 1, requestId: 'run-1', type: 'steering_queued',
+ data: { messages: [{ id: 'corr-1', text: 'Use the short version' }] } });
+ await settle(RETRY_MS * 3);
+ assert.deepEqual(h.sent, [], 'Nothing starts while the background still runs the tab');
+ h.background.running = false;
+ await settle(RETRY_MS * 4);
+ assert.deepEqual(h.sent, [{ tabId: 1, text: 'Use the short version' }]);
+ });
+
+ test(`${build}: corrections handed back by a stopped run stay held`, async () => {
+ const h = panel(build, { currentTabId: 1, queue: [] });
+ h.context.onAgentUpdate({ tabId: 1, requestId: 'run-1', type: 'steering_queued',
+ data: { messages: [{ id: 'corr-1', text: 'Also post it on Mastodon' }], stopped: true } });
+ await h.context.switchToTab(1);
+ await h.context.requestVisibleSidePanelStateRefresh();
+ await settle(RETRY_MS * 3);
+ assert.deepEqual(h.sent, [], 'After Stop nothing starts on its own');
+ assert.deepEqual(h.queue(), [{ text: 'Also post it on Mastodon', held: true }]);
+ });
+
+ test(`${build}: a landing while the panel follows the tab's own run leaves the start to that run`, async () => {
+ const h = panel(build, { currentTabId: 1 });
+ h.context.processingTabs.add(1);
+ h.context.isProcessing = true;
+ h.background.running = true;
+ await h.context.switchToTab(1); // the window regains focus mid-run
+ await h.context.requestVisibleSidePanelStateRefresh();
+ h.context.onAgentUpdate({ tabId: 1, requestId: 'run-1', type: 'steering_queued',
+ data: { messages: [{ id: 'corr-1', text: 'Use the short version' }] } });
+ await settle(RETRY_MS * 3);
+ assert.equal(h.background.runStateProbes, 0, 'No background polling while the panel follows the run');
+ assert.deepEqual(h.sent, []);
+ // The run ends on screen; its own drain starts the queue in order.
+ h.background.running = false;
+ h.context.processingTabs.delete(1);
+ h.context.isProcessing = false;
+ await h.context.drainQueuedPromptsAfterRunSettles(1);
+ await settle();
+ assert.deepEqual(h.sent, [{ tabId: 1, text: 'Use the short version' }]);
+ assert.deepEqual(h.queue(), [{ text: QUEUED, held: false }]);
+ });
+
+ test(`${build}: landing on the tab never replaces the user's draft`, async () => {
+ const h = panel(build, { currentTabId: 2 });
+ h.context.tabInputDrafts.set(1, 'my unsent draft');
+ await h.context.switchToTab(1);
+ await h.context.switchToTab(1);
+ await h.context.requestVisibleSidePanelStateRefresh();
+ await settle(RETRY_MS * 3);
+ assert.deepEqual(h.sent, []);
+ assert.equal(h.context.inputEl.value, 'my unsent draft');
+ assert.deepEqual(h.queue(), [{ text: QUEUED, held: false }]);
+ });
+}
diff --git a/test/run-ui-hidden-panel.mjs b/test/run-ui-hidden-panel.mjs
index 187187a33..9037c5d0f 100644
--- a/test/run-ui-hidden-panel.mjs
+++ b/test/run-ui-hidden-panel.mjs
@@ -183,6 +183,8 @@ async function panelFixture(build, bg) {
reconcilePersistedStagedScreenshots: asyncNoop, newtabHandoff: { consume: asyncNoop },
scheduleHistoryPersist: noop, refreshRenderedStepLabels: noop, syncProgressDisplayMode: noop,
migrateLegacyEmptyStateFromRestoredChat: noop, drainQueuedContextMenuPrompts: noop, syncSendButtonState: noop,
+ // No composer message is queued in this fixture.
+ nextAutomaticQueuedComposerMessage: () => null, drainQueuedPromptsAfterRunSettles: asyncNoop,
showActivity: noop, hideActivity: noop, startThinkingActivity: noop, clearThinkingActivityTimers: noop,
beginThinkingActivity: noop, showInspectionBanner: noop, clearTransientAssistantTextForToolCall: noop,
friendlyToolLabel: name => name, markLastStepDone: noop, finalizeSteps: noop, setMessageCreatedAt: noop,