Skip to content

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

Use a plan translation only when it covers every step and risk

Emre Sokullu92620e3bda40
diff --git a/docs/architecture.md b/docs/architecture.md
index 315245fc9..6a5ea042f 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -354,7 +354,7 @@ Manual action-mode runs (Act or Dev) call the active provider once before the to
In Try, a turn that automatic mode routed to Act or Dev with a sure `plan_need: direct` answer also uses the compact intent schema (`_routedDirectTask`), and the trace records a `planner_skipped` note with `reason: 'direct_task'`. `direct` is an authorizing choice, so it needs the 0.85 threshold, and its description leaves out risky work (payments, purchases, bookings, deletion, bulk changes, credentials, messages to several people) as well as work with several goals, many items, several sites or pages, conditions, schedules or facts to carry across many steps: those answer `plan`. Strict, plan review set to Always, a steering revision, and any action turn without a sure `direct` answer, such as one in a mode the user chose, keep the full planner.
-Planner latency grows with the tokens the model writes, so both prompts ask for little. `summary`, `steps` and `risks` are English; `localized` is `null` for an English `wbLocale`, and for another locale it is required only when the user reads the plan: `clarify`, `plan_only`, and an `execute` plan shown for review, whose rule the full prompt states from the current review settings (`plannerReviewRule()`). An English `clarify` uses its summary as the question. When a plan the user reads arrives without its copy (`normalizePlan()` marks it `localized.missing`), `_localizedPlanForDisplay()` translates the display fields in one small request (trace phase `planner_localize`) before the review card or the plan-only answer is shown. Execution keeps the English plan, and if the translation fails the user sees the English text. A non-English `clarify` without its copy is still rejected and repaired like other invalid planner output. `memory: null` turns off the scratchpad and the progress ledger together, and `normalizePlan()` reads it as a declared `disabled` ledger, so no progress-classifier call follows. The compact intent check writes no steps for `execute` (its plan-only steps stay), and full-plan steps are one short sentence each.
+Planner latency grows with the tokens the model writes, so both prompts ask for little. `summary`, `steps` and `risks` are English; `localized` is `null` for an English `wbLocale`, and for another locale it is required only when the user reads the plan: `clarify`, `plan_only`, and an `execute` plan shown for review, whose rule the full prompt states from the current review settings (`plannerReviewRule()`). An English `clarify` uses its summary as the question. When a plan the user reads arrives without its copy (`normalizePlan()` marks it `localized.missing`), `_localizedPlanForDisplay()` translates the display fields in one small request (trace phase `planner_localize`) before the review card or the plan-only answer is shown. Execution keeps the English plan. A translation that fails or leaves out a step or risk is not used, so the user sees the English text rather than a mix. A non-English `clarify` without its copy is still rejected and repaired like other invalid planner output. `memory: null` turns off the scratchpad and the progress ledger together, and `normalizePlan()` reads it as a declared `disabled` ledger, so no progress-classifier call follows. The compact intent check writes no steps for `execute` (its plan-only steps stay), and full-plan steps are one short sentence each.
When the active site adapter has a validated `webbrain-adapter-workflow/2`
profile, both planner variants also receive its bounded app-owned job IDs and
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index a1f4a7e76..3d7ceadc8 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -26312,7 +26312,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// A plan the user reads (a review card, a plan-only answer) in a language
// other than English, when the planner left out its localized copy: one
// small request translates the display fields. Execution keeps the English
- // plan, and if the translation fails the user sees the English text.
+ // plan, and if the translation fails or is incomplete the user sees the
+ // English text.
async _localizedPlanForDisplay(tabId, plan, provider, costState, runId = null, runtimeMode = 'act') {
if (plan?.localized?.missing !== true || !provider?.chat) return plan;
const messages = buildPlanLocalizationMessages(plan);
diff --git a/src/chrome/src/agent/planner.js b/src/chrome/src/agent/planner.js
index 8662feb53..dcebaac42 100644
--- a/src/chrome/src/agent/planner.js
+++ b/src/chrome/src/agent/planner.js
@@ -1490,8 +1490,8 @@ export function buildPlanLocalizationMessages(plan) {
}
// The plan with the translation in `content` as its localized copy, or null
-// when `content` has no translated summary. A step or risk the translation
-// left out keeps its English text, as in normalizePlan.
+// unless `content` translates the summary, every step (matched by id) and
+// every risk: the user reads the plan in one language, never a mix.
export function localizePlanFromContent(plan, content) {
const obj = extractFirstJsonObject(content);
const summary = sanitizeText(obj?.summary, 400);
@@ -1499,13 +1499,11 @@ export function localizePlanFromContent(plan, content) {
const translatedSteps = new Map((Array.isArray(obj.steps) ? obj.steps : [])
.map(step => [sanitizeText(step?.id, 20), sanitizeText(step?.action, 300)]));
const translatedRisks = Array.isArray(obj.risks) ? obj.risks : [];
+ const steps = (plan.steps || []).map(({ id }) => ({ id, action: translatedSteps.get(id) || '' }));
+ const risks = (plan.risks || []).map((_, index) => sanitizeText(translatedRisks[index], 200));
+ if (steps.some(step => !step.action) || risks.some(risk => !risk)) return null;
return {
...plan,
- localized: {
- locale: plan.localized?.locale || normalizePlannerLocale(obj.locale),
- summary,
- steps: (plan.steps || []).map(({ id, action }) => ({ id, action: translatedSteps.get(id) || action })),
- risks: (plan.risks || []).map((risk, index) => sanitizeText(translatedRisks[index], 200) || risk),
- },
+ localized: { locale: plan.localized?.locale || normalizePlannerLocale(obj.locale), summary, steps, risks },
};
}
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index fe35b96db..eaf2780e8 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -23368,7 +23368,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// A plan the user reads (a review card, a plan-only answer) in a language
// other than English, when the planner left out its localized copy: one
// small request translates the display fields. Execution keeps the English
- // plan, and if the translation fails the user sees the English text.
+ // plan, and if the translation fails or is incomplete the user sees the
+ // English text.
async _localizedPlanForDisplay(tabId, plan, provider, costState, runId = null, runtimeMode = 'act') {
if (plan?.localized?.missing !== true || !provider?.chat) return plan;
const messages = buildPlanLocalizationMessages(plan);
diff --git a/src/firefox/src/agent/planner.js b/src/firefox/src/agent/planner.js
index 8662feb53..dcebaac42 100644
--- a/src/firefox/src/agent/planner.js
+++ b/src/firefox/src/agent/planner.js
@@ -1490,8 +1490,8 @@ export function buildPlanLocalizationMessages(plan) {
}
// The plan with the translation in `content` as its localized copy, or null
-// when `content` has no translated summary. A step or risk the translation
-// left out keeps its English text, as in normalizePlan.
+// unless `content` translates the summary, every step (matched by id) and
+// every risk: the user reads the plan in one language, never a mix.
export function localizePlanFromContent(plan, content) {
const obj = extractFirstJsonObject(content);
const summary = sanitizeText(obj?.summary, 400);
@@ -1499,13 +1499,11 @@ export function localizePlanFromContent(plan, content) {
const translatedSteps = new Map((Array.isArray(obj.steps) ? obj.steps : [])
.map(step => [sanitizeText(step?.id, 20), sanitizeText(step?.action, 300)]));
const translatedRisks = Array.isArray(obj.risks) ? obj.risks : [];
+ const steps = (plan.steps || []).map(({ id }) => ({ id, action: translatedSteps.get(id) || '' }));
+ const risks = (plan.risks || []).map((_, index) => sanitizeText(translatedRisks[index], 200));
+ if (steps.some(step => !step.action) || risks.some(risk => !risk)) return null;
return {
...plan,
- localized: {
- locale: plan.localized?.locale || normalizePlannerLocale(obj.locale),
- summary,
- steps: (plan.steps || []).map(({ id, action }) => ({ id, action: translatedSteps.get(id) || action })),
- risks: (plan.risks || []).map((risk, index) => sanitizeText(translatedRisks[index], 200) || risk),
- },
+ localized: { locale: plan.localized?.locale || normalizePlannerLocale(obj.locale), summary, steps, risks },
};
}
diff --git a/test/plan-when-needed.mjs b/test/plan-when-needed.mjs
index 06c375c62..4083ec2c5 100644
--- a/test/plan-when-needed.mjs
+++ b/test/plan-when-needed.mjs
@@ -272,9 +272,16 @@ for (const build of BUILDS) {
assert.deepEqual(translated.localized, { locale: 'tr', summary: 'Adresi abone et.',
steps: [{ id: '1', action: 'E-posta alanını doldur.' }, { id: '2', action: 'Gönder ve onayı oku.' }], risks: ['Form gönderilir.'] });
assert.deepEqual([translated.summary, translated.steps, translated.risks], [plan.summary, plan.steps, plan.risks], 'execution keeps the English plan');
- const partial = planner.localizePlanFromContent(plan, JSON.stringify({ summary: 'Adresi abone et.', steps: [{ id: '1', action: 'Doldur.' }], risks: [] }));
- assert.deepEqual(partial.localized.steps.map(step => step.action), ['Doldur.', plan.steps[1].action]);
- assert.deepEqual(partial.localized.risks, plan.risks);
+ // An incomplete translation is not used: the plan is read in one language.
+ const complete = { summary: 'Adresi abone et.', steps: [{ id: '1', action: 'Doldur.' }, { id: '2', action: 'Gönder.' }], risks: ['Form gönderilir.'] };
+ assert.ok(planner.localizePlanFromContent(plan, JSON.stringify(complete)));
+ for (const incomplete of [
+ { ...complete, steps: [{ id: '1', action: 'Doldur.' }] },
+ { ...complete, steps: [{ id: '1', action: 'Doldur.' }, { id: '3', action: 'Gönder.' }] },
+ { ...complete, steps: [{ id: '1', action: 'Doldur.' }, { id: '2', action: ' ' }] },
+ { ...complete, risks: [] },
+ { ...complete, summary: '' },
+ ]) assert.equal(planner.localizePlanFromContent(plan, JSON.stringify(incomplete)), null, JSON.stringify(incomplete));
assert.equal(planner.localizePlanFromContent(plan, '{"steps": []}'), null);
assert.equal(planner.localizePlanFromContent(plan, 'Sorry.'), null);
});
@@ -330,8 +337,9 @@ for (const build of BUILDS) {
}
});
- test(`${build}: a failed translation shows the English plan instead`, async () => {
- for (const translation of [new Error('provider unavailable'), 'not json']) {
+ test(`${build}: a failed or incomplete translation shows the English plan instead`, async () => {
+ const incomplete = JSON.stringify({ locale: 'tr', summary: 'Adresi bültene abone et.', steps: [{ id: '1', action: 'E-posta alanını doldur.' }], risks: [] });
+ for (const translation of [new Error('provider unavailable'), 'not json', incomplete]) {
const f = displayFixture({ translation });
const gate = await f.gate();
assert.equal(gate.proceed, true);