Skip to content

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

fix: bind safe-first to the declared first option

Emre Sokullu9adceb68d402
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 34b107b1f..2934cbdbf 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -33851,10 +33851,10 @@ If the user has already named or confirmed this exact recipient, do NOT ask agai
if (!question) {
return { success: false, error: 'clarify: `question` is required (a single sentence asking the user something specific).' };
}
- const options = Array.isArray(args?.options)
- ? args.options.map(s => String(s).trim().slice(0, 200)).filter(Boolean).slice(0, 4)
- : [];
- const safeFirst = args?.safe_first === true && options.length > 0;
+ const rawOptions = Array.isArray(args?.options) ? args.options : [];
+ const options = rawOptions
+ .map(s => String(s).trim().slice(0, 200)).filter(Boolean).slice(0, 4);
+ const safeFirst = args?.safe_first === true && String(rawOptions[0] || '').trim().length > 0;
const reason = args?.reason ? String(args.reason).slice(0, 300) : null;
const purpose = args?.purpose === 'research_escalation'
? 'research_escalation'
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 8825d9c59..f4cf4b012 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -30560,10 +30560,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
if (!question) {
return { success: false, error: 'clarify: `question` is required (a single sentence asking the user something specific).' };
}
- const options = Array.isArray(args?.options)
- ? args.options.map(s => String(s).trim().slice(0, 200)).filter(Boolean).slice(0, 4)
- : [];
- const safeFirst = args?.safe_first === true && options.length > 0;
+ const rawOptions = Array.isArray(args?.options) ? args.options : [];
+ const options = rawOptions
+ .map(s => String(s).trim().slice(0, 200)).filter(Boolean).slice(0, 4);
+ const safeFirst = args?.safe_first === true && String(rawOptions[0] || '').trim().length > 0;
const reason = args?.reason ? String(args.reason).slice(0, 300) : null;
const purpose = args?.purpose === 'research_escalation'
? 'research_escalation'
diff --git a/test/run.js b/test/run.js
index 095f7281c..cde4c81d2 100644
--- a/test/run.js
+++ b/test/run.js
@@ -48809,6 +48809,17 @@ test('clarify result distinguishes waited timeout from user and Instant authoriz
assert.equal(blankOptionTimeout.authorized, false, `${AgentClass.name}: whitespace-only safe_first option was accepted`);
assert.equal(agent._clarificationAuthorizationGuards.get(tabId)?.authorized, false, `${AgentClass.name}: whitespace-only option did not arm a timeout guard`);
+ await agent._recordClarificationAuthorization(tabId, 'user');
+ const promotedOptionTimeout = await agent.executeTool(
+ tabId,
+ 'clarify',
+ { question: 'Delete everything?', options: [' ', 'Yes, delete them'], safe_first: true },
+ (type, data) => {
+ if (type === 'clarify') agent.submitClarifyResponse(tabId, data.clarifyId, 'Yes, delete them', 'timeout');
+ },
+ );
+ assert.equal(promotedOptionTimeout.authorized, false, `${AgentClass.name}: safe_first authorized a later promoted option`);
+
await agent._recordClarificationAuthorization(tabId, 'user');
const affirmativeTimeout = await agent.executeTool(
tabId,