Skip to content

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

Show the English plan when translating it meets the cost cap

Emre Sokullud30933611685
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index b2ebdf649..30c259a0a 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -26344,8 +26344,12 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
await this._tracePlannerAttemptResponse(runId, 0, provider, result, 'planner_localize', 1, startedAt, chatOptions);
return localizePlanFromContent(plan, result?.content) || canonicalPlanDisplay(plan);
} catch (error) {
- if (this._isCostAllowanceError(error) || this._checkAbort(tabId)) throw error;
- await this._tracePlannerAttemptFailure(runId, 'planner_localize', 1, error);
+ if (this._checkAbort(tabId)) throw error;
+ // The translation is optional. Any failure, a spent cost allowance
+ // included, leaves the valid plan to show in English; the next paid
+ // request still meets the allowance.
+ const costLimit = this._isCostAllowanceError(error);
+ await this._tracePlannerAttemptFailure(runId, 'planner_localize', 1, error, costLimit ? 'cost_limit' : undefined);
return canonicalPlanDisplay(plan);
}
}
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 8592800df..87c24fe31 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -23400,8 +23400,12 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
await this._tracePlannerAttemptResponse(runId, 0, provider, result, 'planner_localize', 1, startedAt, chatOptions);
return localizePlanFromContent(plan, result?.content) || canonicalPlanDisplay(plan);
} catch (error) {
- if (this._isCostAllowanceError(error) || this._checkAbort(tabId)) throw error;
- await this._tracePlannerAttemptFailure(runId, 'planner_localize', 1, error);
+ if (this._checkAbort(tabId)) throw error;
+ // The translation is optional. Any failure, a spent cost allowance
+ // included, leaves the valid plan to show in English; the next paid
+ // request still meets the allowance.
+ const costLimit = this._isCostAllowanceError(error);
+ await this._tracePlannerAttemptFailure(runId, 'planner_localize', 1, error, costLimit ? 'cost_limit' : undefined);
return canonicalPlanDisplay(plan);
}
}
diff --git a/test/plan-when-needed.mjs b/test/plan-when-needed.mjs
index 15e6fb09d..c5e5b3775 100644
--- a/test/plan-when-needed.mjs
+++ b/test/plan-when-needed.mjs
@@ -401,8 +401,9 @@ for (const build of BUILDS) {
const incomplete = JSON.stringify({ locale: 'tr', summary: 'Adresi bültene abone et.', steps: [{ id: '1', action: 'E-posta alanını doldur.' }], risks: [] });
// The planner's own partial copy is not shown either: one language, never a mix.
const partialCopy = englishPlan({ confidence: 0.5, localized: { locale: 'tr', summary: 'Bültene abone ol.', steps: [{ id: '1', action: 'Doldur.' }], risks: [] } });
+ const spent = Object.assign(new Error('Cost allowance reached.'), { code: 'WB_COST_ALLOWANCE' });
for (const plan of [englishPlan({ confidence: 0.5 }), partialCopy]) {
- for (const translation of [new Error('provider unavailable'), 'not json', incomplete]) {
+ for (const translation of [new Error('provider unavailable'), 'not json', incomplete, spent]) {
const f = displayFixture({ plan, translation });
const gate = await f.gate();
assert.equal(gate.proceed, true);