Skip to content

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

Hold Google Chat sends in Gmail instead of reading a name from the page

Emre Sokullue1a726ea363e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7c6638faa..48be88401 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,7 +9,7 @@ This changelog was generated from the repository Git history and release tags. V
### Fixed
- When the model provider rate-limits WebBrain (HTTP 429, or Anthropic's 529 "overloaded"), the step is now waited out and retried up to three times (about 5, 15 and 30 seconds, or longer if the provider asks), also when the limit arrives in the middle of a response, as OpenRouter and WebBrain Cloud report it, and for Anthropic (including Vertex), Azure OpenAI, AWS Bedrock and llama.cpp, whose limits ended Act runs at once. An answer you already saw part of is never generated again. A message such as "Rate limit exceeded" is no longer mistaken for an over-long conversation, so WebBrain no longer trims your conversation and asks you to start a new one. Older context is trimmed only when one request alone exceeds the provider's per-minute token limit, and then right away and only once; if the provider does not state its limit, one shortened retry is tried, and the conversation is shortened only if that retry succeeds. Each wait is lengthened at random by up to 20% so several runs do not retry at the same moment, and never comes sooner than the provider asks. An OpenAI "insufficient_quota" billing error now fails at once instead of being retried, and traces label rate limits as rate limiting even when the message mentions a quota.
- The local vision fallback now also runs when an OpenAI-compatible provider such as Ollama or LM Studio rejects a screenshot as unsupported. The rejection's status was read from the wrong field, so the fallback never started.
-- Chat sites: a message is no longer sent to whoever's chat is open just because an e-mail address appears in that chat's earlier messages. When a chat showed no contact name at the top, WebBrain took such an address for the recipient; now it stops and says it cannot tell who the chat is with. An address shown in the conversation's own header, as in help-desk and CRM conversations, still identifies the recipient, while an address in the header's pinned text does not, and mail compose windows read their To, Cc and Bcc addresses as before. In Google Chat inside Gmail, an address mentioned in the chat is never taken as the recipient, while a Gmail compose window open over the Chat view still sends to its To, Cc and Bcc addresses.
+- Chat sites: a message is no longer sent to whoever's chat is open just because an e-mail address appears in that chat's earlier messages. When a chat showed no contact name at the top, WebBrain took such an address for the recipient; now it stops and says it cannot tell who the chat is with. An address shown in the conversation's own header, as in help-desk and CRM conversations, still identifies the recipient, while an address in the header's pinned text does not, and mail compose windows read their To, Cc and Bcc addresses as before. In Google Chat inside Gmail, an address mentioned in the chat is never taken as the recipient either: WebBrain stops before sending there, since nothing on the page reliably tells the chat's name from the names in its messages, while a Gmail compose window open over the Chat view still sends to its To, Cc and Bcc addresses.
- Long text fields: WebBrain no longer replaces a field's text with the shortened copy it was shown, such as the first 60 characters followed by "...", which deleted everything after that point. The write is refused before anything is typed, also in embedded frames, and WebBrain is told to read the full text first. Complete new text and additions are typed as before, and a field whose own text contains a "[… truncated …]" note, such as a pasted log, can still be edited.
- Choosing an option in a dropdown: the hint now suggests pressing the down arrow and then Enter, one key at a time, which the key tool supports, instead of typing the option's first letter in a form the key tool always rejects.
- Reading Google pages while signed in: your Google account's name, e-mail address and profile photo from Google's account button are no longer shown to the AI, in the page structure, click, hover, drag and scroll results, element and link lists, text-click candidates, covering-overlay messages, page media or screenshot element lists. The button is still there, called "Google account", and the signed-out "Sign in" link keeps its name. Account links that belong to the page itself, such as on your Google Account pages or in a security-alert e-mail, and e-mail addresses on the page, such as a business's contact address, are unchanged.
diff --git a/src/chrome/src/agent/adapters.js b/src/chrome/src/agent/adapters.js
index b1288dbf6..2f3702191 100644
--- a/src/chrome/src/agent/adapters.js
+++ b/src/chrome/src/agent/adapters.js
@@ -16089,8 +16089,9 @@ const ADAPTERS = [
messaging: {
verifyActiveRecipient: true,
deferActiveConversationUntilComposer: true,
- // Mail has To/Cc/Bcc recipient sets. Google Chat inside Gmail sends to
- // the one open conversation, so its routes bind a single recipient.
+ // Mail has To/Cc/Bcc recipient sets. Google Chat inside Gmail has none
+ // of its own: a send there is held (content.js), while a compose window
+ // open over it still reports its own rows.
supportsRecipientSets: url => !isGmailChatRoute(url),
},
notes: `
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 1fc2a2c12..520b1efbf 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -1853,14 +1853,17 @@ export class Agent extends LoopDetector {
}
// A successful click_ax the app sent itself to read a native chat, while its
- // ownership still holds: not the model's action. Shared like the above.
- _isOwnedNativeChatReadRepair(tabId, name, args, result, messageRecipientContext) {
+ // ownership still holds: not the model's action. Shared like the above. A
+ // call cut short by Stop or an error (`interrupted`) is judged by the
+ // ownership its guard gave it, since Stop ends the run's ownership before
+ // the interrupted path reads it.
+ _isOwnedNativeChatReadRepair(tabId, name, args, result, messageRecipientContext, { interrupted = false } = {}) {
return name === 'click_ax' && result?.success === true && !result.outcomeUnknown
&& result.noDispatch !== true && ((result._nativeWhatsappReadRepair === true
&& !!messageRecipientContext?.nativeWhatsappReadRepairOwner
- && messageRecipientContext.nativeWhatsappReadRepairOwner === this._nativeChatOwnerScope(tabId))
+ && (interrupted || messageRecipientContext.nativeWhatsappReadRepairOwner === this._nativeChatOwnerScope(tabId)))
|| (result._nativeTelegramReadRepair === true
- && this._nativeTelegramReadPreparationCurrent(tabId, args, messageRecipientContext)));
+ && this._nativeTelegramReadPreparationCurrent(tabId, args, messageRecipientContext, { interrupted })));
}
_recordCompletionToolResult(tabId, name, args, result, { detectedSubmit = null, messageRecipientContext = null, ownedReadRepairBatch = false } = {}) {
@@ -13632,11 +13635,12 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// without one, a call that may have been sent counts as sent, so it can
// back an "acted" row, and only a provably unsent one is held against one.
// The args and the read-repair exemption are the normal path's too; Stop
- // clears the owner scope that exemption checks, so the app's own repair
- // batch is also recognized by its run option.
+ // clears the owner scope that exemption checks, so a repair is judged by
+ // the ownership its guard gave the call, and the app's own repair batch
+ // is recognized by its run option.
if (interrupted?.name && !interrupted.dispatchNoted && runOptions[OWNED_NATIVE_CHAT_READ_REPAIR] !== true
&& !this._isOwnedNativeChatReadRepair(tabId, interrupted.name, interrupted.args || {}, interruptedRaw,
- interrupted.messageRecipientContext)) {
+ interrupted.messageRecipientContext, { interrupted: true })) {
this._noteProgressActionDispatch(tabId, interrupted.name,
this._completionToolArgs(tabId, interrupted.name, interrupted.args || {}), interruptedRaw,
interruptedRaw ? undefined : !interruptedUnsent);
@@ -26631,9 +26635,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
String(provider.model || provider.config?.model || ''), authority.taskSha256, authority.resumeTaskId, authority.providerSha256]);
}
- _nativeTelegramReadPreparationCurrent(tabId, args, context) {
+ _nativeTelegramReadPreparationCurrent(tabId, args, context, { interrupted = false } = {}) {
return !!context?.nativeTelegramReadRepairOwner
- && context.nativeTelegramReadRepairOwner === this._nativeChatOwnerScope(tabId)
+ && (interrupted || context.nativeTelegramReadRepairOwner === this._nativeChatOwnerScope(tabId))
&& typeof args?.ref_id === 'string' && args.ref_id === context.nativeTelegramReadRepairRef
&& typeof context.nativeTelegramReadRepairBinding?.token === 'string'
&& context.nativeTelegramReadRepairBinding.token.length > 0
@@ -42305,7 +42309,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
|| (workflowMessageKind === 'message_draft'
? (this._workflowDraftAuthorizedTarget(executionGuard)?.recipients || [])
: []),
- // Google Chat inside Gmail has one recipient, not mail's sets.
+ // Google Chat routes in Gmail have no recipient set of their own;
+ // a compose window open there reports its rows itself.
supportsRecipientSets: executionGuard.siteWorkflow.adapterName === 'gmail'
&& !isGmailChatRoute(probe?.url || ''),
});
diff --git a/src/chrome/src/agent/planner.js b/src/chrome/src/agent/planner.js
index 7c5c97a33..397a6bcf5 100644
--- a/src/chrome/src/agent/planner.js
+++ b/src/chrome/src/agent/planner.js
@@ -1129,7 +1129,7 @@ export function normalizePlan(obj, opts = {}) {
const risks = riskEntries.map(entry => entry.text);
const localizedInput = obj.localized && typeof obj.localized === 'object' ? obj.localized : {};
const providedLocalizedSteps = Array.isArray(localizedInput.steps)
- ? localizedInput.steps.slice(0, 12).map((step, i) => ({
+ ? localizedInput.steps.slice(0, PLAN_STEP_LIMIT).map((step, i) => ({
id: sanitizeText(step?.id || String(i + 1), 20) || String(i + 1),
action: sanitizeText(step?.action, 300),
})).filter((step) => step.action)
diff --git a/src/chrome/src/content/content.js b/src/chrome/src/content/content.js
index e96317ca5..706aa03c5 100644
--- a/src/chrome/src/content/content.js
+++ b/src/chrome/src/content/content.js
@@ -7935,46 +7935,14 @@
}
return null;
};
- // Google Chat inside Gmail is a chat: on a Chat route, a composer in
- // the page's main region, in no compose window and not Gmail's mail
- // body, is identified by its own conversation header, as any chat is.
- const gmailChatRoute = gmailRecipientMode && (() => {
- try {
- return location.hostname === 'mail.google.com'
- && (/^\/chat(?:\/|$)/.test(String(location.pathname || ''))
- || /^#chat(?:[/?]|$)/.test(String(location.hash || '')));
- } catch { return false; }
- })();
- // Between an element and the Chat's main region: a scrolling area (or,
- // with `lists`, a log, list or feed), where the conversation's history
- // and the threads inside it live.
- const gmailInChatHistory = (el, main, lists = true) => {
- for (let node = el?.parentElement; node && node !== main; node = node.parentElement) {
- if (lists && node.matches?.('[role="log"],[role="list"],[role="feed"]')) return true;
- try {
- const style = getComputedStyle(node);
- if (/^(auto|scroll|overlay)$/.test(String(style.overflowY || style.overflow || '').toLowerCase())
- && Number(node.scrollHeight) > Number(node.clientHeight) + 1) return true;
- } catch {}
- }
- return false;
- };
- // A composer inside that history, such as a thread's reply box in the
- // scrolling message list, is not the Chat's own composer.
- const gmailChatMainOf = (editor, ownWindow = gmailComposeWindowOf(editor)) => {
- if (!gmailChatRoute || !editor || ownWindow || editor.getAttribute?.('g_editable') === 'true'
- || editor.closest?.('[role="dialog"]')) return null;
- const main = editor.closest?.('main,[role="main"]') || null;
- return main && !gmailInChatHistory(editor, main) ? main : null;
- };
// The composer a control (a Send, an attachment input) belongs to: the
// one message editor in the control's nearest ancestor holding any,
- // when the control lies inside that editor's own compose window or
- // Chat region. Its message, not the page's lowest editor, is what the
- // control sends. A click into an editor only focuses it; a page control
- // that merely shares a distant ancestor with one editor (a toolbar's
- // Archive) is no message's; and none, or more than one editor there,
- // leaves the pairing to the page's layout.
+ // when the control lies inside that editor's own compose window. Its
+ // message, not the page's lowest editor, is what the control sends. A
+ // click into an editor only focuses it; a page control that merely
+ // shares a distant ancestor with one editor (a toolbar's Archive) is
+ // no message's; and none, or more than one editor there, leaves the
+ // pairing to the page's layout.
const gmailControlComposer = control => {
if (!gmailRecipientMode || !control || editable(control)) return null;
for (let node = control; node && node !== document.documentElement; node = node.parentElement) {
@@ -7983,9 +7951,7 @@
if (!inside.length) continue;
const owners = inside.filter(editor => !inside.some(other => other !== editor && other.contains?.(editor)));
if (owners.length !== 1) return null;
- const ownWindow = gmailComposeWindowOf(owners[0]);
- const scope = ownWindow || gmailChatMainOf(owners[0], ownWindow);
- return scope?.contains?.(control) ? owners[0] : null;
+ return gmailComposeWindowOf(owners[0])?.contains?.(control) ? owners[0] : null;
}
return null;
};
@@ -8262,9 +8228,6 @@
const addStrongIdentity = (el) => {
if (!visible(el) || editable(el) || el.closest?.('input,textarea,[contenteditable="true"]')) return;
if (!inConversationHeaderBand(el) || independentScrollableRegion(el, composer)) return;
- // In a Gmail Chat, nothing inside a scrolling area below its main
- // region (its history, a thread) names the conversation.
- if (gmailChatMain && gmailInChatHistory(el, gmailChatMain, false)) return;
const text = compact(
el.getAttribute?.('aria-label')
|| el.getAttribute?.('title')
@@ -8293,8 +8256,6 @@
const gmailForeignSend = !!gmailSendOwner && composerCandidates.some(editor => gmailSendOwner.contains(editor)
&& !gmailEditorScope.contains?.(editor) && otherMessageEditor(editor, composer));
const gmailMailSend = !!gmailComposeWindow && !gmailForeignSend;
- const gmailChatMain = gmailForeignSend ? null : gmailChatMainOf(composer, gmailComposeWindow);
- const gmailChatComposer = !!gmailChatMain;
// Gmail's recipient sets come from that window alone, on any route.
const recipientSets = gmailRecipientMode ? gmailMailSend : params.supportsRecipientSets === true;
const nativeTelegramComposer = /^(?:web|webk|weba|webz|k)\.telegram\.org$/i.test(location.hostname)
@@ -8476,11 +8437,14 @@
}
}
}
- } else if (gmailRecipientMode && !gmailChatComposer) {
+ } else if (gmailRecipientMode) {
// Any other Gmail send identifies no one: a Send the page's layout
- // pairs with another message's composer, or, outside Google Chat, a
- // composer in no mail compose window (an inline reply whose chips
- // name no row). Nothing on the page then says where it goes.
+ // pairs with another message's composer, a composer in no mail
+ // compose window (an inline reply whose chips name no row), or a
+ // Google Chat composer. Nothing on the page then says where it goes:
+ // what names a Chat cannot be told by structure from what its
+ // messages, threads and pinned items show, and no address in them is
+ // its recipient.
} else if (twitterConversation) {
const headers = Array.from(document.querySelectorAll('[data-testid="dm-conversation-username"]'))
.filter(el => visible(el) && inConversationHeaderBand(el) && !independentScrollableRegion(el, composer));
@@ -8521,7 +8485,7 @@
}
}
} else {
- for (const el of (gmailChatMain || document).querySelectorAll(
+ for (const el of document.querySelectorAll(
'[aria-selected="true"],[aria-current]:not([aria-current="false"])'
)) {
// Search results and navigation rows can also be selected/current, so
@@ -8531,14 +8495,14 @@
if (strongIdentities.length >= 8) break;
}
- for (const el of (gmailChatMain || document).querySelectorAll(
+ for (const el of document.querySelectorAll(
'h1,h2,h3,h4,[role="heading"]'
)) {
addStrongIdentity(el);
if (strongIdentities.length >= 8) break;
}
- if (!strongIdentities.length && (gmailChatComposer || (params.adapterName === 'generic-messaging'
- && params.supportsRecipientSets !== true))) {
+ if (!strongIdentities.length && params.adapterName === 'generic-messaging'
+ && params.supportsRecipientSets !== true) {
// Some conversation headers expose the contact name as a button
// rather than a heading, or (help desks, CRMs) only the contact's
// address as a mailto link or address chip. A shared local
diff --git a/src/firefox/src/agent/adapters.js b/src/firefox/src/agent/adapters.js
index eb269e0e5..f99e29e50 100644
--- a/src/firefox/src/agent/adapters.js
+++ b/src/firefox/src/agent/adapters.js
@@ -16088,8 +16088,9 @@ const ADAPTERS = [
messaging: {
verifyActiveRecipient: true,
deferActiveConversationUntilComposer: true,
- // Mail has To/Cc/Bcc recipient sets. Google Chat inside Gmail sends to
- // the one open conversation, so its routes bind a single recipient.
+ // Mail has To/Cc/Bcc recipient sets. Google Chat inside Gmail has none
+ // of its own: a send there is held (content.js), while a compose window
+ // open over it still reports its own rows.
supportsRecipientSets: url => !isGmailChatRoute(url),
},
notes: `
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 3cb330ed5..0a2dd7d78 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -1440,14 +1440,17 @@ export class Agent extends LoopDetector {
}
// A successful click_ax the app sent itself to read a native chat, while its
- // ownership still holds: not the model's action. Shared like the above.
- _isOwnedNativeChatReadRepair(tabId, name, args, result, messageRecipientContext) {
+ // ownership still holds: not the model's action. Shared like the above. A
+ // call cut short by Stop or an error (`interrupted`) is judged by the
+ // ownership its guard gave it, since Stop ends the run's ownership before
+ // the interrupted path reads it.
+ _isOwnedNativeChatReadRepair(tabId, name, args, result, messageRecipientContext, { interrupted = false } = {}) {
return name === 'click_ax' && result?.success === true && !result.outcomeUnknown
&& result.noDispatch !== true && ((result._nativeWhatsappReadRepair === true
&& !!messageRecipientContext?.nativeWhatsappReadRepairOwner
- && messageRecipientContext.nativeWhatsappReadRepairOwner === this._nativeChatOwnerScope(tabId))
+ && (interrupted || messageRecipientContext.nativeWhatsappReadRepairOwner === this._nativeChatOwnerScope(tabId)))
|| (result._nativeTelegramReadRepair === true
- && this._nativeTelegramReadPreparationCurrent(tabId, args, messageRecipientContext)));
+ && this._nativeTelegramReadPreparationCurrent(tabId, args, messageRecipientContext, { interrupted })));
}
_recordCompletionToolResult(tabId, name, args, result, { detectedSubmit = null, messageRecipientContext = null, ownedReadRepairBatch = false } = {}) {
@@ -12203,11 +12206,12 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// without one, a call that may have been sent counts as sent, so it can
// back an "acted" row, and only a provably unsent one is held against one.
// The args and the read-repair exemption are the normal path's too; Stop
- // clears the owner scope that exemption checks, so the app's own repair
- // batch is also recognized by its run option.
+ // clears the owner scope that exemption checks, so a repair is judged by
+ // the ownership its guard gave the call, and the app's own repair batch
+ // is recognized by its run option.
if (interrupted?.name && !interrupted.dispatchNoted && runOptions[OWNED_NATIVE_CHAT_READ_REPAIR] !== true
&& !this._isOwnedNativeChatReadRepair(tabId, interrupted.name, interrupted.args || {}, interruptedRaw,
- interrupted.messageRecipientContext)) {
+ interrupted.messageRecipientContext, { interrupted: true })) {
this._noteProgressActionDispatch(tabId, interrupted.name,
this._completionToolArgs(tabId, interrupted.name, interrupted.args || {}), interruptedRaw,
interruptedRaw ? undefined : !interruptedUnsent);
@@ -23990,9 +23994,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
String(provider.model || provider.config?.model || ''), authority.taskSha256, authority.resumeTaskId, authority.providerSha256]);
}
- _nativeTelegramReadPreparationCurrent(tabId, args, context) {
+ _nativeTelegramReadPreparationCurrent(tabId, args, context, { interrupted = false } = {}) {
return !!context?.nativeTelegramReadRepairOwner
- && context.nativeTelegramReadRepairOwner === this._nativeChatOwnerScope(tabId)
+ && (interrupted || context.nativeTelegramReadRepairOwner === this._nativeChatOwnerScope(tabId))
&& typeof args?.ref_id === 'string' && args.ref_id === context.nativeTelegramReadRepairRef
&& typeof context.nativeTelegramReadRepairBinding?.token === 'string'
&& context.nativeTelegramReadRepairBinding.token.length > 0
@@ -38293,7 +38297,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
|| (workflowMessageKind === 'message_draft'
? (this._workflowDraftAuthorizedTarget(executionGuard)?.recipients || [])
: []),
- // Google Chat inside Gmail has one recipient, not mail's sets.
+ // Google Chat routes in Gmail have no recipient set of their own;
+ // a compose window open there reports its rows itself.
supportsRecipientSets: executionGuard.siteWorkflow.adapterName === 'gmail'
&& !isGmailChatRoute(pageState.url || ''),
});
diff --git a/src/firefox/src/agent/planner.js b/src/firefox/src/agent/planner.js
index 7c5c97a33..397a6bcf5 100644
--- a/src/firefox/src/agent/planner.js
+++ b/src/firefox/src/agent/planner.js
@@ -1129,7 +1129,7 @@ export function normalizePlan(obj, opts = {}) {
const risks = riskEntries.map(entry => entry.text);
const localizedInput = obj.localized && typeof obj.localized === 'object' ? obj.localized : {};
const providedLocalizedSteps = Array.isArray(localizedInput.steps)
- ? localizedInput.steps.slice(0, 12).map((step, i) => ({
+ ? localizedInput.steps.slice(0, PLAN_STEP_LIMIT).map((step, i) => ({
id: sanitizeText(step?.id || String(i + 1), 20) || String(i + 1),
action: sanitizeText(step?.action, 300),
})).filter((step) => step.action)
diff --git a/src/firefox/src/content/content.js b/src/firefox/src/content/content.js
index 8e6c7beff..a90d279f7 100644
--- a/src/firefox/src/content/content.js
+++ b/src/firefox/src/content/content.js
@@ -7116,46 +7116,14 @@
}
return null;
};
- // Google Chat inside Gmail is a chat: on a Chat route, a composer in
- // the page's main region, in no compose window and not Gmail's mail
- // body, is identified by its own conversation header, as any chat is.
- const gmailChatRoute = gmailRecipientMode && (() => {
- try {
- return location.hostname === 'mail.google.com'
- && (/^\/chat(?:\/|$)/.test(String(location.pathname || ''))
- || /^#chat(?:[/?]|$)/.test(String(location.hash || '')));
- } catch { return false; }
- })();
- // Between an element and the Chat's main region: a scrolling area (or,
- // with `lists`, a log, list or feed), where the conversation's history
- // and the threads inside it live.
- const gmailInChatHistory = (el, main, lists = true) => {
- for (let node = el?.parentElement; node && node !== main; node = node.parentElement) {
- if (lists && node.matches?.('[role="log"],[role="list"],[role="feed"]')) return true;
- try {
- const style = getComputedStyle(node);
- if (/^(auto|scroll|overlay)$/.test(String(style.overflowY || style.overflow || '').toLowerCase())
- && Number(node.scrollHeight) > Number(node.clientHeight) + 1) return true;
- } catch {}
- }
- return false;
- };
- // A composer inside that history, such as a thread's reply box in the
- // scrolling message list, is not the Chat's own composer.
- const gmailChatMainOf = (editor, ownWindow = gmailComposeWindowOf(editor)) => {
- if (!gmailChatRoute || !editor || ownWindow || editor.getAttribute?.('g_editable') === 'true'
- || editor.closest?.('[role="dialog"]')) return null;
- const main = editor.closest?.('main,[role="main"]') || null;
- return main && !gmailInChatHistory(editor, main) ? main : null;
- };
// The composer a control (a Send, an attachment input) belongs to: the
// one message editor in the control's nearest ancestor holding any,
- // when the control lies inside that editor's own compose window or
- // Chat region. Its message, not the page's lowest editor, is what the
- // control sends. A click into an editor only focuses it; a page control
- // that merely shares a distant ancestor with one editor (a toolbar's
- // Archive) is no message's; and none, or more than one editor there,
- // leaves the pairing to the page's layout.
+ // when the control lies inside that editor's own compose window. Its
+ // message, not the page's lowest editor, is what the control sends. A
+ // click into an editor only focuses it; a page control that merely
+ // shares a distant ancestor with one editor (a toolbar's Archive) is
+ // no message's; and none, or more than one editor there, leaves the
+ // pairing to the page's layout.
const gmailControlComposer = control => {
if (!gmailRecipientMode || !control || editable(control)) return null;
for (let node = control; node && node !== document.documentElement; node = node.parentElement) {
@@ -7164,9 +7132,7 @@
if (!inside.length) continue;
const owners = inside.filter(editor => !inside.some(other => other !== editor && other.contains?.(editor)));
if (owners.length !== 1) return null;
- const ownWindow = gmailComposeWindowOf(owners[0]);
- const scope = ownWindow || gmailChatMainOf(owners[0], ownWindow);
- return scope?.contains?.(control) ? owners[0] : null;
+ return gmailComposeWindowOf(owners[0])?.contains?.(control) ? owners[0] : null;
}
return null;
};
@@ -7416,9 +7382,6 @@
const addStrongIdentity = (el) => {
if (!visible(el) || editable(el) || el.closest?.('input,textarea,[contenteditable="true"]')) return;
if (!inConversationHeaderBand(el) || independentScrollableRegion(el, composer)) return;
- // In a Gmail Chat, nothing inside a scrolling area below its main
- // region (its history, a thread) names the conversation.
- if (gmailChatMain && gmailInChatHistory(el, gmailChatMain, false)) return;
const text = compact(
el.getAttribute?.('aria-label')
|| el.getAttribute?.('title')
@@ -7447,8 +7410,6 @@
const gmailForeignSend = !!gmailSendOwner && composerCandidates.some(editor => gmailSendOwner.contains(editor)
&& !gmailEditorScope.contains?.(editor) && otherMessageEditor(editor, composer));
const gmailMailSend = !!gmailComposeWindow && !gmailForeignSend;
- const gmailChatMain = gmailForeignSend ? null : gmailChatMainOf(composer, gmailComposeWindow);
- const gmailChatComposer = !!gmailChatMain;
// Gmail's recipient sets come from that window alone, on any route.
const recipientSets = gmailRecipientMode ? gmailMailSend : params.supportsRecipientSets === true;
const nativeTelegramComposer = /^(?:web|webk|weba|webz|k)\.telegram\.org$/i.test(location.hostname)
@@ -7622,11 +7583,14 @@
}
}
}
- } else if (gmailRecipientMode && !gmailChatComposer) {
+ } else if (gmailRecipientMode) {
// Any other Gmail send identifies no one: a Send the page's layout
- // pairs with another message's composer, or, outside Google Chat, a
- // composer in no mail compose window (an inline reply whose chips
- // name no row). Nothing on the page then says where it goes.
+ // pairs with another message's composer, a composer in no mail
+ // compose window (an inline reply whose chips name no row), or a
+ // Google Chat composer. Nothing on the page then says where it goes:
+ // what names a Chat cannot be told by structure from what its
+ // messages, threads and pinned items show, and no address in them is
+ // its recipient.
} else if (twitterConversation) {
const headers = Array.from(document.querySelectorAll('[data-testid="dm-conversation-username"]'))
.filter(el => visible(el) && inConversationHeaderBand(el) && !independentScrollableRegion(el, composer));
@@ -7667,7 +7631,7 @@
}
}
} else {
- for (const el of (gmailChatMain || document).querySelectorAll(
+ for (const el of document.querySelectorAll(
'[aria-selected="true"],[aria-current]:not([aria-current="false"])'
)) {
// Search results and navigation rows can also be selected/current, so
@@ -7677,14 +7641,14 @@
if (strongIdentities.length >= 8) break;
}
- for (const el of (gmailChatMain || document).querySelectorAll(
+ for (const el of document.querySelectorAll(
'h1,h2,h3,h4,[role="heading"]'
)) {
addStrongIdentity(el);
if (strongIdentities.length >= 8) break;
}
- if (!strongIdentities.length && (gmailChatComposer || (params.adapterName === 'generic-messaging'
- && params.supportsRecipientSets !== true))) {
+ if (!strongIdentities.length && params.adapterName === 'generic-messaging'
+ && params.supportsRecipientSets !== true) {
// Some conversation headers expose the contact name as a button
// rather than a heading, or (help desks, CRMs) only the contact's
// address as a mailto link or address chip. A shared local
diff --git a/test/improver-content-recipient.mjs b/test/improver-content-recipient.mjs
index 9b8033c87..3153033e9 100644
--- a/test/improver-content-recipient.mjs
+++ b/test/improver-content-recipient.mjs
@@ -78,9 +78,10 @@ const gmailChat = ({ rows = '', raise = 0, chatFile = false, appFile = false, ch
${rows ? `<div role="dialog" aria-label="New Message"><form onsubmit="return false">${rows}
<div id="mail-body" contenteditable="true" role="textbox" aria-label="Message Body" style="min-height:32px">${draft}</div>
<button id="mail-send" type="button" aria-label="Send">Send</button></form></div>` : ''}</div>`;
-// A Gmail Chat space whose history scrolls, with a thread's reply box inside
-// it: a heading in that history names a person, not the space.
-const gmailChatThread = header => `<!doctype html><style>body{margin:0;font:16px sans-serif}
+// A Gmail Chat space whose history scrolls (or, `short`, is too short to
+// scroll yet), with a thread's reply box inside it: a heading in that history
+// names a person, not the space.
+const gmailChatThread = (header, { short = false } = {}) => `<!doctype html><style>body{margin:0;font:16px sans-serif}
#chat{position:absolute;left:0;top:0;width:900px;height:780px}#chat>header{height:60px}
#messages{height:600px;overflow:auto}.t{display:block;width:500px;min-height:32px}footer{display:flex;gap:10px}</style>
<main id="chat" role="main"><header>${header}</header>
@@ -88,9 +89,18 @@ const gmailChatThread = header => `<!doctype html><style>body{margin:0;font:16px
<div style="height:150px"></div>
<div class="thread"><div class="t" contenteditable="true" role="textbox" aria-label="Type a message">The Q3 numbers</div>
<button id="send" type="button" aria-label="Send">Send</button></div>
- <div style="height:600px"></div></section>
+ ${short ? '' : '<div style="height:600px"></div>'}</section>
<footer><div class="t" contenteditable="true" role="textbox" aria-label="Type a message"></div>
<button id="main-send" type="button" aria-label="Send">Send</button></footer></main>`;
+// A Gmail Chat whose main region holds `top` above a short history, which
+// may itself hold a heading naming someone else; `footer` adds to the
+// composer's own area.
+const gmailChatTop = (top, { history = '<div>Bob: see you</div>', footer = '' } = {}) => `<!doctype html>
+ <style>body{margin:0;font:16px sans-serif}#chat{position:absolute;left:0;top:0;width:900px;height:780px}
+ #messages{height:520px;overflow:auto}#body{display:block;width:500px;min-height:32px}footer{display:flex;gap:10px}</style>
+ <main id="chat" role="main">${top}<section id="messages">${history}</section>
+ <footer>${footer}<div id="body" contenteditable="true" role="textbox" aria-label="Type a message">The Q3 numbers</div>
+ <button id="send" type="button" aria-label="Send">Send</button></footer></main>`;
const gmailCompose = rows => `<!doctype html><style>body{margin:0;font:16px sans-serif}[role=dialog]{width:800px}
#body{display:block;width:700px;min-height:60px}</style>
<main role="main"><h2>Inbox</h2></main>
@@ -305,37 +315,42 @@ for (const [build, Agent] of [['chrome', ChromeAgent], ['firefox', FirefoxAgent]
} finally { await f.browser.close(); }
});
- // A Gmail Chat is identified by the person in its own header, as any
- // chat is, and an address in its history still counts for nothing.
- test(`${build}: a Gmail Chat send binds to the person in its header, and asks before anyone else`, async () => {
- const f = await fixture(build, Agent, { url: 'https://mail.google.com/mail/u/0/#chat/dm/abc', recipients: ['Bob'], html: gmailChat() });
- try {
- const { blocked, context } = await f.bind();
- assert.equal(blocked, null, JSON.stringify(blocked));
- assert.ok(context.messageRecipientDispatchBinding?.token);
- const result = await call(f.page, 'click', { ...sendArgs, ...context });
- assert.equal(result.success, true, JSON.stringify(result));
- assert.equal(await f.page.evaluate(() => window.sent), 1);
- } finally { await f.browser.close(); }
- const other = await fixture(build, Agent, { url: 'https://mail.google.com/mail/u/0/#chat/dm/abc', recipients: ['Ada'], html: gmailChat() });
- try {
- const { blocked, context } = await other.bind();
- assert.equal(blocked?.reasonCode, 'active_recipient_unverified', JSON.stringify(blocked));
- assert.deepEqual(blocked.recipientConfirmation?.recipients, [{ identity: 'Bob', role: 'to' }], JSON.stringify(blocked));
- assert.equal(context.messageRecipientDispatchBinding, undefined);
- assert.equal(await other.page.evaluate(() => window.sent), 0);
- } finally { await other.browser.close(); }
- });
+ // Nothing on a Gmail Chat page tells the Chat's name by structure from
+ // what its messages, threads and pinned items show, so a Chat send is held,
+ // whoever it names, and no card offers anyone in its place.
+ const HELD_CHATS = [
+ ['a header heading', gmailChat()],
+ ['a plain header and a heading in a short history', gmailChatTop('<header><div>Bob</div></header>',
+ { history: '<div role="heading" aria-level="3">Ada</div><div>Ada: can you send me the numbers?</div>' })],
+ ['a plain header and a pinned heading', gmailChatTop('<header><div>Bob</div></header>'
+ + '<div class="pinned"><div role="heading" aria-level="3">Ada</div></div>')],
+ ['a heading before the header', gmailChatTop('<div><h3>Ada</h3></div><header><h2>Bob</h2></header>')],
+ ];
+ for (const [kind, html] of HELD_CHATS) {
+ test(`${build}: a Gmail Chat send is held, never bound to a name on the page (${kind})`, async () => {
+ for (const recipients of [['Bob'], ['Ada']]) {
+ const f = await fixture(build, Agent, { url: 'https://mail.google.com/mail/u/0/#chat/dm/abc', recipients, html });
+ try {
+ const { blocked, context } = await f.bind();
+ assert.equal(blocked?.reasonCode, 'recipient_identity_unavailable', `${recipients}: ${JSON.stringify(blocked)}`);
+ assert.equal(blocked.recipientConfirmation, undefined, JSON.stringify(blocked));
+ assert.equal(context.messageRecipientDispatchBinding, undefined);
+ assert.equal(await f.page.evaluate(() => window.sent), 0);
+ } finally { await f.browser.close(); }
+ }
+ });
+ }
// A Chat send never takes the recipients of a compose window open beside
// it: not when the layout pairs its Send with the window's body, not when
// its own composer is the lowest editor, and not when the URL carries the
// compose= Gmail keeps while any compose window is open.
- for (const [rows, recipients] of [
- [TO_ADA, ['[email protected]']],
- [TO_ADA + CC_CEM, [{ identity: '[email protected]', role: 'to' }, { identity: '[email protected]', role: 'cc' }]],
+ for (const [kind, rows, recipients] of [
+ ['To', TO_ADA, ['[email protected]']],
+ ['To and Cc', TO_ADA + CC_CEM, [{ identity: '[email protected]', role: 'to' }, { identity: '[email protected]', role: 'cc' }]],
+ ['typed To', TO_FIELD('[email protected]'), ['[email protected]']],
]) {
- test(`${build}: a Gmail Chat send never goes to the ${recipients.length === 1 ? 'To' : 'To and Cc'} of a compose window open beside it`, async () => {
+ test(`${build}: a Gmail Chat send never goes to the ${kind} of a compose window open beside it`, async () => {
for (const url of ['https://mail.google.com/mail/u/0/#chat/space/AAAA', 'https://mail.google.com/mail/u/0/#chat/space/AAAA?compose=new']) {
for (const raise of [0, 150]) {
const variant = `${url.slice(url.indexOf('#'))}, compose window ${raise ? 'raised' : 'docked'}`;
@@ -343,9 +358,8 @@ for (const [build, Agent] of [['chrome', ChromeAgent], ['firefox', FirefoxAgent]
try {
const { blocked, context } = await f.bind();
assert.equal(blocked?.success, false, `${variant}: ${JSON.stringify(blocked)}`);
+ assert.equal(blocked.recipientConfirmation, undefined, `${variant}: ${JSON.stringify(blocked)}`);
assert.equal(context.messageRecipientDispatchBinding, undefined, variant);
- // A card may name the chat's own person, never the window's.
- for (const item of blocked.recipientConfirmation?.recipients || []) assert.equal(item.identity, 'Bob', variant);
assert.equal(await f.page.evaluate(() => window.sent), 0, variant);
} finally { await f.browser.close(); }
}
@@ -354,8 +368,8 @@ for (const [build, Agent] of [['chrome', ChromeAgent], ['firefox', FirefoxAgent]
}
// Each Send sends its own message, whichever editor is the page's lowest:
- // the compose window's Send goes to its own To row, the Chat's Send to the
- // chat's person and never to the window's recipients.
+ // the compose window's Send goes to its own To row, and the Chat's Send is
+ // held, never sent to the window's recipients.
for (const raise of [0, 150]) {
test(`${build}: beside an open compose window (${raise ? 'raised' : 'docked'}) each Send binds to its own message`, async () => {
const url = 'https://mail.google.com/mail/u/0/#chat/dm/abc?compose=new';
@@ -368,7 +382,7 @@ for (const [build, Agent] of [['chrome', ChromeAgent], ['firefox', FirefoxAgent]
});
const chat = await f.bind();
assert.equal(chat.blocked?.success, false, JSON.stringify(chat.blocked));
- assert.deepEqual(chat.blocked.recipientConfirmation?.recipients, [{ identity: 'Bob', role: 'to' }], JSON.stringify(chat.blocked));
+ assert.equal(chat.blocked.recipientConfirmation, undefined, JSON.stringify(chat.blocked));
assert.equal(chat.context.messageRecipientDispatchBinding, undefined);
const mailContext = {};
const mailBlocked = await f.agent._messageRecipientGuardBlock(71, 'click', mailSend, url, mailContext);
@@ -377,50 +391,107 @@ for (const [build, Agent] of [['chrome', ChromeAgent], ['firefox', FirefoxAgent]
assert.equal(result.success, true, JSON.stringify(result));
assert.equal(await f.page.evaluate(() => [window.sent, window.mailSent]).then(String), '0,1');
} finally { await f.browser.close(); }
- const bob = await fixture(build, Agent, { url, recipients: ['Bob'], html: gmailChat({ rows: TO_ADA, raise }) });
- try {
- const { blocked, context } = await bob.bind();
- assert.equal(blocked, null, JSON.stringify(blocked));
- const result = await call(bob.page, 'click', { ...sendArgs, ...context });
- assert.equal(result.success, true, JSON.stringify(result));
- assert.equal(await bob.page.evaluate(() => window.sent), 1);
- } finally { await bob.browser.close(); }
});
}
// A model's reading of a label never makes a Chat composer something
- // other than a message's editor, even when the label names a person.
+ // other than a message's editor, even when the label names a person, so
+ // the window's To is never the Chat's.
for (const raise of [0, 150]) {
- test(`${build}: a Gmail Chat composer labelled with a contact's name stays the Chat's own (${raise ? 'raised' : 'docked'} compose window)`, async () => {
+ test(`${build}: a Gmail Chat composer labelled with a contact's name stays a message's editor (${raise ? 'raised' : 'docked'} compose window)`, async () => {
const f = await fixture(build, Agent, { url: 'https://mail.google.com/mail/u/0/#chat/dm/abc', recipients: ['[email protected]'],
html: gmailChat({ rows: TO_ADA, raise, chatLabel: 'Reply to Bob' }) });
try {
const { blocked, context } = await f.bind();
assert.equal(blocked?.success, false, JSON.stringify(blocked));
- assert.deepEqual(blocked.recipientConfirmation?.recipients, [{ identity: 'Bob', role: 'to' }], JSON.stringify(blocked));
+ assert.equal(blocked.recipientConfirmation, undefined, JSON.stringify(blocked));
assert.equal(context.messageRecipientDispatchBinding, undefined);
assert.equal(await f.page.evaluate(() => window.sent), 0);
} finally { await f.browser.close(); }
});
}
- // A thread's reply box inside the scrolling history is not the Chat's own
- // composer, and a heading in that history never names its recipient.
+ // A thread's reply box inside the history, scrolling or too short to
+ // scroll yet, sends to no one the history names.
for (const [kind, header] of [['in a plain block', '<div>Team space</div>'], ['as a heading', '<h2>Team space</h2>']]) {
- test(`${build}: a Gmail Chat thread reply never takes its recipient from the history (space name ${kind})`, async () => {
- for (const recipients of [['Ada'], ['Team space']]) {
- const f = await fixture(build, Agent, { url: 'https://mail.google.com/mail/u/0/#chat/space/AAA', recipients, html: gmailChatThread(header) });
- try {
- const { blocked, context } = await f.bind();
- assert.equal(blocked?.success, false, `${recipients}: ${JSON.stringify(blocked)}`);
- for (const item of blocked.recipientConfirmation?.recipients || []) assert.notEqual(item.identity, 'Ada', JSON.stringify(blocked));
- assert.equal(context.messageRecipientDispatchBinding, undefined);
- assert.equal(await f.page.evaluate(() => window.sent), 0);
- } finally { await f.browser.close(); }
- }
- });
+ for (const short of [false, true]) {
+ test(`${build}: a Gmail Chat thread reply never takes its recipient from the history (space name ${kind}${short ? ', short history' : ''})`, async () => {
+ for (const recipients of [['Ada'], ['Team space']]) {
+ const f = await fixture(build, Agent, { url: 'https://mail.google.com/mail/u/0/#chat/space/AAA', recipients,
+ html: gmailChatThread(header, { short }) });
+ try {
+ const { blocked, context } = await f.bind();
+ assert.equal(blocked?.success, false, `${recipients}: ${JSON.stringify(blocked)}`);
+ assert.equal(blocked.recipientConfirmation, undefined, JSON.stringify(blocked));
+ assert.equal(context.messageRecipientDispatchBinding, undefined);
+ assert.equal(await f.page.evaluate(() => window.sent), 0);
+ } finally { await f.browser.close(); }
+ }
+ });
+ }
}
+ // A chip beside a Chat's composer under a label naming someone ("Replying
+ // to Ada") is no To row: the Chat is not a mail compose to Ada.
+ test(`${build}: a labelled chip beside a Gmail Chat composer does not make it a mail compose`, async () => {
+ const f = await fixture(build, Agent, { url: 'https://mail.google.com/mail/u/0/#chat/dm/abc', recipients: ['[email protected]'],
+ html: gmailChatTop('<header><h2>Bob</h2></header>',
+ { footer: '<div aria-label="Replying to Ada"><span data-hovercard-id="[email protected]">Ada</span></div>' }) });
+ try {
+ const { blocked, context } = await f.bind();
+ assert.equal(blocked?.success, false, JSON.stringify(blocked));
+ assert.equal(blocked.recipientConfirmation, undefined, JSON.stringify(blocked));
+ assert.equal(context.messageRecipientDispatchBinding, undefined);
+ assert.equal(await f.page.evaluate(() => window.sent), 0);
+ } finally { await f.browser.close(); }
+ });
+
+ // In a Chat's history, a chip beside a control labelled with a person
+ // ("Reply to Ada") is in no To row: only an input's label marks one.
+ test(`${build}: a chip beside a labelled control in a Gmail Chat's history is no recipient`, async () => {
+ const html = `<!doctype html><style>body{margin:0;font:16px sans-serif}
+ [role=dialog]{position:absolute;right:20px;bottom:0;width:420px}#body{display:block;width:360px;min-height:32px}
+ footer{display:flex;gap:10px}</style>
+ <main role="main"><h2>Inbox</h2></main>
+ <div role="dialog" aria-label="Bob"><header><h2>Bob</h2></header>
+ <div class="msg"><span data-hovercard-id="[email protected]">Ada</span>: see the numbers
+ <button type="button" aria-label="Reply to Ada">Reply</button></div>
+ <footer><div id="body" contenteditable="true" role="textbox" aria-label="Type a message">The Q3 numbers</div>
+ <button id="send" type="button" aria-label="Send">Send</button></footer></div>`;
+ const f = await fixture(build, Agent, { url: 'https://mail.google.com/mail/u/0/#inbox', recipients: ['[email protected]'], html });
+ try {
+ const { blocked, context } = await f.bind();
+ assert.equal(blocked?.success, false, JSON.stringify(blocked));
+ assert.equal(blocked.recipientConfirmation, undefined, JSON.stringify(blocked));
+ assert.equal(context.messageRecipientDispatchBinding, undefined);
+ assert.equal(await f.page.evaluate(() => window.sent), 0);
+ } finally { await f.browser.close(); }
+ });
+
+ // Only a single-line input's label can read as a To row: an editor
+ // labelled with a person ("Note to Ada") never makes a Chat's window a
+ // mail compose window whose To is that person.
+ test(`${build}: an editor labelled with a person never marks a Gmail Chat window as a mail compose`, async () => {
+ const html = `<!doctype html><style>body{margin:0;font:16px sans-serif}
+ [role=dialog]{position:absolute;right:20px;bottom:0;width:420px}#body{display:block;width:360px;min-height:32px}
+ .note{display:block;width:360px;min-height:24px}footer{display:flex;gap:10px}</style>
+ <main role="main"><h2>Inbox</h2></main>
+ <div role="dialog" aria-label="Bob"><header><h2>Bob</h2></header>
+ <div aria-label="Replying to Ada"><span data-hovercard-id="[email protected]">Ada</span></div>
+ <div class="note" contenteditable="true" role="textbox" aria-label="Note to Ada"></div>
+ <div class="msg">Bob: see you tomorrow</div>
+ <footer><div id="body" contenteditable="true" role="textbox" aria-label="Type a message">The Q3 numbers</div>
+ <button id="send" type="button" aria-label="Send">Send</button></footer></div>`;
+ const f = await fixture(build, Agent, { url: 'https://mail.google.com/mail/u/0/#inbox', recipients: ['[email protected]'], html });
+ try {
+ const { blocked, context } = await f.bind();
+ assert.equal(blocked?.success, false, JSON.stringify(blocked));
+ for (const item of blocked.recipientConfirmation?.recipients || []) assert.notEqual(item.identity, '[email protected]');
+ assert.equal(context.messageRecipientDispatchBinding, undefined);
+ assert.equal(await f.page.evaluate(() => window.sent), 0);
+ } finally { await f.browser.close(); }
+ });
+
// A click into an editor only focuses it, and a page control far from
// any message is no message's Send.
test(`${build}: clicks into a Gmail editor or on a page control are not sends`, async () => {
@@ -444,9 +515,9 @@ for (const [build, Agent] of [['chrome', ChromeAgent], ['firefox', FirefoxAgent]
} finally { await f.browser.close(); }
});
- // An attachment goes with the message its file input belongs to: the
- // Chat's input to the chat's person, an input no one message owns to no
- // one, and neither to a compose window's recipients beside it.
+ // An attachment goes with the message its file input belongs to: neither
+ // the Chat's input nor one no message owns goes to a compose window's
+ // recipients beside it, and nothing names the Chat's person.
test(`${build}: a file attached in a Gmail Chat never goes to a compose window's recipients`, async () => {
const recipients = [{ identity: '[email protected]', role: 'to' }, { identity: '[email protected]', role: 'cc' }];
const f = await fixture(build, Agent, { url: 'https://mail.google.com/mail/u/0/#chat/dm/abc', recipients,
@@ -456,7 +527,8 @@ for (const [build, Agent] of [['chrome', ChromeAgent], ['firefox', FirefoxAgent]
uploadSourceKey: 'download:1', expectedRecipients: recipients });
const chatUpload = await upload('#chat-file');
assert.equal(chatUpload.recipientSets, undefined, JSON.stringify(chatUpload));
- assert.deepEqual(chatUpload.strongRecipientCandidates, [{ identity: 'Bob', role: 'to' }], JSON.stringify(chatUpload));
+ assert.deepEqual(chatUpload.strongRecipientCandidates || [], [], JSON.stringify(chatUpload));
+ assert.equal(chatUpload.messageRecipientDispatchBinding, undefined);
const appUpload = await upload('#app-file');
assert.equal(appUpload.recipientSets, undefined, JSON.stringify(appUpload));
assert.deepEqual(appUpload.strongRecipientCandidates || [], [], JSON.stringify(appUpload));
diff --git a/test/improver-guards-ledger.mjs b/test/improver-guards-ledger.mjs
index 0e8282d4f..7aebc0b73 100644
--- a/test/improver-guards-ledger.mjs
+++ b/test/improver-guards-ledger.mjs
@@ -552,6 +552,32 @@ for (const build of BUILDS) {
assert.equal((await realBatch(agent, tabId, 2)).error?.message, 'Capture failed.');
assert.deepEqual(agent.progressActionDispatches.get(tabId), before, 'an interrupted repair counted as sent');
delete agent._captureCompletionSemanticNavigation;
+ // Stop as the repair returns ends the run's ownership; the call is still
+ // the repair its guard owned for the run.
+ agent.executeTool = async () => { agent.abort(tabId); return { ...repaired }; };
+ assert.equal((await realBatch(agent, tabId, 6)).error?.name, 'AbortError');
+ assert.deepEqual(agent.progressActionDispatches.get(tabId), before, 'a stopped repair counted as sent');
+ // So is a Telegram read repair, which its guard binds to the clicked ref.
+ agent._messageRecipientGuardBlock = async (tab, _name, args, _url, context) => {
+ context.nativeTelegramReadRepairOwner = agent._nativeChatOwnerScope(tab);
+ context.nativeTelegramReadRepairRef = args.ref_id;
+ context.nativeTelegramReadRepairBinding = { token: 'tg-repair-8' };
+ assert.ok(context.nativeTelegramReadRepairOwner, 'no native chat owner in this fixture');
+ return null;
+ };
+ agent.executeTool = async () => {
+ agent.abort(tabId);
+ return { success: true, dispatched: true, _nativeTelegramReadRepair: true };
+ };
+ assert.equal((await realBatch(agent, tabId, 8)).error?.name, 'AbortError');
+ assert.deepEqual(agent.progressActionDispatches.get(tabId), before, 'a stopped Telegram repair counted as sent');
+ // A model's click with no repair marked by its guard still counts.
+ agent._messageRecipientGuardBlock = async () => null;
+ assert.equal((await realBatch(agent, tabId, 7)).error?.name, 'AbortError');
+ assert.deepEqual(agent.progressActionDispatches.get(tabId), { sent: 1, unsent: null, fence: null },
+ 'a stopped click of the model was not noted');
+ agent.progressActionDispatches.set(tabId, { ...before });
+ agent.executeTool = async () => ({ ...repaired });
delete agent._messageRecipientGuardBlock;
// Stop during the batch the app runs as its own repair clears the owner