Skip to content

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

fix(agent): retain notice on response errors

Emre Sokullubd07427c0450
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index eeff1b25e..639a6bd9e 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -26369,9 +26369,13 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
quotaFailure = true;
onUpdate('quota', { quota: error.quota });
}
- status = this._isCostAllowanceError(error) ? 'cost_limit' : 'error';
- finalResponse = this._isCostAllowanceError(error)
+ const costAllowance = this._isCostAllowanceError(error);
+ const allowanceNotice = typeof error?.costAllowanceMessage === 'string' ? error.costAllowanceMessage.trim() : '';
+ status = costAllowance ? 'cost_limit' : 'error';
+ finalResponse = costAllowance
? error.message
+ : allowanceNotice
+ ? `${(recoveryDetails = modelFailureRecovery(error, { phase: 'response_generation' })).message}\n\n${allowanceNotice}`
: (recoveryDetails = modelFailureRecovery(error, { phase: 'response_generation' })).message;
}
const stopped = this._consumeContextOnlyAbort(tabId, messages, onUpdate);
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 134127e12..c27d4e71d 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -23510,9 +23510,13 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
quotaFailure = true;
onUpdate('quota', { quota: error.quota });
}
- status = this._isCostAllowanceError(error) ? 'cost_limit' : 'error';
- finalResponse = this._isCostAllowanceError(error)
+ const costAllowance = this._isCostAllowanceError(error);
+ const allowanceNotice = typeof error?.costAllowanceMessage === 'string' ? error.costAllowanceMessage.trim() : '';
+ status = costAllowance ? 'cost_limit' : 'error';
+ finalResponse = costAllowance
? error.message
+ : allowanceNotice
+ ? `${(recoveryDetails = modelFailureRecovery(error, { phase: 'response_generation' })).message}\n\n${allowanceNotice}`
: (recoveryDetails = modelFailureRecovery(error, { phase: 'response_generation' })).message;
}
const stopped = this._consumeContextOnlyAbort(tabId, messages, onUpdate);
diff --git a/test/post-submit-model-recovery.mjs b/test/post-submit-model-recovery.mjs
index ba9d7e6d4..d12e4459f 100644
--- a/test/post-submit-model-recovery.mjs
+++ b/test/post-submit-model-recovery.mjs
@@ -153,6 +153,18 @@ for (const browser of ['chrome', 'firefox']) {
}
});
+ test(`${browser}: non-limit response failures retain their allowance notice`, async () => {
+ const f = fixture(); f.agent._persist = () => {};
+ const notice = 'Cloud cost allowance reached: total cloud/router usage is $5.00 against the $5.00 limit.';
+ f.agent._generateContextOnlyResponse = async () => {
+ throw Object.assign(new Error('The provider filtered the response.'), { costAllowanceMessage: notice });
+ };
+ const answer = await f.agent._completeResponseOnlyTurn(f.tab, f.messages, f.update, {}, {}, null);
+ assert.equal(answer.status, 'error');
+ assert.match(answer.content, /cost allowance reached/i);
+ assert.equal(f.updates.some(x => x.type === 'failure_recovery'), true);
+ });
+
test(`${browser}: textless response-only cutoffs retain their allowance notice`, async () => {
const f = fixture(); f.agent._persist = () => {};
const notice = 'Cloud cost allowance reached: total cloud/router usage is $5.00 against the $5.00 limit.';