Skip to content

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

Ask cards: a second guard's card after an approval is asked in turn

Barack Sokullud0b0fd6a34c7
diff --git a/docs/guards.md b/docs/guards.md
index d22f0fb41..2463fac58 100644
--- a/docs/guards.md
+++ b/docs/guards.md
@@ -81,6 +81,8 @@ When a guard cannot verify a consequential step and its `onCannotDecide` is
- **Answers.** Two fixed values, "Go ahead" (`once`) and "Don't" (`deny`). An
answer covers this one step and the content the user saw: changed content
is asked about again, and a declined step with the same content is not.
+ When the checks after a "Go ahead" reach another guard's question about the
+ same action, that card is asked in turn and the first answer stands.
- **Timeout.** A quality guard's card follows Settings β†’ General: the clarify
timeout (Off waits, Instant answers at once) and "When a question times
out" (`finish` goes ahead, `safe` does not). A hard-class card never times
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index b91726c0d..d56e436b8 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -30486,9 +30486,11 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
* the same page. Returns null when the action may proceed (its note for
* the model goes into `advisories`), otherwise the result for the model.
* With no card to show (no update channel), or nothing to show where the
- * guard requires it, the guard's refusal stands as before.
+ * guard requires it, the guard's refusal stands as before. When the re-run
+ * reaches another guard's question about the same action, that card is
+ * asked in turn (`depth` bounds the chain) and the first answer stands.
*/
- async _resolveUnverifiedStepConfirmation(tabId, block, onUpdate, rerunChecks, advisories = null) {
+ async _resolveUnverifiedStepConfirmation(tabId, block, onUpdate, rerunChecks, advisories = null, depth = 0) {
const ask = block?.unverifiedStepConfirmation;
if (!ask || typeof ask !== 'object') return block;
const { unverifiedStepConfirmation: _ask, ...refusal } = block;
@@ -30514,7 +30516,21 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const decision = this._rememberUnverifiedStepDecision(tabId, ask, reading, choice, receipt.source);
if (choice !== 'once') return this._unverifiedStepDeclined(refusal, ask.guardId, receipt.source);
const next = await rerunChecks();
- if (next?.unverifiedStepConfirmation) {
+ const nextAsk = next?.unverifiedStepConfirmation;
+ if (nextAsk && nextAsk.guardId !== ask.guardId && depth < 3) {
+ // The answer was accepted, and another guard asks about the same
+ // action (a GitHub commit click can also meet the repeat-click lock):
+ // ask that card too. The first answer stays recorded either way.
+ const nextAdvisories = [];
+ const resolved = await this._resolveUnverifiedStepConfirmation(tabId, next, onUpdate, rerunChecks,
+ nextAdvisories, depth + 1);
+ if (resolved) return resolved;
+ if (Array.isArray(advisories)) {
+ advisories.push(guardAdvisory(ask.guardId, this._unverifiedStepNote(ask.guardId, receipt.source)), ...nextAdvisories);
+ }
+ return null;
+ }
+ if (nextAsk) {
// The re-run did not accept the answer: what the page shows changed.
if (decision) decision.stale = true;
const { unverifiedStepConfirmation: _changed, ...changed } = next;
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 7990efa5a..fc1171a40 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -27592,9 +27592,11 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
* the same page. Returns null when the action may proceed (its note for
* the model goes into `advisories`), otherwise the result for the model.
* With no card to show (no update channel), or nothing to show where the
- * guard requires it, the guard's refusal stands as before.
+ * guard requires it, the guard's refusal stands as before. When the re-run
+ * reaches another guard's question about the same action, that card is
+ * asked in turn (`depth` bounds the chain) and the first answer stands.
*/
- async _resolveUnverifiedStepConfirmation(tabId, block, onUpdate, rerunChecks, advisories = null) {
+ async _resolveUnverifiedStepConfirmation(tabId, block, onUpdate, rerunChecks, advisories = null, depth = 0) {
const ask = block?.unverifiedStepConfirmation;
if (!ask || typeof ask !== 'object') return block;
const { unverifiedStepConfirmation: _ask, ...refusal } = block;
@@ -27620,7 +27622,21 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const decision = this._rememberUnverifiedStepDecision(tabId, ask, reading, choice, receipt.source);
if (choice !== 'once') return this._unverifiedStepDeclined(refusal, ask.guardId, receipt.source);
const next = await rerunChecks();
- if (next?.unverifiedStepConfirmation) {
+ const nextAsk = next?.unverifiedStepConfirmation;
+ if (nextAsk && nextAsk.guardId !== ask.guardId && depth < 3) {
+ // The answer was accepted, and another guard asks about the same
+ // action (a GitHub commit click can also meet the repeat-click lock):
+ // ask that card too. The first answer stays recorded either way.
+ const nextAdvisories = [];
+ const resolved = await this._resolveUnverifiedStepConfirmation(tabId, next, onUpdate, rerunChecks,
+ nextAdvisories, depth + 1);
+ if (resolved) return resolved;
+ if (Array.isArray(advisories)) {
+ advisories.push(guardAdvisory(ask.guardId, this._unverifiedStepNote(ask.guardId, receipt.source)), ...nextAdvisories);
+ }
+ return null;
+ }
+ if (nextAsk) {
// The re-run did not accept the answer: what the page shows changed.
if (decision) decision.stale = true;
const { unverifiedStepConfirmation: _changed, ...changed } = next;
diff --git a/test/guard-ask-cards.mjs b/test/guard-ask-cards.mjs
index d34a3a6ee..168d07f32 100644
--- a/test/guard-ask-cards.mjs
+++ b/test/guard-ask-cards.mjs
@@ -703,6 +703,50 @@ for (const { build, Agent, adapters, Scheduler } of builds) {
for (const f of [media, both, partial]) assert.equal(f.audits.length, 0, 'nothing reached the publication audit');
});
+ // ── a second guard after an approval ───────────────────────────────────
+ test(`${build}: a second guard's card after an approval is asked in turn, and the first answer stands`, async () => {
+ const setupTab = () => {
+ const agent = new Agent({});
+ const tab = nextTab++;
+ agent._persist = () => {};
+ agent.clarifyTimeoutSec = 30;
+ agent.conversations.set(tab, [{ role: 'system', content: 'system' }, { role: 'user', content: 'Post Hello on X' }]);
+ agent._startPlanExecutionGuard(tab, 'act', { requestKind: 'execute', requiresStateChange: true, requiresSubmission: true });
+ return { agent, tab };
+ };
+ const refusal = { success: false, dispatched: false, noDispatch: true, error: 'refused' };
+ const draftAsk = { guardId: 'social-publication-draft-quality', hard: false, action: 'publish', reason: 'draft_unverified',
+ host: 'x.com', contentLabel: 'composer', text: 'Helo', stepKey: 'draft-step' };
+ const targetAsk = { guardId: 'steer-prior-submission-target-unresolved', hard: false, action: 'click',
+ reason: 'target_unresolved', host: 'x.com', contentLabel: 'page', stepKey: 'steer-step' };
+ const answerOnce = (agent, tab, cards) => (type, data) => {
+ if (type !== 'clarify') return;
+ cards.push(data.unverifiedStepConfirmation.guardId);
+ agent.submitClarifyResponse(tab, data.clarifyId, 'once', 'option');
+ };
+ // Another guard asks about the same action after the first answer.
+ const { agent, tab } = setupTab();
+ let reruns = 0;
+ const cards = [];
+ const advisories = [];
+ const resolved = await agent._resolveUnverifiedStepConfirmation(tab, { ...refusal, unverifiedStepConfirmation: draftAsk },
+ answerOnce(agent, tab, cards), async () => (++reruns === 1 ? { ...refusal, unverifiedStepConfirmation: targetAsk } : null), advisories);
+ assert.equal(resolved, null, `${build}: both answers let the action go ahead`);
+ assert.deepEqual(cards, [draftAsk.guardId, targetAsk.guardId], `${build}: each guard asked its own card`);
+ assert.deepEqual(advisories.map(item => item.guard), [draftAsk.guardId, targetAsk.guardId]);
+ assert.notEqual(agent._unverifiedStepDecisions(tab).find(entry => entry.guardId === draftAsk.guardId)?.stale, true,
+ `${build}: the first answer is not stale`);
+ // The same guard asking again for another step still means the page changed.
+ const same = setupTab();
+ const sameCards = [];
+ const changed = await same.agent._resolveUnverifiedStepConfirmation(same.tab, { ...refusal, unverifiedStepConfirmation: draftAsk },
+ answerOnce(same.agent, same.tab, sameCards), async () => ({ ...refusal, unverifiedStepConfirmation: { ...draftAsk, stepKey: 'other-step' } }), []);
+ assert.deepEqual(sameCards, [draftAsk.guardId], `${build}: the changed step is not asked in the same breath`);
+ assert.match(changed.error, /What the page shows changed/);
+ assert.equal(changed.unverifiedStepConfirmation, undefined);
+ assert.equal(same.agent._unverifiedStepDecisions(same.tab).find(entry => entry.guardId === draftAsk.guardId)?.stale, true);
+ });
+
// ── steer-prior-submission-target-unresolved ───────────────────────────
test(`${build}: after a correction, an unidentified control asks instead of refusing`, async () => {
for (const strict of [false, true]) {