Skip to content

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

Clarify timeout: load the timeout setting before a run can start

Barack Sokullu531263d2fc1f
diff --git a/src/chrome/src/background.js b/src/chrome/src/background.js
index d9fb48fd4..04cfda034 100644
--- a/src/chrome/src/background.js
+++ b/src/chrome/src/background.js
@@ -291,6 +291,7 @@ const scheduler = new ScheduledJobManager({
systemOneJudge: createSystemOneJudge(),
loadProviders: async () => {
await customSkillsReady;
+ await clarifyTimeoutReady;
await alwaysAllowApiMutationsReady;
await strictSecretModeReady;
await imageGenConfigReady;
@@ -592,7 +593,9 @@ async function loadClarifyTimeout() {
);
agent.clarifyTimeoutPolicy = stored.clarifyTimeoutPolicy === 'safe' ? 'safe' : 'finish';
}
-loadClarifyTimeout();
+// A question's timeout answer is decided when it is asked, so a run must
+// not start before the user's timeout setting is loaded.
+const clarifyTimeoutReady = loadClarifyTimeout().catch(() => {});
async function loadAutoScreenshot() {
const stored = await chrome.storage.local.get('autoScreenshot');
@@ -3297,7 +3300,7 @@ async function handleMessage(msg, sender) {
// Agent toggles and prompt add-ons hydrate once at SW boot — await those
// promises so the first chat can't race ahead of hydration, without a
// storage round-trip on every message.
- await Promise.all([planBeforeActReady, planReviewReady, customSkillsReady, userMemoryReady, imageGenConfigReady, browserBatchEnabledReady]);
+ await Promise.all([planBeforeActReady, planReviewReady, customSkillsReady, userMemoryReady, imageGenConfigReady, browserBatchEnabledReady, clarifyTimeoutReady]);
await alwaysAllowApiMutationsReady;
await strictSecretModeReady;
await webMcpEnabledReady;
diff --git a/src/firefox/src/background.js b/src/firefox/src/background.js
index 1938c3f74..7ec63b409 100644
--- a/src/firefox/src/background.js
+++ b/src/firefox/src/background.js
@@ -219,6 +219,7 @@ const scheduler = new ScheduledJobManager({
systemOneJudge: createSystemOneJudge(),
loadProviders: async () => {
await customSkillsReady;
+ await clarifyTimeoutReady;
await alwaysAllowApiMutationsReady;
await strictSecretModeReady;
await imageGenConfigReady;
@@ -499,7 +500,9 @@ async function loadClarifyTimeout() {
);
agent.clarifyTimeoutPolicy = stored.clarifyTimeoutPolicy === 'safe' ? 'safe' : 'finish';
}
-loadClarifyTimeout();
+// A question's timeout answer is decided when it is asked, so a run must
+// not start before the user's timeout setting is loaded.
+const clarifyTimeoutReady = loadClarifyTimeout().catch(() => {});
async function loadAutoScreenshot() {
const stored = await browser.storage.local.get('autoScreenshot');
@@ -2913,7 +2916,7 @@ async function handleMessage(msg, sender) {
}
// Hydrate agent toggles and prompt add-ons once at boot (not per message);
// onChanged keeps them in sync afterward.
- await Promise.all([planBeforeActReady, planReviewReady, customSkillsReady, userMemoryReady, imageGenConfigReady, browserBatchEnabledReady]);
+ await Promise.all([planBeforeActReady, planReviewReady, customSkillsReady, userMemoryReady, imageGenConfigReady, browserBatchEnabledReady, clarifyTimeoutReady]);
await alwaysAllowApiMutationsReady;
await strictSecretModeReady;
await screenshotRedactionReady;
diff --git a/test/clarify-timeout-policy.mjs b/test/clarify-timeout-policy.mjs
index 1c96a83ed..4b4987d7a 100644
--- a/test/clarify-timeout-policy.mjs
+++ b/test/clarify-timeout-policy.mjs
@@ -273,6 +273,11 @@ for (const { build, Agent, policy, Capability } of builds) {
assert.match(settings, /clarifyTimeoutPolicySelect\.value = stored\.clarifyTimeoutPolicy === 'safe' \? 'safe' : 'finish'/);
assert.match(background, /agent\.clarifyTimeoutPolicy = stored\.clarifyTimeoutPolicy === 'safe' \? 'safe' : 'finish'/);
assert.match(background, /if \(changes\.clarifyTimeoutPolicy\) \{\s*agent\.clarifyTimeoutPolicy = changes\.clarifyTimeoutPolicy\.newValue === 'safe' \? 'safe' : 'finish';/);
+ // A cold service worker must not start a run (side panel or schedule)
+ // before the setting is loaded: the timeout answer is fixed when asked.
+ assert.match(background, /const clarifyTimeoutReady = loadClarifyTimeout\(\)\.catch\(\(\) => \{\}\);/);
+ assert.match(background, /await Promise\.all\(\[planBeforeActReady,[^\]]*\bclarifyTimeoutReady\]\);/);
+ assert.match(background, /loadProviders: async \(\) => \{[^}]*await clarifyTimeoutReady;/);
assert.equal(config.DEFAULT_CONFIG_SETTINGS.clarifyTimeoutPolicy, 'finish');
assert.ok(config.CONFIG_STORAGE_KEYS.includes('clarifyTimeoutPolicy'));
assert.match(panel, /data\.timeoutAnswer/);