Skip to content

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

fix(agent): avoid truncating multi-recipient clarification answers

Emre Sokullu434beb46785e
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index c82fb3510..c52c74645 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -43,7 +43,7 @@ import {
workflowControlLabelIsRequested,
workflowRequiredRowsAreProcessed,
} from './adapter-workflow-evidence.js';
-import { answerNamesAllObservedRecipients, answerNamesIdentity, messageTargetMatchesObservedIdentities, normalizeMessageTarget, normalizeRecipientIdentity } from './message-recipient-guard.js';
+import { answerNamesAllObservedRecipients, answerNamesIdentity, messageTargetMatchesObservedIdentities, normalizeMessageTarget, normalizeRecipientAnswer, normalizeRecipientIdentity } from './message-recipient-guard.js';
import {
fetchUrl,
executeHttpSkillTool,
@@ -17959,7 +17959,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
} else if (clarifyContext && !this._isRecipientClarification(clarifyContext, 'message_recipient', observed)) {
return false;
}
- const normalizedAnswer = normalizeRecipientIdentity(answer);
+ const normalizedAnswer = normalizeRecipientAnswer(answer);
if (!normalizedAnswer) return false;
if (!answerNamesAllObservedRecipients(normalizedAnswer, observed)) return false;
const target = normalizeMessageTarget({ target_kind: 'named', recipients: observed });
diff --git a/src/chrome/src/agent/message-recipient-guard.js b/src/chrome/src/agent/message-recipient-guard.js
index 1bd051726..45209c7eb 100644
--- a/src/chrome/src/agent/message-recipient-guard.js
+++ b/src/chrome/src/agent/message-recipient-guard.js
@@ -50,6 +50,20 @@ export function normalizeRecipientIdentity(value) {
}
}
+export function normalizeRecipientAnswer(value) {
+ const text = String(value ?? '')
+ .replace(/[\u0000-\u001f\u007f]/g, ' ')
+ .replace(/[\u200b-\u200d\ufeff]/g, '')
+ .replace(/\s+/g, ' ')
+ .trim();
+ if (!text) return '';
+ try {
+ return text.normalize('NFKC').toLocaleLowerCase();
+ } catch {
+ return text.toLowerCase();
+ }
+}
+
export function recipientMatchesObservedIdentity(recipient, observedIdentity) {
const expected = normalizeRecipientIdentity(recipient);
const observed = normalizeRecipientIdentity(observedIdentity);
@@ -94,7 +108,7 @@ export function getWordBoundaries(text) {
* or as an exact full-string match for short identities (< 3 chars).
*/
export function findCandidateAnswerSpans(normalizedAnswer, normalizedIdentity) {
- const answer = normalizeRecipientIdentity(normalizedAnswer);
+ const answer = normalizeRecipientAnswer(normalizedAnswer);
const identity = normalizeRecipientIdentity(normalizedIdentity);
if (!identity || !answer) return [];
if (identity.length < 3) {
@@ -141,7 +155,7 @@ export function answerNamesIdentity(normalizedAnswer, normalizedIdentity) {
* required for each observed recipient identity.
*/
export function answerNamesAllObservedRecipients(normalizedAnswer, observedCandidates) {
- const answer = normalizeRecipientIdentity(normalizedAnswer);
+ const answer = normalizeRecipientAnswer(normalizedAnswer);
if (!answer || !Array.isArray(observedCandidates) || observedCandidates.length === 0) {
return false;
}
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index df9971a55..718b45050 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -42,7 +42,7 @@ import {
workflowControlLabelIsRequested,
workflowRequiredRowsAreProcessed,
} from './adapter-workflow-evidence.js';
-import { answerNamesAllObservedRecipients, answerNamesIdentity, messageTargetMatchesObservedIdentities, normalizeMessageTarget, normalizeRecipientIdentity } from './message-recipient-guard.js';
+import { answerNamesAllObservedRecipients, answerNamesIdentity, messageTargetMatchesObservedIdentities, normalizeMessageTarget, normalizeRecipientAnswer, normalizeRecipientIdentity } from './message-recipient-guard.js';
import {
fetchUrl,
executeHttpSkillTool,
@@ -15712,7 +15712,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
} else if (clarifyContext && !this._isRecipientClarification(clarifyContext, 'message_recipient', observed)) {
return false;
}
- const normalizedAnswer = normalizeRecipientIdentity(answer);
+ const normalizedAnswer = normalizeRecipientAnswer(answer);
if (!normalizedAnswer) return false;
if (!answerNamesAllObservedRecipients(normalizedAnswer, observed)) return false;
const target = normalizeMessageTarget({ target_kind: 'named', recipients: observed });
diff --git a/src/firefox/src/agent/message-recipient-guard.js b/src/firefox/src/agent/message-recipient-guard.js
index 1bd051726..45209c7eb 100644
--- a/src/firefox/src/agent/message-recipient-guard.js
+++ b/src/firefox/src/agent/message-recipient-guard.js
@@ -50,6 +50,20 @@ export function normalizeRecipientIdentity(value) {
}
}
+export function normalizeRecipientAnswer(value) {
+ const text = String(value ?? '')
+ .replace(/[\u0000-\u001f\u007f]/g, ' ')
+ .replace(/[\u200b-\u200d\ufeff]/g, '')
+ .replace(/\s+/g, ' ')
+ .trim();
+ if (!text) return '';
+ try {
+ return text.normalize('NFKC').toLocaleLowerCase();
+ } catch {
+ return text.toLowerCase();
+ }
+}
+
export function recipientMatchesObservedIdentity(recipient, observedIdentity) {
const expected = normalizeRecipientIdentity(recipient);
const observed = normalizeRecipientIdentity(observedIdentity);
@@ -94,7 +108,7 @@ export function getWordBoundaries(text) {
* or as an exact full-string match for short identities (< 3 chars).
*/
export function findCandidateAnswerSpans(normalizedAnswer, normalizedIdentity) {
- const answer = normalizeRecipientIdentity(normalizedAnswer);
+ const answer = normalizeRecipientAnswer(normalizedAnswer);
const identity = normalizeRecipientIdentity(normalizedIdentity);
if (!identity || !answer) return [];
if (identity.length < 3) {
@@ -141,7 +155,7 @@ export function answerNamesIdentity(normalizedAnswer, normalizedIdentity) {
* required for each observed recipient identity.
*/
export function answerNamesAllObservedRecipients(normalizedAnswer, observedCandidates) {
- const answer = normalizeRecipientIdentity(normalizedAnswer);
+ const answer = normalizeRecipientAnswer(normalizedAnswer);
if (!answer || !Array.isArray(observedCandidates) || observedCandidates.length === 0) {
return false;
}
diff --git a/test/run.js b/test/run.js
index ead5a0401..3a54cf210 100644
--- a/test/run.js
+++ b/test/run.js
@@ -4669,6 +4669,17 @@ test('direct-message recipient guard uses structured intent and exact active ide
[{ identity: '[email protected]' }, { identity: '[email protected]' }],
), true, 'distinct mentions for both domain variants must succeed');
+ const twelveCandidates = Array.from({ length: 12 }, (_, i) => ({
+ identity: `colleague-user-${i + 1}@enterprise-company-domain.com`,
+ role: i === 0 ? 'to' : 'cc',
+ }));
+ const twelveAnswer = `Please reply all to: ${twelveCandidates.map(c => c.identity).join(', ')}`;
+ assert.ok(twelveAnswer.length > 240, 'reply all answer must exceed 240 chars to test truncation avoidance');
+ assert.equal(
+ helper.answerNamesAllObservedRecipients(twelveAnswer, twelveCandidates),
+ true,
+ 'long multi-recipient reply all answer (>240 chars) must match all candidates without truncation',
+ );
assert.equal(helper.messageTargetMatchesObservedIdentities(
{ target_kind: 'named', recipients: ['迷你世界皓宸'] },
['迷你世界皓宸'],
@@ -5275,6 +5286,23 @@ test('direct-message recipient guard uses structured intent and exact active ide
`${label}: natural Chinese clarification question/answer was rejected`,
);
+ // Multi-recipient Reply-all answer exceeding 240 characters.
+ const twelveAgentCandidates = Array.from({ length: 12 }, (_, i) => ({
+ identity: `colleague-user-${i + 1}@enterprise-company-domain.com`,
+ role: i === 0 ? 'to' : 'cc',
+ }));
+ const twelveAgentAnswer = `Send to: ${twelveAgentCandidates.map(c => c.identity).join(', ')}`;
+ assert.ok(twelveAgentAnswer.length > 240);
+ agent._planExecutionGuards.set(tabId, clarifyGuardState(twelveAgentCandidates));
+ assert.equal(
+ agent._bindClarifiedMessageRecipient(tabId, twelveAgentAnswer, 'user', {
+ question: 'Who should receive this reply?',
+ purpose: 'message_recipient',
+ }),
+ true,
+ `${label}: multi-recipient reply-all answer exceeding 240 chars was rejected`,
+ );
+
// Recipient-change clarification check: when a target was already set, an explicit
// recipient_change context is required.
const recipientChangeGuardState = (candidates) => ({