Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
Guard policy: a plain final accepted over a decided check ends as partial
Barack Sokulludb75df53312b
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 0b1dd5962..3214d6b76 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -5292,6 +5292,14 @@ export class Agent extends LoopDetector {return this._guardAdvises(id, { decided }) && this._guardRunState(tabId).advised.has(id);}+ // A completion accepted over a check that KNOWS the task is not done+ // (OUTCOME_DOWNGRADING_GUARDS) ends the run as partial. The done tool+ // downgrades its own outcome; a plain final has no outcome of its own, so+ // its run reports partial (trace status, run_status, onRunFinished).+ _completionOutcomeDowngraded(tabId) {+ return (this._guardRunState(tabId).outcomeDowngrades?.size || 0) > 0;+ }+// Adds the "WebBrain could not verify everything" line, if any, to the// answer of an accepted completion. _guardRunState first drops a previous// run's caveats.@@ -16632,7 +16640,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d}}if (!scheduledResume && toolResult.outcome === 'success'- && this._guardRunState(tabId).outcomeDowngrades?.size) {+ && this._completionOutcomeDowngraded(tabId)) {// Accepted over a guard that knows the claim is wrong: end the run,// but as partial so schedules and watches do not count a success.toolResult.outcome = 'partial';@@ -53213,6 +53221,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dfinalResponse = this._withCompletionCaveat(tabId, finalResponse);messages.push(this._withResponseItems({ role: 'assistant', content: finalResponse }, result.responseItems, result.reasoningContent, provider));onUpdate('text', { content: finalResponse, replace: true });+ if (this._completionOutcomeDowngraded(tabId)) {+ _traceStatus = 'partial';+ onUpdate('run_status', { status: 'partial', message: finalResponse });+ }break;}@@ -54569,6 +54581,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dmessages.push(this._withResponseItems({ role: 'assistant', content: fullText }, responseItems, reasoningContent, provider));this._persist(tabId);closeTraceStep({ ok: true });+ if (this._completionOutcomeDowngraded(tabId)) {+ onUpdate('run_status', { status: 'partial', message: fullText });+ return finish(fullText, 'partial');+ }return finish(fullText);} catch (e) {diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 33a3cb265..2585d0c9e 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -4844,6 +4844,14 @@ export class Agent extends LoopDetector {return this._guardAdvises(id, { decided }) && this._guardRunState(tabId).advised.has(id);}+ // A completion accepted over a check that KNOWS the task is not done+ // (OUTCOME_DOWNGRADING_GUARDS) ends the run as partial. The done tool+ // downgrades its own outcome; a plain final has no outcome of its own, so+ // its run reports partial (trace status, run_status, onRunFinished).+ _completionOutcomeDowngraded(tabId) {+ return (this._guardRunState(tabId).outcomeDowngrades?.size || 0) > 0;+ }+// Adds the "WebBrain could not verify everything" line, if any, to the// answer of an accepted completion. _guardRunState first drops a previous// run's caveats.@@ -14899,7 +14907,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d}}if (!scheduledResume && toolResult.outcome === 'success'- && this._guardRunState(tabId).outcomeDowngrades?.size) {+ && this._completionOutcomeDowngraded(tabId)) {// Accepted over a guard that knows the claim is wrong: end the run,// but as partial so schedules and watches do not count a success.toolResult.outcome = 'partial';@@ -44843,6 +44851,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dfinalResponse = this._withCompletionCaveat(tabId, finalResponse);messages.push(this._withResponseItems({ role: 'assistant', content: finalResponse }, result.responseItems, result.reasoningContent, provider));onUpdate('text', { content: finalResponse });+ if (this._completionOutcomeDowngraded(tabId)) {+ _traceStatus = 'partial';+ onUpdate('run_status', { status: 'partial', message: finalResponse });+ }break;}@@ -46030,6 +46042,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dmessages.push(this._withResponseItems({ role: 'assistant', content: fullText }, responseItems, reasoningContent, provider));this._persist(tabId);closeTraceStep({ ok: true });+ if (this._completionOutcomeDowngraded(tabId)) {+ onUpdate('run_status', { status: 'partial', message: fullText });+ return finish(fullText, 'partial');+ }return finish(fullText);} catch (e) {diff --git a/test/guard-advisory-completion.mjs b/test/guard-advisory-completion.mjsindex a1eb195f6..af24b4f75 100644--- a/test/guard-advisory-completion.mjs+++ b/test/guard-advisory-completion.mjs@@ -238,6 +238,41 @@ for (const build of ['chrome', 'firefox']) {}}});++ test(`${label}: a plain final accepted over a check that knows the task is not done ends the run as partial`, async () => {+ // decided: the last text went into a formatting toolbar (the check+ // knows). Undecided: the page was not read after the last action.+ for (const decided of [true, false]) {+ const tab = nextTab++;+ let n = 0;+ const agent = loopAgent(Agent, async () => {+ n++;+ if (!decided && n === 1) return call('save', 'click_ax', { ref_id: 'ref_save' });+ return { content: 'Wrote the post.' };+ });+ if (decided) {+ agent._richTextToolbarGuard.hasPending = () => true;+ agent._richTextToolbarGuard.completionAction = () => ({ name: 'type_ax', ref_id: 'ref_bold' });+ }+ const runStatuses = [];+ let finished = null;+ const onUpdate = (type, data) => { if (type === 'run_status') runStatuses.push(data?.status); };+ const options = { detachedRequestId: `guard-${tab}`, onRunFinished: status => { finished = status; } };+ const result = streaming+ ? await agent.processMessageStream(tab, 'Write the post.', onUpdate, 'act', options)+ : await agent.processMessage(tab, 'Write the post.', onUpdate, 'act', [], options);+ assert.ok(String(result).startsWith(`Wrote the post.\n\n${CAVEAT}`), `${label}: the plain final is accepted with its caveat`);+ if (decided) {+ assert.match(result, /formatting toolbar instead of the editor\./);+ assert.equal(finished, 'partial', `${label}: the run finished as a success over a check that knows it is not done`);+ assert.deepEqual(runStatuses, ['partial'], `${label}: the scheduler did not hear the partial ending`);+ } else {+ assert.match(result, /The page was not checked again after the last action\./);+ assert.equal(finished, 'done', `${label}: missing evidence alone must not downgrade the run`);+ assert.deepEqual(runStatuses, []);+ }+ }+ });}test(`${build}: each untraced run gets its own one refusal per guard`, async () => {