Skip to content

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

Clarify timeout: a setting that cannot be read leaves the safe answer

Barack Sokullu1bf9c14d76be
diff --git a/src/chrome/src/background.js b/src/chrome/src/background.js
index 04cfda034..d3a6c75e6 100644
--- a/src/chrome/src/background.js
+++ b/src/chrome/src/background.js
@@ -578,7 +578,15 @@ function normalizeClarifyTimeoutSec(value) {
}
async function loadClarifyTimeout() {
- const stored = await chrome.storage.local.get(['clarifyTimeoutSec', 'clarifyTimeoutSemanticsV2', 'clarifyTimeoutPolicy']);
+ let stored;
+ try {
+ stored = await chrome.storage.local.get(['clarifyTimeoutSec', 'clarifyTimeoutSemanticsV2', 'clarifyTimeoutPolicy']);
+ } catch (error) {
+ // The user's choice could not be read: until a later load succeeds, a
+ // timeout takes the safe answer rather than the finish default.
+ agent.clarifyTimeoutPolicy = 'safe';
+ throw error;
+ }
// One-shot: old 0 meant Off; new 0 means Instant and Off is >1200.
if (!stored.clarifyTimeoutSemanticsV2) {
const updates = { clarifyTimeoutSemanticsV2: true };
@@ -594,7 +602,8 @@ async function loadClarifyTimeout() {
agent.clarifyTimeoutPolicy = stored.clarifyTimeoutPolicy === 'safe' ? 'safe' : 'finish';
}
// 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.
+// not start before the user's timeout setting is loaded (or found unreadable,
+// which leaves the safe answer).
const clarifyTimeoutReady = loadClarifyTimeout().catch(() => {});
async function loadAutoScreenshot() {
diff --git a/src/firefox/src/background.js b/src/firefox/src/background.js
index 7ec63b409..1c8cda1b4 100644
--- a/src/firefox/src/background.js
+++ b/src/firefox/src/background.js
@@ -485,7 +485,15 @@ function normalizeClarifyTimeoutSec(value) {
}
async function loadClarifyTimeout() {
- const stored = await browser.storage.local.get(['clarifyTimeoutSec', 'clarifyTimeoutSemanticsV2', 'clarifyTimeoutPolicy']);
+ let stored;
+ try {
+ stored = await browser.storage.local.get(['clarifyTimeoutSec', 'clarifyTimeoutSemanticsV2', 'clarifyTimeoutPolicy']);
+ } catch (error) {
+ // The user's choice could not be read: until a later load succeeds, a
+ // timeout takes the safe answer rather than the finish default.
+ agent.clarifyTimeoutPolicy = 'safe';
+ throw error;
+ }
// One-shot: old 0 meant Off; new 0 means Instant and Off is >1200.
if (!stored.clarifyTimeoutSemanticsV2) {
const updates = { clarifyTimeoutSemanticsV2: true };
@@ -501,7 +509,8 @@ async function loadClarifyTimeout() {
agent.clarifyTimeoutPolicy = stored.clarifyTimeoutPolicy === 'safe' ? 'safe' : 'finish';
}
// 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.
+// not start before the user's timeout setting is loaded (or found unreadable,
+// which leaves the safe answer).
const clarifyTimeoutReady = loadClarifyTimeout().catch(() => {});
async function loadAutoScreenshot() {
diff --git a/test/clarify-timeout-policy.mjs b/test/clarify-timeout-policy.mjs
index ec6cdab57..a610e401a 100644
--- a/test/clarify-timeout-policy.mjs
+++ b/test/clarify-timeout-policy.mjs
@@ -321,6 +321,32 @@ for (const { build, Agent, policy, Capability } of builds) {
assert.match(tools, /Classify every question\. "none" when answering approves nothing below/);
assert.match(tools, /set consequence on every question/i);
});
+
+ test(`${build}: a timeout setting that cannot be read leaves the safe answer`, async () => {
+ const background = await read(`src/${build}/src/background.js`);
+ const start = background.indexOf('async function loadClarifyTimeout()');
+ assert.ok(start >= 0, 'loadClarifyTimeout is in background.js');
+ const source = background.slice(start, background.indexOf('\n}\n', start) + 2);
+ const api = build === 'chrome' ? 'chrome' : 'browser';
+ const load = get => {
+ const agent = { clarifyTimeoutPolicy: 'finish', clarifyTimeoutSec: 60 };
+ const storage = { local: { get, set: async () => {} } };
+ const run = new Function(api, 'agent', 'normalizeClarifyTimeoutSec', 'CLARIFY_TIMEOUT_OFF_SLIDER',
+ `${source}\nreturn loadClarifyTimeout();`);
+ return { agent, done: run({ storage }, agent, value => Number(value), 1201) };
+ };
+ const unreadable = load(async () => { throw new Error('storage unavailable'); });
+ await assert.rejects(unreadable.done, /storage unavailable/, 'callers still see the failure');
+ assert.equal(unreadable.agent.clarifyTimeoutPolicy, 'safe', 'an unreadable setting fails closed, not to finish');
+ for (const policyName of ['finish', 'safe']) {
+ const stored = load(async () => ({ clarifyTimeoutPolicy: policyName, clarifyTimeoutSemanticsV2: true }));
+ await stored.done;
+ assert.equal(stored.agent.clarifyTimeoutPolicy, policyName);
+ }
+ const unset = load(async () => ({ clarifyTimeoutSemanticsV2: true }));
+ await unset.done;
+ assert.equal(unset.agent.clarifyTimeoutPolicy, 'finish', 'no stored choice keeps the default');
+ });
}
let browser;