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: an accepted done_json over a decided check ends as partial
Barack Sokullu9ec61846556e
diff --git a/docs/guards.md b/docs/guards.mdindex 512e823ae..8a69d03ac 100644--- a/docs/guards.md+++ b/docs/guards.md@@ -33,8 +33,9 @@ the action is wrong (`onDecided`) and when it cannot tell (`onCannotDecide`):completion judge's "not done", an unauthorized mutation, missing, failedor unfinished progress rows, unread pages of a whole thread the userasked for, text that went into a formatting toolbar) ends the run as- `partial`, not `success`. Missing evidence alone keeps the model's- outcome.+ `partial`, not `success`, whether it ended with `done`, a structured+ Cloud run's `done_json` or a plain answer. Missing evidence alone keeps+ the model's outcome.- A write that went out but could not be read back exactly (GitHub'sCodeMirror editor is the usual case) is an unverified success: it locksnothing, arms no text-write debt and is not a loop failure.diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 721590de9..b90162a9b 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -16692,12 +16692,14 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dreturn { action: 'continue' };}if (!scheduledResume) await cancelPendingResumes();- if (!scheduledResume && toolResult.outcome === 'success'- && this._completionOutcomeDowngraded(tabId)) {+ // done_json is always a success claim; its result carries no outcome.+ const claimsSuccess = toolResult.outcome === 'success' || (fnName === 'done_json'+ && toolResult.doneJson === true && toolResult.cloudFailed !== true && toolResult.outcome === undefined);+ if (!scheduledResume && claimsSuccess && 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.- // Before the chat ending below, so a chat run gets the same- // partial contract (runEnded, no auto-resume, the notice).+ // but as partial so schedules, watches and Cloud runs do not count a+ // success. Before the chat ending below, so a chat run gets the+ // same partial contract (runEnded, no auto-resume, the notice).toolResult.outcome = 'partial';}if (!scheduledResume && runOptions?.scheduledRun !== true && this.chatSessions.has(tabId)diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex fe1021205..242e9d1a9 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -14959,12 +14959,14 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dreturn { action: 'continue' };}if (!scheduledResume) await cancelPendingResumes();- if (!scheduledResume && toolResult.outcome === 'success'- && this._completionOutcomeDowngraded(tabId)) {+ // done_json is always a success claim; its result carries no outcome.+ const claimsSuccess = toolResult.outcome === 'success' || (fnName === 'done_json'+ && toolResult.doneJson === true && toolResult.cloudFailed !== true && toolResult.outcome === undefined);+ if (!scheduledResume && claimsSuccess && 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.- // Before the chat ending below, so a chat run gets the same- // partial contract (runEnded, no auto-resume, the notice).+ // but as partial so schedules, watches and Cloud runs do not count a+ // success. Before the chat ending below, so a chat run gets the+ // same partial contract (runEnded, no auto-resume, the notice).toolResult.outcome = 'partial';}if (!scheduledResume && runOptions?.scheduledRun !== true && this.chatSessions.has(tabId)diff --git a/test/guard-advisory-completion.mjs b/test/guard-advisory-completion.mjsindex 06939b44d..8ff1d859e 100644--- a/test/guard-advisory-completion.mjs+++ b/test/guard-advisory-completion.mjs@@ -569,6 +569,37 @@ for (const build of ['chrome', 'firefox']) {}});+ test(`${build}: a done_json accepted over unfinished progress rows ends as partial`, async () => {+ // done_json is always a success claim; its result carries no outcome.+ const outputSchema = { type: 'object', properties: { items: { type: 'integer' } }, required: ['items'], additionalProperties: false };+ const schemas = new Map(getToolsForMode('act', { tier: 'full', cloudRun: true, outputSchema })+ .map(tool => [tool.function.name, tool.function.parameters]));+ assert.ok(schemas.has('done_json'), `${build}: the structured run offers done_json`);+ const h = batchAgent(Agent, { schemas });+ h.agent.cloudRunContexts.set(h.tab, { outputSchema });+ h.agent._currentTaskLedgerRows = () => [{ id: 'item-1', label: 'First', status: 'processed' },+ { id: 'item-2', label: 'Second', status: 'pending' }];+ const stub = h.agent.executeTool;+ h.agent.executeTool = async (tab, name, args, ...rest) => (name === 'done_json'+ ? { done: true, doneJson: true, summary: args.summary, result: args.result, cloudResult: args.result }+ : stub(tab, name, args, ...rest));+ const batch = async (updates = []) => {+ const toolCalls = [{ id: `done_json_${nextCall++}`, function: { name: 'done_json',+ arguments: JSON.stringify({ summary: 'Both items are done.', result: { items: 2 } }) } }];+ const messages = h.agent.conversations.get(h.tab);+ messages.push({ role: 'assistant', content: null, tool_calls: toolCalls });+ return h.agent._executeToolBatch(h.tab, toolCalls, messages, (type, data) => updates.push({ type, data }),+ { supportsVision: false }, null, new Set(['done_json', 'click_ax', 'get_accessibility_tree']), 1, {}, schemas);+ };+ assert.equal((await batch()).action, 'continue', `${build}: the first done_json gets its note`);+ const updates = [];+ const accepted = await batch(updates);+ assert.equal(accepted.action, 'return', `${build}: the second done_json is accepted`);+ const doneResult = updates.filter(update => update.type === 'tool_result' && update.data.name === 'done_json').at(-1)?.data.result;+ assert.equal(doneResult?.outcome, 'partial', `${build}: an accepted done_json over an unfinished item was not downgraded`);+ assert.deepEqual(doneResult?.cloudResult, { items: 2 }, `${build}: the structured result is still delivered`);+ });+test(`${build}: a success claim over skipped or failed progress rows is advised once`, async () => {const rows = [{ id: 'item-1', label: 'First', status: 'processed' }, { id: 'item-2', label: 'Second', status: 'skipped' }];await refusedOnceThenAccepted(Agent, {