Skip to content

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

Publication prefetch: no background checks on an in-browser model

Barack Sokullu7de94f17baed
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 994e01729..4b232a8fc 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -23948,7 +23948,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
}
const state = { key, sources, context, contract: null, outcomes: {}, actionId: null, dispatch: null, error: '' };
if (background) {
- if (!provider?.chat || JSON.stringify(sources).length > 120000) return null;
+ if (!this._socialPublicationBackgroundProvider(provider) || JSON.stringify(sources).length > 120000) return null;
// A background compile of another input can never be installed:
// cancel its request (and an audit of what it compiled) first.
if (prefetch) this._dropSocialPublicationContractPrefetch(guard, prefetch);
@@ -24521,7 +24521,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
_socialPublicationPrefetch(tabId, name, args = {}, result = null, provider = null) {
try {
const guard = this._planExecutionGuards.get(tabId);
- if (!this._socialPublicationPrefetchAllowed(guard) || !provider?.chat
+ if (!this._socialPublicationPrefetchAllowed(guard) || !this._socialPublicationBackgroundProvider(provider)
|| this._checkAbort(tabId) || this._hasPendingSteering(tabId)
|| !result || typeof result !== 'object' || result.success !== true
|| result.noDispatch === true || result.outcomeUnknown === true) return null;
@@ -24544,7 +24544,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const hint = this._socialPublicationPrefetchHint(name, args);
const social = guard?.socialPublication;
const pending = this._socialPublicationContractPrefetches?.get(guard);
- if (!hint || !this._socialPublicationPrefetchAllowed(guard) || !provider?.chat
+ if (!hint || !this._socialPublicationPrefetchAllowed(guard) || !this._socialPublicationBackgroundProvider(provider)
|| this._checkAbort(tabId) || this._hasPendingSteering(tabId)
|| (social && (this._socialPublicationCompiles?.get(social)
|| !social.needsRecompile || Object.keys(social.outcomes || {}).length))
@@ -24555,6 +24555,15 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
}
}
+ // Background checks run only where a superseded one can be cancelled. An
+ // in-browser model (WebGPU) runs one request at a time and ignores the
+ // request's signal, so a stale background check would hold its queue ahead
+ // of the replacement check and of the agent's next turn. With it, the click
+ // checks on its own, as before.
+ _socialPublicationBackgroundProvider(provider) {
+ return typeof provider?.chat === 'function' && provider.name !== 'webgpu';
+ }
+
// A write may prepare the click on Post only in a run that executes a plan
// submitting something and is not bound to another site job (a message to
// send, a file to commit): the planner told those apart from a post.
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index adb29eb9d..e42ebfc19 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -21131,7 +21131,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
}
const state = { key, sources, context, contract: null, outcomes: {}, actionId: null, dispatch: null, error: '' };
if (background) {
- if (!provider?.chat || JSON.stringify(sources).length > 120000) return null;
+ if (!this._socialPublicationBackgroundProvider(provider) || JSON.stringify(sources).length > 120000) return null;
// A background compile of another input can never be installed:
// cancel its request (and an audit of what it compiled) first.
if (prefetch) this._dropSocialPublicationContractPrefetch(guard, prefetch);
@@ -21704,7 +21704,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
_socialPublicationPrefetch(tabId, name, args = {}, result = null, provider = null) {
try {
const guard = this._planExecutionGuards.get(tabId);
- if (!this._socialPublicationPrefetchAllowed(guard) || !provider?.chat
+ if (!this._socialPublicationPrefetchAllowed(guard) || !this._socialPublicationBackgroundProvider(provider)
|| this._checkAbort(tabId) || this._hasPendingSteering(tabId)
|| !result || typeof result !== 'object' || result.success !== true
|| result.noDispatch === true || result.outcomeUnknown === true) return null;
@@ -21727,7 +21727,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const hint = this._socialPublicationPrefetchHint(name, args);
const social = guard?.socialPublication;
const pending = this._socialPublicationContractPrefetches?.get(guard);
- if (!hint || !this._socialPublicationPrefetchAllowed(guard) || !provider?.chat
+ if (!hint || !this._socialPublicationPrefetchAllowed(guard) || !this._socialPublicationBackgroundProvider(provider)
|| this._checkAbort(tabId) || this._hasPendingSteering(tabId)
|| (social && (this._socialPublicationCompiles?.get(social)
|| !social.needsRecompile || Object.keys(social.outcomes || {}).length))
@@ -21738,6 +21738,15 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
}
}
+ // Background checks run only where a superseded one can be cancelled. An
+ // in-browser model (WebGPU) runs one request at a time and ignores the
+ // request's signal, so a stale background check would hold its queue ahead
+ // of the replacement check and of the agent's next turn. With it, the click
+ // checks on its own, as before.
+ _socialPublicationBackgroundProvider(provider) {
+ return typeof provider?.chat === 'function' && provider.name !== 'webgpu';
+ }
+
// A write may prepare the click on Post only in a run that executes a plan
// submitting something and is not bound to another site job (a message to
// send, a file to commit): the planner told those apart from a post.
diff --git a/test/publication-prefetch.mjs b/test/publication-prefetch.mjs
index 4db700ced..507baa15f 100644
--- a/test/publication-prefetch.mjs
+++ b/test/publication-prefetch.mjs
@@ -360,6 +360,23 @@ for (const browser of ['chrome', 'firefox']) {
assert.equal(f.pending()?.compiled?.prefetchedAudit, undefined, 'a cancelled audit stores no verdict');
});
+ test(`${browser}: an in-browser model that cannot cancel a request gets no background checks`, async () => {
+ // WebGPU runs one request at a time and ignores the request's signal: a
+ // superseded background check would hold its queue ahead of the
+ // replacement and of the agent's next turn.
+ const f = setup();
+ const { agent, tabId, provider } = f;
+ provider.name = 'webgpu';
+ assert.equal(agent._socialPublicationContractPrefetch(tabId, 'type_ax', { ref_id: 'ref_7', text: 'Hello' }, provider), null,
+ 'no background compile when the write starts');
+ assert.equal(f.write(), null, 'no background compile or audit after the write');
+ await settle();
+ assert.equal(f.calls.length, 0, 'nothing was sent in the background');
+ assert.equal(f.pending(), null);
+ assert.equal(await f.click(), null, 'the click checks on its own');
+ assert.deepEqual(f.calls.map(call => call.name), ['social_publication_contract', 'social_publication_authorization']);
+ });
+
test(`${browser}: a background check is traced to the run that started it, and not at all once that run moved on`, async () => {
// Bound: a repair attempt is traced to the starting run even when the
// tab's run id changed while the first attempt ran.