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 chat run whose table was not delivered gets the run-ended notice
Barack Sokullu16f92ce3d120
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex d19833660..36581d4c8 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -16738,7 +16738,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d&& ['partial', 'failed'].includes(toolResult.outcome)) {toolResult.runEnded = true;toolResult.autoResumeScheduled = false;- if (!fnArgs.data_ref) {+ // Only an exact table actually delivered as its JSON keeps the+ // notice out of the payload; a reference that delivered nothing+ // (_resolveExactTableDone) gets it like any other answer.+ if (!this._isExactTablePayload(tabId, fnArgs, toolResult.summary)) {const notice = chatRunEndedNotice(this.responseLanguagePolicies.get(tabId)?.framing_locale || runOptions?.locale);toolResult.summary = (toolResult.summary || partialAssistantText || '') + '\n\n' + notice;}diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 4fdfccff8..5cf5d57aa 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -15005,7 +15005,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d&& ['partial', 'failed'].includes(toolResult.outcome)) {toolResult.runEnded = true;toolResult.autoResumeScheduled = false;- if (!fnArgs.data_ref) {+ // Only an exact table actually delivered as its JSON keeps the+ // notice out of the payload; a reference that delivered nothing+ // (_resolveExactTableDone) gets it like any other answer.+ if (!this._isExactTablePayload(tabId, fnArgs, toolResult.summary)) {const notice = chatRunEndedNotice(this.responseLanguagePolicies.get(tabId)?.framing_locale || runOptions?.locale);toolResult.summary = (toolResult.summary || partialAssistantText || '') + '\n\n' + notice;}diff --git a/test/guard-advisory-completion.mjs b/test/guard-advisory-completion.mjsindex 0d7fe7eef..ea519113b 100644--- a/test/guard-advisory-completion.mjs+++ b/test/guard-advisory-completion.mjs@@ -785,6 +785,57 @@ for (const build of ['chrome', 'firefox']) {}});+ test(`${build}: a chat run's undelivered exact table ends with the run-ended notice; a delivered one stays its JSON`, async () => {+ const { chatRunEndedNotice, createChatSession } = await import(`../src/${build}/src/agent/chat-workflow.js`);+ const askSchemas = new Map(getToolsForMode('ask', { tier: 'full' }).map(tool => [tool.function.name, tool.function.parameters]));+ const doneResultOf = updates => updates.filter(update => update.type === 'tool_result' && update.data.name === 'done').at(-1)?.data.result;+ // The reference expired: no table is delivered, so the partial chat run+ // gets its notice like any other answer.+ {+ const h = batchAgent(Agent, { mode: 'ask', realDone: true, schemas: askSchemas });+ h.agent.chatSessions.set(h.tab, createChatSession({ threadKey: 'dom:telegram:k:123456:0' }));+ h.agent.readCompletenessStates.set(h.tab, { runToken: 'owned-run', tablePageObserved: true });+ const done = ['done', { summary: 'Full inventory.', data_ref: 'table_expired' }];+ assert.equal((await h.batch([done])).action, 'continue');+ const updates = [];+ assert.equal((await h.batch([done], updates)).action, 'return');+ const doneResult = doneResultOf(updates);+ assert.equal(doneResult?.outcome, 'partial');+ assert.equal(doneResult?.runEnded, true);+ assert.ok(String(doneResult?.summary).includes(chatRunEndedNotice()), `${build}: the run-ended notice is missing`);+ }+ // A delivered table in a chat run that ends partial for another reason+ // (unread pages of a whole read) stays the exact JSON, without the notice.+ {+ const h = batchAgent(Agent, { mode: 'ask', realDone: true, schemas: askSchemas, task: 'Summarize this whole conversation.' });+ h.agent.chatSessions.set(h.tab, createChatSession({ threadKey: 'dom:telegram:k:123456:0' }));+ h.agent._currentUrl = async () => 'https://outlook.live.com/mail/0/inbox/id/AQMkADAwATM0MDAAMS1i';+ await h.agent._beginReadCompleteness(h.tab, 'Summarize this whole conversation.', {});+ h.agent._armReadCompletenessFromPlan(h.tab, { request_kind: 'execute', read_scope: 'complete_thread' });+ h.agent._recordReadCompleteness(h.tab, 'get_accessibility_tree', { filter: 'all', maxDepth: 15 }, {+ pageContent: 'main\n listitem "First message"', page: 1, totalChars: 9000, hasMore: true, truncated: false, nextPage: 2 });+ const state = h.agent.readCompletenessStates.get(h.tab);+ const owner = { runToken: state.runToken, current: () => true };+ const table = { rowCount: 1, rows: [{ id: 'A' }] };+ const record = { dataRef: 'table_owned', runToken: state.runToken, owner, args: { columns: ['id'] }, summary: JSON.stringify(table) };+ state.exactTableExports = new Map([['table_owned', record]]);+ h.agent._exactTableOwner = () => owner;+ const realExecute = h.agent.executeTool.bind(h.agent);+ h.agent.executeTool = async (tab, name, args, ...rest) => (name === 'extract_data'+ ? { success: true, verifiedExactTable: true } : realExecute(tab, name, args, ...rest));+ const done = ['done', { summary: 'Full inventory.', data_ref: 'table_owned' }];+ assert.equal((await h.batch([done])).action, 'continue', `${build}: the coverage note comes first`);+ const updates = [];+ const accepted = await h.batch([done], updates);+ assert.equal(accepted.action, 'return');+ const doneResult = doneResultOf(updates);+ assert.equal(doneResult?.outcome, 'partial', `${build}: the unread pages downgrade the answer`);+ assert.equal(doneResult?.runEnded, true);+ assert.deepEqual(JSON.parse(accepted.value), table, `${build}: the delivered table stays its exact JSON`);+ assert.ok(!String(doneResult?.summary).includes(chatRunEndedNotice()), `${build}: the notice went into the table JSON`);+ }+ });+test(`${build}: an unverifiable table snapshot is delivered over advice, but not under Strict secret mode`, async () => {for (const strictSecretMode of [false, true]) {const h = batchAgent(Agent, { mode: 'ask' });