Skip to content

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

fix: bind batch execution to run tier and settle delayed navigation

Barack Sokulluef60e25a1575
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fea917393..163f8e0fe 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@ This changelog was generated from the repository Git history and release tags. V
- `browser_batch` runs predictable browser actions in order in one model round trip on Chrome and Firefox. Mid allows up to 6 actions and Full up to 10; Dev inherits its provider tier. Each action keeps its normal permission and verification checks, and failures or submits stop the remaining work for a fresh turn. A final page read can follow navigation. Ask and Compact keep their existing tool surface; an internal `browserBatchEnabled` switch disables batching.
### Fixed
+- Browser batches use the run's selected provider tier for action limits and continuation rules, and wait briefly for delayed navigation before deciding whether another child can run. Navigation that remains unsettled stops the remaining actions for verification.
- Keep each retained browser batch result inside its original untrusted-content boundaries when trimming context. Rejected batches no longer overwrite a native sibling's execution receipt when its call ID resembles a generated batch child ID.
- Mastodon: deleting your own post no longer stops at Mastodon's "Delete post?" confirmation. WebBrain opened the post's "…" menu and chose Delete, and the confirmation that its own click opened was refused as "not inside one identifiable record". When the menu entry was clicked no model had read its caption yet, so WebBrain had not tied the confirmation to the post, and while the confirmation is open Mastodon makes the rest of the page inert, which WebBrain read as the post and your account being hidden. Mastodon's dangerous entries on your own post now count as its deletion by page structure, the post and your account behind the confirmation still count, and Mastodon's own confirm button is recognized in windows narrower than 1175 px, where Mastodon shows no composer beside the timeline. A confirmation that WebBrain's click did not open, another account's post, and anything inert without Mastodon's confirmation open still bind nothing. With Mastodon's confirmation turned off, the dangerous entry is checked as the deletion itself even before its caption is read.
- Ask mode: an answer being written no longer disappears and starts over when you use the page meanwhile. In a WhatsApp trace, typing a draft and clicking in the chat while the answer was written threw the answer away twice and wrote it again each time, and the answer that finally stayed, written after you stopped, was the shortest. Scrolling, selecting, clicking and typing on the page, and the page's changes from them, now leave the answer as it is: it is about the page as you asked about it, and the run ends without waiting for you to stop typing. Navigating the page to another address still starts the answer over.
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 55a1d6c61..c7a70d224 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -13337,7 +13337,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
|| toolResult?.ambiguous || toolResult?.outcomeUnknown || toolResult?.stale) return 'action_failed';
if (toolResult?.inconclusive || toolResult?.verified === false || toolResult?.remoteStateVerified === false) return 'action_unverified';
if (batch.submit && batch.hasRemaining) return 'submit_boundary';
- if (!batch.sameNext && batch.navigationChanged && batch.hasRemaining) return 'navigation_changed';
+ if (batch.navigationChanged && batch.hasRemaining
+ && (!batch.sameNext || !batch.remainingObservations)) return 'navigation_changed';
if (!batch.sameNext && batch.hadMutation && (tier === 'mid' || tier === 'compact')) return 'small_model_action_boundary';
}
if (toolName === 'done' && toolResult?.completionPageBlock === true) {
@@ -13449,14 +13450,27 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
}
async _settleBrowserBatchNavigation(tabId) {
- // Click-like actions may start loading just after their dispatch returns.
- const deadline = Date.now() + 3000;
+ // A complete tab can start navigation after a click's handler returns. Give
+ // it a short grace period, then require quiet completion before continuing.
+ const started = Date.now();
+ const deadline = started + 3000;
+ let completeSince = null;
+ let navigationObserved = false;
do {
this._throwIfAborted(this._runAbortSignal(tabId));
const tab = await chrome.tabs.get(tabId);
- if (tab.status !== 'loading') return;
+ if (tab.status === 'loading') {
+ navigationObserved = true;
+ completeSince = null;
+ } else {
+ completeSince ??= Date.now();
+ if (Date.now() - started >= 500 && Date.now() - completeSince >= 200) {
+ return { settled: true, navigationObserved };
+ }
+ }
await new Promise(resolve => setTimeout(resolve, 100));
} while (Date.now() < deadline);
+ return { settled: false, navigationObserved };
}
async _executeToolBatch(tabId, toolCalls, messages, onUpdate, provider, partialAssistantText = null, allowedToolNames = AGENT_TOOL_NAMES, step = null, runOptions = {}, toolSchemas = null) {
@@ -13476,7 +13490,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const batchStarted = new Set();
const batchSchemas = parentCalls.length ? new Map([...allowedToolNames].map(name => [name, this._toolParametersForValidation(tabId, name, toolSchemas)])) : null;
toolCalls = expandBrowserBatchCalls(toolCalls, {
- enabled: this.browserBatchEnabled !== false, tier: this._resolvePromptTier(), allowedToolNames, toolSchemas: batchSchemas,
+ enabled: this.browserBatchEnabled !== false, tier: this._resolvePromptTier(provider), allowedToolNames, toolSchemas: batchSchemas,
});
const originalUpdate = onUpdate;
const cancellationState = { active: null };
@@ -13680,7 +13694,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const apiMutationsDeniedForRun = runOptions.apiMutationsDenied === true;
const apiMutationsAllowedForRun = () =>
!apiMutationsDeniedForRun && this.isApiMutationsAllowed(tabId);
- const promptTier = this._resolvePromptTier();
+ const promptTier = this._resolvePromptTier(provider);
const readLimits = this._readWindowLimits();
const completionBatchStartState = this.completionInvariants.get(tabId) || null;
// Set of tools whose side effect can navigate the page. We snapshot the
@@ -13783,8 +13797,6 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
{ tier: promptTier, triggeringTool: previous.function.name, reason: 'action_failed', navNotices },
)) { navNotices.length = 0; break; }
}
- if (tc._browserBatch && previous?._browserBatch?.parentId === tc._browserBatch.parentId
- && Agent.NAV_PRONE_TOOLS.has(previous.function.name)) await this._settleBrowserBatchNavigation(tabId);
const callState = { index: toolIndex, invoked: false, consequential: false, result: null, dispatchState: null };
cancellationState.active = callState;
// Abort check before each tool call.
@@ -15256,7 +15268,16 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
&& beforeUrl
&& (!toolResult?.error || toolResult?.dispatched === true)
) {
- await new Promise(r => setTimeout(r, 200));
+ if (tc._browserBatch && toolCalls[toolIndex + 1]?._browserBatch?.parentId === tc._browserBatch.parentId) {
+ const settled = await this._settleBrowserBatchNavigation(tabId);
+ if (settled.navigationObserved) navigatedBrowserBatches.add(tc._browserBatch.parentId);
+ if (!settled.settled && toolResult && typeof toolResult === 'object') {
+ toolResult.inconclusive = true;
+ toolResult.verified = false;
+ }
+ } else {
+ await new Promise(r => setTimeout(r, 200));
+ }
afterUrl = await this._currentUrl(tabId);
const beforeFull = this._normalizeUrl(beforeUrl);
const afterFull = this._normalizeUrl(afterUrl);
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index a94ba0cc6..0763ec33b 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -11981,7 +11981,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
|| toolResult?.ambiguous || toolResult?.outcomeUnknown || toolResult?.stale) return 'action_failed';
if (toolResult?.inconclusive || toolResult?.verified === false || toolResult?.remoteStateVerified === false) return 'action_unverified';
if (batch.submit && batch.hasRemaining) return 'submit_boundary';
- if (!batch.sameNext && batch.navigationChanged && batch.hasRemaining) return 'navigation_changed';
+ if (batch.navigationChanged && batch.hasRemaining
+ && (!batch.sameNext || !batch.remainingObservations)) return 'navigation_changed';
if (!batch.sameNext && batch.hadMutation && (tier === 'mid' || tier === 'compact')) return 'small_model_action_boundary';
}
if (toolName === 'done' && toolResult?.completionPageBlock === true) {
@@ -12098,14 +12099,27 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
}
async _settleBrowserBatchNavigation(tabId) {
- // Click-like actions may start loading just after their dispatch returns.
- const deadline = Date.now() + 3000;
+ // A complete tab can start navigation after a click's handler returns. Give
+ // it a short grace period, then require quiet completion before continuing.
+ const started = Date.now();
+ const deadline = started + 3000;
+ let completeSince = null;
+ let navigationObserved = false;
do {
this._throwIfAborted(this._runAbortSignal(tabId));
const tab = await browser.tabs.get(tabId);
- if (tab.status !== 'loading') return;
+ if (tab.status === 'loading') {
+ navigationObserved = true;
+ completeSince = null;
+ } else {
+ completeSince ??= Date.now();
+ if (Date.now() - started >= 500 && Date.now() - completeSince >= 200) {
+ return { settled: true, navigationObserved };
+ }
+ }
await new Promise(resolve => setTimeout(resolve, 100));
} while (Date.now() < deadline);
+ return { settled: false, navigationObserved };
}
async _executeToolBatch(tabId, toolCalls, messages, onUpdate, provider, partialAssistantText = null, allowedToolNames = AGENT_TOOL_NAMES, step = null, runOptions = {}, toolSchemas = null) {
@@ -12125,7 +12139,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const batchStarted = new Set();
const batchSchemas = parentCalls.length ? new Map([...allowedToolNames].map(name => [name, this._toolParametersForValidation(tabId, name, toolSchemas)])) : null;
toolCalls = expandBrowserBatchCalls(toolCalls, {
- enabled: this.browserBatchEnabled !== false, tier: this._resolvePromptTier(), allowedToolNames, toolSchemas: batchSchemas,
+ enabled: this.browserBatchEnabled !== false, tier: this._resolvePromptTier(provider), allowedToolNames, toolSchemas: batchSchemas,
});
const originalUpdate = onUpdate;
const cancellationState = { active: null };
@@ -12329,7 +12343,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const apiMutationsDeniedForRun = runOptions.apiMutationsDenied === true;
const apiMutationsAllowedForRun = () =>
!apiMutationsDeniedForRun && this.isApiMutationsAllowed(tabId);
- const promptTier = this._resolvePromptTier();
+ const promptTier = this._resolvePromptTier(provider);
const readLimits = this._readWindowLimits();
const completionBatchStartState = this.completionInvariants.get(tabId) || null;
const navNotices = [];
@@ -12428,8 +12442,6 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
{ tier: promptTier, triggeringTool: previous.function.name, reason: 'action_failed', navNotices },
)) { navNotices.length = 0; break; }
}
- if (tc._browserBatch && previous?._browserBatch?.parentId === tc._browserBatch.parentId
- && Agent.NAV_PRONE_TOOLS.has(previous.function.name)) await this._settleBrowserBatchNavigation(tabId);
const callState = { index: toolIndex, invoked: false, consequential: false, result: null, dispatchState: null };
cancellationState.active = callState;
if (this._checkAbort(tabId)) {
@@ -13809,7 +13821,16 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
&& beforeUrl
&& (!toolResult?.error || toolResult?.dispatched === true)
) {
- await new Promise(r => setTimeout(r, 200));
+ if (tc._browserBatch && toolCalls[toolIndex + 1]?._browserBatch?.parentId === tc._browserBatch.parentId) {
+ const settled = await this._settleBrowserBatchNavigation(tabId);
+ if (settled.navigationObserved) navigatedBrowserBatches.add(tc._browserBatch.parentId);
+ if (!settled.settled && toolResult && typeof toolResult === 'object') {
+ toolResult.inconclusive = true;
+ toolResult.verified = false;
+ }
+ } else {
+ await new Promise(r => setTimeout(r, 200));
+ }
afterUrl = await this._currentUrl(tabId);
const beforeFull = this._normalizeUrl(beforeUrl);
const afterFull = this._normalizeUrl(afterUrl);
diff --git a/test/browser-batch-runtime.mjs b/test/browser-batch-runtime.mjs
index a82cf75c2..bc26b3959 100644
--- a/test/browser-batch-runtime.mjs
+++ b/test/browser-batch-runtime.mjs
@@ -14,6 +14,18 @@ const call = (id, name, input) => ({ id, type: 'function', function: { name, arg
const field = n => ({ name: 'set_field', input: { ref_id: `ref_${n}`, text: `value ${n}` } });
const batch = (actions, id = 'batch') => call(id, 'browser_batch', { actions });
+async function withClock(t, operation) {
+ t.mock.timers.enable({ apis: ['Date', 'setTimeout'], now: 0 });
+ let done = false;
+ const pending = operation().finally(() => { done = true; });
+ for (let elapsed = 0; elapsed < 10000 && !done; elapsed += 100) {
+ await new Promise(setImmediate);
+ t.mock.timers.tick(100);
+ }
+ assert.equal(done, true, 'fixture must finish within the bounded settling window');
+ return pending;
+}
+
for (const build of ['chrome', 'firefox']) {
const { Agent } = await import(`../src/${build}/src/agent/agent.js`);
const { getToolsForMode } = await import(`../src/${build}/src/agent/tools.js`);
@@ -79,6 +91,63 @@ for (const build of ['chrome', 'firefox']) {
assert.equal(h.updates.filter(event => event.type === 'tool_result' && event.data.name === 'browser_batch').length, 1);
});
+ for (const scenario of [
+ { tier: 'full', active: 'mid', count: 7, dispatched: 7 },
+ { tier: 'mid', active: 'full', count: 7, dispatched: 0 },
+ { tier: 'mid', active: 'full', count: 2, dispatched: 2, sibling: true },
+ { tier: 'full', active: 'mid', count: 2, dispatched: 3, sibling: true },
+ ]) test(`${build}: ${scenario.tier} run uses its own tier with ${scenario.active} active (${scenario.count} actions${scenario.sibling ? ' and sibling' : ''})`, async () => {
+ const calls = [batch(Array.from({ length: scenario.count }, (_, index) => field(index)))];
+ if (scenario.sibling) calls.push(call('sibling', 'get_window_info', {}));
+ const h = setup(calls, scenario.tier);
+ h.agent.providerManager.getActive = () => ({ ...h.provider, promptTier: scenario.active });
+ await h.run();
+ assert.equal(h.dispatched.length, scenario.dispatched);
+ assertPaired(h.messages);
+ if (!scenario.dispatched) assert.match(h.messages.at(-1).content, /invalid_browser_batch/);
+ else if (scenario.sibling && scenario.tier === 'mid') {
+ assert.equal(JSON.parse(h.messages.at(-1).content).reason, 'small_model_action_boundary');
+ }
+ });
+
+ for (const scenario of ['mutation', 'observation', 'reload', 'timeout']) test(`${build}: delayed navigation ${scenario} settles before a fresh batch decision`, async t => {
+ const next = scenario === 'observation' ? { name: 'read_page', input: {} } : field(2);
+ const h = setup([batch([{ name: 'click_ax', input: { ref_id: 'ref_1' } }, next]), call('sibling', 'get_window_info', {})]);
+ const originalGet = api.tabs.get;
+ t.after(() => { api.tabs.get = originalGet; });
+ let dispatchedAt = null;
+ let nextAt = null;
+ const elapsed = () => dispatchedAt === null ? -1 : Date.now() - dispatchedAt;
+ const loading = () => elapsed() >= 300 && (scenario === 'timeout' || elapsed() < 600);
+ const url = () => elapsed() >= 300 && scenario !== 'reload' ? 'https://example.com/next' : 'https://example.com/';
+ api.tabs.get = async id => ({ id, url: url(), status: loading() ? 'loading' : 'complete' });
+ h.agent._currentUrl = async () => url();
+ h.agent.executeTool = async (_tab, name, args) => {
+ h.dispatched.push({ name, args });
+ if (dispatchedAt === null) dispatchedAt = Date.now();
+ else nextAt = elapsed();
+ return { success: true, verified: true };
+ };
+ await withClock(t, h.run);
+ assertPaired(h.messages);
+ assert.deepEqual(h.dispatched.map(item => item.name), scenario === 'observation' ? ['click_ax', 'read_page'] : ['click_ax']);
+ if (scenario === 'observation') assert.ok(nextAt >= 800, 'observation waits for navigation and quiet completion');
+ assert.equal(JSON.parse(h.messages.find(message => message.tool_call_id === 'sibling').content).reason,
+ scenario === 'timeout' ? 'action_unverified' : 'navigation_changed');
+ });
+
+ test(`${build}: a complete tab gets a bounded delayed-navigation grace period`, async t => {
+ const { agent } = setup([]);
+ let result;
+ let finishedAt;
+ await withClock(t, async () => {
+ result = await agent._settleBrowserBatchNavigation(1);
+ finishedAt = Date.now();
+ });
+ assert.deepEqual(result, { settled: true, navigationObserved: false });
+ assert.ok(finishedAt >= 500 && finishedAt <= 700);
+ });
+
test(`${build}: malformed later input prevents every dispatch`, async () => {
const h = setup([batch([field(1), { name: 'set_field', input: { ref_id: 'ref_2' } }])]);
await h.run();