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
Publication prefetch: timing starts before a call's arguments are prepared
Barack Sokullu2e43bddb68e9
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 416716cbc..7f003caed 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -15535,6 +15535,26 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dif (interruptFailedBrowserAction(toolIndex, fnName)) { navNotices.length = 0; break; }continue;}+ // Where this call's time goes before dispatch (_predispatchTimer), from+ // its first preparation step on: a consequential call whose arguments+ // or coordinates fail, or that a check stops, still records it.+ const predispatch = this._predispatchTimer(tabId);+ let fnArgs = {};+ let protectedPageFailure = null;+ // Whether this call can change something: until the permission+ // capabilities and the submit probe are known, its tool and the+ // arguments known so far decide (reassigned below once they are).+ let predispatchConsequential = () => !protectedPageFailure && (Agent.STATE_CHANGE_TOOLS.has(fnName)+ || capabilitiesFor(fnName, fnArgs).length > 0);+ // A consequential call that a check stops before dispatch still records+ // where its time went, the wait on a card included. One that stops any+ // other way gets its note when the next call starts or the batch ends+ // (_flushPredispatchTiming).+ const predispatchBlocked = stage => {+ predispatch.lap(stage);+ if (predispatchConsequential()) predispatch.emit(step, { tool: fnName, outcome: 'blocked' });+ };+ callState.predispatchTiming = { timer: predispatch, step, tool: fnName, consequential: () => predispatchConsequential() };const parsedArgs = this._parseToolCallArgs(tc);if (parsedArgs.error) {const result = this._invalidToolArgumentsResult(fnName, parsedArgs);@@ -15553,7 +15573,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dif (interruptFailedBrowserAction(toolIndex, fnName)) { navNotices.length = 0; break; }continue;}- let fnArgs = this._toolCallArgsWithReplayMethod(tabId, fnName, argRepair.args);+ fnArgs = this._toolCallArgsWithReplayMethod(tabId, fnName, argRepair.args);const argRepairNotice = argRepair.note || '';let readWindowNotice = '';const readState = this.readCompletenessStates.get(tabId);@@ -15592,22 +15612,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// executeTool(). Keep the failure in the ordinary result pipeline below// so tracing, loop handling, and trusted recovery notes still behave// exactly like other tool results.- const predispatch = this._predispatchTimer(tabId);- const protectedPageFailure = await this._chromeProtectedPageFailure(tabId, fnName);- // Whether this call can change something: until the permission- // capabilities and the submit probe are known, its tool and arguments- // decide (reassigned below once they are).- let predispatchConsequential = () => !protectedPageFailure && (Agent.STATE_CHANGE_TOOLS.has(fnName)- || capabilitiesFor(fnName, fnArgs).length > 0);- // A consequential call that a check stops before dispatch still records- // where its time went, the wait on a card included. One that stops any- // other way gets its note when the next call starts or the batch ends- // (_flushPredispatchTiming).- const predispatchBlocked = stage => {- predispatch.lap(stage);- if (predispatchConsequential()) predispatch.emit(step, { tool: fnName, outcome: 'blocked' });- };- callState.predispatchTiming = { timer: predispatch, step, tool: fnName, consequential: () => predispatchConsequential() };+ predispatch.lap('argumentsMs');+ protectedPageFailure = await this._chromeProtectedPageFailure(tabId, fnName);if (!protectedPageFailure && fnName !== 'done' && !Agent.NAV_TOOLS.has(fnName)) {try {await this._adoptLiveSocialPublishWorkflow(tabId, provider);diff --git a/src/chrome/src/trace/privacy.js b/src/chrome/src/trace/privacy.jsindex 7be26982e..b59a430f3 100644--- a/src/chrome/src/trace/privacy.js+++ b/src/chrome/src/trace/privacy.js@@ -117,7 +117,7 @@ function projectDoneTiming(data) {// in milliseconds, the tool's name and the call's outcome, never what the// page or the model said.const PREDISPATCH_TIMING_MS_FIELDS = [- 'workflowAdoptMs', 'captchaGateMs', 'preparationMs', 'clarificationMs', 'submitPreflightMs',+ 'argumentsMs', 'workflowAdoptMs', 'captchaGateMs', 'preparationMs', 'clarificationMs', 'submitPreflightMs','submitProbeMs', 'submitCaptionReadingMs', 'resultBaselineMs', 'validationSnapshotMs','workflowPreSubmitMs', 'resourceMutationMs', 'githubTransitionMs', 'workflowDispatchMs','publicationContractMs', 'publicationAuditMs', 'publicationAuditReusedMs', 'publicationAuditAwaitedMs',diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex c65fc6670..5692cd05f 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -13894,6 +13894,25 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dif (interruptFailedBrowserAction(toolIndex, fnName)) { navNotices.length = 0; break; }continue;}+ // Where this call's time goes before dispatch (_predispatchTimer), from+ // its first preparation step on: a consequential call whose arguments+ // or coordinates fail, or that a check stops, still records it.+ const predispatch = this._predispatchTimer(tabId);+ let fnArgs = {};+ // Whether this call can change something: until the permission+ // capabilities and the submit probe are known, its tool and the+ // arguments known so far decide (reassigned below once they are).+ let predispatchConsequential = () => (Agent.STATE_CHANGE_TOOLS.has(fnName)+ || capabilitiesFor(fnName, fnArgs).length > 0);+ // A consequential call that a check stops before dispatch still records+ // where its time went, the wait on a card included. One that stops any+ // other way gets its note when the next call starts or the batch ends+ // (_flushPredispatchTiming).+ const predispatchBlocked = stage => {+ predispatch.lap(stage);+ if (predispatchConsequential()) predispatch.emit(step, { tool: fnName, outcome: 'blocked' });+ };+ callState.predispatchTiming = { timer: predispatch, step, tool: fnName, consequential: () => predispatchConsequential() };const parsedArgs = this._parseToolCallArgs(tc);if (parsedArgs.error) {const result = this._invalidToolArgumentsResult(fnName, parsedArgs);@@ -13912,7 +13931,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dif (interruptFailedBrowserAction(toolIndex, fnName)) { navNotices.length = 0; break; }continue;}- let fnArgs = this._toolCallArgsWithReplayMethod(tabId, fnName, argRepair.args);+ fnArgs = this._toolCallArgsWithReplayMethod(tabId, fnName, argRepair.args);const argRepairNotice = argRepair.note || '';let readWindowNotice = '';const readState = this.readCompletenessStates.get(tabId);@@ -13943,21 +13962,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dcontinue;}fnArgs = coordinates.args;- const predispatch = this._predispatchTimer(tabId);- // Whether this call can change something: until the permission- // capabilities and the submit probe are known, its tool and arguments- // decide (reassigned below once they are).- let predispatchConsequential = () => (Agent.STATE_CHANGE_TOOLS.has(fnName)- || capabilitiesFor(fnName, fnArgs).length > 0);- // A consequential call that a check stops before dispatch still records- // where its time went, the wait on a card included. One that stops any- // other way gets its note when the next call starts or the batch ends- // (_flushPredispatchTiming).- const predispatchBlocked = stage => {- predispatch.lap(stage);- if (predispatchConsequential()) predispatch.emit(step, { tool: fnName, outcome: 'blocked' });- };- callState.predispatchTiming = { timer: predispatch, step, tool: fnName, consequential: () => predispatchConsequential() };+ predispatch.lap('argumentsMs');if (fnName !== 'done' && !Agent.NAV_TOOLS.has(fnName)) {try {await this._adoptLiveSocialPublishWorkflow(tabId, provider);diff --git a/src/firefox/src/trace/privacy.js b/src/firefox/src/trace/privacy.jsindex 7be26982e..b59a430f3 100644--- a/src/firefox/src/trace/privacy.js+++ b/src/firefox/src/trace/privacy.js@@ -117,7 +117,7 @@ function projectDoneTiming(data) {// in milliseconds, the tool's name and the call's outcome, never what the// page or the model said.const PREDISPATCH_TIMING_MS_FIELDS = [- 'workflowAdoptMs', 'captchaGateMs', 'preparationMs', 'clarificationMs', 'submitPreflightMs',+ 'argumentsMs', 'workflowAdoptMs', 'captchaGateMs', 'preparationMs', 'clarificationMs', 'submitPreflightMs','submitProbeMs', 'submitCaptionReadingMs', 'resultBaselineMs', 'validationSnapshotMs','workflowPreSubmitMs', 'resourceMutationMs', 'githubTransitionMs', 'workflowDispatchMs','publicationContractMs', 'publicationAuditMs', 'publicationAuditReusedMs', 'publicationAuditAwaitedMs',diff --git a/test/publication-prefetch.mjs b/test/publication-prefetch.mjsindex 50eb290a9..46c7fcfee 100644--- a/test/publication-prefetch.mjs+++ b/test/publication-prefetch.mjs@@ -496,7 +496,8 @@ for (const browser of ['chrome', 'firefox']) {const notes = [];agent._recordPredispatchTiming = (_tabId, step, timing) => notes.push({ step, timing });const messages = [];- await agent._executeToolBatch(tabId, [{ id: 'call', function: { name, arguments: JSON.stringify(args) } }],+ await agent._executeToolBatch(tabId, [{ id: 'call', function: { name,+ arguments: typeof args === 'string' ? args : JSON.stringify(args) } }],messages, () => {}, provider, '', new Set([name]), 6);return { dispatched, notes, result: String(messages.find(message => message.role === 'tool')?.content || '') };};@@ -521,8 +522,11 @@ for (const browser of ['chrome', 'firefox']) {}, 'blocked', 'clarificationMs'],['API mutation without /allow-api', ['fetch_url', { url: 'https://api.example.com/items', method: 'POST', body: '{}' }],() => {}, 'blocked', 'clarificationMs'],- // Any other stop before dispatch: noted when the batch ends.+ // Any other stop before dispatch: noted when the batch ends, arguments+ // that cannot be used included.['failed preparation', click, preparationFails, 'not_dispatched', 'stoppedMs'],+ ['unreadable arguments', ['click_ax', '{"ref_id": "ref_9"'], () => {}, 'not_dispatched', 'stoppedMs'],+ ['invalid arguments', ['click_ax', { ref_id: 9 }], () => {}, 'not_dispatched', 'stoppedMs'],]) {const stopped = await run(name, args, stub);assert.deepEqual(stopped.dispatched, [], `${label}: nothing was sent`);