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: downgrade before the chat partial ending
Barack Sokullu247e8b00cd51
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 3214d6b76..7c1f6e93c 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -16630,6 +16630,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)) {+ // 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).+ toolResult.outcome = 'partial';+ }if (!scheduledResume && runOptions?.scheduledRun !== true && this.chatSessions.has(tabId)&& ['partial', 'failed'].includes(toolResult.outcome)) {toolResult.runEnded = true;@@ -16639,12 +16647,6 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dtoolResult.summary = (toolResult.summary || partialAssistantText || '') + '\n\n' + notice;}}- if (!scheduledResume && toolResult.outcome === 'success'- && 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';- }onUpdate('tool_result', { name: fnName, result: toolResult });this._doneBlockCount.delete(tabId);rawDoneSummary = toolResult.summary || rawDoneSummary;diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 2585d0c9e..aef4785c0 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -14897,6 +14897,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)) {+ // 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).+ toolResult.outcome = 'partial';+ }if (!scheduledResume && runOptions?.scheduledRun !== true && this.chatSessions.has(tabId)&& ['partial', 'failed'].includes(toolResult.outcome)) {toolResult.runEnded = true;@@ -14906,12 +14914,6 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dtoolResult.summary = (toolResult.summary || partialAssistantText || '') + '\n\n' + notice;}}- if (!scheduledResume && toolResult.outcome === 'success'- && 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';- }onUpdate('tool_result', { name: fnName, result: toolResult });this._doneBlockCount.delete(tabId);rawDoneSummary = toolResult.summary || rawDoneSummary;diff --git a/test/guard-advisory-completion.mjs b/test/guard-advisory-completion.mjsindex af24b4f75..e63fe4b3d 100644--- a/test/guard-advisory-completion.mjs+++ b/test/guard-advisory-completion.mjs@@ -419,6 +419,39 @@ for (const build of ['chrome', 'firefox']) {assert.equal(doneResult?.outcome, 'success', `${build}: missing evidence alone must not downgrade the outcome`);});+ test(`${build}: a chat run's success accepted over a decided check ends with the chat partial contract`, async () => {+ const { chatRunEndedNotice, createChatSession } = await import(`../src/${build}/src/agent/chat-workflow.js`);+ for (const decided of [true, false]) {+ const h = batchAgent(Agent);+ h.agent.chatSessions.set(h.tab, createChatSession({ threadKey: 'dom:telegram:k:123456:0' }));+ if (decided) {+ // Text went into a formatting toolbar: the check knows the claim is wrong.+ h.agent._richTextToolbarGuard.completionAction = () => ({ name: 'type_ax', ref_id: 'ref_bold' });+ } else {+ // Only missing evidence: the page was not read again.+ h.agent.completionInvariants.set(h.tab, { ...invariant.createCompletionInvariantState('chat'), hadAction: true,+ verificationDebt: true, sequence: 1, lastAction: { name: 'click_ax', sequence: 1 } });+ }+ const done = ['done', { summary: 'Replied in the chat.', outcome: 'success' }];+ assert.equal((await h.batch([done])).action, 'continue', `${build}: the first completion gets its note`);+ const updates = [];+ const accepted = await h.batch([done], updates);+ assert.equal(accepted.action, 'return');+ const doneResult = updates.filter(update => update.type === 'tool_result' && update.data.name === 'done').at(-1)?.data.result;+ if (decided) {+ assert.equal(doneResult?.outcome, 'partial', `${build}: a success over a decided check was not downgraded`);+ assert.equal(doneResult?.runEnded, true, `${build}: a downgraded chat completion must end the chat run`);+ assert.equal(doneResult?.autoResumeScheduled, false, `${build}: a downgraded chat completion must not auto-resume`);+ assert.ok(String(doneResult?.summary).includes(chatRunEndedNotice()), `${build}: the chat run-ended notice is missing`);+ } else {+ assert.equal(doneResult?.outcome, 'success', `${build}: missing evidence alone must not downgrade a chat success`);+ assert.equal(doneResult?.runEnded, undefined);+ assert.equal(doneResult?.autoResumeScheduled, undefined);+ assert.ok(!String(doneResult?.summary).includes(chatRunEndedNotice()));+ }+ }+ });+test(`${build}: a done with no outcome is advised once, then accepted as partial`, async () => {for (const strict of [false, true]) {const h = batchAgent(Agent, { strict });